1 /* PSPPIRE - a graphical interface for PSPP.
2 Copyright (C) 2007, 2009 Free Software Foundation, Inc.
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.
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.
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/>. */
20 #include <libpspp/cast.h>
21 #include <libpspp/getl.h>
22 #include <libpspp/compiler.h>
23 #include <libpspp/str.h>
27 #include "syntax-string-source.h"
31 struct syntax_string_source
33 struct getl_interface parent;
40 always_false (const struct getl_interface *i UNUSED)
45 /* Returns the name of the source */
47 name (const struct getl_interface *i UNUSED)
53 /* Returns the location within the source */
55 location (const struct getl_interface *i UNUSED)
62 do_close (struct getl_interface *i )
64 struct syntax_string_source *sss = UP_CAST (i, struct syntax_string_source,
67 ds_destroy (&sss->buffer);
75 read_single_line (struct getl_interface *i,
78 struct syntax_string_source *sss = UP_CAST (i, struct syntax_string_source,
86 next = ss_find_char (ds_substr (&sss->buffer,
87 sss->posn, -1), '\n');
89 ds_assign_substring (line,
90 ds_substr (&sss->buffer,
96 sss->posn += next + 1; /* + 1 to skip newline */
98 sss->posn = -1; /* End of file encountered */
103 struct getl_interface *
104 create_syntax_string_source (const char *format, ...)
108 struct syntax_string_source *sss = xzalloc (sizeof *sss);
112 ds_init_empty (&sss->buffer);
114 va_start (args, format);
115 ds_put_vformat (&sss->buffer, format, args);
118 sss->parent.interactive = always_false;
119 sss->parent.close = do_close;
120 sss->parent.read = read_single_line;
122 sss->parent.name = name;
123 sss->parent.location = location;
129 /* Return the syntax currently contained in S.
130 Primarily usefull for debugging */
132 syntax_string_source_get_syntax (const struct syntax_string_source *s)
134 return ds_cstr (&s->buffer);