From: Ben Pfaff Date: Tue, 21 Jun 2011 02:06:11 +0000 (-0700) Subject: gui: Simplify value_to_text() parameters. X-Git-Tag: v0.7.9~270 X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=66ada89a69ed73a1a15abfbd9bffe4cdf9bf307a;p=pspp-builds.git gui: Simplify value_to_text() parameters. Both the format and the dictionary can be inferred from the variable being formatted in every case in the tree but one, so use that as the calling convention. In the one remaining case, it's just as easy to call data_out() directly. --- diff --git a/src/ui/gui/find-dialog.c b/src/ui/gui/find-dialog.c index 61f5a50f..51645d6f 100644 --- a/src/ui/gui/find-dialog.c +++ b/src/ui/gui/find-dialog.c @@ -423,7 +423,6 @@ struct comparator { const struct variable *var; enum string_cmp_flags flags; - const PsppireDict *dict; bool (*compare) (const struct comparator *, const union value *); @@ -498,7 +497,7 @@ string_value_compare (const struct comparator *cmptr, g_return_val_if_fail (width > 0, false); assert ( ! (cmptr->flags & STR_CMP_LABELS)); - text = value_to_text (*val, cmptr->dict, *var_get_print_format (cmptr->var)); + text = value_to_text (*val, cmptr->var); if ( cmptr->flags & STR_CMP_SUBSTR) found = (NULL != g_strstr_len (text, width, ssc->pattern)); @@ -527,7 +526,7 @@ regexp_value_compare (const struct comparator *cmptr, g_return_val_if_fail (width > 0, false); - text = value_to_text (*val, cmptr->dict, *var_get_print_format (cmptr->var)); + text = value_to_text (*val, cmptr->var); /* We must remove trailing whitespace, otherwise $ will not match where one would expect */ g_strchomp (text); @@ -581,7 +580,7 @@ cmptr_value_destroy (struct comparator *cmptr) static struct comparator * -value_comparator_create (const struct variable *var, const PsppireDict *dict, const char *target) +value_comparator_create (const struct variable *var, const char *target) { struct value_comparator *vc = xzalloc (sizeof (*vc)); struct comparator *cmptr = &vc->parent; @@ -590,7 +589,6 @@ value_comparator_create (const struct variable *var, const PsppireDict *dict, co cmptr->var = var; cmptr->compare = value_compare ; cmptr->destroy = cmptr_value_destroy; - cmptr->dict = dict; text_to_value (target, var, &vc->pattern); @@ -598,8 +596,7 @@ value_comparator_create (const struct variable *var, const PsppireDict *dict, co } static struct comparator * -string_comparator_create (const struct variable *var, const PsppireDict *dict, - const char *target, +string_comparator_create (const struct variable *var, const char *target, enum string_cmp_flags flags) { struct string_comparator *ssc = xzalloc (sizeof (*ssc)); @@ -607,7 +604,6 @@ string_comparator_create (const struct variable *var, const PsppireDict *dict, cmptr->flags = flags; cmptr->var = var; - cmptr->dict = dict; if ( flags & STR_CMP_LABELS) cmptr->compare = string_label_compare; @@ -621,7 +617,7 @@ string_comparator_create (const struct variable *var, const PsppireDict *dict, static struct comparator * -regexp_comparator_create (const struct variable *var, const PsppireDict *dict, const char *target, +regexp_comparator_create (const struct variable *var, const char *target, enum string_cmp_flags flags) { int code; @@ -630,7 +626,6 @@ regexp_comparator_create (const struct variable *var, const PsppireDict *dict, c cmptr->flags = flags; cmptr->var = var; - cmptr->dict = dict; cmptr->compare = (flags & STR_CMP_LABELS) ? regexp_label_compare : regexp_value_compare ; @@ -680,16 +675,16 @@ comparator_destroy (struct comparator *cmptr) static struct comparator * -comparator_factory (const struct variable *var, const PsppireDict *dict, const char *str, +comparator_factory (const struct variable *var, const char *str, enum string_cmp_flags flags) { if ( flags & STR_CMP_REGEXP ) - return regexp_comparator_create (var, dict, str, flags); + return regexp_comparator_create (var, str, flags); if ( flags & (STR_CMP_SUBSTR | STR_CMP_LABELS) ) - return string_comparator_create (var, dict, str, flags); + return string_comparator_create (var, str, flags); - return value_comparator_create (var, dict, str); + return value_comparator_create (var, str); } @@ -735,7 +730,7 @@ find_value (const struct find_dialog *fd, casenumber current_row, casenumber i; const struct casenum_iterator *ip = get_iteration_params (fd); struct comparator *cmptr = - comparator_factory (var, fd->dict, target_string, flags); + comparator_factory (var, target_string, flags); value_init (&val, width); if ( ! cmptr) diff --git a/src/ui/gui/helper.c b/src/ui/gui/helper.c index 71b1fb72..f5803d9f 100644 --- a/src/ui/gui/helper.c +++ b/src/ui/gui/helper.c @@ -47,17 +47,13 @@ #include -/* Formats a value according to FORMAT - The returned string must be freed when no longer required */ +/* Formats a value according to VAR's print format. + The returned string must be freed when no longer required. */ gchar * -value_to_text (union value v, const PsppireDict *dict, struct fmt_spec format) +value_to_text (union value v, const struct variable *var) { - gchar *s = NULL; - - s = data_out (&v, dict_get_encoding (dict->dict), &format); - g_strchug (s); - - return s; + gchar *s = data_out (&v, var_get_encoding (var), var_get_print_format (var)); + return g_strchug (s); } diff --git a/src/ui/gui/helper.h b/src/ui/gui/helper.h index 78cd22cf..597fdd78 100644 --- a/src/ui/gui/helper.h +++ b/src/ui/gui/helper.h @@ -48,9 +48,7 @@ null_if_empty_param (const gchar *name, const gchar *nick, } -/* Formats a value according to FORMAT - The returned string must be freed when no longer required */ -gchar * value_to_text (union value v, const PsppireDict *dict, struct fmt_spec format); +gchar * value_to_text (union value v, const struct variable *); union value * diff --git a/src/ui/gui/missing-val-dialog.c b/src/ui/gui/missing-val-dialog.c index 4aa940bd..dbb80a2d 100644 --- a/src/ui/gui/missing-val-dialog.c +++ b/src/ui/gui/missing-val-dialog.c @@ -283,16 +283,12 @@ missing_val_dialog_create (GtkWindow *toplevel) void missing_val_dialog_show (struct missing_val_dialog *dialog) { - const struct fmt_spec *format ; - gint i; g_return_if_fail (dialog); g_return_if_fail (dialog->pv); mv_copy (&dialog->mvl, var_get_missing_values (dialog->pv)); - format = var_get_print_format (dialog->pv); - /* Blank all entry boxes and make them insensitive */ gtk_entry_set_text (GTK_ENTRY (dialog->low), ""); gtk_entry_set_text (GTK_ENTRY (dialog->high), ""); @@ -319,8 +315,8 @@ missing_val_dialog_show (struct missing_val_dialog *dialog) mv_get_range (&dialog->mvl, &low.f, &high.f); - low_text = value_to_text (low, dialog->dict, *format); - high_text = value_to_text (high, dialog->dict, *format); + low_text = value_to_text (low, dialog->pv); + high_text = value_to_text (high, dialog->pv); gtk_entry_set_text (GTK_ENTRY (dialog->low), low_text); gtk_entry_set_text (GTK_ENTRY (dialog->high), high_text); @@ -330,7 +326,7 @@ missing_val_dialog_show (struct missing_val_dialog *dialog) if ( mv_has_value (&dialog->mvl)) { gchar *text; - text = value_to_text (*mv_get_value (&dialog->mvl, 0), dialog->dict, *format); + text = value_to_text (*mv_get_value (&dialog->mvl, 0), dialog->pv); gtk_entry_set_text (GTK_ENTRY (dialog->discrete), text); g_free (text); } @@ -351,8 +347,7 @@ missing_val_dialog_show (struct missing_val_dialog *dialog) { gchar *text ; - text = value_to_text (*mv_get_value (&dialog->mvl, i), dialog->dict, - *format); + text = value_to_text (*mv_get_value (&dialog->mvl, i), dialog->pv); gtk_entry_set_text (GTK_ENTRY (dialog->mv[i]), text); g_free (text); } diff --git a/src/ui/gui/psppire-var-store.c b/src/ui/gui/psppire-var-store.c index 50304ba3..0ef19394 100644 --- a/src/ui/gui/psppire-var-store.c +++ b/src/ui/gui/psppire-var-store.c @@ -750,7 +750,7 @@ text_for_column (PsppireVarStore *vs, g_assert (vl); { - gchar *const vstr = value_to_text (vl->value, dict, *format); + gchar *const vstr = value_to_text (vl->value, pv); return g_strdup_printf (_("{%s,`%s'}_"), vstr, val_lab_get_escaped_label (vl)); diff --git a/src/ui/gui/val-labs-dialog.c b/src/ui/gui/val-labs-dialog.c index 150dcd54..bd2cf0b3 100644 --- a/src/ui/gui/val-labs-dialog.c +++ b/src/ui/gui/val-labs-dialog.c @@ -356,7 +356,7 @@ on_select_row (GtkTreeView *treeview, gpointer data) gchar *text; get_selected_tuple (dialog, &value, &label); - text = value_to_text (value, dialog->dict, *var_get_print_format (dialog->pv)); + text = value_to_text (value, dialog->pv); g_signal_handler_block (GTK_ENTRY (dialog->value_entry), dialog->value_handler_id); @@ -509,8 +509,7 @@ repopulate_dialog (struct val_labs_dialog *dialog) const struct val_lab *vl = labels[i]; gchar *const vstr = - value_to_text (vl->value, dialog->dict, - *var_get_print_format (dialog->pv)); + value_to_text (vl->value, dialog->pv); gchar *const text = g_strdup_printf (_("%s = `%s'"), vstr, val_lab_get_escaped_label (vl)); diff --git a/src/ui/gui/var-display.c b/src/ui/gui/var-display.c index 5f85af2e..72b5731c 100644 --- a/src/ui/gui/var-display.c +++ b/src/ui/gui/var-display.c @@ -29,7 +29,6 @@ measure_to_string (const struct variable *var, GError **err) gchar * missing_values_to_string (const PsppireDict *dict, const struct variable *pv, GError **err) { - const struct fmt_spec *fmt = var_get_print_format (pv); gchar *s; const struct missing_values *miss = var_get_missing_values (pv); if ( mv_is_empty (miss)) @@ -44,7 +43,7 @@ missing_values_to_string (const PsppireDict *dict, const struct variable *pv, GE gint i; for (i = 0 ; i < n; ++i ) { - mv[i] = value_to_text (*mv_get_value (miss, i), dict, *fmt); + mv[i] = value_to_text (*mv_get_value (miss, i), pv); if ( i > 0 ) g_string_append (gstr, ", "); g_string_append (gstr, mv[i]); @@ -60,8 +59,8 @@ missing_values_to_string (const PsppireDict *dict, const struct variable *pv, GE union value low, high; mv_get_range (miss, &low.f, &high.f); - l = value_to_text (low, dict, *fmt); - h = value_to_text (high, dict,*fmt); + l = value_to_text (low, pv); + h = value_to_text (high, pv); g_string_printf (gstr, "%s - %s", l, h); g_free (l); @@ -71,7 +70,7 @@ missing_values_to_string (const PsppireDict *dict, const struct variable *pv, GE { gchar *ss = NULL; - ss = value_to_text (*mv_get_value (miss, 0), dict, *fmt); + ss = value_to_text (*mv_get_value (miss, 0), pv); g_string_append (gstr, ", "); g_string_append (gstr, ss); diff --git a/src/ui/gui/var-type-dialog.c b/src/ui/gui/var-type-dialog.c index fb1977a5..0f12c464 100644 --- a/src/ui/gui/var-type-dialog.c +++ b/src/ui/gui/var-type-dialog.c @@ -21,18 +21,15 @@ #include #include - #include #include -#include "var-type-dialog.h" - -#include "helper.h" - -#include -#include -#include - +#include "data/data-out.h" +#include "data/settings.h" +#include "data/variable.h" +#include "libpspp/message.h" +#include "ui/gui/helper.h" +#include "ui/gui/var-type-dialog.h" struct tgs { @@ -262,12 +259,12 @@ preview_custom (GtkWidget *w, gpointer data) union value v; v.f = 1234.56; - sample_text = value_to_text (v, dialog->vs->dictionary, dialog->fmt_l); + sample_text = g_strchug (data_out (&v, NULL, &dialog->fmt_l)); gtk_label_set_text (GTK_LABEL (dialog->label_psample), sample_text); g_free (sample_text); v.f = -v.f; - sample_text = value_to_text (v, dialog->vs->dictionary, dialog->fmt_l); + sample_text = g_strchug (data_out (&v, NULL, &dialog->fmt_l)); gtk_label_set_text (GTK_LABEL (dialog->label_nsample), sample_text); g_free (sample_text); } diff --git a/src/ui/gui/variable-info-dialog.c b/src/ui/gui/variable-info-dialog.c index 3692a0d2..59206a83 100644 --- a/src/ui/gui/variable-info-dialog.c +++ b/src/ui/gui/variable-info-dialog.c @@ -109,8 +109,7 @@ populate_text (PsppireDictView *treeview, gpointer data) for (i = 0; i < n_labels; i++) { const struct val_lab *vl = labels[i]; - gchar *const vstr = - value_to_text (vl->value, dict, *var_get_print_format (var)); + gchar *const vstr = value_to_text (vl->value, var); g_string_append_printf (gstring, _("%s %s\n"), vstr, val_lab_get_escaped_label (vl));