mirror of
https://github.com/tat3r/tdfiglet.git
synced 2024-11-21 23:56:41 +00:00
sanity check font files
This commit is contained in:
parent
0acf59403f
commit
b0860ceca3
33
tdfiglet.c
33
tdfiglet.c
@ -59,7 +59,7 @@ typedef struct glyph_s {
|
|||||||
cell_t *cell;
|
cell_t *cell;
|
||||||
} glyph_t;
|
} glyph_t;
|
||||||
|
|
||||||
typedef struct __attribute__((packed)) font_s {
|
typedef struct font_s {
|
||||||
uint8_t namelen;
|
uint8_t namelen;
|
||||||
uint8_t *name;
|
uint8_t *name;
|
||||||
uint8_t fonttype;
|
uint8_t fonttype;
|
||||||
@ -71,16 +71,8 @@ typedef struct __attribute__((packed)) font_s {
|
|||||||
uint8_t height;
|
uint8_t height;
|
||||||
} font_t;
|
} font_t;
|
||||||
|
|
||||||
char *magic = "\x13TheDraw FONTS file\x1a";
|
const char *charlist = "!\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNO"
|
||||||
|
"PQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~";
|
||||||
char *charlist = "!\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNO"
|
|
||||||
"PQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~";
|
|
||||||
/* thedraw colors DRK BRT BRT BRT RED BRT */
|
|
||||||
/* thedraw colors BLK BLU GRN CYN RED MAG BRN GRY GRY BLU GRN CYN RED PNK YLW WHT */
|
|
||||||
uint8_t fgacolors[] = {30, 34, 32, 36, 31, 35, 33, 37, 90, 94, 92, 96, 91, 95, 93, 97};
|
|
||||||
uint8_t bgacolors[] = {40, 44, 42, 46, 41, 45, 43, 47};
|
|
||||||
uint8_t fgmcolors[] = { 1, 2, 3, 10, 5, 6, 7, 15, 14, 12, 9, 11, 4, 13, 8, 0};
|
|
||||||
uint8_t bgmcolors[] = { 1, 2, 3, 10, 5, 6, 7, 15, 14, 12, 9, 11, 4, 13, 8, 0};
|
|
||||||
|
|
||||||
void usage(void);
|
void usage(void);
|
||||||
font_t *loadfont(char *fn);
|
font_t *loadfont(char *fn);
|
||||||
@ -211,6 +203,8 @@ font_t
|
|||||||
size_t len;
|
size_t len;
|
||||||
uint8_t *p;
|
uint8_t *p;
|
||||||
|
|
||||||
|
const char *magic = "\x13TheDraw FONTS file\x1a";
|
||||||
|
|
||||||
fd = open(fn, O_RDONLY);
|
fd = open(fn, O_RDONLY);
|
||||||
|
|
||||||
if (opt.info) {
|
if (opt.info) {
|
||||||
@ -263,7 +257,13 @@ font_t
|
|||||||
printf("font: %s\nchar list: ", font->name);
|
printf("font: %s\nchar list: ", font->name);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < NUM_CHARS; i++)
|
for (int i = 0; i < NUM_CHARS; i++) {
|
||||||
|
/* check for invalid glyph addresses */
|
||||||
|
if (charlist[i] + &map[233] > map + st.st_size) {
|
||||||
|
perror(NULL);
|
||||||
|
exit(EX_NOINPUT);
|
||||||
|
}
|
||||||
|
|
||||||
if (lookupchar(charlist[i], font) > -1) {
|
if (lookupchar(charlist[i], font) > -1) {
|
||||||
|
|
||||||
if (opt.info) {
|
if (opt.info) {
|
||||||
@ -275,6 +275,7 @@ font_t
|
|||||||
font->height = *p;
|
font->height = *p;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (opt.info) {
|
if (opt.info) {
|
||||||
printf("\n");
|
printf("\n");
|
||||||
@ -406,9 +407,17 @@ ibmtoutf8(char *a, char *u)
|
|||||||
void
|
void
|
||||||
printcolor(uint8_t color)
|
printcolor(uint8_t color)
|
||||||
{
|
{
|
||||||
|
|
||||||
uint8_t fg = color & 0x0f;
|
uint8_t fg = color & 0x0f;
|
||||||
uint8_t bg = (color & 0xf0) >> 4;
|
uint8_t bg = (color & 0xf0) >> 4;
|
||||||
|
|
||||||
|
/* thedraw colors DRK BRT BRT BRT RED BRT */
|
||||||
|
/* thedraw colors BLK BLU GRN CYN RED MAG BRN GRY GRY BLU GRN CYN RED PNK YLW WHT */
|
||||||
|
uint8_t fgacolors[] = {30, 34, 32, 36, 31, 35, 33, 37, 90, 94, 92, 96, 91, 95, 93, 97};
|
||||||
|
uint8_t bgacolors[] = {40, 44, 42, 46, 41, 45, 43, 47};
|
||||||
|
uint8_t fgmcolors[] = { 1, 2, 3, 10, 5, 6, 7, 15, 14, 12, 9, 11, 4, 13, 8, 0};
|
||||||
|
uint8_t bgmcolors[] = { 1, 2, 3, 10, 5, 6, 7, 15, 14, 12, 9, 11, 4, 13, 8, 0};
|
||||||
|
|
||||||
if (opt.color == COLOR_ANSI) {
|
if (opt.color == COLOR_ANSI) {
|
||||||
printf("\x1b[");
|
printf("\x1b[");
|
||||||
printf("%d;", fgacolors[fg]);
|
printf("%d;", fgacolors[fg]);
|
||||||
|
Loading…
Reference in New Issue
Block a user