gui: Prefer NULL to 0 for initializing pointers.
[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   const struct fmt_spec *fmt =  var_get_print_format (pv);
33   gchar *s;
34   const struct missing_values *miss = var_get_missing_values (pv);
35   if ( mv_is_empty (miss))
36     return xstrdup (gettext (none));
37   else
38     {
39       if ( ! mv_has_range (miss))
40         {
41           GString *gstr = g_string_sized_new (10);
42           const int n = mv_n_values (miss);
43           gchar *mv[4] = {0,0,0,0};
44           gint i;
45           for (i = 0 ; i < n; ++i )
46             {
47               mv[i] = value_to_text (*mv_get_value (miss, i), dict, *fmt);
48               if ( i > 0 )
49                 g_string_append (gstr, ", ");
50               g_string_append (gstr, mv[i]);
51               g_free (mv[i]);
52             }
53           s = gstr->str;
54           g_string_free (gstr, FALSE);
55         }
56       else
57         {
58           GString *gstr = g_string_sized_new (10);
59           gchar *l, *h;
60           union value low, high;
61           mv_get_range (miss, &low.f, &high.f);
62
63           l = value_to_text (low, dict, *fmt);
64           h = value_to_text (high, dict,*fmt);
65
66           g_string_printf (gstr, "%s - %s", l, h);
67           g_free (l);
68           g_free (h);
69
70           if ( mv_has_value (miss))
71             {
72               gchar *ss = NULL;
73
74               ss = value_to_text (*mv_get_value (miss, 0), dict, *fmt);
75
76               g_string_append (gstr, ", ");
77               g_string_append (gstr, ss);
78               free (ss);
79             }
80           s = gstr->str;
81           g_string_free (gstr, FALSE);
82         }
83
84       return s;
85     }
86 }