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