svn commit: r267298 - head/tools/tools/vt/fontcvt

Ed Maste emaste at FreeBSD.org
Mon Jun 9 20:49:13 UTC 2014


Author: emaste
Date: Mon Jun  9 20:49:13 2014
New Revision: 267298
URL: http://svnweb.freebsd.org/changeset/base/267298

Log:
  vt fontcvt: Hide stats by default and improve error handling
  
  The font stats are interesting, but rather verbose.

Modified:
  head/tools/tools/vt/fontcvt/fontcvt.c

Modified: head/tools/tools/vt/fontcvt/fontcvt.c
==============================================================================
--- head/tools/tools/vt/fontcvt/fontcvt.c	Mon Jun  9 20:48:38 2014	(r267297)
+++ head/tools/tools/vt/fontcvt/fontcvt.c	Mon Jun  9 20:49:13 2014	(r267298)
@@ -88,8 +88,8 @@ static void
 usage(void)
 {
 
-	fprintf(stderr,
-"usage: fontcvt [-w width] [-h height] normal.bdf [bold.bdf] out.fnt\n");
+	errx(1,
+"usage: fontcvt [-w width] [-h height] [-v] normal.bdf [bold.bdf] out.fnt\n");
 	exit(1);
 }
 
@@ -137,7 +137,7 @@ add_mapping(struct glyph *gl, unsigned i
 	ml = &maps[map_idx];
 	if (TAILQ_LAST(ml, mapping_list) != NULL &&
 	    TAILQ_LAST(ml, mapping_list)->m_char >= c) {
-		fprintf(stderr, "Bad ordering at character %u\n", c);
+		errx(1, "Bad ordering at character %u\n", c);
 		return (1);
 	}
 	TAILQ_INSERT_TAIL(ml, mp, m_list);
@@ -210,8 +210,8 @@ parse_bitmap_line(uint8_t *left, uint8_t
 	unsigned int i, subline;
 
 	if (dwidth != width && dwidth != width * 2) {
-		fprintf(stderr,
-		    "Unsupported width %u!\n", dwidth);
+		errx(1,
+		    "Bitmap with unsupported width %u!\n", dwidth);
 		return (1);
 	}
 
@@ -230,7 +230,7 @@ parse_bitmap_line(uint8_t *left, uint8_t
 			*p++ = subline >> 8;
 			*p = subline;
 		} else {
-			fprintf(stderr,
+			errx(1,
 			    "Unsupported wbytes %u!\n", wbytes);
 			return (1);
 		}
@@ -264,7 +264,7 @@ parse_bdf(FILE *fp, unsigned int map_idx
 		    (ln[6] == ' ' || ln[6] == '\0')) {
 			for (i = 0; i < height; i++) {
 				if ((ln = fgetln(fp, &length)) == NULL) {
-					fprintf(stderr, "Unexpected EOF!\n");
+					errx(1, "Unexpected EOF!\n");
 					return (1);
 				}
 				ln[length - 1] = '\0';
@@ -450,10 +450,47 @@ write_fnt(const char *filename)
 	return (0);
 }
 
+static void
+print_font_info(void)
+{
+	printf(
+"Statistics:\n"
+"- glyph_total:                 %5u\n"
+"- glyph_normal:                %5u\n"
+"- glyph_normal_right:          %5u\n"
+"- glyph_bold:                  %5u\n"
+"- glyph_bold_right:            %5u\n"
+"- glyph_unique:                %5u\n"
+"- glyph_dupe:                  %5u\n"
+"- mapping_total:               %5u\n"
+"- mapping_normal:              %5u\n"
+"- mapping_normal_folded:       %5u\n"
+"- mapping_normal_right:        %5u\n"
+"- mapping_normal_right_folded: %5u\n"
+"- mapping_bold:                %5u\n"
+"- mapping_bold_folded:         %5u\n"
+"- mapping_bold_right:          %5u\n"
+"- mapping_bold_right_folded:   %5u\n"
+"- mapping_unique:              %5u\n"
+"- mapping_dupe:                %5u\n",
+	    glyph_total,
+	    glyph_count[0],
+	    glyph_count[1],
+	    glyph_count[2],
+	    glyph_count[3],
+	    glyph_unique, glyph_dupe,
+	    mapping_total,
+	    map_count[0], map_folded_count[0],
+	    map_count[1], map_folded_count[1],
+	    map_count[2], map_folded_count[2],
+	    map_count[3], map_folded_count[3],
+	    mapping_unique, mapping_dupe);
+}
+
 int
 main(int argc, char *argv[])
 {
-	int ch;
+	int ch, val, verbose = 0;
 
 	assert(sizeof(struct file_header) == 32);
 	assert(sizeof(struct file_mapping) == 8);
@@ -461,10 +498,23 @@ main(int argc, char *argv[])
 	while ((ch = getopt(argc, argv, "h:w:")) != -1) {
 		switch (ch) {
 		case 'h':
-			height = atoi(optarg);
+			val = atoi(optarg);
+			if (val <= 0 || val > 128) {
+				errx(1, "Invalid height %d", val);
+				return (1);
+			}
+			height = val;
+			break;
+		case 'v':
+			verbose = 1;
 			break;
 		case 'w':
-			width = atoi(optarg);
+			val = atoi(optarg);
+			if (val <= 0 || val > 128) {
+				errx(1, "Invalid width %d", val);
+				return (1);
+			}
+			width = val;
 			break;
 		case '?':
 		default:
@@ -496,39 +546,9 @@ main(int argc, char *argv[])
 	fold_mappings(3);
 	if (write_fnt(argv[0]) != 0)
 		return (1);
-	
-	printf(
-"Statistics:\n"
-"- glyph_total:                 %5u\n"
-"- glyph_normal:                %5u\n"
-"- glyph_normal_right:          %5u\n"
-"- glyph_bold:                  %5u\n"
-"- glyph_bold_right:            %5u\n"
-"- glyph_unique:                %5u\n"
-"- glyph_dupe:                  %5u\n"
-"- mapping_total:               %5u\n"
-"- mapping_normal:              %5u\n"
-"- mapping_normal_folded:       %5u\n"
-"- mapping_normal_right:        %5u\n"
-"- mapping_normal_right_folded: %5u\n"
-"- mapping_bold:                %5u\n"
-"- mapping_bold_folded:         %5u\n"
-"- mapping_bold_right:          %5u\n"
-"- mapping_bold_right_folded:   %5u\n"
-"- mapping_unique:              %5u\n"
-"- mapping_dupe:                %5u\n",
-	    glyph_total,
-	    glyph_count[0],
-	    glyph_count[1],
-	    glyph_count[2],
-	    glyph_count[3],
-	    glyph_unique, glyph_dupe,
-	    mapping_total,
-	    map_count[0], map_folded_count[0],
-	    map_count[1], map_folded_count[1],
-	    map_count[2], map_folded_count[2],
-	    map_count[3], map_folded_count[3],
-	    mapping_unique, mapping_dupe);
-	
+
+	if (verbose)
+		print_font_info();
+
 	return (0);
 }


More information about the svn-src-head mailing list