/* -*-c-*-
- *
- * $Id: scan.c,v 1.4 2001/02/03 20:30:03 mdw Exp $
*
* Character scanners
*
* (c) 1999 Straylight/Edgeware
*/
-/*----- Licensing notice --------------------------------------------------*
+/*----- Licensing notice --------------------------------------------------*
*
- * This file is part of the `fw' port forwarder.
+ * This file is part of the `fwd' port forwarder.
*
- * `fw' is free software; you can redistribute it and/or modify
+ * `fwd' is free software; you can redistribute it and/or modify
* 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,
+ *
+ * `fwd' 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,
+ * along with `fwd'; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
-/*----- Revision history --------------------------------------------------*
- *
- * $Log: scan.c,v $
- * Revision 1.4 2001/02/03 20:30:03 mdw
- * Support re-reading config files on SIGHUP.
- *
- * Revision 1.3 2000/08/01 17:58:10 mdw
- * Fix subtleties with <ctype.h> functions.
- *
- * Revision 1.2 1999/07/26 23:24:33 mdw
- * Complete rewrite. Allow a list of character sources to enable changes
- * during parsing of syntactic constructs.
- *
- * Revision 1.1.1.1 1999/07/01 08:56:23 mdw
- * Initial revision.
- *
- */
-
-/*----- Header files ------------------------------------------------------*/
-
-#include "config.h"
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include <mLib/dstr.h>
-#include <mLib/sub.h>
-
-#include "scan.h"
+#include "fwd.h"
/*----- File scanner source -----------------------------------------------*/
fscan *fs = (fscan *)ss;
if (!(fs->f & SCF_NOCLOSE))
fclose(fs->fp);
- if (fs->f & SCF_FREENAME)
- free(fs->ss.src);
+ xfree(fs->ss.src);
DESTROY(fs);
}
/* --- @scan_file@ --- *
*
* Arguments: @FILE *fp@ = pointer to file descriptor
- * @char *name@ = pointer to source file name
+ * @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.
*/
-scansrc *scan_file(FILE *fp, char *name, unsigned f)
+scansrc *scan_file(FILE *fp, const char *name, unsigned f)
{
fscan *fs = CREATE(fscan);
fs->ss.ops = &fscan_ops;
- fs->ss.src = name;
+ fs->ss.src = xstrdup(name);
fs->ss.line = 1;
fs->fp = fp;
fs->f = f;
/* --- The end of file marker --- */
-static scansrc scan_eof = { &scan_eof, &eof_ops, "<eof>", 0, EOF };
+static scansrc scan_eof = { &scan_eof, &eof_ops, "<eof>", 0, DSTR_INIT };
/*----- General scanner handling ------------------------------------------*/
int scan(scanner *sc)
{
int ch;
- if (sc->head->pushback != EOF) {
- ch = sc->head->pushback;
- sc->head->pushback = EOF;
- } else {
+ if (sc->head->pushback.len)
+ ch = sc->head->pushback.buf[--sc->head->pushback.len];
+ else {
scansrc *ss = sc->head;
if (ss == &scan_eof)
ch = EOF;
void unscan(scanner *sc, int ch)
{
- sc->head->pushback = ch;
+ DPUTC(&sc->head->pushback, ch);
}
/* --- @scan_push@ --- *
if (sc->head == &scan_eof)
sc->tail = &ss->next;
sc->head = ss;
- ss->pushback = EOF;
+ dstr_create(&ss->pushback);
ss->tok = 0;
ss->t = 0;
}
ss->next = &scan_eof;
*sc->tail = ss;
sc->tail = &ss->next;
- ss->pushback = EOF;
+ dstr_create(&ss->pushback);
ss->tok = 0;
ss->t = 0;
}
sc->head = &scan_eof;
sc->tail = &sc->head;
dstr_create(&sc->d);
+ sc->wbegin = sc->wcont = 0;
}
/* --- @scan_destroy@ --- *
scansrc *sss = ss;
ss = ss->next;
if (sss->tok)
- free(sss->tok);
+ xfree(sss->tok);
+ dstr_destroy(&sss->pushback);
sss->ops->destroy(sss);
}
dstr_destroy(&sc->d);
if (scan_eof.tok)
- free(scan_eof.tok);
+ xfree(scan_eof.tok);
scan_eof.tok = 0;
sc->head = &scan_eof;
sc->tail = &sc->head;