/* $Name$ */
#include "gedcom.h"
+#include "output.h"
+#include "portability.h"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
-#include <stdarg.h>
#include <locale.h>
#include <errno.h>
#include <iconv.h>
-#include "utf8-locale.h"
+#include "utf8tools.h"
-#define OUTFILE "testgedcom.out"
-#define BOGUS_FILE_NAME "Makefile.am"
-FILE* outfile = NULL;
-int quiet = 0;
-
-void output(int to_stdout_too, char* format, ...)
-{
- va_list ap;
- va_start(ap, format);
- if (outfile) {
- vfprintf(outfile, format, ap);
- }
- if (to_stdout_too && !quiet) {
- vprintf(format, ap);
- }
- va_end(ap);
-}
+#define BOGUS_FILE_NAME "bogus.ged"
+int total_conv_fails = 0;
void show_help ()
{
printf(" -da Debug setting: libgedcom + yacc debug messages\n");
printf(" -2 Run the test parse 2 times instead of once\n");
printf(" -3 Run the test parse 3 times instead of once\n");
- printf(" -b Parse a bogus file before parsing the main file\n");
+ printf(" -b Parse a bogus file (bogus.ged) before parsing the main file\n");
printf(" -q No output to standard output\n");
+ printf(" -o <outfile> File to generate output to (def. testgedcom.out)\n");
}
Gedcom_ctxt header_start(Gedcom_rec rec, int level, Gedcom_val xref, char *tag,
return (Gedcom_ctxt)1;
}
-void header_end(Gedcom_rec rec, Gedcom_ctxt self)
+void header_end(Gedcom_rec rec, Gedcom_ctxt self, Gedcom_val parsed_value)
{
- output(1, "Header end, context is %d\n", (int)self);
+ output(1, "Header end, context is %ld\n", void_ptr_to_int(self));
}
char family_xreftags[100][255];
struct xref_value *xr = GEDCOM_XREF_PTR(xref);
output(1, "Family start, xref is %s\n", xr->string);
strcpy(family_xreftags[family_nr], xr->string);
- xr->object = (Gedcom_ctxt)family_nr;
- return (Gedcom_ctxt)(family_nr++);
+ xr->object = (Gedcom_ctxt)int_to_void_ptr(family_nr);
+ return (Gedcom_ctxt)int_to_void_ptr(family_nr++);
}
Gedcom_ctxt rec_start(Gedcom_rec rec, int level, Gedcom_val xref, char *tag,
if (! GEDCOM_IS_NULL(xref))
xref_str = GEDCOM_XREF_PTR(xref)->string;
output(1, "Rec %s start, xref is %s\n", tag, xref_str);
- return (Gedcom_ctxt)tag_value;
+ return (Gedcom_ctxt)int_to_void_ptr(tag_value);
}
Gedcom_ctxt note_start(Gedcom_rec rec, int level, Gedcom_val xref, char *tag,
output(1, "== %d %s (%d) %s (xref is %s)\n",
level, tag, tag_value, GEDCOM_STRING(parsed_value),
GEDCOM_XREF_PTR(xref)->string);
- return (Gedcom_ctxt)tag_value;
+ return (Gedcom_ctxt)int_to_void_ptr(tag_value);
}
-void family_end(Gedcom_rec rec, Gedcom_ctxt self)
+void family_end(Gedcom_rec rec, Gedcom_ctxt self, Gedcom_val parsed_value)
{
- output(1, "Family end, xref is %s\n", family_xreftags[(int)self]);
+ output(1, "Family end, xref is %s\n",
+ family_xreftags[void_ptr_to_int(self)]);
}
Gedcom_ctxt submit_start(Gedcom_rec rec, int level, Gedcom_val xref, char *tag,
char *tag, char* raw_value,
int tag_value, Gedcom_val parsed_value)
{
- Gedcom_ctxt self = (Gedcom_ctxt)((int) parent + 1000);
- output(1, "Source is %s (ctxt is %d, parent is %d)\n",
- GEDCOM_STRING(parsed_value), (int) self, (int) parent);
+ Gedcom_ctxt self = (Gedcom_ctxt)(void_ptr_to_int(parent) + 1000);
+ output(1, "Source is %s (ctxt is %ld, parent is %ld)\n",
+ GEDCOM_STRING(parsed_value), void_ptr_to_int(self),
+ void_ptr_to_int(parent));
return self;
}
void source_end(Gedcom_elt elt, Gedcom_ctxt parent, Gedcom_ctxt self,
Gedcom_val parsed_value)
{
- output(1, "Source context %d in parent %d\n", (int)self, (int)parent);
+ output(1, "Source context %ld in parent %ld\n",
+ void_ptr_to_int(self), void_ptr_to_int(parent));
+}
+
+Gedcom_ctxt head_note_start(Gedcom_elt elt, Gedcom_ctxt parent, int level,
+ char *tag, char* raw_value,
+ int tag_value, Gedcom_val parsed_value)
+{
+ Gedcom_ctxt self = (Gedcom_ctxt)(void_ptr_to_int(parent));
+ output(1, "Note: %s (ctxt is %ld, parent is %ld)\n",
+ GEDCOM_STRING(parsed_value), void_ptr_to_int(self),
+ void_ptr_to_int(parent));
+ return self;
+}
+
+void head_note_end(Gedcom_elt elt, Gedcom_ctxt parent, Gedcom_ctxt self,
+ Gedcom_val parsed_value)
+{
+ output(1, "Complete note:\n%s\n", GEDCOM_STRING(parsed_value));
}
Gedcom_ctxt date_start(Gedcom_elt elt, Gedcom_ctxt parent, int level,
int tag_value, Gedcom_val parsed_value)
{
struct date_value dv;
- Gedcom_ctxt self = (Gedcom_ctxt)((int) parent + 1000);
+ Gedcom_ctxt self = (Gedcom_ctxt)(void_ptr_to_int(parent) + 1000);
dv = GEDCOM_DATE(parsed_value);
output(1, "Contents of the date_value:\n");
output(1, " raw value: %s\n", raw_value);
int tag_value, Gedcom_val parsed_value)
{
struct age_value age;
- Gedcom_ctxt self = (Gedcom_ctxt)((int) parent + 1000);
+ Gedcom_ctxt self = (Gedcom_ctxt)(void_ptr_to_int(parent) + 1000);
age = GEDCOM_AGE(parsed_value);
output(1, "Contents of the age_value:\n");
output(1, " raw value: %s\n", raw_value);
int conv_fails = 0;
if (raw_value)
converted = convert_utf8_to_locale(raw_value, &conv_fails);
- output(0, "== %d %s (%d) %s (ctxt is %d, conversion failures: %d)\n",
- level, tag, tag_value, converted, (int)ctxt, conv_fails);
+ output(0, "== %d %s (%d) %s (ctxt is %ld, conversion failures: %d)\n",
+ level, tag, tag_value, converted, void_ptr_to_int(ctxt), conv_fails);
+ total_conv_fails += conv_fails;
}
void subscribe_callbacks()
gedcom_subscribe_to_record(REC_SUBM, submit_start, NULL);
gedcom_subscribe_to_record(REC_USER, rec_start, NULL);
gedcom_subscribe_to_element(ELT_HEAD_SOUR, source_start, source_end);
+ gedcom_subscribe_to_element(ELT_HEAD_NOTE, head_note_start, head_note_end);
gedcom_subscribe_to_element(ELT_SOUR_DATA_EVEN_DATE,
date_start, NULL);
gedcom_subscribe_to_element(ELT_SUB_EVT_DATE, date_start, NULL);
int run_times = 1;
int bogus = 0;
int result = 0;
+ char* outfilename = NULL;
char* file_name = NULL;
if (argc > 1) {
bogus = 1;
}
else if (!strncmp(argv[i], "-q", 3)) {
- quiet = 1;
+ output_set_quiet(1);
+ }
+ else if (!strncmp(argv[i], "-o", 3)) {
+ i++;
+ if (i < argc) {
+ outfilename = argv[i];
+ }
+ else {
+ printf ("Missing output file name\n");
+ show_help();
+ exit(1);
+ }
}
else if (strncmp(argv[i], "-", 1)) {
file_name = argv[i];
gedcom_set_default_callback(default_cb);
subscribe_callbacks();
- outfile = fopen(OUTFILE, "a");
- if (!outfile) {
- printf("Could not open %s for appending\n", OUTFILE);
- }
+ output_open(outfilename);
if (bogus) {
output(0, "\n=== Parsing bogus file %s\n", BOGUS_FILE_NAME);
gedcom_parse_file(BOGUS_FILE_NAME);
}
while (run_times-- > 0) {
- output(0, "\n=== Parsing file %s\n", file_name);
+ output(0, "\n=== Parsing file %s\n", simple_base_name(file_name));
result |= gedcom_parse_file(file_name);
+ output(0, "\n=== Total conversion failures: %d\n", total_conv_fails);
}
if (result == 0) {
output(1, "Parse succeeded\n");
else {
output(1, "Parse failed\n");
}
- fclose(outfile);
+ output_close();
return result;
}