f0b8585f3d6c8ed040847c8564794dc78fa5454e
[pspp-builds.git] / src / libpspp / getl.h
1 /* PSPP - computes sample statistics.
2    Copyright (C) 1997-9, 2000, 2006 Free Software Foundation, Inc.
3    Written by Ben Pfaff <blp@gnu.org>.
4
5    This program is free software; you can redistribute it and/or
6    modify it under the terms of the GNU General Public License as
7    published by the Free Software Foundation; either version 2 of the
8    License, or (at your option) any later version.
9
10    This program is distributed in the hope that it will be useful, but
11    WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13    General Public License for more details.
14
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
18    02110-1301, USA. */
19
20 #ifndef GETL_H
21 #define GETL_H 1
22
23 #include <stdbool.h>
24 #include <libpspp/ll.h>
25
26 struct string;
27
28 struct getl_source;
29
30 /* Syntax rules that apply to a given source line. */
31 enum getl_syntax
32   {
33     /* Each line that begins in column 1 starts a new command.  A
34        `+' or `-' in column 1 is ignored to allow visual
35        indentation of new commands.  Continuation lines must be
36        indented from the left margin.  A period at the end of a
37        line does end a command, but it is optional. */
38     GETL_BATCH,
39
40     /* Each command must end in a period or in a blank line. */
41     GETL_INTERACTIVE
42   };
43
44 /* An abstract base class for objects which act as line buffers for the
45    PSPP.  Ie anything which might contain content for the lexer */
46 struct getl_interface
47   {
48     /* Returns true if the interface is interactive, that is, if
49        it prompts a human user.  This property is independent of
50        the syntax mode returned by the read member function. */
51     bool  (*interactive) (const struct getl_interface *);
52
53     /* Read a line the intended syntax mode from the interface.
54        Returns true if succesful, false on failure or at end of
55        input. */
56     bool  (*read)  (struct getl_interface *,
57                     struct string *, enum getl_syntax *);
58
59     /* Close and destroy the interface */
60     void  (*close) (struct getl_interface *);
61
62     /* Filter for current and all included sources, which may
63        modify the line.  Usually null.  */
64     void  (*filter) (struct getl_interface *,
65                      struct string *line, enum getl_syntax);
66
67     /* Returns the name of the source */
68     const char * (*name) (const struct getl_interface *);
69
70     /* Returns the current location within the source */
71     int (*location) (const struct getl_interface *);
72   };
73
74 struct source_stream;
75
76 struct source_stream * create_source_stream (const char *);
77 void destroy_source_stream (struct source_stream *);
78
79 void getl_clear_include_path (struct source_stream *);
80 void getl_add_include_dir (struct source_stream *, const char *);
81 const char * getl_include_path (const struct source_stream *);
82
83 void getl_abort_noninteractive (struct source_stream *);
84 bool getl_is_interactive (const struct source_stream *);
85
86 bool getl_read_line (struct source_stream *, struct string *,
87                      enum getl_syntax *);
88
89 void getl_append_source (struct source_stream *, struct getl_interface *s) ;
90 void getl_include_source (struct source_stream *, struct getl_interface *s) ;
91
92 const char * getl_source_name (const struct source_stream *);
93 int getl_source_location (const struct source_stream *);
94
95 #endif /* line-buffer.h */