X-Git-Url: https://git.dlugolecki.net.pl/?a=blobdiff_plain;f=t%2Fsrc%2Fstandalone.c;h=7868cf24b9dba1898a756422c6518e606ea4f1ef;hb=66bb0d0211925f3ff0e4f087e6c9a948d1b1260d;hp=5efb08197bc7026034277db5bbb26ac02574c08e;hpb=40b99549ec69cb65fc3b979c6383bed5b88af7f4;p=gedcom-parse.git diff --git a/t/src/standalone.c b/t/src/standalone.c index 5efb081..7868cf2 100644 --- a/t/src/standalone.c +++ b/t/src/standalone.c @@ -22,32 +22,18 @@ /* $Name$ */ #include "gedcom.h" +#include "output.h" +#include "portability.h" #include #include #include -#include #include #include #include -#include "utf8-locale.h" +#include "utf8.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 () { @@ -63,8 +49,9 @@ 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 File to generate output to (def. testgedcom.out)\n"); } Gedcom_ctxt header_start(Gedcom_rec rec, int level, Gedcom_val xref, char *tag, @@ -77,7 +64,7 @@ Gedcom_ctxt header_start(Gedcom_rec rec, int level, Gedcom_val xref, char *tag, void header_end(Gedcom_rec rec, Gedcom_ctxt self) { - 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]; @@ -90,8 +77,8 @@ Gedcom_ctxt family_start(Gedcom_rec rec, int level, Gedcom_val xref, char *tag, 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, @@ -102,7 +89,7 @@ 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, @@ -112,12 +99,13 @@ 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) { - 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, @@ -132,16 +120,18 @@ Gedcom_ctxt source_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)((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 date_start(Gedcom_elt elt, Gedcom_ctxt parent, int level, @@ -149,7 +139,7 @@ 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); @@ -179,7 +169,7 @@ Gedcom_ctxt age_start(Gedcom_elt elt, Gedcom_ctxt parent, int level, 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); @@ -199,8 +189,9 @@ void default_cb(Gedcom_elt elt, Gedcom_ctxt ctxt, int level, char *tag, 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() @@ -241,6 +232,7 @@ int main(int argc, char* argv[]) int run_times = 1; int bogus = 0; int result = 0; + char* outfilename = NULL; char* file_name = NULL; if (argc > 1) { @@ -272,7 +264,18 @@ int main(int argc, char* argv[]) 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]; @@ -301,17 +304,15 @@ int main(int argc, char* argv[]) 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"); @@ -319,6 +320,6 @@ int main(int argc, char* argv[]) else { output(1, "Parse failed\n"); } - fclose(outfile); + output_close(); return result; }