2 PSPPIRE --- A Graphical User Interface for PSPP
3 Copyright (C) 2007 Free Software Foundation
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 2 of the License, or
8 (at your option) any later version.
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.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
23 #include <libpspp/getl.h>
24 #include <libpspp/alloc.h>
25 #include <libpspp/compiler.h>
26 #include <libpspp/str.h>
30 #include "syntax-string-source.h"
32 struct syntax_string_source
34 struct getl_interface parent;
41 always_false (const struct getl_interface *i UNUSED)
46 /* Returns the name of the source */
48 name (const struct getl_interface *i UNUSED)
54 /* Returns the location within the source */
56 location (const struct getl_interface *i UNUSED)
63 close (struct getl_interface *i )
65 struct syntax_string_source *sss = (struct syntax_string_source *) i;
67 ds_destroy (&sss->buffer);
75 read_single_line (struct getl_interface *i,
77 enum getl_syntax *syntax_rules UNUSED)
79 struct syntax_string_source *sss = (struct syntax_string_source *) i;
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 = close;
120 sss->parent.read = read_single_line;
122 sss->parent.name = name;
123 sss->parent.location = location;
126 return (struct getl_interface *) sss;
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);