10 typedef int (*lex_func)(void);
13 int lexer_init(ENCODING enc, FILE* f)
15 if (enc == ONE_BYTE) {
17 lf = &gedcom_1byte_lex;
18 set_encoding_width(enc);
19 return open_conv_to_internal("ASCII");
21 else if (enc == TWO_BYTE_HILO) {
23 lf = &gedcom_hilo_lex;
24 set_encoding_width(enc);
25 return open_conv_to_internal("UNICODE");
27 else if (enc == TWO_BYTE_LOHI) {
29 lf = &gedcom_lohi_lex;
30 set_encoding_width(enc);
31 return open_conv_to_internal("UNICODE");
40 close_conv_to_internal();
48 int determine_encoding(FILE* f)
52 fread(first, 1, 2, f);
53 if ((first[0] == '0') && (first[1] == ' ')) {
54 gedcom_message("One-byte encoding");
58 else if ((first[0] == '\0') && (first[1] == '0'))
60 gedcom_message("Two-byte encoding, high-low");
64 else if ((first[0] == '\xFE') && (first[1] == '\xFF'))
66 gedcom_message("Two-byte encoding, high-low, with BOM");
69 else if ((first[0] == '0') && (first[1] == '\0'))
71 gedcom_message("Two-byte encoding, low-high");
75 else if ((first[0] == '\xFF') && (first[1] == '\xFE'))
77 gedcom_message("Two-byte encoding, low-high, with BOM");
81 gedcom_message("Unknown encoding, falling back to one-byte");
87 int gedcom_parse_file(char* file_name)
91 FILE* file = fopen (file_name, "r");
93 gedcom_error("Could not open file '%s'\n", file_name);
98 enc = determine_encoding(file);
100 if (lexer_init(enc, file)) {
101 result = gedcom_parse();