#define WRITE_GEDCOM "gom_write.ged"
#define PROG_NAME "writegomtest"
#define PROG_VERSION "3.14"
+#define TIMESTAMP 1000000000L
void gedcom_message_handler(Gedcom_msg_type type, char *msg)
{
printf(" -h Show this help text\n");
printf(" -q No output to standard output\n");
printf(" -o <outfile> File to generate errors to (def. testgedcom.out)\n");
+ printf(" -i <gedfile> File to read gedcom from (default: new file)\n");
printf(" -w <gedfile> File to write gedcom to (def. %s)\n", WRITE_GEDCOM);
printf(" -e <encoding> Encoding (UNICODE, ASCII, ANSEL, ...: see gedcom.enc)\n");
printf(" -u <unicode_enc> Encoding details for Unicode\n");
printf(" <terminator> can be CR, LF, CR_LF, LF_CR\n");
}
-int update_charset(char* encoding)
+int update_header(char* encoding)
{
struct header* head = NULL;
char* value;
+ char* long_note = "This note is for testing the continuation stuff\n"
+ "Some Specials: This line is very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very long but too long (255 caharcters is the limit), so this is going over the border\n"
+ "And now we have an at character: @, which should be doubled";
head = gom_get_header();
if (head == NULL)
return 1;
else {
- value = gom_set_string(&head->charset.name, encoding);
- if (value == NULL || strcmp(value, encoding))
+ /* force warning for anything except UNICODE */
+ if (!strcmp(encoding, "UNICODE")) {
+ value = gom_set_string(&head->charset.name, encoding);
+ if (value == NULL || strcmp(value, encoding))
+ return 1;
+ }
+ value = gom_set_string(&head->note, long_note);
+ if (value == NULL || strcmp(value, long_note))
return 1;
else
return 0;
}
}
+int test_timestamps()
+{
+ int result = 0;
+ struct tm* tm_ptr;
+ time_t tval;
+ /* Make sure we get a reproduceable output, in different timezones */
+ tval = TIMESTAMP;
+ tm_ptr = gmtime(&tval);
+ tm_ptr->tm_isdst = 0;
+ tval = mktime(tm_ptr);
+ result = gom_header_update_timestamp(tval);
+
+ /* Also change timestamp of submitter */
+ if (result == 0) {
+ struct submitter* subm = gom_get_first_submitter();
+ if (!subm)
+ result = 100;
+ else {
+ result = gom_update_timestamp(&(subm->change_date), tval);
+ }
+ }
+
+ return result;
+}
+
int main(int argc, char* argv[])
{
int result;
int total_conv_fails = 0;
char* outfilename = NULL;
+ char* infilename = NULL;
char* gedfilename = WRITE_GEDCOM;
char* encoding = "ASCII";
Encoding enc = ONE_BYTE;
exit(1);
}
}
+ else if (!strncmp(argv[i], "-i", 3)) {
+ i++;
+ if (i < argc) {
+ infilename = argv[i];
+ }
+ else {
+ printf ("Missing input file name\n");
+ show_help();
+ exit(1);
+ }
+ }
else if (!strncmp(argv[i], "-e", 3)) {
i++;
if (i < argc) {
gedcom_init();
setlocale(LC_ALL, "");
gedcom_set_message_handler(gedcom_message_handler);
- gedcom_write_set_encoding(encoding, enc, bom);
- gedcom_write_set_line_terminator(end);
output_open(outfilename);
-
- result = gom_new_model();
- /*
- if (result == 0)
- result |= update_charset(encoding);
- */
+
+ if (infilename) {
+ result = gom_parse_file(infilename);
+ }
+ else {
+ gedcom_write_set_encoding(ENC_MANUAL, encoding, enc, bom);
+ gedcom_write_set_line_terminator(ENC_MANUAL, end);
+ result = gom_new_model();
+ if (result == 0)
+ result |= update_header(encoding);
+ }
if (result == 0)
+ result |= test_timestamps();
+ if (result == 0) {
+ output(1, "Writing file...\n");
result |= gom_write_file(gedfilename, &total_conv_fails);
+ }
if (result == 0 && total_conv_fails == 0) {
+ output(1, "Re-parsing file...\n");
+ gedcom_set_compat_handling(0);
+ result |= gom_parse_file(gedfilename);
+ }
+ if (result == 0) {
output(1, "Test succeeded\n");
}
else {