diff options
author | Sigrid <ftrvxmtrx@gmail.com> | 2020-12-15 14:25:59 +0100 |
---|---|---|
committer | Sigrid <ftrvxmtrx@gmail.com> | 2020-12-15 14:25:59 +0100 |
commit | d0c6ade53dd763a92e31333fd789158304e8e842 (patch) | |
tree | 9b1ff9dd2218a1272accb2e77bff3b7bd09e3ccd | |
parent | 3749e92cdb88a157f99c0709a264bd508603be9b (diff) | |
download | plan9front-d0c6ade53dd763a92e31333fd789158304e8e842.tar.xz |
pc: treat EOF gracefully, allowing easier use within sam command language
-rw-r--r-- | sys/src/cmd/pc.y | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/sys/src/cmd/pc.y b/sys/src/cmd/pc.y index 6d828f8a2..1abb328df 100644 --- a/sys/src/cmd/pc.y +++ b/sys/src/cmd/pc.y @@ -7,7 +7,7 @@ #include <thread.h> #include <libsec.h> -int inbase = 10, outbase, divmode, sep, heads, fail, prompt; +int inbase = 10, outbase, divmode, sep, heads, fail, prompt, eof; enum { MAXARGS = 16 }; typedef struct Num Num; @@ -591,18 +591,23 @@ yylex(void) int c, b; char buf[512], *p; Keyword *kw; - - if(prompt && !prompted) {print("; "); prompted = 1;} + + if(prompt && !prompted && !eof) {print("; "); prompted = 1;} do c = Bgetc(in); while(c != '\n' && isspace(c)); - if(c == '\n') prompted = 0; + if(c < 0 && !eof){ + eof = 1; + c = '\n'; + } + if(c == '\n') + prompted = 0; if(isdigit(c)){ for(p = buf, *p++ = c; c = Bgetc(in), isalnum(c) || c == '_'; ) if(p < buf + sizeof(buf) - 1 && c != '_') *p++ = c; *p = 0; - Bungetc(in); + if(c >= 0) Bungetc(in); b = inbase; p = buf; if(*p == '0'){ @@ -636,7 +641,7 @@ yylex(void) for(; kw->name[0] == c; kw++) if(kw->name[0] == b) return kw->tok; - Bungetc(in); + if(c >= 0) Bungetc(in); } return c; } |