-/* $OpenBSD: doas.h,v 1.18 2021/09/07 13:46:07 jcs Exp $ */
+/* $OpenBSD: doas.h,v 1.19 2021/11/30 20:08:15 tobias Exp $ */
/*
* Copyright (c) 2015 Ted Unangst <tedu@openbsd.org>
*
extern struct rule **rules;
extern size_t nrules;
-extern int parse_errors;
+extern int parse_error;
extern const char *formerpath;
-/* $OpenBSD: parse.y,v 1.29 2021/01/27 17:02:50 millert Exp $ */
+/* $OpenBSD: parse.y,v 1.30 2021/11/30 20:08:15 tobias Exp $ */
/*
* Copyright (c) 2015 Ted Unangst <tedu@openbsd.org>
*
%{
#include <sys/types.h>
#include <ctype.h>
+#include <limits.h>
#include <unistd.h>
#include <stdint.h>
#include <stdarg.h>
const char **strlist;
const char *str;
};
- int lineno;
- int colno;
+ unsigned long lineno;
+ unsigned long colno;
} yystype;
#define YYSTYPE yystype
size_t nrules;
static size_t maxrules;
-int parse_errors = 0;
+int parse_error = 0;
static void yyerror(const char *, ...);
static int yylex(void);
va_start(va, fmt);
vfprintf(stderr, fmt, va);
va_end(va);
- fprintf(stderr, " at line %d\n", yylval.lineno + 1);
- parse_errors++;
+ fprintf(stderr, " at line %lu\n", yylval.lineno + 1);
+ parse_error = 1;
}
static struct keyword {
yylex(void)
{
char buf[1024], *ebuf, *p, *str;
- int c, quotes = 0, escape = 0, qpos = -1, nonkw = 0;
+ int c, quoted = 0, quotes = 0, qerr = 0, escape = 0, nonkw = 0;
+ unsigned long qpos = 0;
size_t i;
p = buf;
for (;; c = getc(yyfp), yylval.colno++) {
switch (c) {
case '\0':
- yyerror("unallowed character NUL in column %d",
+ yyerror("unallowed character NUL in column %lu",
yylval.colno + 1);
escape = 0;
continue;
continue;
break;
case '\n':
- if (quotes)
- yyerror("unterminated quotes in column %d",
+ if (quotes && !qerr) {
+ yyerror("unterminated quotes in column %lu",
qpos + 1);
+ qerr = 1;
+ }
if (escape) {
nonkw = 1;
escape = 0;
- yylval.colno = 0;
+ yylval.colno = ULONG_MAX;
yylval.lineno++;
continue;
}
goto eow;
case EOF:
if (escape)
- yyerror("unterminated escape in column %d",
+ yyerror("unterminated escape in column %lu",
yylval.colno);
- if (quotes)
- yyerror("unterminated quotes in column %d",
+ if (quotes && !qerr)
+ yyerror("unterminated quotes in column %lu",
qpos + 1);
goto eow;
- /* FALLTHROUGH */
case '{':
case '}':
case '#':
break;
case '"':
if (!escape) {
+ quoted = 1;
quotes = !quotes;
if (quotes) {
nonkw = 1;
+ qerr = 0;
qpos = yylval.colno;
}
continue;
*/
if (c == EOF)
goto eof;
- else if (qpos == -1) /* accept, e.g., empty args: cmd foo args "" */
+ else if (!quoted) /* accept, e.g., empty args: cmd foo args "" */
goto repeat;
}
if (!nonkw) {