Changed include paths to be explicitly specified in the #include directive.
[pspp-builds.git] / src / ui / gui / helper.c
1
2 #include "helper.h"
3 #include <data/data-in.h>
4 #include <libpspp/message.h>
5
6 #include <ctype.h>
7 #include <string.h>
8
9 /* Formats a value according to FORMAT 
10    The returned string must be freed when no longer required */
11 gchar *
12 value_to_text(union value v, struct fmt_spec format)
13 {
14   gchar *s = 0;
15
16   s = g_new(gchar, format.w + 1);
17   if ( ! data_out(s, &format, &v) ) 
18     {
19       g_warning("Can't format missing discrete value \n");
20     }
21   s[format.w]='\0';
22   g_strchug(s);
23
24   return s;
25 }
26
27
28
29 gboolean 
30 text_to_value(const gchar *text, union value *v, 
31               struct fmt_spec format)
32 {
33   struct data_in di;
34
35   if ( format.type != FMT_A) 
36     {
37       if ( ! text ) return FALSE;
38   
39       const gchar *s = text;
40       while(*s) 
41         {
42           if ( !isspace(*s))
43             break;
44           s++;
45         }
46  
47       if ( !*s) return FALSE;
48     }
49
50   di.s = text;
51   di.e = text + strlen(text);
52   di.v = v;
53   di.flags = DI_IGNORE_ERROR;
54   di.f1 = di.f2 = 0;
55   di.format = format;
56   
57   return data_in(&di);
58
59 }
60
61
62 GtkWidget *
63 get_widget_assert(GladeXML *xml, const gchar *name)
64 {
65   g_assert(xml);
66   g_assert(name);
67   GtkWidget * w = glade_xml_get_widget(xml, name);
68
69   if ( !w ) 
70     g_warning("Widget \"%s\" could not be found\n",name);
71
72   return w;
73 }
74