Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 6 Jul 2012 21:05:30 GMT
From:      Brooks Davis <brooks@FreeBSD.org>
To:        Perforce Change Reviews <perforce@freebsd.org>
Subject:   PERFORCE change 213995 for review
Message-ID:  <201207062105.q66L5UF8079550@skunkworks.freebsd.org>

next in thread | raw e-mail | index | archive | help
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 <err.h>
 #include <errno.h>
 #include <fcntl.h>
+#include <fnmatch.h>
 #include <libutil.h>
 #include <magic.h>
 #include <stdio.h>
@@ -50,6 +51,7 @@
 #include <unistd.h>
 
 #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);



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201207062105.q66L5UF8079550>