X-Git-Url: https://git.dlugolecki.net.pl/?a=blobdiff_plain;f=gedcom%2Fencoding.c;h=c2c3e8980686ae72d30f79d29057f988de278bb1;hb=6103dd898c4de86c68891cc0222543988a2caab7;hp=4828c0a6a7d3c7bc9e9ef89537b6f17b1b39efb7;hpb=246182eba8a18f8d644d0a3ef9556000fae12aa1;p=gedcom-parse.git diff --git a/gedcom/encoding.c b/gedcom/encoding.c index 4828c0a..c2c3e89 100644 --- a/gedcom/encoding.c +++ b/gedcom/encoding.c @@ -28,6 +28,7 @@ #include "gedcom_internal.h" #include "gedcom.h" #include "encoding.h" +#include "encoding_state.h" #include "hash.h" #include "utf8tools.h" @@ -35,8 +36,6 @@ #define GCONV_SEARCH_PATH "GCONV_PATH" #define MAXBUF 255 -struct encoding_state read_encoding; - static hash_t *encodings = NULL; const char* charwidth_string[] = { "1", "2_HILO", "2_LOHI" }; @@ -90,6 +89,10 @@ char* get_encoding(const char* gedcom_n, Encoding enc) 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]); @@ -245,21 +248,6 @@ void init_encodings() } } -void set_encoding_width(Encoding enc) -{ - read_encoding.width = enc; -} - -void set_encoding_bom(Enc_bom bom) -{ - read_encoding.bom = bom; -} - -void set_encoding_terminator(char* term) -{ - strncpy(read_encoding.terminator, term, MAX_TERMINATOR_LEN); -} - static convert_t to_int = NULL; static char* error_value = ""; @@ -280,16 +268,7 @@ int open_conv_to_internal(const char* fromcode) if (to_int != NULL) cleanup_utf8_conversion(to_int); to_int = new_to_int; - strncpy(read_encoding.charset, fromcode, MAX_CHARSET_LEN); - read_encoding.encoding = encoding; - gedcom_debug_print("Encoding state is now: "); - gedcom_debug_print(" charset : %s", read_encoding.charset); - gedcom_debug_print(" encoding : %s", read_encoding.encoding); - gedcom_debug_print(" width : %d", read_encoding.width); - gedcom_debug_print(" BOM : %d", read_encoding.bom); - gedcom_debug_print(" terminator: 0x%02x 0x%02x", - read_encoding.terminator[0], - read_encoding.terminator[1]); + set_read_encoding(fromcode, encoding); } return (new_to_int != NULL);