- FILE* file = fopen (file_name, "r");
- line_no = 1;
- if (!file) {
- gedcom_error("Could not open file '%s'\n", file_name);
- return 1;
+ FILE* file;
+
+ if (!init_called) {
+ gedcom_error(_("Internal error: GEDCOM parser not initialized"));
+ }
+ else {
+ file = fopen(file_name, "r");
+ if (!file) {
+ gedcom_error(_("Could not open file '%s': %s"),
+ file_name, strerror(errno));
+ }
+ else {
+ init_encodings();
+ enc = determine_encoding(file);
+
+ if (lexer_init(enc, file)) {
+ line_no = 0;
+ make_xref_table();
+ result = gedcom_parse();
+ line_no = 0;
+ if (result == 0)
+ result = check_xref_table();
+ }
+ lexer_close();
+ fclose(file);
+ }