/* $Name$ */
#include <string.h>
-#include <iconv.h>
#include <stdio.h>
#include <limits.h>
#include <stdlib.h>
#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" };
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]);
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)) {
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));
}
}
-void set_encoding_width(ENCODING enc)
-{
- the_enc = enc;
-}
-
static convert_t to_int = NULL;
static char* error_value = "<error>";
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);
if (to_int != NULL)
cleanup_utf8_conversion(to_int);
to_int = new_to_int;
+ set_read_encoding(fromcode, encoding);
}
return (new_to_int != NULL);