X-Git-Url: https://git.dlugolecki.net.pl/?a=blobdiff_plain;f=standalone.c;h=75b662cecac7b6d47d773b961f6efb532c165eb3;hb=465e8c27883cb6e9c4df526e91da9c7bc1a7b506;hp=70a3ac17f80a8bb1a0f60ef811a560a6cfa735e1;hpb=3068ed1f64a96d42cdde19cfebf1468ec9169e62;p=gedcom-parse.git diff --git a/standalone.c b/standalone.c index 70a3ac1..75b662c 100644 --- a/standalone.c +++ b/standalone.c @@ -25,10 +25,15 @@ #include #include #include +#include +#include +#include #include "gedcom.h" +#include "utf8-locale.h" #define OUTFILE "testgedcom.out" FILE* outfile = NULL; +int quiet = 0; void output(int to_stdout_too, char* format, ...) { @@ -37,7 +42,7 @@ void output(int to_stdout_too, char* format, ...) if (outfile) { vfprintf(outfile, format, ap); } - if (to_stdout_too) { + if (to_stdout_too && !quiet) { vprintf(format, ap); } va_end(ap); @@ -57,6 +62,7 @@ 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(" -q No output to standard output\n"); } Gedcom_ctxt header_start(int level, Gedcom_val xref, char *tag, @@ -168,8 +174,12 @@ Gedcom_ctxt source_date_start(Gedcom_ctxt parent, int level, char *tag, void default_cb(Gedcom_ctxt ctxt, int level, char *tag, char *raw_value, int tag_value) { - output(0, "== %d %s (%d) %s (ctxt is %d)\n", - level, tag, tag_value, raw_value, (int)ctxt); + char *converted = NULL; + 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); } void subscribe_callbacks() @@ -234,6 +244,9 @@ int main(int argc, char* argv[]) else if (!strncmp(argv[i], "-3", 3)) { run_times = 3; } + else if (!strncmp(argv[i], "-q", 3)) { + quiet = 1; + } else if (strncmp(argv[i], "-", 1)) { file_name = argv[i]; break; @@ -252,6 +265,7 @@ int main(int argc, char* argv[]) exit(1); } + setlocale(LC_ALL, ""); gedcom_set_debug_level(debug_level, NULL); gedcom_set_compat_handling(compat_enabled); gedcom_set_error_handling(mech); @@ -269,11 +283,11 @@ int main(int argc, char* argv[]) } fclose(outfile); if (result == 0) { - printf("Parse succeeded\n"); + output(1, "Parse succeeded\n"); return 0; } else { - printf("Parse failed\n"); + output(1, "Parse failed\n"); return 1; } }