Various changes. Add configuration grammar to help text. Change to
[fwd] / scan.h
1 /* -*-c-*-
2 *
3 * $Id: scan.h,v 1.1 1999/07/01 08:56:23 mdw Exp $
4 *
5 * Character scanners
6 *
7 * (c) 1999 Mark Wooding
8 */
9
10 /*----- Licensing notice --------------------------------------------------*
11 *
12 * This file is part of the `fw' port forwarder.
13 *
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.
18 *
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.
23 *
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.
27 */
28
29 /*----- Revision history --------------------------------------------------*
30 *
31 * $Log: scan.h,v $
32 * Revision 1.1 1999/07/01 08:56:23 mdw
33 * Initial revision
34 *
35 */
36
37 #ifndef SCAN_H
38 #define SCAN_H
39
40 #ifdef __cplusplus
41 extern "C" {
42 #endif
43
44 /*----- Header files ------------------------------------------------------*/
45
46 #include <stdio.h>
47
48 #include <mLib/dstr.h>
49
50 /*----- Data structures ---------------------------------------------------*/
51
52 /* --- A configuration scanner --- */
53
54 typedef struct scan_ops {
55 int (*scan)(void */*p*/); /* Character scan function */
56 void (*unscan)(int /*ch*/, void */*p*/); /* Character pushback function */
57 } scan_ops;
58
59 typedef struct scanner {
60 scan_ops *ops; /* Pointer to scanner operations */
61 const char *src; /* Name of this source */
62 int line; /* Current line number */
63 int t; /* Token type */
64 dstr d; /* Current token value */
65 } scanner;
66
67 /*----- Scanners provided -------------------------------------------------*/
68
69 /* --- The @argv@ scanner --- */
70
71 typedef struct scan_argvctx {
72 scanner sc; /* Scanner base structure */
73 char *p; /* Pointer to next character */
74 char **pp; /* Pointer to next string */
75 int ch; /* Pushback character */
76 } scan_argvctx;
77
78 extern void scan_argvinit(scan_argvctx */*c*/, char **/*pp*/);
79
80 /* --- The file scanner --- */
81
82 typedef struct scan_filectx {
83 scanner sc; /* Scanner base structure */
84 FILE *fp; /* Stream pointer */
85 } scan_filectx;
86
87 extern void scan_fileinit(scan_filectx */*c*/,
88 FILE */*fp*/, const char */*file*/);
89
90 /*----- That's all, folks -------------------------------------------------*/
91
92 #ifdef __cplusplus
93 }
94 #endif
95
96 #endif