From owner-p4-projects@FreeBSD.ORG Fri Jul 6 21:05:32 2012 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 0489B106566C; Fri, 6 Jul 2012 21:05:30 +0000 (UTC) Delivered-To: perforce@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id B12CE106564A for ; Fri, 6 Jul 2012 21:05:30 +0000 (UTC) (envelope-from brooks@freebsd.org) Received: from skunkworks.freebsd.org (skunkworks.freebsd.org [IPv6:2001:4f8:fff6::2d]) by mx1.freebsd.org (Postfix) with ESMTP id 990118FC08 for ; Fri, 6 Jul 2012 21:05:30 +0000 (UTC) Received: from skunkworks.freebsd.org (localhost [127.0.0.1]) by skunkworks.freebsd.org (8.14.4/8.14.4) with ESMTP id q66L5Ubt079553 for ; Fri, 6 Jul 2012 21:05:30 GMT (envelope-from brooks@freebsd.org) Received: (from perforce@localhost) by skunkworks.freebsd.org (8.14.4/8.14.4/Submit) id q66L5UF8079550 for perforce@freebsd.org; Fri, 6 Jul 2012 21:05:30 GMT (envelope-from brooks@freebsd.org) Date: Fri, 6 Jul 2012 21:05:30 GMT Message-Id: <201207062105.q66L5UF8079550@skunkworks.freebsd.org> X-Authentication-Warning: skunkworks.freebsd.org: perforce set sender to brooks@freebsd.org using -f From: Brooks Davis To: Perforce Change Reviews Precedence: bulk Cc: Subject: PERFORCE change 213995 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 06 Jul 2012 21:05:32 -0000 http://p4web.freebsd.org/@@213995?ac=10 Change 213995 by brooks@brooks_ecr_current on 2012/07/06 21:04:54 Add more complete icon support. Icons obtained from the Public Domain section of the Open Icon Library http://openiconlibrary.sourceforge.net/ with exception of the ? which is simply Helvetica Bold. Affected files ... .. //depot/projects/ctsrd/beribsd/src/ctsrd/browser/browser.c#3 edit .. //depot/projects/ctsrd/beribsd/src/ctsrd/browser/images/icons.png#1 add Differences ... ==== //depot/projects/ctsrd/beribsd/src/ctsrd/browser/browser.c#3 (text+ko) ==== @@ -40,6 +40,7 @@ #include #include #include +#include #include #include #include @@ -50,6 +51,7 @@ #include #define BASEIMG "/usr/share/images/browser.png" +#define ICONS "/usr/share/images/icons.png" #define vwhite(v) fb_colour((v), (v), (v)) #define vred(v) fb_colour((v), 0, 0) @@ -104,6 +106,39 @@ /* Start offsets for browser columns */ const int colstart[] = {0, 267, 534}; +/* + * List of mappings between icons in the icons.png file and values from + * the get_desc() function. Processing is first match so most specific + * entries should come first. + */ +struct _iconmap { + int i_offset; + const char *i_type; +} iconmap[] = { + { 0, "prev" }, + { 1, "next" }, + { 2, "special/character" }, + { 2, "special/block" }, + { 3, "unopenable" }, + { 4, "important" }, + { 5, "devil" }, + { 6, "application/x-executable" }, + { 6, "application/x-sharedlib" }, + { 9, "text/html" }, + { 11, "text/x-shellscript" }, + { 13, "badmagic" }, + { 14, "directory" }, + { 15, "application/x-dbm" }, + + { 7, "audio/*" }, + { 8, "image/*" }, + { 10, "text/*" }, + { 12, "video/*" }, + + { 16, "*" }, + { 0, NULL } +}; + enum _sbtype { SB_NONE = 1, SB_CAPSICUM, @@ -122,6 +157,7 @@ }; static u_int32_t *bgimage; +static u_int32_t *icons; static magic_t magic; static void @@ -200,6 +236,19 @@ } static const char * +get_magic(int fd) +{ + switch (sbtype) { + case SB_NONE: + return magic_descriptor(magic, fd); + case SB_CAPSICUM: + return "devil"; + case SB_CHERI: + return "devil"; + } +} + +static const char * get_desc(int dfd, struct dirent *entry) { int fd, type; @@ -220,9 +269,9 @@ break; case DT_REG: if ((fd = openat(dfd, entry->d_name, O_RDONLY)) == -1) - desc = "unknown"; + desc = "unopenable"; else { - desc = magic_descriptor(magic, fd); + desc = get_magic(fd); close(fd); } break; @@ -251,26 +300,34 @@ return (desc); } +static u_int32_t * +get_icon(const char *desc) +{ + struct _iconmap *icon; + + for (icon = iconmap; icon->i_type != NULL; icon++) + if (fnmatch(icon->i_type, desc, 0) != FNM_NOMATCH) + return (icons + (ICON_WH * ICON_WH * icon->i_offset)); + + return (NULL); +} + static int browsedir(int dfd) { - int f, i, j, s, nlines; + int f, i, j, s; long curloc, nextloc; DIR *dirp; struct dirent *entry, *entry2; - u_int32_t iconbuf[ICON_WH*ICON_WH], textbuf[TEXTSPACE*CHAR_HEIGHT]; + u_int32_t *icon, textbuf[TEXTSPACE*CHAR_HEIGHT]; char line[256]; + const char *desc; if ((dirp = fdopendir(dfd)) == NULL) err(1, "fdopendir()"); - for (i = 0; i < 32*32; i++) - iconbuf[i] = blue; - - fb_fill_region(black, colstart[0], FROW, - colstart[NCOL-1] - colstart[0], NROW * RHEIGHT); + fb_fill_region(black, colstart[0], FROW, fb_width, NROW * RHEIGHT); - nlines = NSLOTS - 1; curloc = telldir(dirp); nextloc = 0; i = 0; @@ -287,19 +344,22 @@ fb_post_region(textbuf, colstart[(s/NROW)] + TEXT_OFFSET, FROW + (RHEIGHT * (s % NROW)) + BORDER, TEXTSPACE, CHAR_HEIGHT); - fb_post_region(iconbuf, colstart[(s/NROW)] + BORDER, + icon = get_icon("prev"); + fb_post_region(icon, colstart[(s/NROW)] + BORDER, FROW + (RHEIGHT * (s % NROW)) + BORDER, ICON_WH, ICON_WH); s = 1; } entry = NULL; /* XXX: gcc warning */ while(s < NSLOTS - 1 && (entry = readdir(dirp)) != NULL) { - printf("%2d %20s %s\n", s, entry->d_name, get_desc(dfd, entry)); + desc = get_desc(dfd, entry); + printf("%2d %20s %s\n", s, entry->d_name, desc); memset(textbuf, 0, sizeof(textbuf)); fb_render_text(entry->d_name, 2, white, black, textbuf, TEXTSPACE, CHAR_HEIGHT); fb_post_region(textbuf, colstart[(s/NROW)]+TEXT_OFFSET, FROW + (RHEIGHT * (s % NROW)) + BORDER, TEXTSPACE, CHAR_HEIGHT); - fb_post_region(iconbuf, colstart[(s/NROW)] + BORDER, + icon = get_icon(desc); + fb_post_region(icon, colstart[(s/NROW)] + BORDER, FROW + (RHEIGHT * (s % NROW)) + BORDER, ICON_WH, ICON_WH); s++; } @@ -317,9 +377,9 @@ else { entry2 = readdir(dirp); if (entry2 == NULL) { + desc = get_desc(dfd, entry); printf("%2d %20s %s\n", s, - entry->d_name, - get_desc(dfd, entry)); + entry->d_name, desc); memset(textbuf, 0, sizeof(textbuf)); fb_render_text(entry->d_name, 2, white, black, textbuf, TEXTSPACE, CHAR_HEIGHT); @@ -327,7 +387,8 @@ colstart[(s/NROW)]+TEXT_OFFSET, FROW + (RHEIGHT * (s % NROW)) + BORDER, TEXTSPACE, CHAR_HEIGHT); - fb_post_region(iconbuf, + icon = get_icon(desc); + fb_post_region(icon, colstart[(s/NROW)] + BORDER, FROW + (RHEIGHT * (s % NROW)) + BORDER, ICON_WH, ICON_WH); @@ -341,7 +402,8 @@ colstart[(s/NROW)]+TEXT_OFFSET, FROW + (RHEIGHT * (s % NROW)) + BORDER, TEXTSPACE, CHAR_HEIGHT); - fb_post_region(iconbuf, + icon = get_icon("next"); + fb_post_region(icon, colstart[(s/NROW)] + BORDER, FROW + (RHEIGHT * (s % NROW)) + BORDER, ICON_WH, ICON_WH); @@ -380,7 +442,7 @@ goto prompt; } f = atoi(line); - if (f < 0 || f >= nlines) { + if (f < 0 || f >= NSLOTS - 1) { printf("invalid file %s\n", line); goto prompt; } @@ -443,13 +505,16 @@ bgimage = malloc(sizeof(u_int32_t) * fb_height * fb_width); if (bgimage == NULL) err(1, "malloc"); + read_png_file(BASEIMG, bgimage, fb_width, fb_height); - read_png_file(BASEIMG, bgimage, fb_width, fb_height); - syslog(LOG_ALERT, "tty set up"); + icons = malloc(sizeof(u_int32_t) * ICON_WH * 640); + if (icons == NULL) + err(1, "malloc"); + read_png_file(ICONS, icons, 32, 640); fb_post(bgimage); - //fb_fade2on(); - fb_fade2text(127); + fb_fade2on(); + //fb_fade2text(127); fb_text_cursor(255, 255); update_sandbox(SB_NONE);