72b5731ca90e956388b790f23780cf98449bdea1
[pspp-builds.git] / src / ui / gui / var-display.c
1 #include <config.h>
2 #include "var-display.h"
3
4 #include <data/variable.h>
5 #include <data/format.h>
6 #include <stdlib.h>
7 #include "psppire-dict.h"
8
9 #include <gettext.h>
10 #define _(msgid) gettext (msgid)
11 #define N_(msgid) msgid
12
13 #include "helper.h"
14 #include <libpspp/i18n.h>
15
16 static const gchar none[] = N_("None");
17
18
19 const gchar *
20 measure_to_string (const struct variable *var, GError **err)
21 {
22   const gint measure = var_get_measure (var);
23
24   g_assert (measure < n_MEASURES);
25   return gettext (measures[measure]);
26 }
27
28
29 gchar *
30 missing_values_to_string (const PsppireDict *dict, const struct variable *pv, GError **err)
31 {
32   gchar *s;
33   const struct missing_values *miss = var_get_missing_values (pv);
34   if ( mv_is_empty (miss))
35     return xstrdup (gettext (none));
36   else
37     {
38       if ( ! mv_has_range (miss))
39         {
40           GString *gstr = g_string_sized_new (10);
41           const int n = mv_n_values (miss);
42           gchar *mv[4] = {0,0,0,0};
43           gint i;
44           for (i = 0 ; i < n; ++i )
45             {
46               mv[i] = value_to_text (*mv_get_value (miss, i), pv);
47               if ( i > 0 )
48                 g_string_append (gstr, ", ");
49               g_string_append (gstr, mv[i]);
50               g_free (mv[i]);
51             }
52           s = gstr->str;
53           g_string_free (gstr, FALSE);
54         }
55       else
56         {
57           GString *gstr = g_string_sized_new (10);
58           gchar *l, *h;
59           union value low, high;
60           mv_get_range (miss, &low.f, &high.f);
61
62           l = value_to_text (low, pv);
63           h = value_to_text (high, pv);
64
65           g_string_printf (gstr, "%s - %s", l, h);
66           g_free (l);
67           g_free (h);
68
69           if ( mv_has_value (miss))
70             {
71               gchar *ss = NULL;
72
73               ss = value_to_text (*mv_get_value (miss, 0), pv);
74
75               g_string_append (gstr, ", ");
76               g_string_append (gstr, ss);
77               free (ss);
78             }
79           s = gstr->str;
80           g_string_free (gstr, FALSE);
81         }
82
83       return s;
84     }
85 }