#include <setjmp.h>
#include <stdlib.h>
+#include <libpspp/i18n.h>
#include <libpspp/assertion.h>
#include <libpspp/message.h>
#include <libpspp/compiler.h>
size_t size, size_t count,
struct dictionary *);
+/* Convert all the strings in DICT from the dict encoding to UTF8 */
+static void
+recode_strings (struct dictionary *dict)
+{
+ int i;
+
+ const char *enc = dict_get_encoding (dict);
+ if ( NULL == enc)
+ return;
+
+ for (i = 0 ; i < dict_get_var_cnt (dict); ++i)
+ {
+ /* Convert the long variable name */
+ struct variable *var = dict_get_var (dict, i);
+ char *utf8_name = recode_string (UTF8, enc, var_get_name (var), -1);
+ dict_rename_var (dict, var, utf8_name);
+ free (utf8_name);
+
+ /* Convert the variable label */
+ if (var_has_label (var))
+ {
+ char *utf8_label = recode_string (UTF8, enc, var_get_label (var), -1);
+ var_set_label (var, utf8_label);
+ free (utf8_label);
+ }
+
+ if (var_has_value_labels (var))
+ {
+ const struct val_lab *vl = NULL;
+ const struct val_labs *vlabs = var_get_value_labels (var);
+
+ for (vl = val_labs_first (vlabs); vl != NULL; vl = val_labs_next (vlabs, vl))
+ {
+ const union value *val = val_lab_get_value (vl);
+ const char *label = val_lab_get_label (vl);
+ char *new_label = NULL;
+
+ new_label = recode_string (UTF8, enc, label, -1);
+
+ var_replace_value_label (var, val, new_label);
+ free (new_label);
+ }
+ }
+ }
+}
+
/* Opens the system file designated by file handle FH for
reading. Reads the system file's dictionary into *DICT.
If INFO is non-null, then it receives additional info about the
r->has_long_var_names = true;
}
+ recode_strings (*dict);
+
/* Read record 999 data, which is just filler. */
read_int (r);
size_t hash;
struct hmapx_node *node;
struct converter *converter;
+ assert (fromcode);
hash = hash_string (tocode, hash_string (fromcode, 0));
HMAPX_FOR_EACH_WITH_HASH (converter, node, hash, &map)
gchar *text = g_strdup_printf ("%d: %s", row + FIRST_CASE_NUMBER,
var_get_name (var));
- gchar *s = recode_string (UTF8,
- psppire_dict_encoding (data_store->dict),
- text, -1);
- g_free (text);
-
- gtk_entry_set_text (GTK_ENTRY (de->cell_ref_entry), s);
+ gtk_entry_set_text (GTK_ENTRY (de->cell_ref_entry), text);
- g_free (s);
+ g_free (text);
}
else
goto blank_entry;
static gchar *
get_column_subtitle (const PsppireSheetModel *model, gint col)
{
- gchar *text;
const struct variable *v ;
PsppireDataStore *ds = PSPPIRE_DATA_STORE (model);
if ( ! var_has_label (v))
return NULL;
- text = recode_string (UTF8, psppire_dict_encoding (ds->dict),
- var_get_label (v), -1);
-
- return text;
+ return xstrdup (var_get_label (v));
}
static gchar *
get_column_button_label (const PsppireSheetModel *model, gint col)
{
- gchar *text;
struct variable *pv ;
PsppireDataStore *ds = PSPPIRE_DATA_STORE (model);
pv = psppire_dict_get_variable (ds->dict, col);
- text = recode_string (UTF8, psppire_dict_encoding (ds->dict),
- var_get_name (pv), -1);
-
- return text;
+ return xstrdup (var_get_name (pv));
}
static gboolean
switch (col)
{
case PSPPIRE_VAR_STORE_COL_LABEL:
- var_set_label (pv, 0);
+ var_set_label (pv, NULL);
return TRUE;
break;
}
case PSPPIRE_VAR_STORE_COL_NAME:
{
gboolean ok;
- char *s = recode_string (psppire_dict_encoding (var_store->dict),
- UTF8,
- text, -1);
-
- ok = psppire_dict_rename_var (var_store->dict, pv, s);
-
- free (s);
+ ok = psppire_dict_rename_var (var_store->dict, pv, text);
return ok;
}
case PSPPIRE_VAR_STORE_COL_COLUMNS:
break;
case PSPPIRE_VAR_STORE_COL_LABEL:
{
- gchar *s = recode_string (psppire_dict_encoding (var_store->dict),
- UTF8,
- text, -1);
- var_set_label (pv, s);
- free (s);
+ var_set_label (pv, text);
return TRUE;
}
break;
N_("Custom"),
N_("String")
};
+
enum {VT_NUMERIC, VT_COMMA, VT_DOT, VT_SCIENTIFIC, VT_DATE, VT_DOLLAR,
VT_CUSTOM, VT_STRING};
switch (c)
{
case PSPPIRE_VAR_STORE_COL_NAME:
- return recode_string (UTF8, psppire_dict_encoding (dict),
- var_get_name (pv), -1);
+ return xstrdup (var_get_name (pv));
break;
case PSPPIRE_VAR_STORE_COL_TYPE:
{
}
break;
case PSPPIRE_VAR_STORE_COL_LABEL:
- return recode_string (UTF8, psppire_dict_encoding (dict),
- var_get_label (pv), -1);
+ {
+ const char *label = var_get_label (pv);
+ if (label)
+ return xstrdup (label);
+ return NULL;
+ }
break;
case PSPPIRE_VAR_STORE_COL_MISSING:
return g_locale_to_utf8 (gettext (none), -1, 0, 0, err);
else
{
- gchar *ss;
- GString *gstr = g_string_sized_new (10);
const struct val_labs *vls = var_get_value_labels (pv);
const struct val_lab **labels = val_labs_sorted (vls);
const struct val_lab *vl = labels[0];
{
gchar *const vstr = value_to_text (vl->value, *write_spec);
- g_string_printf (gstr, "{%s,\"%s\"}_",
- vstr, val_lab_get_label (vl));
- g_free (vstr);
+ return g_strdup_printf ( "{%s,\"%s\"}_", vstr, val_lab_get_label (vl));
}
-
- ss = recode_string (UTF8, psppire_dict_encoding (dict),
- gstr->str, gstr->len);
- g_string_free (gstr, TRUE);
- return ss;
}
}
break;
static void
on_select_row (GtkTreeView *treeview, gpointer data)
{
- gchar *labeltext;
struct val_labs_dialog *dialog = data;
union value value;
- const char *label;
+ const char *label = NULL;
gchar *text;
- PsppireVarStore *var_store =
- PSPPIRE_VAR_STORE (psppire_sheet_get_model (dialog->vs));
-
get_selected_tuple (dialog, &value, &label);
text = value_to_text (value, *var_get_write_format (dialog->pv));
dialog->change_handler_id);
- labeltext = recode_string (UTF8, psppire_dict_encoding (var_store->dict),
- label, -1);
-
gtk_entry_set_text (GTK_ENTRY (dialog->label_entry),
- labeltext);
- g_free (labeltext);
+ label);
g_signal_handler_unblock (GTK_ENTRY (dialog->label_entry),
dialog->change_handler_id);
GtkTreeIter iter;
- PsppireVarStore *var_store =
- PSPPIRE_VAR_STORE (psppire_sheet_get_model (dialog->vs));
-
GtkListStore *list_store = gtk_list_store_new (2,
G_TYPE_STRING,
G_TYPE_DOUBLE);
value_to_text (vl->value,
*var_get_write_format (dialog->pv));
- gchar *labeltext =
- recode_string (UTF8,
- psppire_dict_encoding (var_store->dict),
- val_lab_get_label (vl), -1);
-
gchar *const text = g_strdup_printf ("%s = \"%s\"",
- vstr, labeltext);
+ vstr, val_lab_get_label (vl));
gtk_list_store_append (list_store, &iter);
gtk_list_store_set (list_store, &iter,
1, vl->value.f,
-1);
- g_free (labeltext);
g_free (text);
g_free (vstr);
}