Fixed bug reporting the significance of paired value t-test.
[pspp-builds.git] / src / ui / gui / syntax-editor-source.c
1 /* PSPPIRE - a graphical user interface for PSPP.
2    Copyright (C) 2006  Free Software Foundation
3
4    This program is free software: you can redistribute it and/or modify
5    it under the terms of the GNU General Public License as published by
6    the Free Software Foundation, either version 3 of the License, or
7    (at your option) any later version.
8
9    This program is distributed in the hope that it will be useful,
10    but WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12    GNU General Public License for more details.
13
14    You should have received a copy of the GNU General Public License
15    along with this program.  If not, see <http://www.gnu.org/licenses/>. */
16
17
18 #include <config.h>
19
20 #include <libpspp/getl.h>
21 #include <libpspp/compiler.h>
22 #include <libpspp/str.h>
23
24 #include <stdlib.h>
25
26 #include <gtk/gtk.h>
27
28 #include "syntax-editor-source.h"
29 #include "syntax-editor.h"
30
31 #include "xalloc.h"
32
33 struct syntax_editor_source
34   {
35     struct getl_interface parent;
36     const struct syntax_editor *se;
37     GtkTextIter i;
38     GtkTextIter end;
39   };
40
41
42 static bool
43 always_false (const struct getl_interface *i UNUSED)
44 {
45   return false;
46 }
47
48 /* Returns the name of the source */
49 static const char *
50 name (const struct getl_interface *i)
51 {
52   const struct syntax_editor_source *ses =
53     (const struct syntax_editor_source *) i;
54
55   return window_name ((const struct editor_window *) ses->se);
56 }
57
58
59 /* Returns the location within the source */
60 static int
61 location (const struct getl_interface *i)
62 {
63   const struct syntax_editor_source *ses = (const struct syntax_editor_source *) i;
64
65   return gtk_text_iter_get_line (&ses->i);
66 }
67
68
69 static bool
70 read_line_from_buffer (struct getl_interface *i,
71                        struct string *line)
72 {
73   gchar *text;
74   GtkTextIter next_line;
75
76   struct syntax_editor_source *ses = (struct syntax_editor_source *) i;
77
78   if ( gtk_text_iter_compare (&ses->i, &ses->end) >= 0)
79     return false;
80
81   next_line = ses->i;
82   gtk_text_iter_forward_line (&next_line);
83
84   text = gtk_text_buffer_get_text (ses->se->buffer,
85                                    &ses->i, &next_line,
86                                    FALSE);
87   g_strchomp (text);
88
89   ds_assign_cstr (line, text);
90
91   g_free (text);
92
93   gtk_text_iter_forward_line (&ses->i);
94
95   return true;
96 }
97
98
99 static void
100 do_close (struct getl_interface *i )
101 {
102   free (i);
103 }
104
105 struct getl_interface *
106 create_syntax_editor_source (const struct syntax_editor *se,
107                              GtkTextIter start,
108                              GtkTextIter stop
109                              )
110 {
111   struct syntax_editor_source *ses = xzalloc (sizeof *ses);
112
113   ses->se = se;
114   ses->i = start;
115   ses->end = stop;
116
117
118   ses->parent.interactive = always_false;
119   ses->parent.read = read_line_from_buffer;
120   ses->parent.close = do_close;
121
122   ses->parent.name = name;
123   ses->parent.location = location;
124
125
126   return (struct getl_interface *) ses;
127 }