summaryrefslogtreecommitdiffstats
path: root/contrib/one-true-awk/lex.c
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/one-true-awk/lex.c')
-rw-r--r--contrib/one-true-awk/lex.c22
1 files changed, 8 insertions, 14 deletions
diff --git a/contrib/one-true-awk/lex.c b/contrib/one-true-awk/lex.c
index 374bc85..49d7c5c 100644
--- a/contrib/one-true-awk/lex.c
+++ b/contrib/one-true-awk/lex.c
@@ -89,12 +89,7 @@ Keyword keywords[] ={ /* keep sorted: binary searched */
{ "while", WHILE, WHILE },
};
-#define DEBUG
-#ifdef DEBUG
#define RET(x) { if(dbg)printf("lex %s\n", tokname(x)); return(x); }
-#else
-#define RET(x) return(x)
-#endif
int peek(void)
{
@@ -122,7 +117,7 @@ int gettok(char **pbuf, int *psz) /* get next input token */
if (isalpha(c) || c == '_') { /* it's a varname */
for ( ; (c = input()) != 0; ) {
if (bp-buf >= sz)
- if (!adjbuf(&buf, &sz, bp-buf+2, 100, &bp, 0))
+ if (!adjbuf(&buf, &sz, bp-buf+2, 100, &bp, "gettok"))
FATAL( "out of space for name %.10s...", buf );
if (isalnum(c) || c == '_')
*bp++ = c;
@@ -139,7 +134,7 @@ int gettok(char **pbuf, int *psz) /* get next input token */
/* read input until can't be a number */
for ( ; (c = input()) != 0; ) {
if (bp-buf >= sz)
- if (!adjbuf(&buf, &sz, bp-buf+2, 100, &bp, 0))
+ if (!adjbuf(&buf, &sz, bp-buf+2, 100, &bp, "gettok"))
FATAL( "out of space for number %.10s...", buf );
if (isdigit(c) || c == 'e' || c == 'E'
|| c == '.' || c == '+' || c == '-')
@@ -176,7 +171,7 @@ int yylex(void)
{
int c;
static char *buf = 0;
- static int bufsize = 500;
+ static int bufsize = 5; /* BUG: setting this small causes core dump! */
if (buf == 0 && (buf = (char *) malloc(bufsize)) == NULL)
FATAL( "out of space in yylex" );
@@ -188,10 +183,8 @@ int yylex(void)
reg = 0;
return regexpr();
}
-/* printf("top\n"); */
for (;;) {
c = gettok(&buf, &bufsize);
-/* printf("gettok [%s]\n", buf); */
if (c == 0)
return 0;
if (isalpha(c) || c == '_')
@@ -371,7 +364,7 @@ int string(void)
if (buf == 0 && (buf = (char *) malloc(bufsz)) == NULL)
FATAL("out of space for strings");
for (bp = buf; (c = input()) != '"'; ) {
- if (!adjbuf(&buf, &bufsz, bp-buf+2, 500, &bp, 0))
+ if (!adjbuf(&buf, &bufsz, bp-buf+2, 500, &bp, "string"))
FATAL("out of space for string %.10s...", buf);
switch (c) {
case '\n':
@@ -465,12 +458,13 @@ int word(char *w)
int c, n;
n = binsearch(w, keywords, sizeof(keywords)/sizeof(keywords[0]));
+/* BUG: this ought to be inside the if; in theory could fault (daniel barrett) */
kp = keywords + n;
if (n != -1) { /* found in table */
yylval.i = kp->sub;
switch (kp->type) { /* special handling */
- case FSYSTEM:
- if (safe)
+ case BLTIN:
+ if (kp->sub == FSYSTEM && safe)
SYNTAX( "system is unsafe" );
RET(kp->type);
case FUNC:
@@ -518,7 +512,7 @@ int regexpr(void)
FATAL("out of space for rex expr");
bp = buf;
for ( ; (c = input()) != '/' && c != 0; ) {
- if (!adjbuf(&buf, &bufsz, bp-buf+3, 500, &bp, 0))
+ if (!adjbuf(&buf, &bufsz, bp-buf+3, 500, &bp, "regexpr"))
FATAL("out of space for reg expr %.10s...", buf);
if (c == '\n') {
SYNTAX( "newline in regular expression %.10s...", buf );
OpenPOWER on IntegriCloud