Index: usr.bin/vtfontcvt/vtfontcvt.c =================================================================== --- usr.bin/vtfontcvt/vtfontcvt.c +++ usr.bin/vtfontcvt/vtfontcvt.c @@ -31,21 +31,21 @@ __FBSDID("$FreeBSD$"); #include -#include -#include #include -#include +#include +#include #include +#include #include #include +#include +#include #include #include #include -#include #include #include -#include #define VFNT_MAXGLYPHS 131072 #define VFNT_MAXDIMENSION 128 @@ -53,13 +53,13 @@ static unsigned int width = 8, wbytes, height = 16; struct glyph { - TAILQ_ENTRY(glyph) g_list; - SLIST_ENTRY(glyph) g_hash; - uint8_t *g_data; - unsigned int g_index; + TAILQ_ENTRY(glyph) g_list; + SLIST_ENTRY(glyph) g_hash; + uint8_t *g_data; + unsigned int g_index; }; -#define FONTCVT_NHASH 4096 +#define FONTCVT_NHASH 4096 TAILQ_HEAD(glyph_list, glyph); static SLIST_HEAD(, glyph) glyph_hash[FONTCVT_NHASH]; static struct glyph_list glyphs[VFNT_MAPS] = { @@ -71,10 +71,10 @@ static unsigned int glyph_total, glyph_count[4], glyph_unique, glyph_dupe; struct mapping { - TAILQ_ENTRY(mapping) m_list; - unsigned int m_char; - unsigned int m_length; - struct glyph *m_glyph; + TAILQ_ENTRY(mapping) m_list; + unsigned int m_char; + unsigned int m_length; + struct glyph *m_glyph; }; TAILQ_HEAD(mapping_list, mapping); @@ -88,9 +88,9 @@ mapping_unique, mapping_dupe; enum output_format { - VT_FONT, /* default */ - VT_C_SOURCE, /* C source for built in fonts */ - VT_C_COMPRESSED /* C source with compressed font data */ + VT_FONT, /* default */ + VT_C_SOURCE, /* C source for built in fonts */ + VT_C_COMPRESSED /* C source with compressed font data */ }; struct whitelist { @@ -103,15 +103,15 @@ * ascii set and box drawing chars. */ static struct whitelist c_list[] = { - { .c = 0, .len = 0 }, /* deault char */ + { .c = 0, .len = 0 }, /* deault char */ { .c = 0x20, .len = 0x5f }, - { .c = 0x2500, .len = 0 }, /* single frame */ + { .c = 0x2500, .len = 0 }, /* single frame */ { .c = 0x2502, .len = 0 }, { .c = 0x250c, .len = 0 }, { .c = 0x2510, .len = 0 }, { .c = 0x2514, .len = 0 }, { .c = 0x2518, .len = 0 }, - { .c = 0x2550, .len = 1 }, /* double frame */ + { .c = 0x2550, .len = 1 }, /* double frame */ { .c = 0x2554, .len = 0 }, { .c = 0x2557, .len = 0 }, { .c = 0x255a, .len = 0 }, @@ -123,11 +123,11 @@ * can program font into the vga card. */ static struct whitelist s_list[] = { - { .c = 0, .len = 0 }, /* deault char */ - { .c = 0x20, .len = 0x5f }, /* ascii set */ - { .c = 0xA0, .len = 0x5f }, /* latin 1 */ + { .c = 0, .len = 0 }, /* deault char */ + { .c = 0x20, .len = 0x5f }, /* ascii set */ + { .c = 0xA0, .len = 0x5f }, /* latin 1 */ { .c = 0x0192, .len = 0 }, - { .c = 0x0332, .len = 0 }, /* composing lower line */ + { .c = 0x0332, .len = 0 }, /* composing lower line */ { .c = 0x0393, .len = 0 }, { .c = 0x0398, .len = 0 }, { .c = 0x03A3, .len = 0 }, @@ -180,7 +180,8 @@ usage(void) { - (void)fprintf(stderr, "usage: vtfontcvt " + (void)fprintf(stderr, + "usage: vtfontcvt " "[-n] [-f font|source|compressed-source] [-w width] " "[-h height]\n\t[-v] normal.bdf [bold.bdf] out.fnt\n"); exit(1); @@ -216,7 +217,7 @@ TAILQ_INSERT_TAIL(ml, mp, m_list); } else { /* Find insertion point for char; cannot be at end. */ - TAILQ_FOREACH(mp_temp, ml, m_list) { + TAILQ_FOREACH (mp_temp, ml, m_list) { if (mp_temp->m_char >= c) { TAILQ_INSERT_BEFORE(mp_temp, mp, m_list); break; @@ -238,7 +239,7 @@ assert(map_idx == VFNT_MAP_BOLD || map_idx == VFNT_MAP_BOLD_RIGHT); mp_normal = TAILQ_FIRST(&maps[normal_map_idx]); - TAILQ_FOREACH_SAFE(mp_bold, &maps[map_idx], m_list, mp_temp) { + TAILQ_FOREACH_SAFE (mp_bold, &maps[map_idx], m_list, mp_temp) { while (mp_normal->m_char < mp_bold->m_char) mp_normal = TAILQ_NEXT(mp_normal, m_list); if (mp_bold->m_char != mp_normal->m_char) @@ -266,7 +267,7 @@ /* Return existing glyph if we have an identical one. */ hash = fnv_32_buf(bytes, wbytes * height, FNV1_32_INIT) % FONTCVT_NHASH; - SLIST_FOREACH(gl, &glyph_hash[hash], g_hash) { + SLIST_FOREACH (gl, &glyph_hash[hash], g_hash) { if (memcmp(gl->g_data, bytes, wbytes * height) == 0) { glyph_dupe++; return (gl); @@ -300,11 +301,11 @@ if (format == VT_C_SOURCE) { w = s_list; - n = sizeof (s_list) / sizeof (s_list[0]); + n = sizeof(s_list) / sizeof(s_list[0]); } if (format == VT_C_COMPRESSED) { w = c_list; - n = sizeof (c_list) / sizeof (c_list[0]); + n = sizeof(c_list) / sizeof(c_list[0]); } if (w == NULL) return (true); @@ -405,8 +406,8 @@ size_t length; uint8_t *line, *bytes, *bytes_r; unsigned int curchar = 0, i, j, linenum = 0, bbwbytes; - int bbw, bbh, bbox, bboy; /* Glyph bounding box. */ - int fbbw = 0, fbbh, fbbox, fbboy; /* Font bounding box. */ + int bbw, bbh, bbox, bboy; /* Glyph bounding box. */ + int fbbw = 0, fbbh, fbbox, fbboy; /* Font bounding box. */ int dwidth = 0, dwy = 0; int rv = -1; char spc = '\0'; @@ -432,7 +433,7 @@ } } else if (strncmp(ln, "FONTBOUNDINGBOX ", 16) == 0) { if (sscanf(ln + 16, "%d %d %d %d", &fbbw, &fbbh, &fbbox, - &fbboy) != 4) + &fbboy) != 4) errx(1, "invalid FONTBOUNDINGBOX at line %u", linenum); set_width(fbbw); @@ -454,7 +455,8 @@ if (sscanf(ln + 7, "%d %d", &dwidth, &dwy) != 2) errx(1, "invalid DWIDTH at line %u", linenum); if (dwy != 0 || (dwidth != fbbw && dwidth * 2 != fbbw)) - errx(1, "bitmap with unsupported DWIDTH %d %d at line %u", + errx(1, + "bitmap with unsupported DWIDTH %d %d at line %u", dwidth, dwy, linenum); if (dwidth < fbbw) set_width(dwidth); @@ -479,12 +481,13 @@ dwidth = atoi(ln + 7); } else if (strncmp(ln, "BBX ", 4) == 0) { if (sscanf(ln + 4, "%d %d %d %d", &bbw, &bbh, &bbox, - &bboy) != 4) + &bboy) != 4) errx(1, "invalid BBX at line %u", linenum); if (bbw < 1 || bbh < 1 || bbw > fbbw || bbh > fbbh || bbox < fbbox || bboy < fbboy || bbh + bboy > fbbh + fbboy) - errx(1, "broken bitmap with BBX %d %d %d %d at line %u", + errx(1, + "broken bitmap with BBX %d %d %d %d at line %u", bbw, bbh, bbox, bboy, linenum); bbwbytes = howmany(bbw, 8); } else if (strncmp(ln, "BITMAP", 6) == 0 && @@ -502,7 +505,7 @@ * is ignored. */ for (i = (fbbh + fbboy) - (bbh + bboy); - i < (unsigned int)((fbbh + fbboy) - bboy); i++) { + i < (unsigned int)((fbbh + fbboy) - bboy); i++) { if ((ln = fgetln(fp, &length)) == NULL) errx(1, "unexpected EOF"); linenum++; @@ -523,7 +526,7 @@ rshift_row(line, wbytes * 2, bbox - fbbox); rv = split_row(bytes + i * wbytes, - bytes_r + i * wbytes, line, dwidth); + bytes_r + i * wbytes, line, dwidth); if (rv != 0) goto out; } @@ -560,11 +563,13 @@ if (strncmp(ln, "# Height: ", 10) == 0) { if (bytes != NULL) - errx(1, "malformed input: Height tag after font data"); + errx(1, + "malformed input: Height tag after font data"); set_height(atoi(ln + 10)); } else if (strncmp(ln, "# Width: ", 9) == 0) { if (bytes != NULL) - errx(1, "malformed input: Width tag after font data"); + errx(1, + "malformed input: Width tag after font data"); set_width(atoi(ln + 9)); } else if (sscanf(ln, "%6x:", &curchar)) { if (bytes == NULL) { @@ -643,7 +648,7 @@ unsigned int i, idx = 0; for (i = 0; i < VFNT_MAPS; i++) - TAILQ_FOREACH(gl, &glyphs[i], g_list) + TAILQ_FOREACH (gl, &glyphs[i], g_list) gl->g_index = idx++; } @@ -671,13 +676,13 @@ /* Write to buffer */ static size_t -write_glyph_buf(const void *ptr, size_t size, size_t nitems, - FILE *stream __unused) +write_glyph_buf( + const void *ptr, size_t size, size_t nitems, FILE *stream __unused) { static size_t index = 0; size *= nitems; - (void) memmove(uncompressed + index, ptr, size); + (void)memmove(uncompressed + index, ptr, size); index += size; return (nitems); @@ -690,7 +695,7 @@ unsigned int i; for (i = 0; i < VFNT_MAPS; i++) { - TAILQ_FOREACH(gl, &glyphs[i], g_list) + TAILQ_FOREACH (gl, &glyphs[i], g_list) if (cb(gl->g_data, wbytes * height, 1, fp) != 1) return (1); } @@ -723,7 +728,7 @@ vfnt_map_t fm; unsigned int i = 0, j = 0; - TAILQ_FOREACH(mp, ml, m_list) { + TAILQ_FOREACH (mp, ml, m_list) { j++; if (mp->m_length > 0) { i += mp->m_length; @@ -745,13 +750,13 @@ struct mapping *mp; unsigned int i = 0, j = 0; - TAILQ_FOREACH(mp, ml, m_list) { + TAILQ_FOREACH (mp, ml, m_list) { j++; if (mp->m_length > 0) { i += mp->m_length; if (fprintf(fp, "\t{ 0x%08x, 0x%04x, 0x%04x },\n", - mp->m_char, mp->m_glyph->g_index, - mp->m_length - 1) < 0) + mp->m_char, mp->m_glyph->g_index, + mp->m_length - 1) < 0) return (1); } } @@ -819,8 +824,8 @@ uncompressed = xmalloc(uncompressed_size); compressed = xmalloc(uncompressed_size); } - if (fprintf(fp, "/* Generated %ux%u console font source. */\n\n", - width, height) < 0) + if (fprintf(fp, "/* Generated %ux%u console font source. */\n\n", width, + height) < 0) goto done; if (fprintf(fp, "#include \n") < 0) goto done; @@ -830,8 +835,8 @@ goto done; /* Write font bytes. */ - if (fprintf(fp, "static uint8_t FONTDATA_%ux%u[] = {\n", - width, height) < 0) + if (fprintf( + fp, "static uint8_t FONTDATA_%ux%u[] = {\n", width, height) < 0) goto done; if (lz4 == true) { if (write_glyphs(fp, &write_glyph_buf) != 0) @@ -847,12 +852,14 @@ goto done; } if (fprintf(fp, "};\n\n") < 0) - goto done; + goto done; /* Write font maps. */ if (!TAILQ_EMPTY(&maps[VFNT_MAP_NORMAL])) { - if (fprintf(fp, "static vfnt_map_t " - "FONTMAP_NORMAL_%ux%u[] = {\n", width, height) < 0) + if (fprintf(fp, + "static vfnt_map_t " + "FONTMAP_NORMAL_%ux%u[] = {\n", + width, height) < 0) goto done; if (write_source_mappings(fp, VFNT_MAP_NORMAL) != 0) goto done; @@ -860,8 +867,10 @@ goto done; } if (!TAILQ_EMPTY(&maps[VFNT_MAP_NORMAL_RIGHT])) { - if (fprintf(fp, "static vfnt_map_t " - "FONTMAP_NORMAL_RH_%ux%u[] = {\n", width, height) < 0) + if (fprintf(fp, + "static vfnt_map_t " + "FONTMAP_NORMAL_RH_%ux%u[] = {\n", + width, height) < 0) goto done; if (write_source_mappings(fp, VFNT_MAP_NORMAL_RIGHT) != 0) goto done; @@ -869,8 +878,10 @@ goto done; } if (!TAILQ_EMPTY(&maps[VFNT_MAP_BOLD])) { - if (fprintf(fp, "static vfnt_map_t " - "FONTMAP_BOLD_%ux%u[] = {\n", width, height) < 0) + if (fprintf(fp, + "static vfnt_map_t " + "FONTMAP_BOLD_%ux%u[] = {\n", + width, height) < 0) goto done; if (write_source_mappings(fp, VFNT_MAP_BOLD) != 0) goto done; @@ -878,8 +889,10 @@ goto done; } if (!TAILQ_EMPTY(&maps[VFNT_MAP_BOLD_RIGHT])) { - if (fprintf(fp, "static vfnt_map_t " - "FONTMAP_BOLD_RH_%ux%u[] = {\n", width, height) < 0) + if (fprintf(fp, + "static vfnt_map_t " + "FONTMAP_BOLD_RH_%ux%u[] = {\n", + width, height) < 0) goto done; if (write_source_mappings(fp, VFNT_MAP_BOLD_RIGHT) != 0) goto done; @@ -888,8 +901,7 @@ } /* Write struct font. */ - if (fprintf(fp, "struct vt_font font_%ux%u = {\n", - width, height) < 0) + if (fprintf(fp, "struct vt_font font_%ux%u = {\n", width, height) < 0) goto done; if (fprintf(fp, "\t.vf_map\t= {\n") < 0) goto done; @@ -897,32 +909,32 @@ if (fprintf(fp, "\t\t\tNULL,\n") < 0) goto done; } else { - if (fprintf(fp, "\t\t\tFONTMAP_NORMAL_%ux%u,\n", - width, height) < 0) + if (fprintf( + fp, "\t\t\tFONTMAP_NORMAL_%ux%u,\n", width, height) < 0) goto done; } if (TAILQ_EMPTY(&maps[VFNT_MAP_NORMAL_RIGHT])) { if (fprintf(fp, "\t\t\tNULL,\n") < 0) goto done; } else { - if (fprintf(fp, "\t\t\tFONTMAP_NORMAL_RH_%ux%u,\n", - width, height) < 0) + if (fprintf(fp, "\t\t\tFONTMAP_NORMAL_RH_%ux%u,\n", width, + height) < 0) goto done; } if (TAILQ_EMPTY(&maps[VFNT_MAP_BOLD])) { if (fprintf(fp, "\t\t\tNULL,\n") < 0) goto done; } else { - if (fprintf(fp, "\t\t\tFONTMAP_BOLD_%ux%u,\n", - width, height) < 0) + if (fprintf(fp, "\t\t\tFONTMAP_BOLD_%ux%u,\n", width, height) < + 0) goto done; } if (TAILQ_EMPTY(&maps[VFNT_MAP_BOLD_RIGHT])) { if (fprintf(fp, "\t\t\tNULL\n") < 0) goto done; } else { - if (fprintf(fp, "\t\t\tFONTMAP_BOLD_RH_%ux%u\n", - width, height) < 0) + if (fprintf( + fp, "\t\t\tFONTMAP_BOLD_RH_%ux%u\n", width, height) < 0) goto done; } if (fprintf(fp, "\t\t},\n") < 0) @@ -931,8 +943,8 @@ if (fprintf(fp, "\t.vf_bytes\t= NULL,\n") < 0) goto done; } else { - if (fprintf(fp, "\t.vf_bytes\t= FONTDATA_%ux%u,\n", - width, height) < 0) { + if (fprintf(fp, "\t.vf_bytes\t= FONTDATA_%ux%u,\n", width, + height) < 0) { goto done; } } @@ -941,16 +953,16 @@ if (fprintf(fp, "\t.vf_height\t= %u,\n", height) < 0) goto done; if (fprintf(fp, "\t.vf_map_count\t= { %u, %u, %u, %u }\n", - map_folded_count[0], map_folded_count[1], map_folded_count[2], - map_folded_count[3]) < 0) { + map_folded_count[0], map_folded_count[1], map_folded_count[2], + map_folded_count[3]) < 0) { goto done; } if (fprintf(fp, "};\n\n") < 0) goto done; /* Write bitmap data. */ - if (fprintf(fp, "vt_font_bitmap_data_t font_data_%ux%u = {\n", - width, height) < 0) + if (fprintf(fp, "vt_font_bitmap_data_t font_data_%ux%u = {\n", width, + height) < 0) goto done; if (fprintf(fp, "\t.vfbd_width\t= %u,\n", width) < 0) goto done; @@ -958,22 +970,22 @@ goto done; if (lz4 == true) { if (fprintf(fp, "\t.vfbd_compressed_size\t= %zu,\n", - compressed_size) < 0) { + compressed_size) < 0) { goto done; } if (fprintf(fp, "\t.vfbd_uncompressed_size\t= %zu,\n", - uncompressed_size) < 0) { + uncompressed_size) < 0) { goto done; } if (fprintf(fp, "\t.vfbd_compressed_data\t= FONTDATA_%ux%u,\n", - width, height) < 0) { + width, height) < 0) { goto done; } } else { if (fprintf(fp, "\t.vfbd_compressed_size\t= 0,\n") < 0) goto done; if (fprintf(fp, "\t.vfbd_uncompressed_size\t= %zu,\n", - uncompressed_size) < 0) { + uncompressed_size) < 0) { goto done; } if (fprintf(fp, "\t.vfbd_compressed_data\t= NULL,\n") < 0) @@ -995,41 +1007,32 @@ static void print_font_info(void) { - printf( -"Statistics:\n" -"- width: %6u\n" -"- height: %6u\n" -"- glyph_total: %6u\n" -"- glyph_normal: %6u\n" -"- glyph_normal_right: %6u\n" -"- glyph_bold: %6u\n" -"- glyph_bold_right: %6u\n" -"- glyph_unique: %6u\n" -"- glyph_dupe: %6u\n" -"- mapping_total: %6u\n" -"- mapping_normal: %6u\n" -"- mapping_normal_folded: %6u\n" -"- mapping_normal_right: %6u\n" -"- mapping_normal_right_folded: %6u\n" -"- mapping_bold: %6u\n" -"- mapping_bold_folded: %6u\n" -"- mapping_bold_right: %6u\n" -"- mapping_bold_right_folded: %6u\n" -"- mapping_unique: %6u\n" -"- mapping_dupe: %6u\n", - width, height, - 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); + printf("Statistics:\n" + "- width: %6u\n" + "- height: %6u\n" + "- glyph_total: %6u\n" + "- glyph_normal: %6u\n" + "- glyph_normal_right: %6u\n" + "- glyph_bold: %6u\n" + "- glyph_bold_right: %6u\n" + "- glyph_unique: %6u\n" + "- glyph_dupe: %6u\n" + "- mapping_total: %6u\n" + "- mapping_normal: %6u\n" + "- mapping_normal_folded: %6u\n" + "- mapping_normal_right: %6u\n" + "- mapping_normal_right_folded: %6u\n" + "- mapping_bold: %6u\n" + "- mapping_bold_folded: %6u\n" + "- mapping_bold_right: %6u\n" + "- mapping_bold_right_folded: %6u\n" + "- mapping_unique: %6u\n" + "- mapping_dupe: %6u\n", + width, height, 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