Change license from GPLv2+ to GPLv3+.
[pspp-builds.git] / src / libpspp / getl.h
1 /* PSPP - a program for statistical analysis.
2    Copyright (C) 1997-9, 2000, 2006 Free Software Foundation, Inc.
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 #ifndef GETL_H
18 #define GETL_H 1
19
20 #include <stdbool.h>
21 #include <libpspp/ll.h>
22
23 struct string;
24
25 struct getl_source;
26
27 /* Syntax rules that apply to a given source line. */
28 enum getl_syntax
29   {
30     /* Each line that begins in column 1 starts a new command.  A
31        `+' or `-' in column 1 is ignored to allow visual
32        indentation of new commands.  Continuation lines must be
33        indented from the left margin.  A period at the end of a
34        line does end a command, but it is optional. */
35     GETL_BATCH,
36
37     /* Each command must end in a period or in a blank line. */
38     GETL_INTERACTIVE
39   };
40
41 /* An abstract base class for objects which act as line buffers for the
42    PSPP.  Ie anything which might contain content for the lexer */
43 struct getl_interface
44   {
45     /* Returns true if the interface is interactive, that is, if
46        it prompts a human user.  This property is independent of
47        the syntax mode returned by the read member function. */
48     bool  (*interactive) (const struct getl_interface *);
49
50     /* Read a line the intended syntax mode from the interface.
51        Returns true if succesful, false on failure or at end of
52        input. */
53     bool  (*read)  (struct getl_interface *,
54                     struct string *, enum getl_syntax *);
55
56     /* Close and destroy the interface */
57     void  (*close) (struct getl_interface *);
58
59     /* Filter for current and all included sources, which may
60        modify the line.  Usually null.  */
61     void  (*filter) (struct getl_interface *,
62                      struct string *line, enum getl_syntax);
63
64     /* Returns the name of the source */
65     const char * (*name) (const struct getl_interface *);
66
67     /* Returns the current location within the source */
68     int (*location) (const struct getl_interface *);
69   };
70
71 struct source_stream;
72
73 struct source_stream * create_source_stream (const char *);
74 void destroy_source_stream (struct source_stream *);
75
76 void getl_clear_include_path (struct source_stream *);
77 void getl_add_include_dir (struct source_stream *, const char *);
78 const char * getl_include_path (const struct source_stream *);
79
80 void getl_abort_noninteractive (struct source_stream *);
81 bool getl_is_interactive (const struct source_stream *);
82
83 bool getl_read_line (struct source_stream *, struct string *,
84                      enum getl_syntax *);
85
86 void getl_append_source (struct source_stream *, struct getl_interface *s) ;
87 void getl_include_source (struct source_stream *, struct getl_interface *s) ;
88
89 const char * getl_source_name (const struct source_stream *);
90 int getl_source_location (const struct source_stream *);
91
92 #endif /* line-buffer.h */