X-Git-Url: https://git.dlugolecki.net.pl/?a=blobdiff_plain;ds=sidebyside;f=gedcom%2Fencoding.c;h=4828c0a6a7d3c7bc9e9ef89537b6f17b1b39efb7;hb=de22c4a7da9703ac654a271fcd0212023192d256;hp=e0140b2f1dff7d32e24743748f10b42004d74f21;hpb=4c78192cf17bde2f3c6bff7bb90757c21d1e3792;p=gedcom-parse.git diff --git a/gedcom/encoding.c b/gedcom/encoding.c index e0140b2..4828c0a 100644 --- a/gedcom/encoding.c +++ b/gedcom/encoding.c @@ -29,13 +29,14 @@ #include "gedcom.h" #include "encoding.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 Encoding the_enc = ONE_BYTE; +struct encoding_state read_encoding; + static hash_t *encodings = NULL; const char* charwidth_string[] = { "1", "2_HILO", "2_LOHI" }; @@ -246,7 +247,17 @@ void init_encodings() void set_encoding_width(Encoding enc) { - the_enc = 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; @@ -255,7 +266,7 @@ 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); @@ -269,6 +280,16 @@ 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]); } return (new_to_int != NULL);