diff options
author | zoulasc <zoulasc@users.noreply.github.com> | 2020-01-24 04:11:59 -0500 |
---|---|---|
committer | Arnold Robbins <arnold@skeeve.com> | 2020-01-24 11:11:59 +0200 |
commit | 6a8770929d4653725e75f4a7a3446f227c4c6817 (patch) | |
tree | 26e77b640c45ba59f5bc093f38bcc6033babef2b /lex.c | |
parent | 5a18f63b8dfc35fb7bcda4688661e354783d2bb7 (diff) | |
download | one-true-awk-6a8770929d4653725e75f4a7a3446f227c4c6817.tar.gz |
Small fixes (#68)
* sprinkle const, static
* account for lineno in unput
* Add an EMPTY string that is used when a non-const empty string is needed.
* make inputFS static and dynamically allocated
* Simplify and in the process avoid -Wwritable-strings
* make fs const to avoid -Wwritable-strings
Diffstat (limited to 'lex.c')
-rw-r--r-- | lex.c | 12 |
1 files changed, 7 insertions, 5 deletions
@@ -43,7 +43,7 @@ typedef struct Keyword { int type; } Keyword; -Keyword keywords[] ={ /* keep sorted: binary searched */ +const Keyword keywords[] = { /* keep sorted: binary searched */ { "BEGIN", XBEGIN, XBEGIN }, { "END", XEND, XEND }, { "NF", VARNF, VARNF }, @@ -91,14 +91,14 @@ Keyword keywords[] ={ /* keep sorted: binary searched */ #define RET(x) { if(dbg)printf("lex %s\n", tokname(x)); return(x); } -int peek(void) +static int peek(void) { int c = input(); unput(c); return c; } -int gettok(char **pbuf, int *psz) /* get next input token */ +static int gettok(char **pbuf, int *psz) /* get next input token */ { int c, retc; char *buf = *pbuf; @@ -440,7 +440,7 @@ int string(void) } -int binsearch(char *w, Keyword *kp, int n) +static int binsearch(char *w, const Keyword *kp, int n) { int cond, low, mid, high; @@ -460,7 +460,7 @@ int binsearch(char *w, Keyword *kp, int n) int word(char *w) { - Keyword *kp; + const Keyword *kp; int c, n; n = binsearch(w, keywords, sizeof(keywords)/sizeof(keywords[0])); @@ -572,6 +572,8 @@ int input(void) /* get next lexical input character */ 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; |