Character set conversion in value label dialog box.
Made more robust in the presence of bad alignment and measure parameters.
assert (check_output_specifier (&f, 0));
return f;
}
+
+
+bool
+measure_is_valid(enum measure m)
+{
+ if ( m <= 0 ) return false;
+ if ( m >= n_MEASURES) false;
+ return true;
+}
+
+bool
+alignment_is_valid(enum alignment a)
+{
+ if ( a < 0 ) return false;
+ if ( a >= n_ALIGN) return false;
+ return true;
+}
{
ALIGN_LEFT = 0,
ALIGN_RIGHT = 1,
- ALIGN_CENTRE = 2
+ ALIGN_CENTRE = 2,
+ n_ALIGN
};
{
MEASURE_NOMINAL=1,
MEASURE_ORDINAL=2,
- MEASURE_SCALE=3
+ MEASURE_SCALE=3,
+ n_MEASURES
};
+bool measure_is_valid(enum measure m);
+bool alignment_is_valid(enum alignment a);
/* Descriptions of all the display formats above. */
assertive_buf_read (r, ¶ms, sizeof(params), 0);
+ if ( ! measure_is_valid(params.measure)
+ ||
+ ! alignment_is_valid(params.align))
+ {
+ msg(MW,
+ _("Invalid variable display parameters. Default parameters substituted."),
+ fh_get_file_name(r->fh));
+ continue;
+ }
+
v = dict_get_var(*dict, i);
v->measure = params.measure;
/* FIXME: Need to ensure that this char is valid in the target encoding */
const char fallbackchar = '?';
+ if ( text == NULL )
+ return NULL;
+
if ( length == -1 )
length = strlen(text);
inbytes = length;
do {
-
-
result = iconv(convertor[how], &ip, &inbytes,
&op, &outbytes);
}
}
-
} while ( -1 == result );
+ if (outbytes == 0 )
+ {
+ char *const oldaddr = outbuf;
+ outbuf = xrealloc(outbuf, outbufferlength + 1);
+
+ op += (outbuf - oldaddr) ;
+ }
+
*op = '\0';
-
return outbuf;
}
gchar *title = g_strdup_printf("%s --- %s", text, gettext(window_title));
gtk_window_set_title(GTK_WINDOW(data_editor), title);
+
+ g_free(title);
}
}
break;
case COL_ALIGN:
- return g_locale_to_utf8(gettext(alignments[psppire_variable_get_alignment(pv)]),
- -1, -0, 0, err);
+ {
+ const gint align = psppire_variable_get_alignment(pv);
+
+ g_assert(align < n_ALIGNMENTS);
+ return g_locale_to_utf8(gettext(alignments[align]),-1, -0, 0, err);
+ }
break;
case COL_MEASURE:
- return g_locale_to_utf8(gettext(measures[psppire_variable_get_measure(pv)]),
- -1, -0, 0, err);
- break;
+ {
+ const gint measure = psppire_variable_get_measure(pv);
+ g_assert(measure < n_MEASURES);
+ return g_locale_to_utf8(gettext(measures[measure]), -1, -0, 0, err);
+ }
+ break;
}
return 0;
}
on_select_row (GtkTreeView *treeview,
gpointer data)
{
+ gchar *labeltext;
struct val_labs_dialog *dialog = data;
struct val_lab * vl = get_selected_tuple(dialog);
g_signal_handler_block(GTK_ENTRY(dialog->label_entry),
dialog->change_handler_id);
+ labeltext = pspp_locale_to_utf8(vl->label, -1, 0);
gtk_entry_set_text(GTK_ENTRY(dialog->label_entry),
- vl->label);
+ labeltext);
+ g_free(labeltext);
g_signal_handler_unblock(GTK_ENTRY(dialog->label_entry),
dialog->change_handler_id);
vl;
vl = val_labs_next(dialog->labs, &vli))
{
+
gchar *const vstr =
value_to_text(vl->value,
*psppire_variable_get_write_spec(dialog->pv));
+ gchar *labeltext =
+ pspp_locale_to_utf8(vl->label, -1, 0);
-
gchar *const text = g_strdup_printf("%s = \"%s\"",
- vstr, vl->label);
-
+ vstr, labeltext);
+
+
gtk_list_store_append (list_store, &iter);
gtk_list_store_set (list_store, &iter,
0, text,
1, vl->value.f,
-1);
+ g_free(labeltext);
g_free(text);
g_free(vstr);
}
-const gchar *alignments[]={
+const gchar *alignments[n_ALIGNMENTS + 1]={
N_("Left"),
N_("Right"),
N_("Centre"),
0
};
-const gchar *measures[]={
+const gchar *measures[n_MEASURES + 1]={
N_("Nominal"),
N_("Ordinal"),
N_("Scale"),
gchar *string2,
gint int1, gint int2);
+#define n_ALIGNMENTS 3
-extern const gchar *alignments[];
+extern const gchar *alignments[n_ALIGNMENTS + 1];
-extern const gchar *measures[];
+#define n_MEASURES 3
+
+extern const gchar *measures[n_MEASURES + 1];
#endif