5 * (c) 1999 Straylight/Edgeware
8 /*----- Licensing notice --------------------------------------------------*
10 * This file is part of the `fw' port forwarder.
12 * `fw' is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * `fw' is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with `fw'; if not, write to the Free Software Foundation,
24 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
34 /*----- Header files ------------------------------------------------------*/
38 #include <mLib/dstr.h>
40 /*----- Data structures ---------------------------------------------------*/
42 /* --- A low-level scanner source --- */
44 typedef struct scansrc {
45 struct scansrc *next; /* Next one in the list */
46 struct scansrc_ops *ops; /* Pointer to operations table */
47 char *src; /* Name of this source */
48 int line; /* Current line number */
49 dstr pushback; /* Pushback characters */
50 char *tok; /* Token pushback */
51 unsigned t; /* Token type pushback */
54 /* --- Scanner source operations --- */
56 typedef struct scansrc_ops {
57 int (*scan)(scansrc */*ss*/); /* Read another character */
58 void (*destroy)(scansrc */*ss*/); /* Destroy an unwanted source */
61 /* --- A character scanner --- */
63 typedef struct scanner {
64 scansrc *head, **tail; /* Scanner list head and tail */
65 int t; /* Token type */
66 dstr d; /* Current token value */
67 const char *wbegin, *wcont; /* Parsing exception strings */
70 /*----- Particular scanner types ------------------------------------------*/
72 /* --- @scan_file@ --- *
74 * Arguments: @FILE *fp@ = pointer to file descriptor
75 * @const char *name@ = pointer to source file name
76 * @unsigned f@ = flags
78 * Returns: A scanner source.
80 * Use: Creates a new scanner source for reading from a file.
83 #define SCF_NOCLOSE 1u /* Don't close @fp@ when finished */
85 extern scansrc *scan_file(FILE */*fp*/, const char */*name*/,
88 /* --- @scan_argv@ --- *
90 * Arguments: @char **av@ = pointer to argument array (null terminated)
92 * Returns: A scanner source.
94 * Use: Creates a new scanner source for reading from an @argv@
98 extern scansrc *scan_argv(char **/*av*/);
100 /*----- General scanner handling ------------------------------------------*/
104 * Arguments: @scanner *sc@ = pointer to main scanner context
106 * Returns: Character read, or end-of-file.
108 * Use: Scans a character from a source of characters.
111 extern int scan(scanner */*sc*/);
113 /* --- @unscan@ --- *
115 * Arguments: @scanner *sc@ = pointer to main scanner context
116 * @int ch@ = character to unscan
120 * Use: Scans a character from a source of characters.
123 extern void unscan(scanner */*sc*/, int /*ch*/);
125 /* --- @scan_push@ --- *
127 * Arguments: @scanner *sc@ = pointer to main scanner context
128 * @scansrc *ss@ = souorce to push
132 * Use: Pushes a scanner source onto the front of the queue.
135 extern void scan_push(scanner */*sc*/, scansrc */*ss*/);
137 /* --- @scan_add@ --- *
139 * Arguments: @scanner *sc@ = pointer to main scanner context
140 * @scansrc *ss@ = souorce to push
144 * Use: Adds a scanner source onto the end of the queue.
147 extern void scan_add(scanner */*sc*/, scansrc */*ss*/);
149 /* --- @scan_create@ --- *
151 * Arguments: @scanner *sc@ = scanner context to initialize
155 * Use: Initializes a scanner block ready for use.
158 extern void scan_create(scanner */*sc*/);
160 /* --- @scan_destroy@ --- *
162 * Arguments: @scanner *sc@ = pointer to scanner context
166 * Use: Destroys a scanner and all the sources attached to it.
169 extern void scan_destroy(scanner */*sc*/);
171 /*----- That's all, folks -------------------------------------------------*/