build: Actually compile the `blast' helper program.
[fwd] / scan.h
diff --git a/scan.h b/scan.h
index f08fe01..966b939 100644 (file)
--- a/scan.h
+++ b/scan.h
@@ -1,13 +1,11 @@
 /* -*-c-*-
  *
- * $Id: scan.h,v 1.1 1999/07/01 08:56:23 mdw Exp $
- *
  * Character scanners
  *
- * (c) 1999 Mark Wooding
+ * (c) 1999 Straylight/Edgeware
  */
 
-/*----- Licensing notice --------------------------------------------------* 
+/*----- Licensing notice --------------------------------------------------*
  *
  * This file is part of the `fw' port forwarder.
  *
  * it under the terms of the GNU General Public License as published by
  * the Free Software Foundation; either version 2 of the License, or
  * (at your option) any later version.
- * 
+ *
  * `fw' is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU General Public License
  * along with `fw'; if not, write to the Free Software Foundation,
  * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  */
 
-/*----- Revision history --------------------------------------------------* 
- *
- * $Log: scan.h,v $
- * Revision 1.1  1999/07/01 08:56:23  mdw
- * Initial revision
- *
- */
-
 #ifndef SCAN_H
 #define SCAN_H
 
 
 /*----- Data structures ---------------------------------------------------*/
 
-/* --- A configuration scanner --- */
+/* --- A low-level scanner source --- */
 
-typedef struct scan_ops {
-  int (*scan)(void */*p*/);            /* Character scan function */
-  void (*unscan)(int /*ch*/, void */*p*/); /* Character pushback function */
-} scan_ops;
+typedef struct scansrc {
+  struct scansrc *next;                        /* Next one in the list */
+  struct scansrc_ops *ops;             /* Pointer to operations table */
+  char *src;                           /* Name of this source */
+  int line;                            /* Current line number */
+  dstr pushback;                       /* Pushback characters */
+  char *tok;                           /* Token pushback */
+  unsigned t;                          /* Token type pushback */
+} scansrc;
+
+/* --- Scanner source operations --- */
+
+typedef struct scansrc_ops {
+  int (*scan)(scansrc */*ss*/);                /* Read another character */
+  void (*destroy)(scansrc */*ss*/);    /* Destroy an unwanted source */
+} scansrc_ops;
+
+/* --- A character scanner --- */
 
 typedef struct scanner {
-  scan_ops *ops;                       /* Pointer to scanner operations */
-  const char *src;                     /* Name of this source */
-  int line;                            /* Current line number */
+  scansrc *head, **tail;               /* Scanner list head and tail */
   int t;                               /* Token type */
   dstr d;                              /* Current token value */
+  const char *wbegin, *wcont;          /* Parsing exception strings */
 } scanner;
 
-/*----- Scanners provided -------------------------------------------------*/
+/*----- Particular scanner types ------------------------------------------*/
+
+/* --- @scan_file@ --- *
+ *
+ * Arguments:  @FILE *fp@ = pointer to file descriptor
+ *             @const char *name@ = pointer to source file name
+ *             @unsigned f@ = flags
+ *
+ * Returns:    A scanner source.
+ *
+ * Use:                Creates a new scanner source for reading from a file.
+ */
+
+#define SCF_NOCLOSE 1u                 /* Don't close @fp@ when finished */
+
+extern scansrc *scan_file(FILE */*fp*/, const char */*name*/,
+                         unsigned /*f*/);
+
+/* --- @scan_argv@ --- *
+ *
+ * Arguments:  @char **av@ = pointer to argument array (null terminated)
+ *
+ * Returns:    A scanner source.
+ *
+ * Use:                Creates a new scanner source for reading from an @argv@
+ *             array.
+ */
+
+extern scansrc *scan_argv(char **/*av*/);
+
+/*----- General scanner handling ------------------------------------------*/
+
+/* --- @scan@ --- *
+ *
+ * Arguments:  @scanner *sc@ = pointer to main scanner context
+ *
+ * Returns:    Character read, or end-of-file.
+ *
+ * Use:                Scans a character from a source of characters.
+ */
+
+extern int scan(scanner */*sc*/);
+
+/* --- @unscan@ --- *
+ *
+ * Arguments:  @scanner *sc@ = pointer to main scanner context
+ *             @int ch@ = character to unscan
+ *
+ * Returns:    ---
+ *
+ * Use:                Scans a character from a source of characters.
+ */
+
+extern void unscan(scanner */*sc*/, int /*ch*/);
+
+/* --- @scan_push@ --- *
+ *
+ * Arguments:  @scanner *sc@ = pointer to main scanner context
+ *             @scansrc *ss@ = souorce to push
+ *
+ * Returns:    ---
+ *
+ * Use:                Pushes a scanner source onto the front of the queue.
+ */
+
+extern void scan_push(scanner */*sc*/, scansrc */*ss*/);
 
-/* --- The @argv@ scanner --- */
+/* --- @scan_add@ --- *
+ *
+ * Arguments:  @scanner *sc@ = pointer to main scanner context
+ *             @scansrc *ss@ = souorce to push
+ *
+ * Returns:    ---
+ *
+ * Use:                Adds a scanner source onto the end of the queue.
+ */
 
-typedef struct scan_argvctx {
-  scanner sc;                          /* Scanner base structure */
-  char *p;                             /* Pointer to next character */
-  char **pp;                           /* Pointer to next string */
-  int ch;                              /* Pushback character */
-} scan_argvctx;
+extern void scan_add(scanner */*sc*/, scansrc */*ss*/);
 
-extern void scan_argvinit(scan_argvctx */*c*/, char **/*pp*/);
+/* --- @scan_create@ --- *
+ *
+ * Arguments:  @scanner *sc@ = scanner context to initialize
+ *
+ * Returns:    ---
+ *
+ * Use:                Initializes a scanner block ready for use.
+ */
 
-/* --- The file scanner --- */
+extern void scan_create(scanner */*sc*/);
 
-typedef struct scan_filectx {
-  scanner sc;                          /* Scanner base structure */
-  FILE *fp;                            /* Stream pointer */
-} scan_filectx;
+/* --- @scan_destroy@ --- *
+ *
+ * Arguments:  @scanner *sc@ = pointer to scanner context
+ *
+ * Returns:    ---
+ *
+ * Use:                Destroys a scanner and all the sources attached to it.
+ */
 
-extern void scan_fileinit(scan_filectx */*c*/,
-                         FILE */*fp*/, const char */*file*/);
+extern void scan_destroy(scanner */*sc*/);
 
 /*----- That's all, folks -------------------------------------------------*/