key = (char *) malloc(strlen(gedcom_n) + strlen(charwidth) + 3);
val = (char *) malloc(strlen(iconv_n) + 1);
key = (char *) malloc(strlen(gedcom_n) + strlen(charwidth) + 3);
val = (char *) malloc(strlen(iconv_n) + 1);
- /* sprintf is safe here (malloc'ed before) */
- sprintf(key, "%s(%s)", gedcom_n, charwidth);
- strcpy(val, 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);
+ if (key && val) {
+ /* sprintf is safe here (malloc'ed before) */
+ sprintf(key, "%s(%s)", gedcom_n, charwidth);
+ strcpy(val, 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);
+ }
- node = hash_lookup(encodings, key);
- free(key);
- if (node) {
- return hnode_get(node);
+ if (key) {
+ /* sprintf is safe here (malloc'ed before) */
+ sprintf(key, "%s(%s)", gedcom_n, charwidth_string[enc]);
+
+ node = hash_lookup(encodings, key);
+ free(key);
+ if (node) {
+ return hnode_get(node);
+ }
+ else {
+ gedcom_error(_("No encoding defined for '%s'"), gedcom_n);
+ return NULL;
+ }
- sprintf(new_gconv_path, "%s=%s", GCONV_SEARCH_PATH, PKGDATADIR);
+ if (new_gconv_path)
+ sprintf(new_gconv_path, "%s=%s", GCONV_SEARCH_PATH, PKGDATADIR);
- sprintf(new_gconv_path, "%s=%s:%s",
- GCONV_SEARCH_PATH, gconv_path, PKGDATADIR);
+ if (new_gconv_path)
+ sprintf(new_gconv_path, "%s=%s:%s",
+ GCONV_SEARCH_PATH, gconv_path, PKGDATADIR);
+ }
+ if (new_gconv_path)
+ /* Ignore failures of putenv (can't do anything about it anyway) */
+ putenv(new_gconv_path);
+ else {
+ fprintf(stderr, "Could not allocate memory at %s, %d\n",
+ __FILE__, __LINE__);
+ abort();
encodings = hash_create(HASHCOUNT_T_MAX, NULL, NULL);
hash_set_allocator(encodings, node_alloc, node_free, NULL);
encodings = hash_create(HASHCOUNT_T_MAX, NULL, NULL);
hash_set_allocator(encodings, node_alloc, node_free, NULL);
- gedcom_warning(_("Could not open encoding configuration file '%s'"),
- ENCODING_CONF_FILE);
+ gedcom_warning(_("Could not open encoding configuration file '%s': %s"),
+ ENCODING_CONF_FILE, strerror(errno));
}
/* then shift what is left over to the head of the input buffer */
memmove(conv_buf, rdptr, conv_buf_size);
}
/* then shift what is left over to the head of the input buffer */
memmove(conv_buf, rdptr, conv_buf_size);