Now, text_to_value initialises the value, and expects
the caller to destroy it.
This fixes some gui bugs where strange things happened with long string
value labels and missing values.
static struct comparator *
value_comparator_create (const struct variable *var, const PsppireDict *dict, const char *target)
{
static struct comparator *
value_comparator_create (const struct variable *var, const PsppireDict *dict, const char *target)
{
- const struct fmt_spec *fmt;
- int width ;
struct value_comparator *vc = xzalloc (sizeof (*vc));
struct comparator *cmptr = (struct comparator *) vc;
struct value_comparator *vc = xzalloc (sizeof (*vc));
struct comparator *cmptr = (struct comparator *) vc;
cmptr->destroy = cmptr_value_destroy;
cmptr->dict = dict;
cmptr->destroy = cmptr_value_destroy;
cmptr->dict = dict;
- width = var_get_width (var);
- fmt = var_get_write_format (var);
-
- value_init (&vc->pattern, width);
-
- text_to_value (target, &vc->pattern, dict, *var_get_write_format (var) );
+ text_to_value (target, dict, var, &vc->pattern);
+/* Converts TEXT to a value.
-gboolean
-text_to_value (const gchar *text, union value *v,
+ VAL will be initialised and filled by this function.
+ It is the caller's responsibility to destroy VAL when no longer needed.
+ VAR and DICT must be the variable and dictionary with which VAL
+ is associated.
+
+ On success, VAL is returned, NULL otherwise.
+*/
+union value *
+text_to_value (const gchar *text,
- struct fmt_spec format)
+ const struct variable *var,
+ union value *val)
+ const struct fmt_spec *format = var_get_print_format (var);
+ int width = var_get_width (var);
- if ( format.type != FMT_A)
+ if ( format->type != FMT_A)
- if ( ! text ) return FALSE;
+ if ( ! text ) return NULL;
- if ( !*s) return FALSE;
+ value_init (val, width);
- ok = data_in (ss_cstr (text), UTF8, format.type, 0, 0, 0,
+ data_in (ss_cstr (text), UTF8, format->type, 0, 0, 0,
- v, fmt_var_width (&format));
gchar * value_to_text (union value v, const PsppireDict *dict, struct fmt_spec format);
gchar * value_to_text (union value v, const PsppireDict *dict, struct fmt_spec format);
-gboolean text_to_value (const gchar *text, union value *v,
- const PsppireDict *dict,
- struct fmt_spec format);
+union value *
+text_to_value (const gchar *text,
+ const PsppireDict *dict,
+ const struct variable *var,
+ union value *);
GObject *get_object_assert (GtkBuilder *builder, const gchar *name, GType type);
GtkAction * get_action_assert (GtkBuilder *builder, const gchar *name);
GObject *get_object_assert (GtkBuilder *builder, const gchar *name, GType type);
GtkAction * get_action_assert (GtkBuilder *builder, const gchar *name);
{
struct missing_val_dialog *dialog = data;
{
struct missing_val_dialog *dialog = data;
- const struct fmt_spec *write_spec = var_get_write_format (dialog->pv);
-
if ( gtk_toggle_button_get_active (dialog->button_discrete))
{
gint nvals = 0;
if ( gtk_toggle_button_get_active (dialog->button_discrete))
{
gint nvals = 0;
- if ( text_to_value (text, &v,
- dialog->dict, *write_spec))
+ if ( text_to_value (text, dialog->dict, dialog->pv, &v))
{
nvals++;
mv_add_value (&dialog->mvl, &v);
{
nvals++;
mv_add_value (&dialog->mvl, &v);
else
badvals++;
g_free (text);
else
badvals++;
g_free (text);
+ value_destroy (&v, var_get_width (dialog->pv));
}
if ( nvals == 0 || badvals > 0 )
{
}
if ( nvals == 0 || badvals > 0 )
{
const gchar *low_text = gtk_entry_get_text (GTK_ENTRY (dialog->low));
const gchar *high_text = gtk_entry_get_text (GTK_ENTRY (dialog->high));
const gchar *low_text = gtk_entry_get_text (GTK_ENTRY (dialog->low));
const gchar *high_text = gtk_entry_get_text (GTK_ENTRY (dialog->high));
- if ( text_to_value (low_text, &low_val, dialog->dict, *write_spec)
+ if ( text_to_value (low_text, dialog->dict, dialog->pv, &low_val)
- text_to_value (high_text, &high_val, dialog->dict, *write_spec) )
+ text_to_value (high_text, dialog->dict, dialog->pv, &high_val))
{
if ( low_val.f > high_val.f )
{
err_dialog (_("Incorrect range specification"),
GTK_WINDOW (dialog->window));
{
if ( low_val.f > high_val.f )
{
err_dialog (_("Incorrect range specification"),
GTK_WINDOW (dialog->window));
+ value_destroy (&low_val, var_get_width (dialog->pv));
+ value_destroy (&high_val, var_get_width (dialog->pv));
{
err_dialog (_("Incorrect range specification"),
GTK_WINDOW (dialog->window));
{
err_dialog (_("Incorrect range specification"),
GTK_WINDOW (dialog->window));
+ value_destroy (&low_val, var_get_width (dialog->pv));
+ value_destroy (&high_val, var_get_width (dialog->pv));
mv_clear (&dialog->mvl);
mv_add_range (&dialog->mvl, low_val.f, high_val.f);
mv_clear (&dialog->mvl);
mv_add_range (&dialog->mvl, low_val.f, high_val.f);
+ value_destroy (&low_val, var_get_width (dialog->pv));
+ value_destroy (&high_val, var_get_width (dialog->pv));
+
if ( discrete_text && strlen (g_strstrip (discrete_text)) > 0 )
{
union value discrete_val;
if ( discrete_text && strlen (g_strstrip (discrete_text)) > 0 )
{
union value discrete_val;
- if ( !text_to_value (discrete_text, &discrete_val,
+ if ( !text_to_value (discrete_text,
+ dialog->pv,
+ &discrete_val))
{
err_dialog (_("Incorrect value for variable type"),
GTK_WINDOW (dialog->window) );
g_free (discrete_text);
{
err_dialog (_("Incorrect value for variable type"),
GTK_WINDOW (dialog->window) );
g_free (discrete_text);
+ value_destroy (&discrete_val, var_get_width (dialog->pv));
return;
}
mv_add_value (&dialog->mvl, &discrete_val);
return;
}
mv_add_value (&dialog->mvl, &discrete_val);
+ value_destroy (&discrete_val, var_get_width (dialog->pv));
}
g_free (discrete_text);
}
}
g_free (discrete_text);
}
text = gtk_entry_get_text (GTK_ENTRY (dialog->value_entry));
text = gtk_entry_get_text (GTK_ENTRY (dialog->value_entry));
- text_to_value (text, &v,
- *var_get_write_format (dialog->pv));
-
if (val_labs_find (dialog->labs, &v))
{
if (val_labs_find (dialog->labs, &v))
{
gtk_widget_set_sensitive (dialog->change_button, FALSE);
gtk_widget_set_sensitive (dialog->add_button, TRUE);
}
gtk_widget_set_sensitive (dialog->change_button, FALSE);
gtk_widget_set_sensitive (dialog->add_button, TRUE);
}
+
+ value_destroy (&v, var_get_width (dialog->pv));
const gchar *text = gtk_entry_get_text (GTK_ENTRY (dialog->value_entry));
union value v;
const gchar *text = gtk_entry_get_text (GTK_ENTRY (dialog->value_entry));
union value v;
- text_to_value (text, &v,
- *var_get_write_format (dialog->pv));
g_signal_handler_block (GTK_ENTRY (dialog->label_entry),
g_signal_handler_block (GTK_ENTRY (dialog->label_entry),
g_signal_handler_unblock (GTK_ENTRY (dialog->label_entry),
dialog->change_handler_id);
g_signal_handler_unblock (GTK_ENTRY (dialog->label_entry),
dialog->change_handler_id);
+
+ value_destroy (&v, var_get_width (dialog->pv));
- text_to_value (val_text, &v,
+ text_to_value (val_text,
- *var_get_write_format (dialog->pv));
val_labs_replace (dialog->labs, &v,
gtk_entry_get_text (GTK_ENTRY (dialog->label_entry)));
val_labs_replace (dialog->labs, &v,
gtk_entry_get_text (GTK_ENTRY (dialog->label_entry)));
repopulate_dialog (dialog);
gtk_widget_grab_focus (dialog->value_entry);
repopulate_dialog (dialog);
gtk_widget_grab_focus (dialog->value_entry);
+
+ value_destroy (&v, var_get_width (dialog->pv));
}
/* Callback which occurs when the "Add" button is clicked */
}
/* Callback which occurs when the "Add" button is clicked */
const gchar *text = gtk_entry_get_text (GTK_ENTRY (dialog->value_entry));
const gchar *text = gtk_entry_get_text (GTK_ENTRY (dialog->value_entry));
- text_to_value (text, &v,
- *var_get_write_format (dialog->pv));
-
- if ( ! val_labs_add (dialog->labs, &v,
- gtk_entry_get_text
- ( GTK_ENTRY (dialog->label_entry)) ) )
- return ;
+ if (val_labs_add (dialog->labs, &v,
+ gtk_entry_get_text
+ ( GTK_ENTRY (dialog->label_entry)) ) )
+ {
+ gtk_widget_set_sensitive (dialog->add_button, FALSE);
- gtk_widget_set_sensitive (dialog->add_button, FALSE);
+ repopulate_dialog (dialog);
+ gtk_widget_grab_focus (dialog->value_entry);
+ }
- repopulate_dialog (dialog);
- gtk_widget_grab_focus (dialog->value_entry);
+ value_destroy (&v, var_get_width (dialog->pv));
}
/* Callback which occurs when the "Remove" button is clicked */
}
/* Callback which occurs when the "Remove" button is clicked */