diff options
author | Cody Peter Mello <melloc@writev.io> | 2018-09-21 11:16:27 -0700 |
---|---|---|
committer | Cody Peter Mello <melloc@writev.io> | 2018-09-21 11:16:27 -0700 |
commit | 6fe0a049bb5d5e5608f399245f1e519664c6af5a (patch) | |
tree | 01d0ad523dcadb8ef02fe05593e70f319cc8907a /lex.c | |
parent | 2dc7e5ff1a4feeeb549f32706cf34e17aba89192 (diff) | |
download | one-true-awk-6fe0a049bb5d5e5608f399245f1e519664c6af5a.tar.gz |
Improve error reporting messages
Diffstat (limited to 'lex.c')
-rw-r--r-- | lex.c | 18 |
1 files changed, 11 insertions, 7 deletions
@@ -198,6 +198,7 @@ int yylex(void) yylval.i = c; switch (c) { case '\n': /* {EOL} */ + lineno++; RET(NL); case '\r': /* assume \n is coming */ case ' ': /* {WS}+ */ @@ -213,6 +214,7 @@ int yylex(void) case '\\': if (peek() == '\n') { input(); + lineno++; } else if (peek() == '\r') { input(); input(); /* \n */ lineno++; @@ -370,10 +372,11 @@ int string(void) case '\n': case '\r': case 0: + *bp = '\0'; SYNTAX( "non-terminated string %.10s...", buf ); - lineno++; if (c == 0) /* hopeless */ FATAL( "giving up" ); + lineno++; break; case '\\': c = input(); @@ -515,6 +518,7 @@ int regexpr(void) if (!adjbuf(&buf, &bufsz, bp-buf+3, 500, &bp, "regexpr")) FATAL("out of space for reg expr %.10s...", buf); if (c == '\n') { + *bp = '\0'; SYNTAX( "newline in regular expression %.10s...", buf ); unput('\n'); break; @@ -553,19 +557,19 @@ int input(void) /* get next lexical input character */ lexprog++; } else /* awk -f ... */ c = pgetc(); - if (c == '\n') - lineno++; - else if (c == EOF) + if (c == EOF) c = 0; if (ep >= ebuf + sizeof ebuf) ep = ebuf; - return *ep++ = c; + *ep = c; + if (c != 0) { + ep++; + } + return (c); } void unput(int c) /* put lexical character back on input */ { - if (c == '\n') - lineno--; if (yysptr >= yysbuf + sizeof(yysbuf)) FATAL("pushed back too much: %.20s...", yysbuf); *yysptr++ = c; |