X-Git-Url: https://git.dlugolecki.net.pl/?a=blobdiff_plain;f=gedcom%2Fencoding.c;h=c2c3e8980686ae72d30f79d29057f988de278bb1;hb=0ed444394c30a2e3983fb551e7f788804116a8b4;hp=469854b0d8528aa78203db911c594f70cb8a547c;hpb=6cb2fba281c993d06b725b0ecb7cbe404f81aff7;p=gedcom-parse.git diff --git a/gedcom/encoding.c b/gedcom/encoding.c index 469854b..c2c3e89 100644 --- a/gedcom/encoding.c +++ b/gedcom/encoding.c @@ -22,24 +22,20 @@ /* $Name$ */ #include -#include #include #include #include #include "gedcom_internal.h" #include "gedcom.h" #include "encoding.h" +#include "encoding_state.h" #include "hash.h" -#include "utf8.h" +#include "utf8tools.h" #define ENCODING_CONF_FILE "gedcom.enc" #define GCONV_SEARCH_PATH "GCONV_PATH" #define MAXBUF 255 -/* -static iconv_t cd_to_internal = (iconv_t) -1; -*/ -static ENCODING the_enc = ONE_BYTE; static hash_t *encodings = NULL; const char* charwidth_string[] = { "1", "2_HILO", "2_LOHI" }; @@ -83,14 +79,20 @@ void add_encoding(const char *gedcom_n, const char* charwidth, MEMORY_ERROR; } -char* get_encoding(const char* gedcom_n, ENCODING enc) +char* get_encoding(const char* gedcom_n, Encoding enc) { char *key; hnode_t *node; + + if (encodings == NULL) return NULL; key = (char*)malloc(strlen(gedcom_n) + strlen(charwidth_string[enc]) + 3); if (key) { + char* sp_pos = NULL; + while ((sp_pos = strchr(gedcom_n, ' ')) != NULL) { + *sp_pos = '_'; + } /* sprintf is safe here (malloc'ed before) */ sprintf(key, "%s(%s)", gedcom_n, charwidth_string[enc]); @@ -222,6 +224,7 @@ void init_encodings() if (buffer[strlen(buffer) - 1] != '\n') { gedcom_error(_("Line too long in encoding configuration file '%s'"), ENCODING_CONF_FILE); + line_no = 0; return; } else if ((buffer[0] != '#') && (strcmp(buffer, "\n") != 0)) { @@ -231,10 +234,12 @@ void init_encodings() else { gedcom_error(_("Missing data in encoding configuration file '%s'"), ENCODING_CONF_FILE); + line_no = 0; return; } } } + line_no = 0; if (fclose(in) != 0) { gedcom_warning(_("Error closing file '%s': %s"), ENCODING_CONF_FILE, strerror(errno)); @@ -243,18 +248,13 @@ void init_encodings() } } -void set_encoding_width(ENCODING enc) -{ - the_enc = enc; -} - static convert_t to_int = NULL; static char* error_value = ""; int open_conv_to_internal(const char* fromcode) { convert_t new_to_int = NULL; - const char *encoding = get_encoding(fromcode, the_enc); + const char *encoding = get_encoding(fromcode, read_encoding.width); if (encoding != NULL) { new_to_int = initialize_utf8_conversion(encoding, 1); @@ -268,6 +268,7 @@ int open_conv_to_internal(const char* fromcode) if (to_int != NULL) cleanup_utf8_conversion(to_int); to_int = new_to_int; + set_read_encoding(fromcode, encoding); } return (new_to_int != NULL);