Changeset View
Standalone View
usr.bin/vtfontcvt/vtfontcvt.c
Show All 25 Lines | |||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||||
* SUCH DAMAGE. | * SUCH DAMAGE. | ||||
*/ | */ | ||||
#include <sys/cdefs.h> | #include <sys/cdefs.h> | ||||
__FBSDID("$FreeBSD$"); | __FBSDID("$FreeBSD$"); | ||||
#include <sys/types.h> | #include <sys/types.h> | ||||
#include <sys/fnv_hash.h> | |||||
#include <sys/endian.h> | |||||
#include <sys/param.h> | #include <sys/param.h> | ||||
#include <sys/queue.h> | #include <sys/endian.h> | ||||
#include <sys/fnv_hash.h> | |||||
#include <sys/font.h> | #include <sys/font.h> | ||||
#include <sys/queue.h> | |||||
#include <assert.h> | #include <assert.h> | ||||
#include <err.h> | #include <err.h> | ||||
#include <lz4.h> | |||||
#include <stdbool.h> | |||||
#include <stdint.h> | #include <stdint.h> | ||||
#include <stdio.h> | #include <stdio.h> | ||||
#include <stdlib.h> | #include <stdlib.h> | ||||
#include <stdbool.h> | |||||
#include <string.h> | #include <string.h> | ||||
#include <unistd.h> | #include <unistd.h> | ||||
#include <lz4.h> | |||||
#define VFNT_MAXGLYPHS 131072 | #define VFNT_MAXGLYPHS 131072 | ||||
#define VFNT_MAXDIMENSION 128 | #define VFNT_MAXDIMENSION 128 | ||||
static unsigned int width = 8, wbytes, height = 16; | static unsigned int width = 8, wbytes, height = 16; | ||||
struct glyph { | struct glyph { | ||||
TAILQ_ENTRY(glyph) g_list; | TAILQ_ENTRY(glyph) g_list; | ||||
SLIST_ENTRY(glyph) g_hash; | SLIST_ENTRY(glyph) g_hash; | ||||
uint8_t *g_data; | uint8_t *g_data; | ||||
unsigned int g_index; | unsigned int g_index; | ||||
}; | }; | ||||
#define FONTCVT_NHASH 4096 | #define FONTCVT_NHASH 4096 | ||||
TAILQ_HEAD(glyph_list, glyph); | TAILQ_HEAD(glyph_list, glyph); | ||||
static SLIST_HEAD(, glyph) glyph_hash[FONTCVT_NHASH]; | static SLIST_HEAD(, glyph) glyph_hash[FONTCVT_NHASH]; | ||||
static struct glyph_list glyphs[VFNT_MAPS] = { | static struct glyph_list glyphs[VFNT_MAPS] = { | ||||
TAILQ_HEAD_INITIALIZER(glyphs[0]), | TAILQ_HEAD_INITIALIZER(glyphs[0]), | ||||
TAILQ_HEAD_INITIALIZER(glyphs[1]), | TAILQ_HEAD_INITIALIZER(glyphs[1]), | ||||
TAILQ_HEAD_INITIALIZER(glyphs[2]), | TAILQ_HEAD_INITIALIZER(glyphs[2]), | ||||
TAILQ_HEAD_INITIALIZER(glyphs[3]), | TAILQ_HEAD_INITIALIZER(glyphs[3]), | ||||
}; | }; | ||||
static unsigned int glyph_total, glyph_count[4], glyph_unique, glyph_dupe; | static unsigned int glyph_total, glyph_count[4], glyph_unique, glyph_dupe; | ||||
struct mapping { | struct mapping { | ||||
TAILQ_ENTRY(mapping) m_list; | TAILQ_ENTRY(mapping) m_list; | ||||
unsigned int m_char; | unsigned int m_char; | ||||
unsigned int m_length; | unsigned int m_length; | ||||
struct glyph *m_glyph; | struct glyph *m_glyph; | ||||
}; | }; | ||||
TAILQ_HEAD(mapping_list, mapping); | TAILQ_HEAD(mapping_list, mapping); | ||||
static struct mapping_list maps[VFNT_MAPS] = { | static struct mapping_list maps[VFNT_MAPS] = { | ||||
TAILQ_HEAD_INITIALIZER(maps[0]), | TAILQ_HEAD_INITIALIZER(maps[0]), | ||||
TAILQ_HEAD_INITIALIZER(maps[1]), | TAILQ_HEAD_INITIALIZER(maps[1]), | ||||
TAILQ_HEAD_INITIALIZER(maps[2]), | TAILQ_HEAD_INITIALIZER(maps[2]), | ||||
TAILQ_HEAD_INITIALIZER(maps[3]), | TAILQ_HEAD_INITIALIZER(maps[3]), | ||||
}; | }; | ||||
static unsigned int mapping_total, map_count[4], map_folded_count[4], | static unsigned int mapping_total, map_count[4], map_folded_count[4], | ||||
mapping_unique, mapping_dupe; | mapping_unique, mapping_dupe; | ||||
enum output_format { | enum output_format { | ||||
VT_FONT, /* default */ | VT_FONT, /* default */ | ||||
VT_C_SOURCE, /* C source for built in fonts */ | VT_C_SOURCE, /* C source for built in fonts */ | ||||
VT_C_COMPRESSED /* C source with compressed font data */ | VT_C_COMPRESSED /* C source with compressed font data */ | ||||
}; | }; | ||||
struct whitelist { | struct whitelist { | ||||
uint32_t c; | uint32_t c; | ||||
uint32_t len; | uint32_t len; | ||||
}; | }; | ||||
/* | /* | ||||
* Compressed font glyph list. To be used with boot loader, we need to have | * Compressed font glyph list. To be used with boot loader, we need to have | ||||
* ascii set and box drawing chars. | * ascii set and box drawing chars. | ||||
*/ | */ | ||||
static struct whitelist c_list[] = { | static struct whitelist c_list[] = { | ||||
{ .c = 0, .len = 0 }, /* deault char */ | { .c = 0, .len = 0 }, /* deault char */ | ||||
{ .c = 0x20, .len = 0x5f }, | { .c = 0x20, .len = 0x5f }, | ||||
{ .c = 0x2500, .len = 0 }, /* single frame */ | { .c = 0x2500, .len = 0 }, /* single frame */ | ||||
emaste: Alignment applies to consecutive lines of comments, each new block gets its own alignment. This… | |||||
{ .c = 0x2502, .len = 0 }, | { .c = 0x2502, .len = 0 }, | ||||
{ .c = 0x250c, .len = 0 }, | { .c = 0x250c, .len = 0 }, | ||||
{ .c = 0x2510, .len = 0 }, | { .c = 0x2510, .len = 0 }, | ||||
{ .c = 0x2514, .len = 0 }, | { .c = 0x2514, .len = 0 }, | ||||
{ .c = 0x2518, .len = 0 }, | { .c = 0x2518, .len = 0 }, | ||||
{ .c = 0x2550, .len = 1 }, /* double frame */ | { .c = 0x2550, .len = 1 }, /* double frame */ | ||||
{ .c = 0x2554, .len = 0 }, | { .c = 0x2554, .len = 0 }, | ||||
{ .c = 0x2557, .len = 0 }, | { .c = 0x2557, .len = 0 }, | ||||
{ .c = 0x255a, .len = 0 }, | { .c = 0x255a, .len = 0 }, | ||||
{ .c = 0x255d, .len = 0 }, | { .c = 0x255d, .len = 0 }, | ||||
}; | }; | ||||
/* | /* | ||||
* Uncompressed source. For x86 we need cp437 so the vga text mode | * Uncompressed source. For x86 we need cp437 so the vga text mode | ||||
* can program font into the vga card. | * can program font into the vga card. | ||||
*/ | */ | ||||
static struct whitelist s_list[] = { | static struct whitelist s_list[] = { | ||||
{ .c = 0, .len = 0 }, /* deault char */ | { .c = 0, .len = 0 }, /* deault char */ | ||||
{ .c = 0x20, .len = 0x5f }, /* ascii set */ | { .c = 0x20, .len = 0x5f }, /* ascii set */ | ||||
{ .c = 0xA0, .len = 0x5f }, /* latin 1 */ | { .c = 0xA0, .len = 0x5f }, /* latin 1 */ | ||||
{ .c = 0x0192, .len = 0 }, | { .c = 0x0192, .len = 0 }, | ||||
{ .c = 0x0332, .len = 0 }, /* composing lower line */ | { .c = 0x0332, .len = 0 }, /* composing lower line */ | ||||
{ .c = 0x0393, .len = 0 }, | { .c = 0x0393, .len = 0 }, | ||||
{ .c = 0x0398, .len = 0 }, | { .c = 0x0398, .len = 0 }, | ||||
{ .c = 0x03A3, .len = 0 }, | { .c = 0x03A3, .len = 0 }, | ||||
{ .c = 0x03A6, .len = 0 }, | { .c = 0x03A6, .len = 0 }, | ||||
{ .c = 0x03A9, .len = 0 }, | { .c = 0x03A9, .len = 0 }, | ||||
{ .c = 0x03B1, .len = 1 }, | { .c = 0x03B1, .len = 1 }, | ||||
{ .c = 0x03B4, .len = 0 }, | { .c = 0x03B4, .len = 0 }, | ||||
{ .c = 0x03C0, .len = 0 }, | { .c = 0x03C0, .len = 0 }, | ||||
Show All 36 Lines | |||||
/* Type for write callback. */ | /* Type for write callback. */ | ||||
typedef size_t (*vt_write)(const void *, size_t, size_t, FILE *); | typedef size_t (*vt_write)(const void *, size_t, size_t, FILE *); | ||||
static uint8_t *uncompressed; | static uint8_t *uncompressed; | ||||
static void | static void | ||||
usage(void) | usage(void) | ||||
{ | { | ||||
(void)fprintf(stderr, "usage: vtfontcvt " | (void)fprintf(stderr, | ||||
"usage: vtfontcvt " | |||||
"[-n] [-f font|source|compressed-source] [-w width] " | "[-n] [-f font|source|compressed-source] [-w width] " | ||||
"[-h height]\n\t[-v] normal.bdf [bold.bdf] out.fnt\n"); | "[-h height]\n\t[-v] normal.bdf [bold.bdf] out.fnt\n"); | ||||
exit(1); | exit(1); | ||||
} | } | ||||
static void * | static void * | ||||
xmalloc(size_t size) | xmalloc(size_t size) | ||||
{ | { | ||||
Show All 19 Lines | add_mapping(struct glyph *gl, unsigned int c, unsigned int map_idx) | ||||
ml = &maps[map_idx]; | ml = &maps[map_idx]; | ||||
if (TAILQ_LAST(ml, mapping_list) == NULL || | if (TAILQ_LAST(ml, mapping_list) == NULL || | ||||
TAILQ_LAST(ml, mapping_list)->m_char < c) { | TAILQ_LAST(ml, mapping_list)->m_char < c) { | ||||
/* Common case: empty list or new char at end of list. */ | /* Common case: empty list or new char at end of list. */ | ||||
TAILQ_INSERT_TAIL(ml, mp, m_list); | TAILQ_INSERT_TAIL(ml, mp, m_list); | ||||
} else { | } else { | ||||
/* Find insertion point for char; cannot be at end. */ | /* Find insertion point for char; cannot be at end. */ | ||||
TAILQ_FOREACH(mp_temp, ml, m_list) { | TAILQ_FOREACH (mp_temp, ml, m_list) { | ||||
Not Done Inline ActionsHow do feel about space vs no space for the foreach macros? My guess is that most don't have the space, but I haven't checked. arichardson: How do feel about space vs no space for the foreach macros?
It seems like there is already a… | |||||
Done Inline ActionsI'd also guess most don't have the space, but it seems to me that these should be treated the same as regular for loops. We call them out explicitly as ForEachMacros in .clang-format; I guess that without doing so they would have no space, but the { would also move to the next line? emaste: I'd also guess most don't have the space, but it seems to me that these should be treated the… | |||||
Not Done Inline ActionsYes, they would be formatted like a function call with a missing semicolon and the braces then become a plain scope rather than part of the line before. arichardson: Yes, they would be formatted like a function call with a missing semicolon and the braces then… | |||||
if (mp_temp->m_char >= c) { | if (mp_temp->m_char >= c) { | ||||
TAILQ_INSERT_BEFORE(mp_temp, mp, m_list); | TAILQ_INSERT_BEFORE(mp_temp, mp, m_list); | ||||
break; | break; | ||||
} | } | ||||
} | } | ||||
} | } | ||||
map_count[map_idx]++; | map_count[map_idx]++; | ||||
mapping_unique++; | mapping_unique++; | ||||
return (0); | return (0); | ||||
} | } | ||||
static int | static int | ||||
dedup_mapping(unsigned int map_idx) | dedup_mapping(unsigned int map_idx) | ||||
{ | { | ||||
struct mapping *mp_bold, *mp_normal, *mp_temp; | struct mapping *mp_bold, *mp_normal, *mp_temp; | ||||
unsigned normal_map_idx = map_idx - VFNT_MAP_BOLD; | unsigned normal_map_idx = map_idx - VFNT_MAP_BOLD; | ||||
assert(map_idx == VFNT_MAP_BOLD || map_idx == VFNT_MAP_BOLD_RIGHT); | assert(map_idx == VFNT_MAP_BOLD || map_idx == VFNT_MAP_BOLD_RIGHT); | ||||
mp_normal = TAILQ_FIRST(&maps[normal_map_idx]); | 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) | while (mp_normal->m_char < mp_bold->m_char) | ||||
mp_normal = TAILQ_NEXT(mp_normal, m_list); | mp_normal = TAILQ_NEXT(mp_normal, m_list); | ||||
if (mp_bold->m_char != mp_normal->m_char) | if (mp_bold->m_char != mp_normal->m_char) | ||||
errx(1, "Character %u not in normal font!", | errx(1, "Character %u not in normal font!", | ||||
mp_bold->m_char); | mp_bold->m_char); | ||||
if (mp_bold->m_glyph != mp_normal->m_glyph) | if (mp_bold->m_glyph != mp_normal->m_glyph) | ||||
continue; | continue; | ||||
Show All 11 Lines | add_glyph(const uint8_t *bytes, unsigned int map_idx, int fallback) | ||||
struct glyph *gl; | struct glyph *gl; | ||||
int hash; | int hash; | ||||
glyph_total++; | glyph_total++; | ||||
glyph_count[map_idx]++; | glyph_count[map_idx]++; | ||||
/* Return existing glyph if we have an identical one. */ | /* Return existing glyph if we have an identical one. */ | ||||
hash = fnv_32_buf(bytes, wbytes * height, FNV1_32_INIT) % FONTCVT_NHASH; | 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) { | if (memcmp(gl->g_data, bytes, wbytes * height) == 0) { | ||||
glyph_dupe++; | glyph_dupe++; | ||||
return (gl); | return (gl); | ||||
} | } | ||||
} | } | ||||
/* Allocate new glyph. */ | /* Allocate new glyph. */ | ||||
gl = xmalloc(sizeof *gl); | gl = xmalloc(sizeof *gl); | ||||
Show All 17 Lines | check_whitelist(unsigned c) | ||||
struct whitelist *w = NULL; | struct whitelist *w = NULL; | ||||
int i, n = 0; | int i, n = 0; | ||||
if (filter == false) | if (filter == false) | ||||
return (true); | return (true); | ||||
if (format == VT_C_SOURCE) { | if (format == VT_C_SOURCE) { | ||||
w = s_list; | w = s_list; | ||||
n = sizeof (s_list) / sizeof (s_list[0]); | n = sizeof(s_list) / sizeof(s_list[0]); | ||||
emasteAuthorUnsubmitted Done Inline Actions"Casts and sizeof's are not followed by a space" - this is a valid fix from clang-format emaste: "Casts and sizeof's are not followed by a space" - this is a valid fix from clang-format | |||||
} | } | ||||
if (format == VT_C_COMPRESSED) { | if (format == VT_C_COMPRESSED) { | ||||
w = c_list; | w = c_list; | ||||
n = sizeof (c_list) / sizeof (c_list[0]); | n = sizeof(c_list) / sizeof(c_list[0]); | ||||
} | } | ||||
if (w == NULL) | if (w == NULL) | ||||
return (true); | return (true); | ||||
for (i = 0; i < n; i++) { | for (i = 0; i < n; i++) { | ||||
if (c >= w[i].c && c <= w[i].c + w[i].len) | if (c >= w[i].c && c <= w[i].c + w[i].len) | ||||
return (true); | return (true); | ||||
} | } | ||||
return (false); | return (false); | ||||
▲ Show 20 Lines • Show All 84 Lines • ▼ Show 20 Lines | |||||
static int | static int | ||||
parse_bdf(FILE *fp, unsigned int map_idx) | parse_bdf(FILE *fp, unsigned int map_idx) | ||||
{ | { | ||||
char *ln, *p; | char *ln, *p; | ||||
size_t length; | size_t length; | ||||
uint8_t *line, *bytes, *bytes_r; | uint8_t *line, *bytes, *bytes_r; | ||||
unsigned int curchar = 0, i, j, linenum = 0, bbwbytes; | unsigned int curchar = 0, i, j, linenum = 0, bbwbytes; | ||||
int bbw, bbh, bbox, bboy; /* Glyph bounding box. */ | int bbw, bbh, bbox, bboy; /* Glyph bounding box. */ | ||||
int fbbw = 0, fbbh, fbbox, fbboy; /* Font bounding box. */ | int fbbw = 0, fbbh, fbbox, fbboy; /* Font bounding box. */ | ||||
int dwidth = 0, dwy = 0; | int dwidth = 0, dwy = 0; | ||||
int rv = -1; | int rv = -1; | ||||
char spc = '\0'; | char spc = '\0'; | ||||
/* | /* | ||||
* Step 1: Parse FONT logical font descriptor and FONTBOUNDINGBOX | * Step 1: Parse FONT logical font descriptor and FONTBOUNDINGBOX | ||||
* bounding box. | * bounding box. | ||||
*/ | */ | ||||
Show All 9 Lines | if (strncmp(ln, "FONT ", 5) == 0) { | ||||
i++; | i++; | ||||
if (i == 11) { | if (i == 11) { | ||||
spc = *p; | spc = *p; | ||||
break; | break; | ||||
} | } | ||||
} | } | ||||
} else if (strncmp(ln, "FONTBOUNDINGBOX ", 16) == 0) { | } else if (strncmp(ln, "FONTBOUNDINGBOX ", 16) == 0) { | ||||
if (sscanf(ln + 16, "%d %d %d %d", &fbbw, &fbbh, &fbbox, | if (sscanf(ln + 16, "%d %d %d %d", &fbbw, &fbbh, &fbbox, | ||||
&fbboy) != 4) | &fbboy) != 4) | ||||
Done Inline Actionsthese ones are the case I really want to see fixed emaste: these ones are the case I really want to see fixed | |||||
Not Done Inline ActionsClang-format currently indents each new opening paren by 4. Should this be handled differently for if/for/while statements and function calls? Or do we want something like int x = fn1(fn2(inner_arg1, inner_arg2), outer_arg2); where a continuation line is always indented by 4 regardless of how many nested function calls there are? arichardson: Clang-format currently indents each new opening paren by 4. Should this be handled differently… | |||||
Not Done Inline ActionsThe latter. We don't indent by paren-depth, just by continuation or brace (if/for/etc). cem: The latter. We don't indent by paren-depth, just by continuation or brace (if/for/etc). | |||||
Not Done Inline ActionsI had a quick look into fixing this but it seemed non-trivial, so I've filed https://bugs.llvm.org/show_bug.cgi?id=47635 for now. arichardson: I had a quick look into fixing this but it seemed non-trivial, so I've filed https://bugs.llvm. | |||||
Done Inline ActionsWe've talked a bit about having submitters use git format-patch (from llvm); of all clang-format I am aware of I think this one here is the only one that stands in the way of that. emaste: We've talked a bit about having submitters use `git format-patch` (from llvm); of all clang… | |||||
Not Done Inline ActionsWe've talked about telling submitters to submit style(9) compliant patches, and to use git clang-format when in doubt. git format-patch is something different that just prints the patches as an email. imp: We've talked about telling submitters to submit style(9) compliant patches, and to use `git… | |||||
Done Inline ActionsYes, brain was decoupled from my fingers, I meant git clang-format emaste: Yes, brain was decoupled from my fingers, I meant `git clang-format` | |||||
errx(1, "invalid FONTBOUNDINGBOX at line %u", | errx(1, "invalid FONTBOUNDINGBOX at line %u", | ||||
linenum); | linenum); | ||||
set_width(fbbw); | set_width(fbbw); | ||||
set_height(fbbh); | set_height(fbbh); | ||||
break; | break; | ||||
} | } | ||||
} | } | ||||
if (fbbw == 0) | if (fbbw == 0) | ||||
errx(1, "broken font header"); | errx(1, "broken font header"); | ||||
if (spc != 'c' && spc != 'C') | if (spc != 'c' && spc != 'C') | ||||
errx(1, "font spacing \"C\" (character cell) required"); | errx(1, "font spacing \"C\" (character cell) required"); | ||||
/* Step 2: Validate DWIDTH (Device Width) of all glyphs. */ | /* Step 2: Validate DWIDTH (Device Width) of all glyphs. */ | ||||
while ((ln = fgetln(fp, &length)) != NULL) { | while ((ln = fgetln(fp, &length)) != NULL) { | ||||
linenum++; | linenum++; | ||||
ln[length - 1] = '\0'; | ln[length - 1] = '\0'; | ||||
if (strncmp(ln, "DWIDTH ", 7) == 0) { | if (strncmp(ln, "DWIDTH ", 7) == 0) { | ||||
if (sscanf(ln + 7, "%d %d", &dwidth, &dwy) != 2) | if (sscanf(ln + 7, "%d %d", &dwidth, &dwy) != 2) | ||||
errx(1, "invalid DWIDTH at line %u", linenum); | errx(1, "invalid DWIDTH at line %u", linenum); | ||||
if (dwy != 0 || (dwidth != fbbw && dwidth * 2 != fbbw)) | if (dwy != 0 || (dwidth != fbbw && dwidth * 2 != fbbw)) | ||||
errx(1, "bitmap with unsupported DWIDTH %d %d at line %u", | errx(1, | ||||
impUnsubmitted Not Done Inline ActionsI find this reformatting gratuitous. Then again, I want to relax the width to 100. imp: I find this reformatting gratuitous. Then again, I want to relax the width to 100. | |||||
emasteAuthorUnsubmitted Done Inline ActionsI agree, I prefer the original version here. But if someone ran clang-format over their submitted patch and it produced the new version I'd be fine leaving it emaste: I agree, I prefer the original version here. But if someone ran clang-format over their… | |||||
impUnsubmitted Not Done Inline ActionsOK. In the context of 'is this wrong if we got a patch like this' likely no. imp: OK. In the context of 'is this wrong if we got a patch like this' likely no.
In the context of… | |||||
"bitmap with unsupported DWIDTH %d %d at line %u", | |||||
dwidth, dwy, linenum); | dwidth, dwy, linenum); | ||||
if (dwidth < fbbw) | if (dwidth < fbbw) | ||||
set_width(dwidth); | set_width(dwidth); | ||||
} | } | ||||
} | } | ||||
/* Step 3: Restart at the beginning of the file and read glyph data. */ | /* Step 3: Restart at the beginning of the file and read glyph data. */ | ||||
dwidth = bbw = bbh = 0; | dwidth = bbw = bbh = 0; | ||||
rewind(fp); | rewind(fp); | ||||
linenum = 0; | linenum = 0; | ||||
bbwbytes = 0; /* GCC 4.2.1 "may be used uninitialized" workaround. */ | bbwbytes = 0; /* GCC 4.2.1 "may be used uninitialized" workaround. */ | ||||
bytes = xmalloc(wbytes * height); | bytes = xmalloc(wbytes * height); | ||||
bytes_r = xmalloc(wbytes * height); | bytes_r = xmalloc(wbytes * height); | ||||
line = xmalloc(wbytes * 2); | line = xmalloc(wbytes * 2); | ||||
while ((ln = fgetln(fp, &length)) != NULL) { | while ((ln = fgetln(fp, &length)) != NULL) { | ||||
linenum++; | linenum++; | ||||
ln[length - 1] = '\0'; | ln[length - 1] = '\0'; | ||||
if (strncmp(ln, "ENCODING ", 9) == 0) { | if (strncmp(ln, "ENCODING ", 9) == 0) { | ||||
curchar = atoi(ln + 9); | curchar = atoi(ln + 9); | ||||
} else if (strncmp(ln, "DWIDTH ", 7) == 0) { | } else if (strncmp(ln, "DWIDTH ", 7) == 0) { | ||||
dwidth = atoi(ln + 7); | dwidth = atoi(ln + 7); | ||||
} else if (strncmp(ln, "BBX ", 4) == 0) { | } else if (strncmp(ln, "BBX ", 4) == 0) { | ||||
if (sscanf(ln + 4, "%d %d %d %d", &bbw, &bbh, &bbox, | if (sscanf(ln + 4, "%d %d %d %d", &bbw, &bbh, &bbox, | ||||
&bboy) != 4) | &bboy) != 4) | ||||
impUnsubmitted Not Done Inline ActionsThis is an extra indent, but there's already a bug upstream. imp: This is an extra indent, but there's already a bug upstream. | |||||
errx(1, "invalid BBX at line %u", linenum); | errx(1, "invalid BBX at line %u", linenum); | ||||
if (bbw < 1 || bbh < 1 || bbw > fbbw || bbh > fbbh || | if (bbw < 1 || bbh < 1 || bbw > fbbw || bbh > fbbh || | ||||
bbox < fbbox || bboy < fbboy || | bbox < fbbox || bboy < fbboy || | ||||
bbh + bboy > fbbh + 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); | bbw, bbh, bbox, bboy, linenum); | ||||
bbwbytes = howmany(bbw, 8); | bbwbytes = howmany(bbw, 8); | ||||
} else if (strncmp(ln, "BITMAP", 6) == 0 && | } else if (strncmp(ln, "BITMAP", 6) == 0 && | ||||
(ln[6] == ' ' || ln[6] == '\0')) { | (ln[6] == ' ' || ln[6] == '\0')) { | ||||
if (dwidth == 0 || bbw == 0 || bbh == 0) | if (dwidth == 0 || bbw == 0 || bbh == 0) | ||||
errx(1, "broken char header at line %u!", | errx(1, "broken char header at line %u!", | ||||
linenum); | linenum); | ||||
memset(bytes, 0, wbytes * height); | memset(bytes, 0, wbytes * height); | ||||
memset(bytes_r, 0, wbytes * height); | memset(bytes_r, 0, wbytes * height); | ||||
/* | /* | ||||
* Assume that the next _bbh_ lines are bitmap data. | * Assume that the next _bbh_ lines are bitmap data. | ||||
* ENDCHAR is allowed to terminate the bitmap | * ENDCHAR is allowed to terminate the bitmap | ||||
* early but is not otherwise checked; any extra data | * early but is not otherwise checked; any extra data | ||||
* is ignored. | * is ignored. | ||||
*/ | */ | ||||
for (i = (fbbh + fbboy) - (bbh + bboy); | for (i = (fbbh + fbboy) - (bbh + bboy); | ||||
i < (unsigned int)((fbbh + fbboy) - bboy); i++) { | i < (unsigned int)((fbbh + fbboy) - bboy); i++) { | ||||
impUnsubmitted Not Done Inline ActionsThis is also wrong: there's an extra space to align it with the ( which isn't something style(9) does. imp: This is also wrong: there's an extra space to align it with the ( which isn't something style… | |||||
if ((ln = fgetln(fp, &length)) == NULL) | if ((ln = fgetln(fp, &length)) == NULL) | ||||
errx(1, "unexpected EOF"); | errx(1, "unexpected EOF"); | ||||
linenum++; | linenum++; | ||||
ln[length - 1] = '\0'; | ln[length - 1] = '\0'; | ||||
if (strcmp(ln, "ENDCHAR") == 0) | if (strcmp(ln, "ENDCHAR") == 0) | ||||
break; | break; | ||||
if (strlen(ln) < bbwbytes * 2) | if (strlen(ln) < bbwbytes * 2) | ||||
errx(1, "broken bitmap at line %u", | errx(1, "broken bitmap at line %u", | ||||
linenum); | linenum); | ||||
memset(line, 0, wbytes * 2); | memset(line, 0, wbytes * 2); | ||||
for (j = 0; j < bbwbytes; j++) { | for (j = 0; j < bbwbytes; j++) { | ||||
unsigned int val; | unsigned int val; | ||||
if (sscanf(ln + j * 2, "%2x", &val) == | if (sscanf(ln + j * 2, "%2x", &val) == | ||||
0) | 0) | ||||
break; | break; | ||||
*(line + j) = (uint8_t)val; | *(line + j) = (uint8_t)val; | ||||
} | } | ||||
rshift_row(line, wbytes * 2, bbox - fbbox); | rshift_row(line, wbytes * 2, bbox - fbbox); | ||||
rv = split_row(bytes + i * wbytes, | rv = split_row(bytes + i * wbytes, | ||||
bytes_r + i * wbytes, line, dwidth); | bytes_r + i * wbytes, line, dwidth); | ||||
if (rv != 0) | if (rv != 0) | ||||
goto out; | goto out; | ||||
} | } | ||||
if (check_whitelist(curchar) == true) { | if (check_whitelist(curchar) == true) { | ||||
rv = add_char(curchar, map_idx, bytes, | rv = add_char(curchar, map_idx, bytes, | ||||
dwidth > (int)width ? bytes_r : NULL); | dwidth > (int)width ? bytes_r : NULL); | ||||
if (rv != 0) | if (rv != 0) | ||||
Show All 20 Lines | parse_hex(FILE *fp, unsigned int map_idx) | ||||
unsigned curchar = 0, gwidth, gwbytes, i, j, chars_per_row; | unsigned curchar = 0, gwidth, gwbytes, i, j, chars_per_row; | ||||
int rv = 0; | int rv = 0; | ||||
while ((ln = fgetln(fp, &length)) != NULL) { | while ((ln = fgetln(fp, &length)) != NULL) { | ||||
ln[length - 1] = '\0'; | ln[length - 1] = '\0'; | ||||
if (strncmp(ln, "# Height: ", 10) == 0) { | if (strncmp(ln, "# Height: ", 10) == 0) { | ||||
if (bytes != NULL) | 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)); | set_height(atoi(ln + 10)); | ||||
} else if (strncmp(ln, "# Width: ", 9) == 0) { | } else if (strncmp(ln, "# Width: ", 9) == 0) { | ||||
if (bytes != NULL) | 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)); | set_width(atoi(ln + 9)); | ||||
} else if (sscanf(ln, "%6x:", &curchar)) { | } else if (sscanf(ln, "%6x:", &curchar)) { | ||||
if (bytes == NULL) { | if (bytes == NULL) { | ||||
bytes = xmalloc(wbytes * height); | bytes = xmalloc(wbytes * height); | ||||
bytes_r = xmalloc(wbytes * height); | bytes_r = xmalloc(wbytes * height); | ||||
line = xmalloc(wbytes * 2); | line = xmalloc(wbytes * 2); | ||||
} | } | ||||
/* ln is guaranteed to have a colon here. */ | /* ln is guaranteed to have a colon here. */ | ||||
▲ Show 20 Lines • Show All 62 Lines • ▼ Show 20 Lines | |||||
static void | static void | ||||
number_glyphs(void) | number_glyphs(void) | ||||
{ | { | ||||
struct glyph *gl; | struct glyph *gl; | ||||
unsigned int i, idx = 0; | unsigned int i, idx = 0; | ||||
for (i = 0; i < VFNT_MAPS; i++) | for (i = 0; i < VFNT_MAPS; i++) | ||||
TAILQ_FOREACH(gl, &glyphs[i], g_list) | TAILQ_FOREACH (gl, &glyphs[i], g_list) | ||||
impUnsubmitted Not Done Inline ActionsThis is also wrong: this space shouldn't be there. We don't do this in sys/kern at all, for example. imp: This is also wrong: this space shouldn't be there. We don't do this in sys/kern at all, for… | |||||
emasteAuthorUnsubmitted Done Inline ActionsI might argue this is a bug in style(9), in that the queue macros should be syntactically similar to for() emaste: I might argue this is a bug in style(9), in that the queue macros should be syntactically… | |||||
impUnsubmitted Not Done Inline Actionsstyle(9) generally is supposed to document what's in the tree so that new submissions fall within an acceptable range. imp: style(9) generally is supposed to document what's in the tree so that new submissions fall… | |||||
gl->g_index = idx++; | gl->g_index = idx++; | ||||
} | } | ||||
/* Note we only deal with byte stream here. */ | /* Note we only deal with byte stream here. */ | ||||
static size_t | static size_t | ||||
write_glyph_source(const void *ptr, size_t size, size_t nitems, FILE *stream) | write_glyph_source(const void *ptr, size_t size, size_t nitems, FILE *stream) | ||||
{ | { | ||||
const uint8_t *data = ptr; | const uint8_t *data = ptr; | ||||
Show All 11 Lines | write_glyph_source(const void *ptr, size_t size, size_t nitems, FILE *stream) | ||||
if (fprintf(stream, "\n") < 0) | if (fprintf(stream, "\n") < 0) | ||||
nitems = 0; | nitems = 0; | ||||
return (nitems); | return (nitems); | ||||
} | } | ||||
/* Write to buffer */ | /* Write to buffer */ | ||||
static size_t | static size_t | ||||
write_glyph_buf(const void *ptr, size_t size, size_t nitems, | write_glyph_buf( | ||||
FILE *stream __unused) | const void *ptr, size_t size, size_t nitems, FILE *stream __unused) | ||||
emasteAuthorUnsubmitted Done Inline ActionsI'm surprised by this one emaste: I'm surprised by this one | |||||
arichardsonUnsubmitted Not Done Inline ActionsClang-format 12 should do the right thing here: https://reviews.llvm.org/D90246 arichardson: Clang-format 12 should do the right thing here: https://reviews.llvm.org/D90246 | |||||
emasteAuthorUnsubmitted Done Inline ActionsConfirmed, this is not changed now w/ clang-format12 emaste: Confirmed, this is not changed now w/ clang-format12 | |||||
{ | { | ||||
static size_t index = 0; | static size_t index = 0; | ||||
size *= nitems; | size *= nitems; | ||||
(void) memmove(uncompressed + index, ptr, size); | (void)memmove(uncompressed + index, ptr, size); | ||||
emasteAuthorUnsubmitted Done Inline Actions"Casts and sizeof's are not followed by a space" but it seems much of our existing code implicitly adds "except (void) casts to intentionally discard a return value are followed by a space." IMO this is not worth trying to support and we should just drop those spaces. emaste: "Casts and sizeof's are not followed by a space" but it seems much of our existing code… | |||||
impUnsubmitted Not Done Inline Actionsstyle(9) should be changed to allow the space, but not require it so clang-format can do either and we're fine either way. imp: style(9) should be changed to allow the space, but not require it so clang-format can do either… | |||||
index += size; | index += size; | ||||
return (nitems); | return (nitems); | ||||
} | } | ||||
static int | static int | ||||
write_glyphs(FILE *fp, vt_write cb) | write_glyphs(FILE *fp, vt_write cb) | ||||
{ | { | ||||
struct glyph *gl; | struct glyph *gl; | ||||
unsigned int i; | unsigned int i; | ||||
for (i = 0; i < VFNT_MAPS; 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) | if (cb(gl->g_data, wbytes * height, 1, fp) != 1) | ||||
return (1); | return (1); | ||||
} | } | ||||
return (0); | return (0); | ||||
} | } | ||||
static void | static void | ||||
fold_mappings(unsigned int map_idx) | fold_mappings(unsigned int map_idx) | ||||
Show All 16 Lines | |||||
static int | static int | ||||
write_mappings(FILE *fp, unsigned int map_idx) | write_mappings(FILE *fp, unsigned int map_idx) | ||||
{ | { | ||||
struct mapping_list *ml = &maps[map_idx]; | struct mapping_list *ml = &maps[map_idx]; | ||||
struct mapping *mp; | struct mapping *mp; | ||||
vfnt_map_t fm; | vfnt_map_t fm; | ||||
unsigned int i = 0, j = 0; | unsigned int i = 0, j = 0; | ||||
TAILQ_FOREACH(mp, ml, m_list) { | TAILQ_FOREACH (mp, ml, m_list) { | ||||
j++; | j++; | ||||
if (mp->m_length > 0) { | if (mp->m_length > 0) { | ||||
i += mp->m_length; | i += mp->m_length; | ||||
fm.vfm_src = htobe32(mp->m_char); | fm.vfm_src = htobe32(mp->m_char); | ||||
fm.vfm_dst = htobe16(mp->m_glyph->g_index); | fm.vfm_dst = htobe16(mp->m_glyph->g_index); | ||||
fm.vfm_len = htobe16(mp->m_length - 1); | fm.vfm_len = htobe16(mp->m_length - 1); | ||||
if (fwrite(&fm, sizeof fm, 1, fp) != 1) | if (fwrite(&fm, sizeof fm, 1, fp) != 1) | ||||
return (1); | return (1); | ||||
} | } | ||||
} | } | ||||
assert(i == j); | assert(i == j); | ||||
return (0); | return (0); | ||||
} | } | ||||
static int | static int | ||||
write_source_mappings(FILE *fp, unsigned int map_idx) | write_source_mappings(FILE *fp, unsigned int map_idx) | ||||
{ | { | ||||
struct mapping_list *ml = &maps[map_idx]; | struct mapping_list *ml = &maps[map_idx]; | ||||
struct mapping *mp; | struct mapping *mp; | ||||
unsigned int i = 0, j = 0; | unsigned int i = 0, j = 0; | ||||
TAILQ_FOREACH(mp, ml, m_list) { | TAILQ_FOREACH (mp, ml, m_list) { | ||||
j++; | j++; | ||||
if (mp->m_length > 0) { | if (mp->m_length > 0) { | ||||
i += mp->m_length; | i += mp->m_length; | ||||
if (fprintf(fp, "\t{ 0x%08x, 0x%04x, 0x%04x },\n", | if (fprintf(fp, "\t{ 0x%08x, 0x%04x, 0x%04x },\n", | ||||
mp->m_char, mp->m_glyph->g_index, | mp->m_char, mp->m_glyph->g_index, | ||||
mp->m_length - 1) < 0) | mp->m_length - 1) < 0) | ||||
return (1); | return (1); | ||||
} | } | ||||
} | } | ||||
assert(i == j); | assert(i == j); | ||||
return (0); | return (0); | ||||
} | } | ||||
static int | static int | ||||
▲ Show 20 Lines • Show All 51 Lines • ▼ Show 20 Lines | if (fp == NULL) { | ||||
perror(filename); | perror(filename); | ||||
return (1); | return (1); | ||||
} | } | ||||
if (lz4 == true) { | if (lz4 == true) { | ||||
uncompressed = xmalloc(uncompressed_size); | uncompressed = xmalloc(uncompressed_size); | ||||
compressed = xmalloc(uncompressed_size); | compressed = xmalloc(uncompressed_size); | ||||
} | } | ||||
if (fprintf(fp, "/* Generated %ux%u console font source. */\n\n", | if (fprintf(fp, "/* Generated %ux%u console font source. */\n\n", width, | ||||
width, height) < 0) | height) < 0) | ||||
goto done; | goto done; | ||||
if (fprintf(fp, "#include <sys/types.h>\n") < 0) | if (fprintf(fp, "#include <sys/types.h>\n") < 0) | ||||
goto done; | goto done; | ||||
if (fprintf(fp, "#include <sys/param.h>\n") < 0) | if (fprintf(fp, "#include <sys/param.h>\n") < 0) | ||||
goto done; | goto done; | ||||
if (fprintf(fp, "#include <sys/font.h>\n\n") < 0) | if (fprintf(fp, "#include <sys/font.h>\n\n") < 0) | ||||
goto done; | goto done; | ||||
/* Write font bytes. */ | /* Write font bytes. */ | ||||
if (fprintf(fp, "static uint8_t FONTDATA_%ux%u[] = {\n", | if (fprintf( | ||||
width, height) < 0) | fp, "static uint8_t FONTDATA_%ux%u[] = {\n", width, height) < 0) | ||||
goto done; | goto done; | ||||
if (lz4 == true) { | if (lz4 == true) { | ||||
if (write_glyphs(fp, &write_glyph_buf) != 0) | if (write_glyphs(fp, &write_glyph_buf) != 0) | ||||
goto done; | goto done; | ||||
compressed_size = lz4_compress(uncompressed, compressed, | compressed_size = lz4_compress(uncompressed, compressed, | ||||
uncompressed_size, compressed_size, 0); | uncompressed_size, compressed_size, 0); | ||||
if (write_glyph_source(compressed, compressed_size, 1, fp) != 1) | if (write_glyph_source(compressed, compressed_size, 1, fp) != 1) | ||||
goto done; | goto done; | ||||
free(uncompressed); | free(uncompressed); | ||||
free(compressed); | free(compressed); | ||||
} else { | } else { | ||||
if (write_glyphs(fp, &write_glyph_source) != 0) | if (write_glyphs(fp, &write_glyph_source) != 0) | ||||
goto done; | goto done; | ||||
} | } | ||||
if (fprintf(fp, "};\n\n") < 0) | if (fprintf(fp, "};\n\n") < 0) | ||||
goto done; | goto done; | ||||
emasteAuthorUnsubmitted Done Inline Actionsvalid fix emaste: valid fix | |||||
/* Write font maps. */ | /* Write font maps. */ | ||||
if (!TAILQ_EMPTY(&maps[VFNT_MAP_NORMAL])) { | if (!TAILQ_EMPTY(&maps[VFNT_MAP_NORMAL])) { | ||||
if (fprintf(fp, "static vfnt_map_t " | if (fprintf(fp, | ||||
"FONTMAP_NORMAL_%ux%u[] = {\n", width, height) < 0) | "static vfnt_map_t " | ||||
"FONTMAP_NORMAL_%ux%u[] = {\n", | |||||
width, height) < 0) | |||||
impUnsubmitted Not Done Inline ActionsThis is wrong. In addition to the normal "shouldn't have moved this from the end of the end" this compounds the problem by not collapsing the strings. But it's another example of why 100 would produce clearer code. Though given clang-format's penchant for always packing things optimally (which I'd really like to suppress), a change to 100 would introduce more churn... imp: This is wrong. In addition to the normal "shouldn't have moved this from the end of the end"… | |||||
goto done; | goto done; | ||||
if (write_source_mappings(fp, VFNT_MAP_NORMAL) != 0) | if (write_source_mappings(fp, VFNT_MAP_NORMAL) != 0) | ||||
goto done; | goto done; | ||||
if (fprintf(fp, "};\n\n") < 0) | if (fprintf(fp, "};\n\n") < 0) | ||||
goto done; | goto done; | ||||
} | } | ||||
if (!TAILQ_EMPTY(&maps[VFNT_MAP_NORMAL_RIGHT])) { | if (!TAILQ_EMPTY(&maps[VFNT_MAP_NORMAL_RIGHT])) { | ||||
if (fprintf(fp, "static vfnt_map_t " | if (fprintf(fp, | ||||
"FONTMAP_NORMAL_RH_%ux%u[] = {\n", width, height) < 0) | "static vfnt_map_t " | ||||
"FONTMAP_NORMAL_RH_%ux%u[] = {\n", | |||||
width, height) < 0) | |||||
goto done; | goto done; | ||||
if (write_source_mappings(fp, VFNT_MAP_NORMAL_RIGHT) != 0) | if (write_source_mappings(fp, VFNT_MAP_NORMAL_RIGHT) != 0) | ||||
goto done; | goto done; | ||||
if (fprintf(fp, "};\n\n") < 0) | if (fprintf(fp, "};\n\n") < 0) | ||||
goto done; | goto done; | ||||
} | } | ||||
if (!TAILQ_EMPTY(&maps[VFNT_MAP_BOLD])) { | if (!TAILQ_EMPTY(&maps[VFNT_MAP_BOLD])) { | ||||
if (fprintf(fp, "static vfnt_map_t " | if (fprintf(fp, | ||||
"FONTMAP_BOLD_%ux%u[] = {\n", width, height) < 0) | "static vfnt_map_t " | ||||
"FONTMAP_BOLD_%ux%u[] = {\n", | |||||
width, height) < 0) | |||||
goto done; | goto done; | ||||
if (write_source_mappings(fp, VFNT_MAP_BOLD) != 0) | if (write_source_mappings(fp, VFNT_MAP_BOLD) != 0) | ||||
goto done; | goto done; | ||||
if (fprintf(fp, "};\n\n") < 0) | if (fprintf(fp, "};\n\n") < 0) | ||||
goto done; | goto done; | ||||
} | } | ||||
if (!TAILQ_EMPTY(&maps[VFNT_MAP_BOLD_RIGHT])) { | if (!TAILQ_EMPTY(&maps[VFNT_MAP_BOLD_RIGHT])) { | ||||
if (fprintf(fp, "static vfnt_map_t " | if (fprintf(fp, | ||||
"FONTMAP_BOLD_RH_%ux%u[] = {\n", width, height) < 0) | "static vfnt_map_t " | ||||
"FONTMAP_BOLD_RH_%ux%u[] = {\n", | |||||
width, height) < 0) | |||||
goto done; | goto done; | ||||
if (write_source_mappings(fp, VFNT_MAP_BOLD_RIGHT) != 0) | if (write_source_mappings(fp, VFNT_MAP_BOLD_RIGHT) != 0) | ||||
goto done; | goto done; | ||||
if (fprintf(fp, "};\n\n") < 0) | if (fprintf(fp, "};\n\n") < 0) | ||||
goto done; | goto done; | ||||
} | } | ||||
/* Write struct font. */ | /* Write struct font. */ | ||||
if (fprintf(fp, "struct vt_font font_%ux%u = {\n", | if (fprintf(fp, "struct vt_font font_%ux%u = {\n", width, height) < 0) | ||||
width, height) < 0) | |||||
goto done; | goto done; | ||||
if (fprintf(fp, "\t.vf_map\t= {\n") < 0) | if (fprintf(fp, "\t.vf_map\t= {\n") < 0) | ||||
goto done; | goto done; | ||||
if (TAILQ_EMPTY(&maps[VFNT_MAP_NORMAL])) { | if (TAILQ_EMPTY(&maps[VFNT_MAP_NORMAL])) { | ||||
if (fprintf(fp, "\t\t\tNULL,\n") < 0) | if (fprintf(fp, "\t\t\tNULL,\n") < 0) | ||||
goto done; | goto done; | ||||
} else { | } else { | ||||
if (fprintf(fp, "\t\t\tFONTMAP_NORMAL_%ux%u,\n", | if (fprintf( | ||||
width, height) < 0) | fp, "\t\t\tFONTMAP_NORMAL_%ux%u,\n", width, height) < 0) | ||||
goto done; | goto done; | ||||
} | } | ||||
if (TAILQ_EMPTY(&maps[VFNT_MAP_NORMAL_RIGHT])) { | if (TAILQ_EMPTY(&maps[VFNT_MAP_NORMAL_RIGHT])) { | ||||
if (fprintf(fp, "\t\t\tNULL,\n") < 0) | if (fprintf(fp, "\t\t\tNULL,\n") < 0) | ||||
goto done; | goto done; | ||||
} else { | } else { | ||||
if (fprintf(fp, "\t\t\tFONTMAP_NORMAL_RH_%ux%u,\n", | if (fprintf(fp, "\t\t\tFONTMAP_NORMAL_RH_%ux%u,\n", width, | ||||
width, height) < 0) | height) < 0) | ||||
goto done; | goto done; | ||||
} | } | ||||
if (TAILQ_EMPTY(&maps[VFNT_MAP_BOLD])) { | if (TAILQ_EMPTY(&maps[VFNT_MAP_BOLD])) { | ||||
if (fprintf(fp, "\t\t\tNULL,\n") < 0) | if (fprintf(fp, "\t\t\tNULL,\n") < 0) | ||||
goto done; | goto done; | ||||
} else { | } else { | ||||
if (fprintf(fp, "\t\t\tFONTMAP_BOLD_%ux%u,\n", | if (fprintf(fp, "\t\t\tFONTMAP_BOLD_%ux%u,\n", width, height) < | ||||
width, height) < 0) | 0) | ||||
goto done; | goto done; | ||||
} | } | ||||
if (TAILQ_EMPTY(&maps[VFNT_MAP_BOLD_RIGHT])) { | if (TAILQ_EMPTY(&maps[VFNT_MAP_BOLD_RIGHT])) { | ||||
if (fprintf(fp, "\t\t\tNULL\n") < 0) | if (fprintf(fp, "\t\t\tNULL\n") < 0) | ||||
goto done; | goto done; | ||||
} else { | } else { | ||||
if (fprintf(fp, "\t\t\tFONTMAP_BOLD_RH_%ux%u\n", | if (fprintf( | ||||
width, height) < 0) | fp, "\t\t\tFONTMAP_BOLD_RH_%ux%u\n", width, height) < 0) | ||||
goto done; | goto done; | ||||
} | } | ||||
if (fprintf(fp, "\t\t},\n") < 0) | if (fprintf(fp, "\t\t},\n") < 0) | ||||
goto done; | goto done; | ||||
if (lz4 == true) { | if (lz4 == true) { | ||||
if (fprintf(fp, "\t.vf_bytes\t= NULL,\n") < 0) | if (fprintf(fp, "\t.vf_bytes\t= NULL,\n") < 0) | ||||
goto done; | goto done; | ||||
} else { | } else { | ||||
if (fprintf(fp, "\t.vf_bytes\t= FONTDATA_%ux%u,\n", | if (fprintf(fp, "\t.vf_bytes\t= FONTDATA_%ux%u,\n", width, | ||||
width, height) < 0) { | height) < 0) { | ||||
goto done; | goto done; | ||||
} | } | ||||
} | } | ||||
if (fprintf(fp, "\t.vf_width\t= %u,\n", width) < 0) | if (fprintf(fp, "\t.vf_width\t= %u,\n", width) < 0) | ||||
goto done; | goto done; | ||||
if (fprintf(fp, "\t.vf_height\t= %u,\n", height) < 0) | if (fprintf(fp, "\t.vf_height\t= %u,\n", height) < 0) | ||||
goto done; | goto done; | ||||
if (fprintf(fp, "\t.vf_map_count\t= { %u, %u, %u, %u }\n", | 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[0], map_folded_count[1], map_folded_count[2], | ||||
map_folded_count[3]) < 0) { | map_folded_count[3]) < 0) { | ||||
goto done; | goto done; | ||||
} | } | ||||
if (fprintf(fp, "};\n\n") < 0) | if (fprintf(fp, "};\n\n") < 0) | ||||
goto done; | goto done; | ||||
/* Write bitmap data. */ | /* Write bitmap data. */ | ||||
if (fprintf(fp, "vt_font_bitmap_data_t font_data_%ux%u = {\n", | if (fprintf(fp, "vt_font_bitmap_data_t font_data_%ux%u = {\n", width, | ||||
width, height) < 0) | height) < 0) | ||||
goto done; | goto done; | ||||
if (fprintf(fp, "\t.vfbd_width\t= %u,\n", width) < 0) | if (fprintf(fp, "\t.vfbd_width\t= %u,\n", width) < 0) | ||||
goto done; | goto done; | ||||
if (fprintf(fp, "\t.vfbd_height\t= %u,\n", height) < 0) | if (fprintf(fp, "\t.vfbd_height\t= %u,\n", height) < 0) | ||||
goto done; | goto done; | ||||
if (lz4 == true) { | if (lz4 == true) { | ||||
if (fprintf(fp, "\t.vfbd_compressed_size\t= %zu,\n", | if (fprintf(fp, "\t.vfbd_compressed_size\t= %zu,\n", | ||||
compressed_size) < 0) { | compressed_size) < 0) { | ||||
goto done; | goto done; | ||||
} | } | ||||
if (fprintf(fp, "\t.vfbd_uncompressed_size\t= %zu,\n", | if (fprintf(fp, "\t.vfbd_uncompressed_size\t= %zu,\n", | ||||
uncompressed_size) < 0) { | uncompressed_size) < 0) { | ||||
goto done; | goto done; | ||||
} | } | ||||
if (fprintf(fp, "\t.vfbd_compressed_data\t= FONTDATA_%ux%u,\n", | if (fprintf(fp, "\t.vfbd_compressed_data\t= FONTDATA_%ux%u,\n", | ||||
width, height) < 0) { | width, height) < 0) { | ||||
goto done; | goto done; | ||||
} | } | ||||
} else { | } else { | ||||
if (fprintf(fp, "\t.vfbd_compressed_size\t= 0,\n") < 0) | if (fprintf(fp, "\t.vfbd_compressed_size\t= 0,\n") < 0) | ||||
goto done; | goto done; | ||||
if (fprintf(fp, "\t.vfbd_uncompressed_size\t= %zu,\n", | if (fprintf(fp, "\t.vfbd_uncompressed_size\t= %zu,\n", | ||||
uncompressed_size) < 0) { | uncompressed_size) < 0) { | ||||
goto done; | goto done; | ||||
} | } | ||||
if (fprintf(fp, "\t.vfbd_compressed_data\t= NULL,\n") < 0) | if (fprintf(fp, "\t.vfbd_compressed_data\t= NULL,\n") < 0) | ||||
goto done; | goto done; | ||||
} | } | ||||
if (fprintf(fp, "\t.vfbd_font = &font_%ux%u\n", width, height) < 0) | if (fprintf(fp, "\t.vfbd_font = &font_%ux%u\n", width, height) < 0) | ||||
goto done; | goto done; | ||||
if (fprintf(fp, "};\n") < 0) | if (fprintf(fp, "};\n") < 0) | ||||
goto done; | goto done; | ||||
rv = 0; | rv = 0; | ||||
done: | done: | ||||
if (rv != 0) | if (rv != 0) | ||||
perror(filename); | perror(filename); | ||||
fclose(fp); | fclose(fp); | ||||
return (0); | return (0); | ||||
} | } | ||||
static void | static void | ||||
print_font_info(void) | print_font_info(void) | ||||
{ | { | ||||
printf( | printf("Statistics:\n" | ||||
"Statistics:\n" | |||||
"- width: %6u\n" | "- width: %6u\n" | ||||
"- height: %6u\n" | "- height: %6u\n" | ||||
"- glyph_total: %6u\n" | "- glyph_total: %6u\n" | ||||
"- glyph_normal: %6u\n" | "- glyph_normal: %6u\n" | ||||
"- glyph_normal_right: %6u\n" | "- glyph_normal_right: %6u\n" | ||||
"- glyph_bold: %6u\n" | "- glyph_bold: %6u\n" | ||||
"- glyph_bold_right: %6u\n" | "- glyph_bold_right: %6u\n" | ||||
"- glyph_unique: %6u\n" | "- glyph_unique: %6u\n" | ||||
"- glyph_dupe: %6u\n" | "- glyph_dupe: %6u\n" | ||||
"- mapping_total: %6u\n" | "- mapping_total: %6u\n" | ||||
"- mapping_normal: %6u\n" | "- mapping_normal: %6u\n" | ||||
"- mapping_normal_folded: %6u\n" | "- mapping_normal_folded: %6u\n" | ||||
"- mapping_normal_right: %6u\n" | "- mapping_normal_right: %6u\n" | ||||
"- mapping_normal_right_folded: %6u\n" | "- mapping_normal_right_folded: %6u\n" | ||||
"- mapping_bold: %6u\n" | "- mapping_bold: %6u\n" | ||||
"- mapping_bold_folded: %6u\n" | "- mapping_bold_folded: %6u\n" | ||||
"- mapping_bold_right: %6u\n" | "- mapping_bold_right: %6u\n" | ||||
"- mapping_bold_right_folded: %6u\n" | "- mapping_bold_right_folded: %6u\n" | ||||
"- mapping_unique: %6u\n" | "- mapping_unique: %6u\n" | ||||
"- mapping_dupe: %6u\n", | "- mapping_dupe: %6u\n", | ||||
width, height, | width, height, glyph_total, glyph_count[0], glyph_count[1], | ||||
glyph_total, | glyph_count[2], glyph_count[3], glyph_unique, glyph_dupe, | ||||
glyph_count[0], | mapping_total, map_count[0], map_folded_count[0], map_count[1], | ||||
glyph_count[1], | map_folded_count[1], map_count[2], map_folded_count[2], | ||||
glyph_count[2], | map_count[3], map_folded_count[3], mapping_unique, mapping_dupe); | ||||
emasteAuthorUnsubmitted Done Inline ActionsWe can /* clang-format off */ to leave these as is if desired. emaste: We can `/* clang-format off */` to leave these as is if desired. | |||||
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 | int | ||||
main(int argc, char *argv[]) | main(int argc, char *argv[]) | ||||
{ | { | ||||
int ch, verbose = 0, rv = 0; | int ch, verbose = 0, rv = 0; | ||||
char *outfile = NULL; | char *outfile = NULL; | ||||
▲ Show 20 Lines • Show All 84 Lines • Show Last 20 Lines |
Alignment applies to consecutive lines of comments, each new block gets its own alignment. This is probably the best that can be expected from a tool and I think it's a win over the previous version, even if not perfect.