1 /*-----------------------------------------------------------------------
2 
3 File  : cio_streams.h
4 
5 Author: Stephan Schulz
6 
7 Contents
8 
9   Definitions for a stream type, i.e. an object associated with a file
10   pointer (and possibly a file name), allowing read operations,
11   arbitrary look-aheads, and maintaining line and column numbers for
12   error messages.
13 
14   Copyright 1998, 1999 by the author.
15   This code is released under the GNU General Public Licence and
16   the GNU Lesser General Public License.
17   See the file COPYING in the main E directory for details..
18   Run "eprover -h" for contact information.
19 
20 Changes
21 
22 <1> Wed Aug 20 00:02:32 MET DST 1997
23     New
24 
25 -----------------------------------------------------------------------*/
26 
27 #ifndef CIO_STREAMS
28 
29 #define CIO_STREAMS
30 
31 #include <cio_initio.h>
32 #include <cio_fileops.h>
33 
34 /*---------------------------------------------------------------------*/
35 /*                    Data type declarations                           */
36 /*---------------------------------------------------------------------*/
37 
38 #define MAXLOOKAHEAD 64
39 
40 
41 /* Streams can read either from a file or from several predefined
42    classes of strings. We use a StreamType 'virtual type' to denote
43    this, because we can thus code the string type in a convenient
44    way. */
45 
46 typedef char* StreamType;
47 
48 
49 /* The following data structure describes the state of a (named) input
50    stream with lookahead-capability. Streams are stackable, with new
51    data being read from the top of the stack. The empty stack is a
52    NULL-valued pointer of type Inpstack_p! */
53 
54 
55 typedef struct streamcell
56 {
57    struct streamcell* next;
58    DStr_p             source;
59    StreamType         stream_type; /* Only constant strings allowed
60                   here! */
61    long               string_pos;
62    FILE*              file;
63    bool               eof_seen;
64    long               line;
65    long               column;
66    int                buffer[MAXLOOKAHEAD];
67    int                current;
68 }StreamCell, *Stream_p, **Inpstack_p;
69 
70 
71 /*---------------------------------------------------------------------*/
72 /*                Exported Functions and Variables                     */
73 /*---------------------------------------------------------------------*/
74 
75 extern const StreamType StreamTypeFile;
76 extern const StreamType StreamTypeInternalString;
77 extern const StreamType StreamTypeUserString;
78 extern const StreamType StreamTypeOptionString;
79 
80 
81 #define StreamCellAlloc() (StreamCell*)SizeMalloc(sizeof(StreamCell))
82 #define StreamCellFree(junk)         SizeFree(junk, sizeof(StreamCell))
83 
84 Stream_p CreateStream(StreamType type, char* source, bool fail);
85 void     DestroyStream(Stream_p stream);
86 
87 #define  STREAMREALPOS(pos) ((pos) % MAXLOOKAHEAD)
88 
89 #define  StreamLookChar(stream, look)\
90          (assert((look)<MAXLOOKAHEAD),\
91      (stream)->buffer[STREAMREALPOS((stream)->current+(look))])
92 #define  StreamCurrChar(stream) ((stream)->buffer[(stream)->current])
93 #define  StreamCurrLine(stream)   ((stream)->line)
94 #define  StreamCurrColumn(stream) ((stream)->column)
95 
96 int      StreamNextChar(Stream_p stream);
97 
98 Stream_p OpenStackedInput(Inpstack_p stack, StreamType type,
99            char* source, bool fail);
100 void     CloseStackedInput(Inpstack_p stack);
101 
102 
103 #endif
104 
105 /*---------------------------------------------------------------------*/
106 /*                        End of File                                  */
107 /*---------------------------------------------------------------------*/
108 
109 
110 
111 
112 
113