/* The lexer multiplexer for Gedcom.
- Copyright (C) 2001 The Genes Development Team
+ Copyright (C) 2001,2002 The Genes Development Team
This file is part of the Gedcom parser library.
Contributed by Peter Verthez <Peter.Verthez@advalvas.be>, 2001.
#include "gedcom_internal.h"
#include "multilex.h"
#include "encoding.h"
+#include "xref.h"
int line_no;
}
}
+static int init_called = 0;
+
+void gedcom_init()
+{
+ init_called = 1;
+ update_gconv_search_path();
+}
+
int gedcom_parse_file(char* file_name)
{
ENCODING enc;
int result = 1;
FILE* file;
+ char *save_locale = strdup(setlocale(LC_ALL, NULL));
char *save_textdom = textdomain(NULL);
- setlocale(LC_ALL, ""); /* In fact only necessary if main program doesn't
- do this */
+ setlocale(LC_ALL, "");
bindtextdomain(PACKAGE, LOCALEDIR);
+ bind_textdomain_codeset(PACKAGE, INTERNAL_ENCODING);
textdomain(PACKAGE);
- line_no = 1;
- file = fopen(file_name, "r");
- if (!file) {
- gedcom_error(_("Could not open file '%s'"), file_name);
+ if (!init_called) {
+ gedcom_error(_("Internal error: GEDCOM parser not initialized"));
}
else {
- init_encodings();
- enc = determine_encoding(file);
-
- if (lexer_init(enc, file)) {
- line_no = 1;
- result = gedcom_parse();
+ line_no = 1;
+ file = fopen(file_name, "r");
+ if (!file) {
+ gedcom_error(_("Could not open file '%s'"), file_name);
+ }
+ else {
+ init_encodings();
+ enc = determine_encoding(file);
+
+ if (lexer_init(enc, file)) {
+ line_no = 1;
+ make_xref_table();
+ result = gedcom_parse();
+ if (result == 0)
+ result = check_xref_table();
+ }
+ lexer_close();
+ fclose(file);
}
- lexer_close();
- fclose(file);
}
textdomain(save_textdom);
+ setlocale(LC_ALL, save_locale);
+ free(save_locale);
return result;
}