src/ui/gui/var-display.c (missing_values_to_string): Reduce scope of local variable.
[pspp] / src / ui / gui / var-display.c
1 /*
2 PSPP - a program for statistical analysis.
3 Copyright (C) 2017 Free Software Foundation, Inc.
4
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program.  If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 #include <config.h>
20 #include "var-display.h"
21
22 #include <data/variable.h>
23 #include <data/format.h>
24 #include <stdlib.h>
25 #include "psppire-dict.h"
26
27 #include <gettext.h>
28 #define _(msgid) gettext (msgid)
29 #define N_(msgid) msgid
30
31 #include "helper.h"
32 #include <libpspp/i18n.h>
33
34 static const gchar none[] = N_("None");
35
36
37 gchar *
38 missing_values_to_string (const struct variable *pv, GError **err)
39 {
40   const struct missing_values *miss = var_get_missing_values (pv);
41   if (mv_is_empty (miss))
42     return xstrdup (gettext (none));
43   else
44     {
45       gchar *s = NULL;
46       if (! mv_has_range (miss))
47         {
48           GString *gstr = g_string_sized_new (10);
49           const int n = mv_n_values (miss);
50           gchar *mv[4] = {0,0,0,0};
51           gint i;
52           for (i = 0 ; i < n; ++i)
53             {
54               mv[i] = value_to_text (*mv_get_value (miss, i), pv);
55               if (i > 0)
56                 g_string_append (gstr, ", ");
57               g_string_append (gstr, mv[i]);
58               g_free (mv[i]);
59             }
60           s = gstr->str;
61           g_string_free (gstr, FALSE);
62         }
63       else
64         {
65           GString *gstr = g_string_sized_new (10);
66           gchar *l, *h;
67           union value low, high;
68           mv_get_range (miss, &low.f, &high.f);
69
70           l = value_to_text (low, pv);
71           h = value_to_text (high, pv);
72
73           g_string_printf (gstr, "%s - %s", l, h);
74           g_free (l);
75           g_free (h);
76
77           if (mv_has_value (miss))
78             {
79               gchar *ss = NULL;
80
81               ss = value_to_text (*mv_get_value (miss, 0), pv);
82
83               g_string_append (gstr, ", ");
84               g_string_append (gstr, ss);
85               free (ss);
86             }
87           s = gstr->str;
88           g_string_free (gstr, FALSE);
89         }
90
91       return s;
92     }
93 }