3 * $Id: scan.h,v 1.5 2004/04/08 01:36:25 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.
36 /*----- Header files ------------------------------------------------------*/
40 #include <mLib/dstr.h>
42 /*----- Data structures ---------------------------------------------------*/
44 /* --- A low-level scanner source --- */
46 typedef struct scansrc
{
47 struct scansrc
*next
; /* Next one in the list */
48 struct scansrc_ops
*ops
; /* Pointer to operations table */
49 char *src
; /* Name of this source */
50 int line
; /* Current line number */
51 dstr pushback
; /* Pushback characters */
52 char *tok
; /* Token pushback */
53 unsigned t
; /* Token type pushback */
56 /* --- Scanner source operations --- */
58 typedef struct scansrc_ops
{
59 int (*scan
)(scansrc */
*ss*/
); /* Read another character */
60 void (*destroy
)(scansrc */
*ss*/
); /* Destroy an unwanted source */
63 /* --- A character scanner --- */
65 typedef struct scanner
{
66 scansrc
*head
, **tail
; /* Scanner list head and tail */
67 int t
; /* Token type */
68 dstr d
; /* Current token value */
69 const char *wbegin
, *wcont
; /* Parsing exception strings */
72 /*----- Particular scanner types ------------------------------------------*/
74 /* --- @scan_file@ --- *
76 * Arguments: @FILE *fp@ = pointer to file descriptor
77 * @const char *name@ = pointer to source file name
78 * @unsigned f@ = flags
80 * Returns: A scanner source.
82 * Use: Creates a new scanner source for reading from a file.
85 #define SCF_NOCLOSE 1u /* Don't close @fp@ when finished */
87 extern scansrc
*scan_file(FILE */
*fp*/
, const char */
*name*/
,
90 /* --- @scan_argv@ --- *
92 * Arguments: @char **av@ = pointer to argument array (null terminated)
94 * Returns: A scanner source.
96 * Use: Creates a new scanner source for reading from an @argv@
100 extern scansrc
*scan_argv(char **/
*av*/
);
102 /*----- General scanner handling ------------------------------------------*/
106 * Arguments: @scanner *sc@ = pointer to main scanner context
108 * Returns: Character read, or end-of-file.
110 * Use: Scans a character from a source of characters.
113 extern int scan(scanner */
*sc*/
);
115 /* --- @unscan@ --- *
117 * Arguments: @scanner *sc@ = pointer to main scanner context
118 * @int ch@ = character to unscan
122 * Use: Scans a character from a source of characters.
125 extern void unscan(scanner */
*sc*/
, int /*ch*/);
127 /* --- @scan_push@ --- *
129 * Arguments: @scanner *sc@ = pointer to main scanner context
130 * @scansrc *ss@ = souorce to push
134 * Use: Pushes a scanner source onto the front of the queue.
137 extern void scan_push(scanner */
*sc*/
, scansrc */
*ss*/
);
139 /* --- @scan_add@ --- *
141 * Arguments: @scanner *sc@ = pointer to main scanner context
142 * @scansrc *ss@ = souorce to push
146 * Use: Adds a scanner source onto the end of the queue.
149 extern void scan_add(scanner */
*sc*/
, scansrc */
*ss*/
);
151 /* --- @scan_create@ --- *
153 * Arguments: @scanner *sc@ = scanner context to initialize
157 * Use: Initializes a scanner block ready for use.
160 extern void scan_create(scanner */
*sc*/
);
162 /* --- @scan_destroy@ --- *
164 * Arguments: @scanner *sc@ = pointer to scanner context
168 * Use: Destroys a scanner and all the sources attached to it.
171 extern void scan_destroy(scanner */
*sc*/
);
173 /*----- That's all, folks -------------------------------------------------*/