added font info option

This commit is contained in:
tater 2018-06-24 00:30:56 -05:00
parent f8425f84d6
commit 6f2332ff71
1 changed files with 22 additions and 14 deletions

View File

@ -45,6 +45,7 @@ typedef struct opt_s {
uint8_t width; uint8_t width;
uint8_t color; uint8_t color;
uint8_t encoding; uint8_t encoding;
bool info;
} opt_t; } opt_t;
typedef struct cell_s { typedef struct cell_s {
@ -102,6 +103,7 @@ usage(void)
fprintf(stderr, " -w n set screen width. Default is 80.\n"); fprintf(stderr, " -w n set screen width. Default is 80.\n");
fprintf(stderr, " -c a|m color format ANSI or mirc. Default is ANSI\n"); fprintf(stderr, " -c a|m color format ANSI or mirc. Default is ANSI\n");
fprintf(stderr, " -e u|a encode as unicode or ASCII. Default is unicode\n"); fprintf(stderr, " -e u|a encode as unicode or ASCII. Default is unicode\n");
fprintf(stderr, " -i print font details.\n");
fprintf(stderr, "\n"); fprintf(stderr, "\n");
exit(EX_USAGE); exit(EX_USAGE);
@ -120,8 +122,10 @@ main(int argc, char *argv[])
opt.justify = LEFT_JUSTIFY; opt.justify = LEFT_JUSTIFY;
opt.width = 80; opt.width = 80;
opt.info = false;
opt.encoding = ENC_UNICODE;
while((o = getopt(argc, argv, "w:j:c:e:")) != -1) { while((o = getopt(argc, argv, "w:j:c:e:i")) != -1) {
switch (o) { switch (o) {
case 'w': case 'w':
opt.width = atoi(optarg); opt.width = atoi(optarg);
@ -168,7 +172,9 @@ main(int argc, char *argv[])
exit(EX_USAGE); exit(EX_USAGE);
} }
break; break;
case 'i':
opt.info = true;
break;
default: default:
usage(); usage();
exit(EX_USAGE); exit(EX_USAGE);
@ -207,9 +213,9 @@ font_t
fd = open(fn, O_RDONLY); fd = open(fn, O_RDONLY);
#ifdef DEBUG if (opt.info) {
printf("file: %s\n", fn); printf("file: %s\n", fn);
#endif /* DEBUG */ }
font = malloc(sizeof(font_t)); font = malloc(sizeof(font_t));
@ -245,24 +251,26 @@ font_t
exit(EX_NOINPUT); exit(EX_NOINPUT);
} }
#ifdef DEBUG if (opt.info) {
printf("font: %s\nchar list: ", font->name); printf("font: %s\nchar list: ", font->name);
#endif /* DEBUG */ }
for (int i = 0; i < NUM_CHARS; i++) for (int i = 0; i < NUM_CHARS; i++)
if (lookupchar(charlist[i], font) > -1) { if (lookupchar(charlist[i], font) > -1) {
#ifdef DEBUG
printf("%c", charlist[i]); if (opt.info) {
#endif /* DEBUG */ printf("%c", charlist[i]);
}
p = font->data + font->charlist[i] + 2; p = font->data + font->charlist[i] + 2;
if (*p > font->height) { if (*p > font->height) {
font->height = *p; font->height = *p;
} }
} }
#ifdef DEBUG if (opt.info) {
printf("\n"); printf("\n");
#endif /* DEBUG */ }
for (int i = 0; i < NUM_CHARS; i++) { for (int i = 0; i < NUM_CHARS; i++) {