summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Tatham <anakin@pobox.com>2010-02-27 23:42:39 +0000
committerSimon Tatham <anakin@pobox.com>2010-02-27 23:42:39 +0000
commite28f65738fadfe12b945db1e82f5d2c1a3f14553 (patch)
treed9b5d4a3ddf00f6a0c995d3cb491b86965fb2aad
parent70c9bbe29108065fdf1449e8b7b8b989d9bde36b (diff)
downloadhalibut-e28f65738fadfe12b945db1e82f5d2c1a3f14553.zip
halibut-e28f65738fadfe12b945db1e82f5d2c1a3f14553.tar.gz
halibut-e28f65738fadfe12b945db1e82f5d2c1a3f14553.tar.bz2
halibut-e28f65738fadfe12b945db1e82f5d2c1a3f14553.tar.xz
A user recently reported that Halibut's font-file handling doesn't
work on Windows, because input files are never opened in binary mode. Introduce a small piece of compensatory mechanism, which opens files initially in binary mode and then reopens them as text if they're determined not to match any binary file type. I hope. [originally from svn r8889]
-rw-r--r--input.c32
1 files changed, 23 insertions, 9 deletions
diff --git a/input.c b/input.c
index 4978bb9..8556d9f 100644
--- a/input.c
+++ b/input.c
@@ -1581,14 +1581,15 @@ static void read_file(paragraph ***ret, input *in, indexdata *idx,
struct {
char const *magic;
size_t nmagic;
+ int binary;
void (*reader)(input *);
} magics[] = {
- { "%!FontType1-", 12, &read_pfa_file },
- { "%!PS-AdobeFont-", 15, &read_pfa_file },
- { "\x80\x01", 2, &read_pfb_file },
- { "StartFontMetrics", 16, &read_afm_file },
- { "\x00\x01\x00\x00", 4, &read_sfnt_file },
- { "true", 4, &read_sfnt_file },
+ { "%!FontType1-", 12, FALSE, &read_pfa_file },
+ { "%!PS-AdobeFont-", 15, FALSE, &read_pfa_file },
+ { "\x80\x01", 2, TRUE, &read_pfb_file },
+ { "StartFontMetrics", 16, FALSE, &read_afm_file },
+ { "\x00\x01\x00\x00", 4, TRUE, &read_sfnt_file },
+ { "true", 4, TRUE, &read_sfnt_file },
};
paragraph *read_input(input *in, indexdata *idx) {
@@ -1597,6 +1598,7 @@ paragraph *read_input(input *in, indexdata *idx) {
tree234 *macros;
char mag[16];
size_t len, i;
+ int binary;
void (*reader)(input *);
macros = newtree234(macrocmp);
@@ -1618,7 +1620,13 @@ paragraph *read_input(input *in, indexdata *idx) {
*/
reader = NULL;
} else {
- in->currfp = fopen(in->filenames[in->currindex], "r");
+ /*
+ * Open the file in binary mode to look for magic
+ * numbers. We'll switch to text mode if we find we're
+ * looking at a text file type.
+ */
+ in->currfp = fopen(in->filenames[in->currindex], "rb");
+ binary = FALSE; /* default to Halibut source, which is text */
if (in->currfp) {
in->wantclose = TRUE;
reader = NULL;
@@ -1627,17 +1635,23 @@ paragraph *read_input(input *in, indexdata *idx) {
if (len >= magics[i].nmagic &&
memcmp(mag, magics[i].magic, magics[i].nmagic) == 0) {
reader = magics[i].reader;
+ binary = magics[i].binary;
break;
}
}
rewind(in->currfp);
}
+ if (!binary) {
+ fclose(in->currfp);
+ in->currfp = fopen(in->filenames[in->currindex], "r");
+ }
}
if (in->currfp) {
- if (reader == NULL)
+ if (reader == NULL) {
read_file(&hptr, in, idx, macros);
- else
+ } else {
(*reader)(in);
+ }
}
in->currindex++;
}