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;
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);
return cmptr;
}
}
+/* 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,
const PsppireDict *dict,
- struct fmt_spec format)
+ const struct variable *var,
+ union value *val)
{
- bool ok;
+ 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;
{
const gchar *s = text;
s++;
}
- if ( !*s) return FALSE;
+ if ( !*s) return NULL;
}
}
+ value_init (val, width);
msg_disable ();
- ok = data_in (ss_cstr (text), UTF8, format.type, 0, 0, 0,
+ data_in (ss_cstr (text), UTF8, format->type, 0, 0, 0,
dict->dict,
- v, fmt_var_width (&format));
+ val, width);
msg_enable ();
- return ok;
+ return val;
}
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);
{
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;
continue;
}
- 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);
else
badvals++;
g_free (text);
+ value_destroy (&v, var_get_width (dialog->pv));
}
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));
- 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));
+ value_destroy (&low_val, var_get_width (dialog->pv));
+ value_destroy (&high_val, var_get_width (dialog->pv));
return ;
}
}
{
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));
return;
}
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 ( !text_to_value (discrete_text, &discrete_val,
+ if ( !text_to_value (discrete_text,
dialog->dict,
- *write_spec))
+ dialog->pv,
+ &discrete_val))
{
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);
+ value_destroy (&discrete_val, var_get_width (dialog->pv));
}
g_free (discrete_text);
}
text = gtk_entry_get_text (GTK_ENTRY (dialog->value_entry));
- text_to_value (text, &v,
+ text_to_value (text,
dialog->var_store->dict,
- *var_get_write_format (dialog->pv));
-
+ dialog->pv,
+ &v);
if (val_labs_find (dialog->labs, &v))
{
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;
- text_to_value (text, &v,
+ text_to_value (text,
dialog->var_store->dict,
- *var_get_write_format (dialog->pv));
+ dialog->pv,
+ &v);
g_signal_handler_block (GTK_ENTRY (dialog->label_entry),
g_signal_handler_unblock (GTK_ENTRY (dialog->label_entry),
dialog->change_handler_id);
+
+ value_destroy (&v, var_get_width (dialog->pv));
}
union value v;
- text_to_value (val_text, &v,
+ text_to_value (val_text,
dialog->var_store->dict,
- *var_get_write_format (dialog->pv));
+ dialog->pv,
+ &v);
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);
+
+ value_destroy (&v, var_get_width (dialog->pv));
}
/* Callback which occurs when the "Add" button is clicked */
const gchar *text = gtk_entry_get_text (GTK_ENTRY (dialog->value_entry));
- text_to_value (text, &v,
+ text_to_value (text,
dialog->var_store->dict,
- *var_get_write_format (dialog->pv));
-
+ dialog->pv,
+ &v);
- 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 */