summaryrefslogtreecommitdiff
path: root/usr.sbin/config/scan.l
diff options
context:
space:
mode:
authorbriggs <briggs@cvs.openbsd.org>1997-01-18 02:24:22 +0000
committerbriggs <briggs@cvs.openbsd.org>1997-01-18 02:24:22 +0000
commit3365c90dc4687554bb99299cf49004ba542297e0 (patch)
tree4b800c042060d3d58df05513f78ee52a1d93bdfb /usr.sbin/config/scan.l
parent2b5c10d28c4ef509dc19fbd6de2b20d9c1410699 (diff)
Sync. with current NetBSD--keeping local changes.
Diffstat (limited to 'usr.sbin/config/scan.l')
-rw-r--r--usr.sbin/config/scan.l148
1 files changed, 82 insertions, 66 deletions
diff --git a/usr.sbin/config/scan.l b/usr.sbin/config/scan.l
index 542c5e31eff..b5779841ea7 100644
--- a/usr.sbin/config/scan.l
+++ b/usr.sbin/config/scan.l
@@ -1,6 +1,6 @@
%{
-/* $OpenBSD: scan.l,v 1.6 1996/10/23 22:37:59 niklas Exp $ */
-/* $NetBSD: scan.l,v 1.7 1996/08/31 21:15:13 mycroft Exp $ */
+/* $OpenBSD: scan.l,v 1.7 1997/01/18 02:24:18 briggs Exp $ */
+/* $NetBSD: scan.l,v 1.11 1996/11/13 18:42:18 gwr Exp $ */
/*
* Copyright (c) 1992, 1993
@@ -59,8 +59,6 @@ int yyline;
const char *yyfile;
const char *lastfile;
-int include __P((const char *, int));
-
/*
* Data for returning to previous files from include files.
*/
@@ -69,61 +67,68 @@ struct incl {
YY_BUFFER_STATE in_buf; /* previous lex state */
const char *in_fname; /* previous file name */
int in_lineno; /* previous line number */
- int in_preveof; /* previous eoftoken */
+ int in_ateof; /* token to insert at EOF */
};
static struct incl *incl;
-static int eoftoken; /* current EOF token */
-static void endinclude __P((void));
+static int endinclude __P((void));
#define yywrap() 1
%}
-PATH [-/A-Za-z0-9_.]*[./][-/A-Za-z0-9_.]*
+PATH [A-Za-z_0-9]*[./][-A-Za-z_0-9./]*
WORD [A-Za-z_][-A-Za-z_0-9]*
%%
+ /* Local variables for yylex() */
+ int tok;
+
+and return AND;
+at return AT;
+attach return ATTACH;
+build return BUILD;
+compile-with return COMPILE_WITH;
+config return CONFIG;
+define return DEFINE;
+device return DEVICE;
+disable return DISABLE;
+dumps return DUMPS;
+file return XFILE;
+flags return FLAGS;
+include return INCLUDE;
+machine return XMACHINE;
+major return MAJOR;
+makeoptions return MAKEOPTIONS;
+maxpartitions return MAXPARTITIONS;
+maxusers return MAXUSERS;
+minor return MINOR;
+needs-count return NEEDS_COUNT;
+needs-flag return NEEDS_FLAG;
+on return ON;
+options return OPTIONS;
+option return OPTIONS;
+pseudo-device return PSEUDO_DEVICE;
+root return ROOT;
+source return SOURCE;
+swap return SWAP;
+with return WITH;
+
+{PATH} {
+ yylval.str = intern(yytext);
+ return PATHNAME;
+ }
+{WORD} {
+ yylval.str = intern(yytext);
+ return WORD;
+ }
- /* plain keywords */
-and { return AND; }
-at { return AT; }
-attach { return ATTACH; }
-build { return BUILD; }
-compile-with { return COMPILE_WITH; }
-config { return CONFIG; }
-define { return DEFINE; }
-device { return DEVICE; }
-disable { return DISABLE; }
-dumps { return DUMPS; }
-flags { return FLAGS; }
-file { return XFILE; }
-include { return INCLUDE; }
-machine { return XMACHINE; }
-major { return MAJOR; }
-makeoptions { return MAKEOPTIONS; }
-maxusers { return MAXUSERS; }
-maxpartitions { return MAXPARTITIONS; }
-minor { return MINOR; }
-on { return ON; }
-options { return OPTIONS; }
-option { return OPTIONS; }
-"pseudo-device" { return PSEUDO_DEVICE; }
-root { return ROOT; }
-source { return SOURCE; }
-swap { return SWAP; }
-with { return WITH; }
-
- /* keywords with values */
-needs-count { yylval.val = FI_NEEDSCOUNT; return FFLAG; }
-needs-flag { yylval.val = FI_NEEDSFLAG; return FFLAG; }
-
- /* all the rest */
-{PATH} { yylval.str = intern(yytext); return PATHNAME; }
-{WORD} { yylval.str = intern(yytext); return WORD; }
-
-\"([^"]|\\\")*/\" {
+\"([^"\n]|\\\")+ {
+ tok = input(); /* eat closing quote */
+ if (tok != '"') {
+ error("closing quote missing\n");
+ unput(tok);
+ }
yylval.str = intern(yytext + 1);
- (void)input(); /* eat closing quote */
return WORD;
}
0[0-7]* {
@@ -138,7 +143,12 @@ needs-flag { yylval.val = FI_NEEDSFLAG; return FFLAG; }
yylval.val = strtol(yytext, NULL, 10);
return NUMBER;
}
-\n/[ \t] {
+\n[ \t] {
+ /*
+ * Note: newline followed by whitespace is always a
+ * continuation of the previous line, so do NOT
+ * return a token in this case.
+ */
yyline++;
}
\n {
@@ -146,16 +156,15 @@ needs-flag { yylval.val = FI_NEEDSFLAG; return FFLAG; }
return '\n';
}
#.* { /* ignored (comment) */; }
-[ \t]* { /* ignored (white space) */; }
+[ \t]+ { /* ignored (white space) */; }
. { return yytext[0]; }
<<EOF>> {
- int tok;
-
- tok = eoftoken;
- eoftoken = YY_NULL;
- if (incl != NULL)
- endinclude();
- return (tok);
+ if (incl == NULL)
+ return YY_NULL;
+ tok = endinclude();
+ if (tok)
+ return tok;
+ /* otherwise continue scanning */
}
%%
@@ -172,7 +181,6 @@ firstfile(fname)
return (-1);
yyfile = conffile = fname;
yyline = 1;
- eoftoken = YY_NULL;
return (0);
}
@@ -180,17 +188,23 @@ firstfile(fname)
* Open the named file for inclusion at the current point. Returns 0 on
* success (file opened and previous state pushed), nonzero on failure
* (fopen failed, complaint made). The `ateof' parameter controls the
- * token to be returned at the end of the include file (typically '\n'
- * or ENDFILE).
+ * token to be inserted at the end of the include file (i.e. ENDFILE).
+ * If ateof == 0 then nothing is inserted.
*/
int
include(fname, ateof)
const char *fname;
int ateof;
{
- register FILE *fp;
- register struct incl *in;
+ FILE *fp;
+ struct incl *in;
char *s;
+ static int havedirs;
+
+ if (havedirs == 0) {
+ havedirs = 1;
+ setupdirs();
+ }
/* Kludge until files.* files are fixed. */
if (strncmp(fname, "../../../", 9) == 0)
@@ -207,12 +221,11 @@ include(fname, ateof)
in->in_buf = YY_CURRENT_BUFFER;
in->in_fname = yyfile;
in->in_lineno = yyline;
- in->in_preveof = eoftoken;
+ in->in_ateof = ateof;
incl = in;
yy_switch_to_buffer(yy_create_buffer(fp, YY_BUF_SIZE));
yyfile = intern(s);
yyline = 1;
- eoftoken = ateof;
free(s);
return (0);
}
@@ -220,10 +233,11 @@ include(fname, ateof)
/*
* Terminate the most recent inclusion.
*/
-static void
+static int
endinclude()
{
- register struct incl *in;
+ struct incl *in;
+ int ateof;
if ((in = incl) == NULL)
panic("endinclude");
@@ -234,8 +248,10 @@ endinclude()
yy_switch_to_buffer(in->in_buf);
yyfile = in->in_fname;
yyline = in->in_lineno;
- eoftoken = in->in_preveof;
+ ateof = in->in_ateof;
free(in);
+
+ return (ateof);
}
/*