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