X-Git-Url: https://git.dlugolecki.net.pl/?a=blobdiff_plain;f=gedcom%2Fcompat.c;h=3b725483ba8b684798f5d896a1c02d0c70874ac5;hb=7cbefaec45b82eb0449465da19d38a89f2ff2cf3;hp=21cac35344407b1d6d4168f8017e372b4c72d985;hpb=9e93d730fa358da974e770e8778b78645e2043f9;p=gedcom-parse.git diff --git a/gedcom/compat.c b/gedcom/compat.c index 21cac35..3b72548 100644 --- a/gedcom/compat.c +++ b/gedcom/compat.c @@ -31,7 +31,7 @@ int compat_enabled = 1; int compatibility = 0; int compat_at = 0; -char* default_charset = ""; +const char* default_charset = ""; #define SUBMITTER_LINK "@__COMPAT__SUBM__@" #define DEFAULT_SUBMITTER_NAME "Submitter" @@ -61,8 +61,13 @@ void gedcom_set_compat_handling(int enable_compat) compat_enabled = enable_compat; } -void set_compatibility(char* program) +void set_compatibility(const char* program) { + /* Reinitialize compatibility */ + compat_at = 0; + default_charset = ""; + compatibility = 0; + if (compat_enabled) { if (! strncmp(program, "ftree", 6)) { gedcom_warning(_("Enabling compatibility with 'ftree'")); @@ -75,9 +80,6 @@ void set_compatibility(char* program) default_charset = "ANSI"; compat_at = 1; } - else { - compatibility = 0; - } } } @@ -166,15 +168,24 @@ int compat_generate_char(Gedcom_ctxt parent) { struct tag_struct ts; Gedcom_ctxt self1; + char* charset; /* first generate "1 CHAR " */ ts.string = "CHAR"; ts.value = TAG_CHAR; - self1 = start_element(ELT_HEAD_CHAR, parent, 1, ts, default_charset, - GEDCOM_MAKE_STRING(val1, default_charset)); - - /* close "1 CHAR" */ - end_element(ELT_HEAD_CHAR, parent, self1, NULL); + + /* Must strdup, because default_charset is const char */ + charset = strdup(default_charset); + if (! charset) + MEMORY_ERROR; + else { + self1 = start_element(ELT_HEAD_CHAR, parent, 1, ts, charset, + GEDCOM_MAKE_STRING(val1, charset)); + free(charset); + + /* close "1 CHAR" */ + end_element(ELT_HEAD_CHAR, parent, self1, NULL); + } if (open_conv_to_internal(default_charset) == 0) return 1; else