X-Git-Url: https://git.dlugolecki.net.pl/?a=blobdiff_plain;f=gedcom%2Fencoding.c;h=9e4e9199561ca0778914aedf7ed89dff227d7628;hb=9d3427915335b190847849effbd33a9e568b6fbe;hp=7e00f767b9f85cdc546fceba9ff36e1d0318fb24;hpb=ba123c650193eb37ab152b5083b67364e8bacf30;p=gedcom-parse.git diff --git a/gedcom/encoding.c b/gedcom/encoding.c index 7e00f76..9e4e919 100644 --- a/gedcom/encoding.c +++ b/gedcom/encoding.c @@ -33,7 +33,6 @@ #define ENCODING_CONF_FILE "gedcom.enc" #define GCONV_SEARCH_PATH "GCONV_PATH" #define MAXBUF 255 -#define INIT_NR_ENCODINGS 10 static iconv_t cd_to_internal = (iconv_t) -1; static ENCODING the_enc = ONE_BYTE; @@ -67,6 +66,8 @@ void add_encoding(char *gedcom_n, char* charwidth, char *iconv_n) if (hash_lookup(encodings, key)) { gedcom_warning(_("Duplicate entry found for encoding '%s', ignoring"), gedcom_n); + free(key); + free(val); } else { hash_alloc_insert(encodings, key, val); @@ -98,6 +99,35 @@ void cleanup_encodings() hash_free(encodings); } +/* Let function be called before main() */ +void update_gconv_search_path() __attribute__ ((constructor)); + +void update_gconv_search_path() +{ + char *gconv_path; + /* Add gedcom data directory to gconv search path */ + gconv_path = getenv(GCONV_SEARCH_PATH); + if (gconv_path == NULL || strstr(gconv_path, PKGDATADIR) == NULL) { + char *new_gconv_path; + if (gconv_path == NULL) { + new_gconv_path = (char *)malloc(strlen(GCONV_SEARCH_PATH) + + strlen(PKGDATADIR) + + 2); + sprintf(new_gconv_path, "%s=%s", GCONV_SEARCH_PATH, PKGDATADIR); + } + else { + new_gconv_path = (char *)malloc(strlen(GCONV_SEARCH_PATH) + + strlen(gconv_path) + + strlen(PKGDATADIR) + + 3); + sprintf(new_gconv_path, "%s=%s:%s", + GCONV_SEARCH_PATH, gconv_path, PKGDATADIR); + } + /* Ignore failures of putenv (can't do anything about it anyway) */ + putenv(new_gconv_path); + } +} + void init_encodings() { if (encodings == NULL) { @@ -106,34 +136,10 @@ void init_encodings() char gedcom_n[MAXBUF + 1]; char charwidth[MAXBUF + 1]; char iconv_n[MAXBUF + 1]; - char *gconv_path; atexit(cleanup_encodings); - /* Add gedcom data directory to gconv search path */ - gconv_path = getenv(GCONV_SEARCH_PATH); - if (gconv_path == NULL || strstr(gconv_path, PKGDATADIR) == NULL) { - char *new_gconv_path; - if (gconv_path == NULL) { - new_gconv_path = (char *)malloc(strlen(GCONV_SEARCH_PATH) - + strlen(PKGDATADIR) - + 2); - sprintf(new_gconv_path, "%s=%s", GCONV_SEARCH_PATH, PKGDATADIR); - } - else { - new_gconv_path = (char *)malloc(strlen(GCONV_SEARCH_PATH) - + strlen(gconv_path) - + strlen(PKGDATADIR) - + 3); - sprintf(new_gconv_path, "%s=%s:%s", - GCONV_SEARCH_PATH, gconv_path, PKGDATADIR); - } - if (putenv(new_gconv_path) != 0) { - gedcom_warning(_("Failed updating conversion module path")); - } - } - - encodings = hash_create(INIT_NR_ENCODINGS, NULL, NULL); + encodings = hash_create(HASHCOUNT_T_MAX, NULL, NULL); hash_set_allocator(encodings, node_alloc, node_free, NULL); /* Open gedcom configuration file and read */