diff options
| author | Ben Harris <bjh21@bjh21.me.uk> | 2006-12-05 00:04:18 +0000 |
|---|---|---|
| committer | Ben Harris <bjh21@bjh21.me.uk> | 2006-12-05 00:04:18 +0000 |
| commit | 293cc0fcf0f33b5d70635acf7379088a23e19d65 (patch) | |
| tree | b0d0e80575c5e8afd19aa04b8ee0a5c9c6fd2ea2 | |
| parent | 1fd1d665dfd86fe3d0586a4ba2a651de2617080a (diff) | |
| download | halibut-293cc0fcf0f33b5d70635acf7379088a23e19d65.zip halibut-293cc0fcf0f33b5d70635acf7379088a23e19d65.tar.gz halibut-293cc0fcf0f33b5d70635acf7379088a23e19d65.tar.bz2 halibut-293cc0fcf0f33b5d70635acf7379088a23e19d65.tar.xz | |
Distingush font files from other input by magic number rather than name.
This prevents one having Halibut files that begin "StartFontMetrics",
"%!FontType1-", or "%!PS-AdobeFont-", but I doubt that will be a great
hardship.
[originally from svn r6960]
| -rw-r--r-- | input.c | 33 |
1 files changed, 26 insertions, 7 deletions
@@ -1561,10 +1561,23 @@ static void read_file(paragraph ***ret, input *in, indexdata *idx, stk_free(crossparastk); } +struct { + char const *magic; + size_t nmagic; + void (*reader)(input *); +} magics[] = { + { "%!FontType1-", 12, &read_pfa_file }, + { "%!PS-AdobeFont-", 15, &read_pfa_file }, + { "StartFontMetrics", 16, &read_afm_file }, +}; + paragraph *read_input(input *in, indexdata *idx) { paragraph *head = NULL; paragraph **hptr = &head; tree234 *macros; + char mag[16]; + size_t len, i; + void (*reader)(input *); macros = newtree234(macrocmp); @@ -1576,14 +1589,20 @@ paragraph *read_input(input *in, indexdata *idx) { in->csstate = charset_init_state; in->wcpos = in->nwc = 0; in->pushback_chars = NULL; - if (strcmp(in->filenames[in->currindex] + - strlen(in->filenames[in->currindex]) - 4, ".afm") == 0) - read_afm_file(in); - else if (strcmp(in->filenames[in->currindex] + - strlen(in->filenames[in->currindex]) - 4, ".pfa") == 0) - read_pfa_file(in); - else + reader = NULL; + len = fread(mag, 1, sizeof(mag), in->currfp); + for (i = 0; i < lenof(magics); i++) { + if (len >= magics[i].nmagic && + memcmp(mag, magics[i].magic, magics[i].nmagic) == 0) { + reader = magics[i].reader; + break; + } + } + rewind(in->currfp); + if (reader == NULL) read_file(&hptr, in, idx, macros); + else + (*reader)(in); } in->currindex++; } |