+ else
+ return 0;
+}
+
+/** This function parses the given file. By itself, it doesn't provide any
+ other information than the parse result.
+
+ The function also empties the cross-reference table before parsing, and
+ checks the validity of the
+ cross-references if the parse was successful.
+ The following conditions can occur in the cross-reference table:
+ - An xref was defined, but not used (warning)
+ - An xref was used, but not defined (error)
+ - An xref was used as a different type than the defined type (error)
+
+ \param file_name The name of the Gedcom file to parse
+
+ \retval 0 if the parse was successful and no errors were found in the
+ cross-reference table
+ \retval nonzero on errors, which can include:
+ - \ref gedcom_init() was not called
+ - The given file was not found
+ - The parse of the given file failed
+ - There were errors found in the cross-reference table
+ */
+
+int gedcom_parse_file(const char* file_name)
+{
+ Encoding enc;
+ int result = 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 {
+ line_no = 1;
+ 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);
+ }