-/* $OpenBSD: parse.y,v 1.1 2015/07/16 20:44:21 tedu Exp $ */
+/* $OpenBSD: parse.y,v 1.5 2015/07/19 22:09:08 benno Exp $ */
/*
* Copyright (c) 2015 Ted Unangst <tedu@openbsd.org>
*
struct rule **rules;
int nrules, maxrules;
+void yyerror(const char *, ...);
+int yylex(void);
+int yyparse(void);
+
%}
%token TPERMIT TDENY TAS TCMD
maxrules = 63;
else
maxrules *= 2;
- if (!(rules = reallocarray(rules, maxrules, sizeof(*rules))))
+ if (!(rules = reallocarray(rules, maxrules,
+ sizeof(*rules))))
errx(1, "can't allocate rules");
}
rules[nrules++] = r;
errx(1, "can't allocate envlist");
} | envlist TSTRING {
int nenv = arraylen($1.envlist);
- if (!($$.envlist = reallocarray($1.envlist, nenv + 2, sizeof(char *))))
+ if (!($$.envlist = reallocarray($1.envlist, nenv + 2,
+ sizeof(char *))))
errx(1, "can't allocate envlist");
$$.envlist[nenv] = $2.str;
$$.envlist[nenv + 1] = NULL;
va_list va;
va_start(va, fmt);
- fprintf(stderr, "doas: ");
- vfprintf(stderr, fmt, va);
- fprintf(stderr, "\n");
- va_end(va);
- exit(1);
+ verrx(1, fmt, va);
}
struct keyword {
yylex(void)
{
char buf[1024], *ebuf, *p, *str;
- int i, c;
+ int i, c, next;
p = buf;
ebuf = buf + sizeof(buf);
- while ((c = getc(yyfp)) == ' ' || c == '\t')
- ; /* skip spaces */
+repeat:
+ c = getc(yyfp);
switch (c) {
+ case ' ':
+ case '\t':
+ goto repeat; /* skip spaces */
+ case '\\':
+ next = getc(yyfp);
+ if (next == '\n')
+ goto repeat;
+ else
+ c = next;
case '\n':
case '{':
case '}':
return c;
case EOF:
return 0;
- case ':':
- *p++ = c;
- c = getc(yyfp);
- break;
- default:
- break;
}
- while (isalnum(c)) {
+ while (1) {
+ switch (c) {
+ case '\n':
+ case '{':
+ case '}':
+ case '#':
+ case ' ':
+ case '\t':
+ case EOF:
+ goto eow;
+ }
*p++ = c;
if (p == ebuf)
yyerror("too much stuff");
c = getc(yyfp);
}
+eow:
*p = 0;
if (c != EOF)
ungetc(c, yyfp);