3 * $Id: scan.h,v 1.2 1999/07/26 23:24:33 mdw Exp $
7 * (c) 1999 Straylight/Edgeware
10 /*----- Licensing notice --------------------------------------------------*
12 * This file is part of the `fw' port forwarder.
14 * `fw' is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2 of the License, or
17 * (at your option) any later version.
19 * `fw' is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with `fw'; if not, write to the Free Software Foundation,
26 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
29 /*----- Revision history --------------------------------------------------*
32 * Revision 1.2 1999/07/26 23:24:33 mdw
33 * Complete rewrite. Allow a list of character sources to enable changes
34 * during parsing of syntactic constructs.
36 * Revision 1.1.1.1 1999/07/01 08:56:23 mdw
48 /*----- Header files ------------------------------------------------------*/
52 #include <mLib/dstr.h>
54 /*----- Data structures ---------------------------------------------------*/
56 /* --- A low-level scanner source --- */
58 typedef struct scansrc
{
59 struct scansrc
*next
; /* Next one in the list */
60 struct scansrc_ops
*ops
; /* Pointer to operations table */
61 char *src
; /* Name of this source */
62 int line
; /* Current line number */
63 int pushback
; /* Pushback character */
64 char *tok
; /* Token pushback */
65 unsigned t
; /* Token type pushback */
68 /* --- Scanner source operations --- */
70 typedef struct scansrc_ops
{
71 int (*scan
)(scansrc */
*ss*/
); /* Read another character */
72 void (*destroy
)(scansrc */
*ss*/
); /* Destroy an unwanted source */
75 /* --- A character scanner --- */
77 typedef struct scanner
{
78 scansrc
*head
, **tail
; /* Scanner list head and tail */
79 int t
; /* Token type */
80 dstr d
; /* Current token value */
83 /*----- Particular scanner types ------------------------------------------*/
85 /* --- @scan_file@ --- *
87 * Arguments: @FILE *fp@ = pointer to file descriptor
88 * @char *name@ = pointer to source file name
89 * @unsigned f@ = flags
91 * Returns: A scanner source.
93 * Use: Creates a new scanner source for reading from a file.
96 extern scansrc
*scan_file(FILE */
*fp*/
, char */
*name*/
, unsigned /*f*/);
98 #define SCF_NOCLOSE 1u
99 #define SCF_FREENAME 2u
101 /* --- @scan_argv@ --- *
103 * Arguments: @char **av@ = pointer to argument array (null terminated)
105 * Returns: A scanner source.
107 * Use: Creates a new scanner source for reading from an @argv@
111 extern scansrc
*scan_argv(char **/
*av*/
);
113 /*----- General scanner handling ------------------------------------------*/
117 * Arguments: @scanner *sc@ = pointer to main scanner context
119 * Returns: Character read, or end-of-file.
121 * Use: Scans a character from a source of characters.
124 extern int scan(scanner */
*sc*/
);
126 /* --- @unscan@ --- *
128 * Arguments: @scanner *sc@ = pointer to main scanner context
129 * @int ch@ = character to unscan
133 * Use: Scans a character from a source of characters.
136 extern void unscan(scanner */
*sc*/
, int /*ch*/);
138 /* --- @scan_push@ --- *
140 * Arguments: @scanner *sc@ = pointer to main scanner context
141 * @scansrc *ss@ = souorce to push
145 * Use: Pushes a scanner source onto the front of the queue.
148 extern void scan_push(scanner */
*sc*/
, scansrc */
*ss*/
);
150 /* --- @scan_add@ --- *
152 * Arguments: @scanner *sc@ = pointer to main scanner context
153 * @scansrc *ss@ = souorce to push
157 * Use: Adds a scanner source onto the end of the queue.
160 extern void scan_add(scanner */
*sc*/
, scansrc */
*ss*/
);
162 /* --- @scan_create@ --- *
164 * Arguments: @scanner *sc@ = scanner context to initialize
168 * Use: Initializes a scanner block ready for use.
171 extern void scan_create(scanner */
*sc*/
);
173 /* --- @scan_destroy@ --- *
175 * Arguments: @scanner *sc@ = pointer to scanner context
179 * Use: Destroys a scanner and all the sources attached to it.
182 extern void scan_destroy(scanner */
*sc*/
);
184 /*----- That's all, folks -------------------------------------------------*/