From 503f53bfdde87fc40466dadb77bc04cee0be2567 Mon Sep 17 00:00:00 2001 From: John Darrington Date: Fri, 27 Mar 2009 13:47:01 +0900 Subject: [PATCH] Read dictionary encoding from data files. If record 7 subtype 20 exists, use it to set the encoding of the dictionary when reading a file. --- src/data/dictionary.c | 19 +++++++++++++++++++ src/data/dictionary.h | 5 +++++ src/data/sys-file-reader.c | 7 ++++++- src/libpspp/i18n.c | 3 --- src/ui/gui/psppire-dict.c | 2 +- 5 files changed, 31 insertions(+), 5 deletions(-) diff --git a/src/data/dictionary.c b/src/data/dictionary.c index ba840898..1c50ac7f 100644 --- a/src/data/dictionary.c +++ b/src/data/dictionary.c @@ -63,6 +63,9 @@ struct dictionary struct vector **vector; /* Vectors of variables. */ size_t vector_cnt; /* Number of vectors. */ struct attrset attributes; /* Custom attributes. */ + + char *encoding; /* Character encoding of string data */ + const struct dict_callbacks *callbacks; /* Callbacks on dictionary modification */ void *cb_data ; /* Data passed to callbacks */ @@ -71,6 +74,20 @@ struct dictionary void *changed_data; }; + +void +dict_set_encoding (struct dictionary *d, const char *enc) +{ + d->encoding = strdup (enc); +} + +const char * +dict_get_encoding (const struct dictionary *d) +{ + return d->encoding ; +} + + void dict_set_change_callback (struct dictionary *d, void (*changed) (struct dictionary *, void*), @@ -194,6 +211,8 @@ dict_clone (const struct dictionary *s) for (i = 0; i < s->vector_cnt; i++) d->vector[i] = vector_clone (s->vector[i], s, d); + d->encoding = strdup (s->encoding); + dict_set_attributes (d, dict_get_attributes (s)); return d; diff --git a/src/data/dictionary.h b/src/data/dictionary.h index 18bf3f78..4efb953c 100644 --- a/src/data/dictionary.h +++ b/src/data/dictionary.h @@ -147,6 +147,11 @@ struct attrset *dict_get_attributes (const struct dictionary *); void dict_set_attributes (struct dictionary *, const struct attrset *); bool dict_has_attributes (const struct dictionary *); + +void dict_set_encoding (struct dictionary *d, const char *enc); +const char *dict_get_encoding (const struct dictionary *d); + + /* Functions to be called upon dictionary changes. */ struct dict_callbacks { diff --git a/src/data/sys-file-reader.c b/src/data/sys-file-reader.c index 84d7f83c..fb4f6f93 100644 --- a/src/data/sys-file-reader.c +++ b/src/data/sys-file-reader.c @@ -778,7 +778,12 @@ read_extension_record (struct sfm_reader *r, struct dictionary *dict, case 20: /* New in SPSS 16. Contains a single string that describes the character encoding, e.g. "windows-1252". */ - break; + { + char *encoding = calloc (size, count + 1); + read_string (r, encoding, count + 1); + dict_set_encoding (dict, encoding); + return; + } case 21: /* New in SPSS 16. Encodes value labels for long string diff --git a/src/libpspp/i18n.c b/src/libpspp/i18n.c index 674a9a27..b323bf85 100644 --- a/src/libpspp/i18n.c +++ b/src/libpspp/i18n.c @@ -88,9 +88,6 @@ recode_string (const char *to, const char *from, if (from == NULL) from = default_encoding; - - fprintf (stderr, "from: %s; to %s\n", from, to); - if ( 0 == strcmp (to, from)) return xstrndup (text, length); diff --git a/src/ui/gui/psppire-dict.c b/src/ui/gui/psppire-dict.c index c4f30783..afc7d570 100644 --- a/src/ui/gui/psppire-dict.c +++ b/src/ui/gui/psppire-dict.c @@ -868,5 +868,5 @@ psppire_dict_dump (const PsppireDict *dict) const gchar * psppire_dict_encoding (const PsppireDict *dict) { - return NULL; + return dict_get_encoding (dict->dict); } -- 2.30.2