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.
{
const struct variable *var;
enum string_cmp_flags flags;
{
const struct variable *var;
enum string_cmp_flags flags;
- const PsppireDict *dict;
bool (*compare) (const struct comparator *,
const union value *);
bool (*compare) (const struct comparator *,
const union value *);
g_return_val_if_fail (width > 0, false);
assert ( ! (cmptr->flags & STR_CMP_LABELS));
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));
if ( cmptr->flags & STR_CMP_SUBSTR)
found = (NULL != g_strstr_len (text, width, ssc->pattern));
g_return_val_if_fail (width > 0, false);
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);
/* We must remove trailing whitespace, otherwise $ will not match where
one would expect */
g_strchomp (text);
static struct comparator *
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;
{
struct value_comparator *vc = xzalloc (sizeof (*vc));
struct comparator *cmptr = &vc->parent;
cmptr->var = var;
cmptr->compare = value_compare ;
cmptr->destroy = cmptr_value_destroy;
cmptr->var = var;
cmptr->compare = value_compare ;
cmptr->destroy = cmptr_value_destroy;
text_to_value (target, var, &vc->pattern);
text_to_value (target, var, &vc->pattern);
}
static struct comparator *
}
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));
enum string_cmp_flags flags)
{
struct string_comparator *ssc = xzalloc (sizeof (*ssc));
cmptr->flags = flags;
cmptr->var = var;
cmptr->flags = flags;
cmptr->var = var;
if ( flags & STR_CMP_LABELS)
cmptr->compare = string_label_compare;
if ( flags & STR_CMP_LABELS)
cmptr->compare = string_label_compare;
static struct comparator *
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;
enum string_cmp_flags flags)
{
int code;
cmptr->flags = flags;
cmptr->var = var;
cmptr->flags = flags;
cmptr->var = var;
cmptr->compare = (flags & STR_CMP_LABELS)
? regexp_label_compare : regexp_value_compare ;
cmptr->compare = (flags & STR_CMP_LABELS)
? regexp_label_compare : regexp_value_compare ;
static struct comparator *
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 )
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) )
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);
casenumber i;
const struct casenum_iterator *ip = get_iteration_params (fd);
struct comparator *cmptr =
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)
value_init (&val, width);
if ( ! cmptr)
-/* 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. */
-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);
-/* 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 *);
void
missing_val_dialog_show (struct missing_val_dialog *dialog)
{
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));
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), "");
/* Blank all entry boxes and make them insensitive */
gtk_entry_set_text (GTK_ENTRY (dialog->low), "");
gtk_entry_set_text (GTK_ENTRY (dialog->high), "");
mv_get_range (&dialog->mvl, &low.f, &high.f);
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);
gtk_entry_set_text (GTK_ENTRY (dialog->low), low_text);
gtk_entry_set_text (GTK_ENTRY (dialog->high), high_text);
if ( mv_has_value (&dialog->mvl))
{
gchar *text;
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);
}
gtk_entry_set_text (GTK_ENTRY (dialog->discrete), text);
g_free (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);
}
gtk_entry_set_text (GTK_ENTRY (dialog->mv[i]), text);
g_free (text);
}
- 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));
return g_strdup_printf (_("{%s,`%s'}_"), vstr,
val_lab_get_escaped_label (vl));
gchar *text;
get_selected_tuple (dialog, &value, &label);
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);
g_signal_handler_block (GTK_ENTRY (dialog->value_entry),
dialog->value_handler_id);
const struct val_lab *vl = labels[i];
gchar *const vstr =
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));
gchar *const text = g_strdup_printf (_("%s = `%s'"), vstr,
val_lab_get_escaped_label (vl));
gchar *
missing_values_to_string (const PsppireDict *dict, const struct variable *pv, 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))
gchar *s;
const struct missing_values *miss = var_get_missing_values (pv);
if ( mv_is_empty (miss))
gint i;
for (i = 0 ; i < n; ++i )
{
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]);
if ( i > 0 )
g_string_append (gstr, ", ");
g_string_append (gstr, mv[i]);
union value low, high;
mv_get_range (miss, &low.f, &high.f);
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);
g_string_printf (gstr, "%s - %s", l, h);
g_free (l);
- 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);
g_string_append (gstr, ", ");
g_string_append (gstr, ss);
#include <config.h>
#include <gtk/gtk.h>
#include <config.h>
#include <gtk/gtk.h>
#include <stdlib.h>
#include <string.h>
#include <stdlib.h>
#include <string.h>
-#include "var-type-dialog.h"
-
-#include "helper.h"
-
-#include <data/variable.h>
-#include <data/settings.h>
-#include <libpspp/message.h>
-
+#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"
union value v;
v.f = 1234.56;
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;
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);
}
gtk_label_set_text (GTK_LABEL (dialog->label_nsample), sample_text);
g_free (sample_text);
}
for (i = 0; i < n_labels; i++)
{
const struct val_lab *vl = labels[i];
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));
g_string_append_printf (gstring, _("%s %s\n"),
vstr, val_lab_get_escaped_label (vl));