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
21 #include <libpspp/getl.h>
22 #include <libpspp/alloc.h>
23 #include <libpspp/compiler.h>
24 #include <libpspp/str.h>
28 #include "syntax-string-source.h"
30 struct syntax_string_source
32 struct getl_interface parent;
39 always_false (const struct getl_interface *i UNUSED)
44 /* Returns the name of the source */
46 name (const struct getl_interface *i UNUSED)
52 /* Returns the location within the source */
54 location (const struct getl_interface *i UNUSED)
61 close (struct getl_interface *i )
63 struct syntax_string_source *sss = (struct syntax_string_source *) i;
65 ds_destroy (&sss->buffer);
73 read_single_line (struct getl_interface *i,
75 enum getl_syntax *syntax_rules UNUSED)
77 struct syntax_string_source *sss = (struct syntax_string_source *) i;
84 next = ss_find_char (ds_substr (&sss->buffer,
85 sss->posn, -1), '\n');
87 ds_assign_substring (line,
88 ds_substr (&sss->buffer,
94 sss->posn += next + 1; /* + 1 to skip newline */
96 sss->posn = -1; /* End of file encountered */
101 struct getl_interface *
102 create_syntax_string_source (const char *format, ...)
106 struct syntax_string_source *sss = xzalloc (sizeof *sss);
110 ds_init_empty (&sss->buffer);
112 va_start (args, format);
113 ds_put_vformat (&sss->buffer, format, args);
116 sss->parent.interactive = always_false;
117 sss->parent.close = close;
118 sss->parent.read = read_single_line;
120 sss->parent.name = name;
121 sss->parent.location = location;
124 return (struct getl_interface *) sss;
127 /* Return the syntax currently contained in S.
128 Primarily usefull for debugging */
130 syntax_string_source_get_syntax (const struct syntax_string_source *s)
132 return ds_cstr (&s->buffer);