diff options
author | Nicholas Noll <nbnoll@eml.cc> | 2021-12-04 14:10:21 -0800 |
---|---|---|
committer | Nicholas Noll <nbnoll@eml.cc> | 2021-12-04 14:10:21 -0800 |
commit | 12e09f9f85ac48ff891adf92f3b2c9a5fea27273 (patch) | |
tree | 60051793885e9978dadf6672ef85cdda216676a2 /src | |
parent | b80a3d28ce42be4fdec451f74620b10ee75219dc (diff) |
Chore(REMOVE): finished deprecation of old io functions.
The old methods were simple wrappers of C standard library functions.
We've moved (painfully) over to a new interface that allows for files to
live on the stack. All users of the functionality are ported over.
Diffstat (limited to 'src')
57 files changed, 804 insertions, 951 deletions
diff --git a/src/base/bufio/flush.c b/src/base/bufio/flush.c deleted file mode 100644 index 0974766..0000000 --- a/src/base/bufio/flush.c +++ /dev/null @@ -1,36 +0,0 @@ -#include "internal.h" - -int -bio·flush(io·Header *io) -{ - intptr ni, no; - - switch(io->state){ - case io·BufWtr: - if((ni = io->cap + io->olen)) - return 0; - - sys·write(io->fd, ni, io->b, &no); - - if(no!=ni){ - io->pos += ni; - io->olen = -io->cap; - return 0; - } - - io->state = io·BufNil; - io->olen = 0; - break; - - case io·BufEof: - io->state = io·BufRdr; - /* fallthrough */ - case io·BufRdr: - io->ilen = 0; - io->g = io->e; - return 0; - default: - ; - } - return io·BufEof; -} diff --git a/src/base/bufio/internal.h b/src/base/bufio/internal.h deleted file mode 100644 index a59e787..0000000 --- a/src/base/bufio/internal.h +++ /dev/null @@ -1,4 +0,0 @@ -#include <u.h> -#include <base.h> - -#define header(io) ((io·Header*)(io)) diff --git a/src/base/bufio/open.c b/src/base/bufio/open.c deleted file mode 100644 index 29ccae1..0000000 --- a/src/base/bufio/open.c +++ /dev/null @@ -1,27 +0,0 @@ -#include "internal.h" - -int -bio·open(char *path, int flag, io·Buffer *io) -{ - int fd; - switch(flag & ~(sys·OCloseExec|sys·OTrunc)){ - default: - fmt·fprint(2, "open: unknown flag %d\n", flag); - return 1; - - case sys·ORead: - if(sys·open(path, flag, 0, &fd)) - return 1; - break; - - case sys·OWrite: - if(sys·open(path, flag, 0666, &fd)) - return 1; - break; - } - if(bio·openfd(fd, flag, io)){ - sys·close(fd); - return 1; - } - return 0; -} diff --git a/src/base/bufio/read.c b/src/base/bufio/read.c deleted file mode 100644 index ad0275c..0000000 --- a/src/base/bufio/read.c +++ /dev/null @@ -1,54 +0,0 @@ -#include "internal.h" - -intptr -bio·read(io·Header *io, intptr len, void *buf) -{ - uchar *b; - intptr c0, c, nr, n, ic; - - b = buf; - c = len; - ic = io->ilen; // how many bytes we've read and not flushed - - while(c > 0){ - n = -ic; - if(n > c) - n = c; - if(n == 0){ - /* only continue if we are a file reader */ - if(io->state != io·BufRdr) - break; - - /* get more bytes */ - if(sys·read(io->fd, io->cap, io->b, &nr)){ - io->state = io·BufNil; - break; - } - - if(nr == 0){ - io->state = io·BufEnd; - break; - } - - /* shift bytes within buffer so they end at terminal */ - io->g = io->b; - io->pos += nr; - if(nr < io->cap){ - io->g = io->e-nr; - mem·move(io->g, io->b, nr); - } - ic -= nr; - continue; - } - /* move our read bytes into the caller's buffer */ - mem·move(b, io->e+ic, n); - c -= n; - ic += n; - b += n; - } - io->ilen = ic; - if(c == len && io->state == io·BufNil) - return -1; - - return len-c; -} diff --git a/src/base/bufio/rules.mk b/src/base/bufio/rules.mk deleted file mode 100644 index f367b8e..0000000 --- a/src/base/bufio/rules.mk +++ /dev/null @@ -1,18 +0,0 @@ -SRCS_$(d)+=\ - $(d)/bufio/flush.c\ - $(d)/bufio/getc.c\ - $(d)/bufio/getr.c\ - $(d)/bufio/init.c\ - $(d)/bufio/offset.c\ - $(d)/bufio/open.c\ - $(d)/bufio/openfd.c\ - $(d)/bufio/print.c\ - $(d)/bufio/putc.c\ - $(d)/bufio/read.c\ - $(d)/bufio/readline.c\ - $(d)/bufio/readuntil.c\ - $(d)/bufio/seek.c\ - $(d)/bufio/ungetc.c\ - $(d)/bufio/ungetr.c\ - $(d)/bufio/vprint.c\ - $(d)/bufio/write.c diff --git a/src/base/bufio/seek.c b/src/base/bufio/seek.c deleted file mode 100644 index 5d25173..0000000 --- a/src/base/bufio/seek.c +++ /dev/null @@ -1,57 +0,0 @@ -#include "internal.h" - -int -bio·seek(io·Header *io, intptr offset, int whence, intptr *pos) -{ - intptr n,d,cap; - - switch(io->state){ - default: - fmt·fprint(2, "seek: unknown state %d\n", io->state); - return io·BufEof; - case io·BufEnd: - io->state = io·BufRdr; - io->ilen = 0; - io->g = io->e; - /* fallthrough */ - case io·BufRdr: - n = offset; - if(whence == sys·SeekCur){ - n += bio·offset(io); - whence = sys·SeekSet; - } - - /* can we seek inside our buffer */ - if(whence == sys·SeekSet){ - d = n - bio·offset(io); - cap = io->e - io->g; - if(-cap <= d && d <= cap){ - io->ilen += d; - if(d >= 0){ - if(io->ilen <= 0){ - *pos = n; - return 0; - } - }else{ - if(io->e - io->g >= -io->ilen){ - *pos = n; - return 0; - } - } - } - } - - /* nope, call the kernel to do it for us */ - sys·seek(io->fd, offset, whence, &n); - io->ilen = 0; - io->g = io->e; - break; - - case io·BufWtr: - bio·flush(io); - sys·seek(io->fd, offset, whence, &n); - break; - } - io->pos = *pos = n; - return 0; -} diff --git a/src/base/bufio/write.c b/src/base/bufio/write.c deleted file mode 100644 index 8b64055..0000000 --- a/src/base/bufio/write.c +++ /dev/null @@ -1,40 +0,0 @@ -#include "internal.h" - -intptr -bio·write(io·Header *io, intptr len, void *buf) -{ - char *b; - intptr c, o, nw, n; - - b = buf; - c = len; - o = io->olen; - - while(c > 0){ - n = -o; - if(n > c) - n = c; - if(n == 0){ - if(io->state != io·BufWtr) - return io·BufEof; - switch(sys·write(io->fd, io->cap, io->b, &nw)){ - case 0: - if(nw != io->cap) goto error; - io->pos += nw; - o = -io->cap; - continue; - case sys·ErrorInterrupt: - io->state = io·BufNil; - /* fallthrough */ - default: error: - return io·BufEof; - } - } - mem·move(io->e+o, b, n); - o += n; - c -= n; - b += n; - } - io->olen = o; - return len-c; -} diff --git a/src/base/fs/walk.c b/src/base/fs/walk.c index 8842633..752791d 100644 --- a/src/base/fs/walk.c +++ b/src/base/fs/walk.c @@ -3,22 +3,19 @@ #define hash(k) ((int32)k.ino ^ (int32)k.dev) #define equal(k1, k2) (k1.ino == k2.ino && k1.dev == k2.dev) -static -int +static int morehistory(fs·History *h, int n) { SET_GROW(h, struct Key, n, hash, sys·Memory, nil); } -static -int +static int addentry(fs·History *h, struct Key key, int *err) { SET_PUT(h, key, hash, equal, morehistory, err); } -static -void +static void forget(fs·History *h) { if (!h) @@ -35,7 +32,7 @@ fs·walk(fs·Walker *fs) int new, fd, ofd, flags; fs·History *h; struct dirent *d; - io·Stat cwd; + struct stat cwd; struct fs·Entry *it; flags = 0; diff --git a/src/base/io/close.c b/src/base/io/close.c deleted file mode 100644 index 5a773cd..0000000 --- a/src/base/io/close.c +++ /dev/null @@ -1,7 +0,0 @@ -#include "internal.h" - -int -io·close(io·Stream *s) -{ - return fclose(s); -} diff --git a/src/base/io/fd.c b/src/base/io/fd.c deleted file mode 100644 index ded1b02..0000000 --- a/src/base/io/fd.c +++ /dev/null @@ -1,7 +0,0 @@ -#include "internal.h" - -int -io·fd(io·Stream *s) -{ - return fileno(s); -} diff --git a/src/base/io/flush.c b/src/base/io/flush.c index 0f1217a..ff970b4 100644 --- a/src/base/io/flush.c +++ b/src/base/io/flush.c @@ -1,7 +1,36 @@ #include "internal.h" int -io·flush(io·Stream *s) +io·flush(io·Header *io) { - return fflush(s); + intptr ni, no; + + switch(io->state){ + case io·BufWtr: + if((ni = io->cap + io->olen)) + return 0; + + sys·write(io->fd, ni, io->b, &no); + + if(no!=ni){ + io->pos += ni; + io->olen = -io->cap; + return 0; + } + + io->state = io·BufNil; + io->olen = 0; + break; + + case io·BufEof: + io->state = io·BufRdr; + /* fallthrough */ + case io·BufRdr: + io->ilen = 0; + io->g = io->e; + return 0; + default: + ; + } + return io·BufEof; } diff --git a/src/base/io/get.c b/src/base/io/get.c deleted file mode 100644 index d4e52f8..0000000 --- a/src/base/io/get.c +++ /dev/null @@ -1,7 +0,0 @@ -#include "internal.h" - -byte -io·getbyte(io·Stream *s) -{ - return fgetc(s); -} diff --git a/src/base/bufio/getc.c b/src/base/io/getc.c index 264e01d..68e1772 100644 --- a/src/base/bufio/getc.c +++ b/src/base/io/getc.c @@ -1,7 +1,7 @@ #include "internal.h" int -bio·getc(io·Header *io) +io·getc(io·Header *io) { int i; intptr nr; diff --git a/src/base/bufio/getr.c b/src/base/io/getr.c index 579a387..01b0f45 100644 --- a/src/base/bufio/getr.c +++ b/src/base/io/getr.c @@ -1,13 +1,13 @@ #include "internal.h" rune -bio·getr(io·Header *io) +io·getr(io·Header *io) { int c, i; rune r; char buf[UTFmax]; - c = bio·getc(io); + c = io·getc(io); if(utf8·onebyte(c)){ io->runesz = 1; return c; @@ -15,14 +15,14 @@ bio·getr(io·Header *io) buf[0] = c; for(i=1;;){ - if((c = bio·getc(io))<0) + if((c = io·getc(io))<0) return c; buf[i++] = c; if(utf8·fullrune(buf, i)){ io->runesz = utf8·decode(buf, &r); while(i-- > io->runesz) - bio·ungetc(io); + io·ungetc(io); return r; } } diff --git a/src/base/bufio/init.c b/src/base/io/init.c index b6814e1..81b26c2 100644 --- a/src/base/bufio/init.c +++ b/src/base/io/init.c @@ -14,7 +14,7 @@ untrackall(void *arg) it = tracked[i]; if(it){ tracked[i] = nil; - bio·flush(it); + io·flush(it); } } } @@ -50,14 +50,14 @@ track(io·Header *io) } int -bio·initcap(io·Header *io, int fd, int mode, int cap, uchar *buf) +io·initcap(io·Header *io, int fd, int mode, int cap, uchar *buf) { buf += io·BufUngets; cap += io·BufUngets; switch(mode & ~(sys·OCloseExec|sys·OTrunc)){ default: - fmt·fprint(2, "initcap: unknown mode %d\n" , mode); + /* fmt·fprint(2, "initcap: unknown mode %d\n" , mode); */ return io·BufErr; case sys·ORead: io->state = io·BufRdr; @@ -80,19 +80,19 @@ bio·initcap(io·Header *io, int fd, int mode, int cap, uchar *buf) } int -bio·init(io·Buffer *io, int fd, int mode) +io·init(io·Buffer *io, int fd, int mode) { - return bio·initcap(header(io), fd, mode, io·BufLen + io·BufUngets, io->bytes); + return io·initcap(header(io), fd, mode, io·BufLen + io·BufUngets, io->bytes); } int -bio·close(io·Header *io) +io·close(io·Header *io) { int err; untrack(io); - err = bio·flush(io); + err = io·flush(io); if(io->flag == io·BufMagic){ io->flag = 0; if((err=sys·close(io->fd))) diff --git a/src/base/io/interface.c b/src/base/io/interface.c deleted file mode 100644 index 80469bf..0000000 --- a/src/base/io/interface.c +++ /dev/null @@ -1,70 +0,0 @@ -#include "internal.h" - -static -int -·read(void *rdr, int size, int n, void *buf) -{ - return io·read((io·Stream *)rdr, size, n, buf); -} - -static -byte -·get(void *rdr) -{ - return io·getbyte((io·Stream *)rdr); -} - -static -int -·unget(void *rdr, byte c) -{ - return io·ungetbyte((io·Stream *)rdr, c); -} - -static -int -·write(void *wtr, int sz, int n, void *buf) -{ - return io·write((io·Stream *)wtr, sz, n, buf); -} - -static -int -·put(void *wtr, byte c) -{ - return io·putbyte((io·Stream *)wtr, c); -} - -static -int -·puts(void *wtr, string s) -{ - return io·putstring((io·Stream *)wtr, s); -} - -static -int -·seek(void *skr, long off, int whence) -{ - return io·seek((io·Stream *)skr, off, whence); -} - -static -long -·tell(void *skr) -{ - return io·tell((io·Stream *)skr); -} - -/* actual interfaces */ -io·Reader sys·Reader = (io·Reader){ ·read }; -io·Seeker sys·Seeker = (io·Seeker){ ·seek, ·tell }; -io·Peeker sys·Peeker = (io·Peeker){ ·get, ·unget }; -io·SeekReader sys·SeekReader = (io·SeekReader){ ·seek, ·tell, ·read }; -io·PeekReader sys·PeekReader = (io·PeekReader){ ·read, ·get, ·unget }; - -io·Writer sys·Writer = (io·Writer){ ·write }; -io·Putter sys·Putter = (io·Putter){ ·put, ·puts }; -io·PutWriter sys·PutWriter = (io·PutWriter){ ·write, ·put, ·puts }; - -io·ReadWriter sys·ReadWriter = (io·ReadWriter){ ·read, ·write }; diff --git a/src/base/io/internal.h b/src/base/io/internal.h index 302c035..a59e787 100644 --- a/src/base/io/internal.h +++ b/src/base/io/internal.h @@ -1,4 +1,4 @@ -#pragma once - #include <u.h> #include <base.h> + +#define header(io) ((io·Header*)(io)) diff --git a/src/base/bufio/offset.c b/src/base/io/offset.c index 15579c4..81ef994 100644 --- a/src/base/bufio/offset.c +++ b/src/base/io/offset.c @@ -1,7 +1,7 @@ #include "internal.h" intptr -bio·offset(io·Header *io) +io·offset(io·Header *io) { intptr n; switch(io->state){ diff --git a/src/base/io/open.c b/src/base/io/open.c index fe78255..ed0be92 100644 --- a/src/base/io/open.c +++ b/src/base/io/open.c @@ -1,7 +1,28 @@ #include "internal.h" -io·Stream* -io·open(byte *name, byte *mode) +int +io·open(char *path, int flag, io·Buffer *io) { - return fopen(name, mode); + int err,fd; + switch(flag & ~(sys·OCloseExec|sys·OTrunc)){ + default: + /* fmt·fprint(2, "open: unknown flag %d\n", flag); */ + return 1; + + case sys·ORead: + if((err=sys·open(path, flag, 0, &fd))) + return err; + break; + + case sys·OWrite: + if((err=sys·open(path, flag, 0666, &fd))) + return err; + break; + } + + if((err=io·openfd(fd, flag, io))){ + sys·close(fd); + return err; + } + return 0; } diff --git a/src/base/bufio/openfd.c b/src/base/io/openfd.c index 66ca967..db13413 100644 --- a/src/base/bufio/openfd.c +++ b/src/base/io/openfd.c @@ -1,10 +1,10 @@ #include "internal.h" int -bio·openfd(int fd, int flag, io·Buffer *io) +io·openfd(int fd, int flag, io·Buffer *io) { int err; - if((err=bio·init(io, fd, flag))) + if((err=io·init(io, fd, flag))) return err; io->flag = io·BufMagic; diff --git a/src/base/bufio/print.c b/src/base/io/print.c index 04a85f9..00d39d9 100644 --- a/src/base/bufio/print.c +++ b/src/base/io/print.c @@ -1,13 +1,13 @@ #include "internal.h" int -bio·print(io·Header *io, char *fmt, ...) +io·print(io·Header *io, char *fmt, ...) { int n; va_list args; va_start(args, fmt); - n = bio·vprint(io, fmt, args); + n = io·vprint(io, fmt, args); va_end(args); return n; diff --git a/src/base/io/putbyte.c b/src/base/io/putbyte.c deleted file mode 100644 index 2350a8d..0000000 --- a/src/base/io/putbyte.c +++ /dev/null @@ -1,7 +0,0 @@ -#include "internal.h" - -int -io·putbyte(io·Stream *s, byte c) -{ - return fputc(c, s); -} diff --git a/src/base/bufio/putc.c b/src/base/io/putc.c index e91a1f1..167f10f 100644 --- a/src/base/bufio/putc.c +++ b/src/base/io/putc.c @@ -1,7 +1,7 @@ #include "internal.h" int -bio·putc(io·Header *io, int c) +io·putc(io·Header *io, int c) { intptr i; @@ -12,7 +12,7 @@ bio·putc(io·Header *io, int c) io->olen = i; return 0; } - if(bio·flush(io) == io·BufEof) + if(io·flush(io) == io·BufEof) break; } return io·BufEof; diff --git a/src/base/io/putstring.c b/src/base/io/putstring.c deleted file mode 100644 index 53fa993..0000000 --- a/src/base/io/putstring.c +++ /dev/null @@ -1,7 +0,0 @@ -#include "internal.h" - -int -io·putstring(io·Stream *s, string str) -{ - return fputs(str, s); -} diff --git a/src/base/io/read.c b/src/base/io/read.c index b0ed3d2..d4f7bd9 100644 --- a/src/base/io/read.c +++ b/src/base/io/read.c @@ -1,7 +1,54 @@ #include "internal.h" -int -io·read(io·Stream *s, int sz, int n, void *buf) +intptr +io·read(io·Header *io, intptr len, void *buf) { - return fread(buf, sz, n, s); + uchar *b; + intptr c0, c, nr, n, ic; + + b = buf; + c = len; + ic = io->ilen; // how many bytes we've read and not flushed + + while(c > 0){ + n = -ic; + if(n > c) + n = c; + if(n == 0){ + /* only continue if we are a file reader */ + if(io->state != io·BufRdr) + break; + + /* get more bytes */ + if(sys·read(io->fd, io->cap, io->b, &nr)){ + io->state = io·BufNil; + break; + } + + if(nr == 0){ + io->state = io·BufEnd; + break; + } + + /* shift bytes within buffer so they end at terminal */ + io->g = io->b; + io->pos += nr; + if(nr < io->cap){ + io->g = io->e-nr; + mem·move(io->g, io->b, nr); + } + ic -= nr; + continue; + } + /* move our read bytes into the caller's buffer */ + mem·move(b, io->e+ic, n); + c -= n; + ic += n; + b += n; + } + io->ilen = ic; + if(c == len && io->state == io·BufNil) + return -1; + + return len-c; } diff --git a/src/base/bufio/readline.c b/src/base/io/readline.c index 0a50098..2be19db 100644 --- a/src/base/bufio/readline.c +++ b/src/base/io/readline.c @@ -1,9 +1,9 @@ #include "internal.h" void * -bio·readline(io·Header *io, int null) +io·readline(io·Header *io, int null) { - char *start = bio·readuntil(io, '\n'); + char *start = io·readuntil(io, '\n'); if(null && start) start[io->nread-1] = 0; diff --git a/src/base/io/readln.c b/src/base/io/readln.c deleted file mode 100644 index 283472d..0000000 --- a/src/base/io/readln.c +++ /dev/null @@ -1,12 +0,0 @@ -#include "internal.h" - -int -io·readln(io·Stream *s, int n, byte* buf) -{ - byte* b; - b = fgets(buf, n+1, s); - if(b == nil) - return -1; - - return strlen(buf); -} diff --git a/src/base/bufio/readuntil.c b/src/base/io/readuntil.c index 1a0faaf..d5c2ed6 100644 --- a/src/base/bufio/readuntil.c +++ b/src/base/io/readuntil.c @@ -1,7 +1,7 @@ #include "internal.h" void * -bio·readuntil(io·Header *io, int delim) +io·readuntil(io·Header *io, int delim) { char *b, *e; intptr i, j; diff --git a/src/base/io/rules.mk b/src/base/io/rules.mk index 124cd09..3a091be 100644 --- a/src/base/io/rules.mk +++ b/src/base/io/rules.mk @@ -1,15 +1,18 @@ SRCS_$(d)+=\ - $(d)/io/fd.c\ $(d)/io/flush.c\ - $(d)/io/interface.c\ + $(d)/io/getc.c\ + $(d)/io/getr.c\ + $(d)/io/init.c\ + $(d)/io/offset.c\ $(d)/io/open.c\ - $(d)/io/close.c\ - $(d)/io/putbyte.c\ - $(d)/io/putstring.c\ + $(d)/io/openfd.c\ + $(d)/io/print.c\ + $(d)/io/putc.c\ $(d)/io/read.c\ - $(d)/io/readln.c\ + $(d)/io/readline.c\ + $(d)/io/readuntil.c\ $(d)/io/seek.c\ - $(d)/io/stat.c\ - $(d)/io/tell.c\ - $(d)/io/unget.c\ + $(d)/io/ungetc.c\ + $(d)/io/ungetr.c\ + $(d)/io/vprint.c\ $(d)/io/write.c diff --git a/src/base/io/seek.c b/src/base/io/seek.c index 1be4ee7..4fa1aff 100644 --- a/src/base/io/seek.c +++ b/src/base/io/seek.c @@ -1,7 +1,57 @@ #include "internal.h" int -io·seek(io·Stream *s, long off, int whence) +io·seek(io·Header *io, intptr offset, int whence, intptr *pos) { - return fseek(s, off, whence); + intptr n,d,cap; + + switch(io->state){ + default: + fmt·fprint(2, "seek: unknown state %d\n", io->state); + return io·BufEof; + case io·BufEnd: + io->state = io·BufRdr; + io->ilen = 0; + io->g = io->e; + /* fallthrough */ + case io·BufRdr: + n = offset; + if(whence == sys·SeekCur){ + n += io·offset(io); + whence = sys·SeekSet; + } + + /* can we seek inside our buffer */ + if(whence == sys·SeekSet){ + d = n - io·offset(io); + cap = io->e - io->g; + if(-cap <= d && d <= cap){ + io->ilen += d; + if(d >= 0){ + if(io->ilen <= 0){ + *pos = n; + return 0; + } + }else{ + if(io->e - io->g >= -io->ilen){ + *pos = n; + return 0; + } + } + } + } + + /* nope, call the kernel to do it for us */ + sys·seek(io->fd, offset, whence, &n); + io->ilen = 0; + io->g = io->e; + break; + + case io·BufWtr: + io·flush(io); + sys·seek(io->fd, offset, whence, &n); + break; + } + io->pos = *pos = n; + return 0; } diff --git a/src/base/io/stat.c b/src/base/io/stat.c deleted file mode 100644 index 063ff8f..0000000 --- a/src/base/io/stat.c +++ /dev/null @@ -1,7 +0,0 @@ -#include "internal.h" - -int -io·stat(io·Stream *s, io·Stat *buf) -{ - return fstat(fileno(s), buf); -} diff --git a/src/base/io/tell.c b/src/base/io/tell.c deleted file mode 100644 index 1c50439..0000000 --- a/src/base/io/tell.c +++ /dev/null @@ -1,7 +0,0 @@ -#include "internal.h" - -long -io·tell(io·Stream *s) -{ - return ftell(s); -} diff --git a/src/base/io/unget.c b/src/base/io/unget.c deleted file mode 100644 index 5c37433..0000000 --- a/src/base/io/unget.c +++ /dev/null @@ -1,7 +0,0 @@ -#include "internal.h" - -int -io·ungetbyte(io·Stream *s, byte c) -{ - return ungetc(c, s); -} diff --git a/src/base/bufio/ungetc.c b/src/base/io/ungetc.c index 70abbab..201ffd6 100644 --- a/src/base/bufio/ungetc.c +++ b/src/base/io/ungetc.c @@ -1,7 +1,7 @@ #include "internal.h" int -bio·ungetc(io·Header *io) +io·ungetc(io·Header *io) { if(io->state == io·BufEnd) io->state = io·BufRdr; diff --git a/src/base/bufio/ungetr.c b/src/base/io/ungetr.c index 8abdc39..c0b8e9d 100644 --- a/src/base/bufio/ungetr.c +++ b/src/base/io/ungetr.c @@ -1,7 +1,7 @@ #include "internal.h" rune -bio·ungetr(io·Header *io) +io·ungetr(io·Header *io) { if(io->state == io·BufEnd) io->state = io·BufRdr; diff --git a/src/base/bufio/vprint.c b/src/base/io/vprint.c index 70be6bf..6fa446e 100644 --- a/src/base/bufio/vprint.c +++ b/src/base/io/vprint.c @@ -5,7 +5,7 @@ flush(fmt·State *fmt) { io·Header *io = fmt->file; io->olen = fmt->buffer.cur - fmt->buffer.end; - if(bio·flush(io)) + if(io·flush(io)) return 0; fmt->buffer.end = (char*)io->e; @@ -14,7 +14,7 @@ flush(fmt·State *fmt) } int -bio·vprint(io·Header *io, char *fmt, va_list args) +io·vprint(io·Header *io, char *fmt, va_list args) { int n; fmt·State f; diff --git a/src/base/io/write.c b/src/base/io/write.c index 63df664..2f37200 100644 --- a/src/base/io/write.c +++ b/src/base/io/write.c @@ -1,7 +1,40 @@ #include "internal.h" -int -io·write(io·Stream *s, int sz, int n, void *buf) +intptr +io·write(io·Header *io, intptr len, void *buf) { - return fwrite(buf, sz, n, s); + char *b; + intptr c, o, nw, n; + + b = buf; + c = len; + o = io->olen; + + while(c > 0){ + n = -o; + if(n > c) + n = c; + if(n == 0){ + if(io->state != io·BufWtr) + return io·BufEof; + switch(sys·write(io->fd, io->cap, io->b, &nw)){ + case 0: + if(nw != io->cap) goto error; + io->pos += nw; + o = -io->cap; + continue; + case sys·ErrorInterrupt: + io->state = io·BufNil; + /* fallthrough */ + default: error: + return io·BufEof; + } + } + mem·move(io->e+o, b, n); + o += n; + c -= n; + b += n; + } + io->olen = o; + return len-c; } diff --git a/src/base/mmap/internal.h b/src/base/mmap/internal.h index 7606c7e..302c035 100644 --- a/src/base/mmap/internal.h +++ b/src/base/mmap/internal.h @@ -2,4 +2,3 @@ #include <u.h> #include <base.h> -#include <sys/mman.h> diff --git a/src/base/mmap/mmap.c b/src/base/mmap/mmap.c index e5cedbb..c3709d7 100644 --- a/src/base/mmap/mmap.c +++ b/src/base/mmap/mmap.c @@ -3,37 +3,36 @@ mmap·Reader mmap·open(byte *filename) { - int fd; int err; void *buf; - io·Stream *s; - io·Stat st; + io·Buffer io; + sys·Info info; + mmap·Reader rdr = {0}; - s = io·open(filename, "r"); - fd = io·fd(s); - err = io·stat(s, &st); - if(err){ + if(io·open(filename, sys·ORead, &io)){ + errorf("failed to open %s", filename); + goto done; + } + + if(sys·infofd(io.fd, &info)){ errorf("file stat: error code %d", err); - goto ERROR; + goto done; } - buf = mmap(nil, st.st_size, PROT_READ, MAP_SHARED, fd, 0); - if(!buf){ + if(sys·mmap(nil, info.size, sys·ProtRead, sys·MapShared, io.fd, 0, &buf)){ errorf("mmap: failed"); - goto ERROR; + goto done; } // NOTE: posix systems require that reference kept to mmap file after fd is closed - io·close(s); - return (mmap·Reader){.len=st.st_size, .b=buf}; - -ERROR: - io·close(s); - return (mmap·Reader){ 0 }; + rdr = (mmap·Reader){.len=info.size, .b=buf}; +done: + io·close((io·Header*)&io); + return rdr; } int mmap·close(mmap·Reader rdr) { - munmap(rdr.b, rdr.len); + sys·munmap(rdr.b, rdr.len); return 0; } diff --git a/src/base/rules.mk b/src/base/rules.mk index 64f0797..0fefead 100644 --- a/src/base/rules.mk +++ b/src/base/rules.mk @@ -6,14 +6,13 @@ include share/push.mk SRCS_$(d):=\ $(d)/arg.c -include $(d)/bufio/rules.mk +include $(d)/io/rules.mk include $(d)/coro/rules.mk include $(d)/error/rules.mk include $(d)/flate/rules.mk include $(d)/fmt/rules.mk include $(d)/fs/rules.mk include $(d)/gz/rules.mk -include $(d)/io/rules.mk include $(d)/mem/rules.mk include $(d)/mmap/rules.mk include $(d)/os/rules.mk diff --git a/src/base/string/itoa.c b/src/base/string/itoa.c new file mode 100644 index 0000000..a2910f4 --- /dev/null +++ b/src/base/string/itoa.c @@ -0,0 +1,23 @@ +#include "internal.h" + +static char * +kernel(char *s, int x) +{ + if(x/10) + s = kernel(s, x/10); + *s++ = x%10 + '0'; + return s; +} + +char * +str·itoa(char *s, int x) +{ + if(x<0){ + *s++ = '-'; + x=-x; + } + s = kernel(s, x); + *s = '0'; + + return s; +} diff --git a/src/base/string/rules.mk b/src/base/string/rules.mk index 0352f54..5fa6c5e 100644 --- a/src/base/string/rules.mk +++ b/src/base/string/rules.mk @@ -1,5 +1,6 @@ SRCS_$(d)+=\ $(d)/string/atoi.c\ + $(d)/string/itoa.c\ $(d)/string/append.c\ $(d)/string/appendf.c\ $(d)/string/clear.c\ diff --git a/src/base/utf/rules.mk b/src/base/utf/rules.mk index dfe2da1..554ba6a 100644 --- a/src/base/utf/rules.mk +++ b/src/base/utf/rules.mk @@ -20,9 +20,14 @@ NEED_OBJS=\ $(OBJ_DIR)/base/arg.o\ $(OBJ_DIR)/base/utf/decode.o\ $(OBJ_DIR)/base/error/panicf.o\ - $(OBJ_DIR)/base/io/readln.o\ + $(OBJ_DIR)/base/io/readline.o\ + $(OBJ_DIR)/base/io/readuntil.o\ $(OBJ_DIR)/base/io/open.o\ - $(OBJ_DIR)/base/io/close.o\ + $(OBJ_DIR)/base/io/openfd.o\ + $(OBJ_DIR)/base/io/flush.o\ + $(OBJ_DIR)/base/io/init.o\ + $(OBJ_DIR)/base/mem/move.o\ + $(OBJ_DIR)/base/mem/findc.o\ $(d)/utf/vendor/common.o $(d)/utf/vendor/common.o: $(d)/utf/vendor/common.c diff --git a/src/base/utf/vendor/common.c b/src/base/utf/vendor/common.c index fcf1177..c35d022 100644 --- a/src/base/utf/vendor/common.c +++ b/src/base/utf/vendor/common.c @@ -4,36 +4,32 @@ // input functions int -parse(io·Stream *io, int nfield, char **field, int len, char *line) +parse(io·Buffer *io, int nfield, char field[][FieldLen]) { int n; - if((n=io·readln(io, len, line)) <= 0) - return ParseEOF; - - if(n == len) - panicf("line too long"); - - if(line[n-1] != '\n') - panicf("invalid line: expected '\n', found '%c'", line[n]); + char *b, *e; - line[n-1] = 0; + if(!(b=io·readline((io·Header*)io,1))) + return ParseEOF; - if(line[0] == '#' || line[0] == 0) + if(b[0] == '#' || b[0] == 0) return ParseSkip; /* tokenize line into fields */ n = 0; - field[n] = line; - while(*line){ - if(*line == ';'){ - *line = 0; - field[++n] = line+1; - } - line++; + e = b; + while(*e){ + if(*e == ';'){ + *e = 0; + strcpy(field[n++], b); + b = ++e; + }else + ++e; } + strcpy(field[n++], b); - if(n != nfield-1) - panicf("expected %d number of fields, got %d: %s", nfield, n, line); + if(n != nfield) + panicf("expected %d number of fields, got %d: %s", nfield, n, b); return ParseOK; } @@ -58,10 +54,10 @@ codepoint(char *s) } void -codepointrange(io·Stream *utf8, char *field[NumFields], int *start, int *stop) +codepointrange(io·Buffer *utf8, char field[NumFields][FieldLen], int *start, int *stop) { int e, c; - char *other[NumFields], line[1024]; + char other[NumFields][FieldLen]; // XXX: the stop variable passes in the previous stopping character e = *stop; @@ -74,7 +70,7 @@ codepointrange(io·Stream *utf8, char *field[NumFields], int *start, int *stop) e = c; if(strstr(field[Fname], ", First>") != nil){ - if(!parse(utf8, arrlen(other), other, arrlen(line), line)) + if(!parse(utf8, arrlen(other), other)) panicf("range start at end of file"); if(strstr(other[Fname], ", Last>") == nil) panicf("range start not followed by range end"); @@ -101,8 +97,7 @@ putsearch(void) "#include <u.h>\n" "#include <base/utf.h>\n" "\n" - "static\n" - "rune*\n" + "static rune*\n" "rangesearch(rune c, rune *t, int n, int ne)\n" "{\n" " rune *p;\n" diff --git a/src/base/utf/vendor/common.h b/src/base/utf/vendor/common.h index 51a53bd..95d7eaf 100644 --- a/src/base/utf/vendor/common.h +++ b/src/base/utf/vendor/common.h @@ -25,6 +25,7 @@ enum NumFields, NumRunes = 1 << 21, }; +#define FieldLen 128 /* input functions */ enum @@ -34,9 +35,9 @@ enum ParseSkip, }; -int parse(io·Stream *io, int nfield, char **field, int len, char *line); +int parse(io·Buffer *io, int nfield, char field[][FieldLen]); int codepoint(char *s); -void codepointrange(io·Stream *utf8, char *field[NumFields], int *start, int *stop); +void codepointrange(io·Buffer *utf8, char field[NumFields][FieldLen], int *start, int *stop); /* output functions */ void putsearch(void); diff --git a/src/base/utf/vendor/mkgraphemedata.c b/src/base/utf/vendor/mkgraphemedata.c index ce5a952..1d2394f 100644 --- a/src/base/utf/vendor/mkgraphemedata.c +++ b/src/base/utf/vendor/mkgraphemedata.c @@ -1,6 +1,5 @@ #include <u.h> #include <base.h> -#include <libutf.h> // ----------------------------------------------------------------------- // main point of entry diff --git a/src/base/utf/vendor/mkrunetype.c b/src/base/utf/vendor/mkrunetype.c index b33df32..3d75ce8 100644 --- a/src/base/utf/vendor/mkrunetype.c +++ b/src/base/utf/vendor/mkrunetype.c @@ -34,8 +34,7 @@ static struct Table table; // ----------------------------------------------------------------------- // internal functions -static -int +static int isrange(char *label, char *prop, int force) { char ident[128]; @@ -45,8 +44,7 @@ isrange(char *label, char *prop, int force) return putrange(ident, prop, force); } -static -int +static int ispair(char *label, char *prop) { char ident[128]; @@ -56,8 +54,7 @@ ispair(char *label, char *prop) return putpair(ident, prop); } -static -int +static int issingle(char *label, char *prop) { char ident[128]; @@ -67,8 +64,7 @@ issingle(char *label, char *prop) return putsingle(ident, prop); } -static -void +static void makeis(char *label, char *table, int pairs, int onlyranges) { int hasr, hasp=0, hass=0; @@ -116,8 +112,7 @@ makeis(char *label, char *table, int pairs, int onlyranges) "\n"); } -static -int +static int torange(char *label, int *index, int force) { int l, r, d, start = 0; @@ -154,8 +149,7 @@ torange(char *label, int *index, int force) return start; } -static -int +static int topair(char *label, int *index) { int l, r, d, start = 0; @@ -193,8 +187,7 @@ topair(char *label, int *index) return start; } -static -int +static int tosingle(char *label, int *index) { int i, d, start = 0; @@ -220,8 +213,7 @@ tosingle(char *label, int *index) return start; } -static -void +static void mkto(char *label, int *index, int pairs, int onlyrange) { int hasr, hasp=0, hass=0; @@ -272,8 +264,7 @@ mkto(char *label, int *index, int pairs, int onlyrange) // ----------------------------------------------------------------------- // main point of entry -static -void +static void usage(void) { fprintf(stderr, "usage: mkrunetype <UnicodeData.txt>\n"); @@ -283,9 +274,9 @@ usage(void) int main(int argc, char *argv[]) { - int i, sc, c, ec; - io·Stream *utf8; - char *prop, *field[NumFields], line[1024]; + int i, sc, c, ec, err; + static io·Buffer utf8; + char *prop, field[NumFields][FieldLen]; ARGBEGIN{ }ARGEND; @@ -293,8 +284,8 @@ main(int argc, char *argv[]) if(argc != 1) usage(); - if(!(utf8 = io·open(argv[0], "r"))) - panicf("can't open %s\n", argv[0]); + if((err=io·open(argv[0], sys·ORead, &utf8))) + panicf("can't open %s: %d: %s\n", argv[0], err, strerror(err)); /* by default each character maps to itself */ for(i = 0; i < NumRunes; i++) { @@ -313,9 +304,9 @@ main(int argc, char *argv[]) ec = -1; // NOTE: we don't check for comments here: assume UnicodeData.txt doesn't have any - while(parse(utf8, arrlen(field), field, arrlen(line), line)){ + while(parse(&utf8, arrlen(field), field)){ /* parse unicode range */ - codepointrange(utf8, field, &sc, &ec); + codepointrange(&utf8, field, &sc, &ec); prop = field[Fcategory]; for(c = sc; c <= ec; c++){ @@ -370,7 +361,7 @@ main(int argc, char *argv[]) table.totitle[c] = codepoint(field[Ftitle]); } } - io·close(utf8); + io·close((io·Header *)&utf8); putsearch(); diff --git a/src/base/utf/vendor/mkrunewidth.c b/src/base/utf/vendor/mkrunewidth.c index 14e6973..c911b66 100644 --- a/src/base/utf/vendor/mkrunewidth.c +++ b/src/base/utf/vendor/mkrunewidth.c @@ -30,21 +30,20 @@ static struct Table table; // ----------------------------------------------------------------------- // internal functions -static -void +static void parse_category(char *path) { int sc, c, ec, w; - io·Stream *utf8; - char *prop, *field[NumFields], line[1024]; + static io·Buffer utf8; + char *prop, field[NumFields][FieldLen]; - if(!(utf8 = io·open(path, "r"))) + if(io·open(path, sys·ORead, &utf8)) panicf("can't open %s\n", path); // NOTE: we don't check for comments here ec = -1; - while(parse(utf8, arrlen(field), field, arrlen(line), line)){ - codepointrange(utf8, field, &sc, &ec); + while(parse(&utf8, arrlen(field), field)){ + codepointrange(&utf8, field, &sc, &ec); prop = field[Fcategory]; @@ -86,11 +85,10 @@ parse_category(char *path) table.width[w][c] = 1; } - io·close(utf8); + io·close((io·Header *)&utf8); } -static -void +static void coderange(char *field, int *l, int *r) { char *s; @@ -104,17 +102,18 @@ coderange(char *field, int *l, int *r) } } -static -void +static void parse_eawidths(char *path) { int at, w; int l, c, r; - io·Stream *utf8; - char *field[2], line[1024]; + static io·Buffer utf8; + char field[2][FieldLen]; - utf8 = io·open(path, "r"); - while((at=parse(utf8, arrlen(field), field, arrlen(line), line)) != ParseEOF){ + if(io·open(path, sys·ORead, &utf8)) + panicf("can't open %s\n", path); + + while((at=parse(&utf8, arrlen(field), field)) != ParseEOF){ if(at == ParseSkip) continue; @@ -142,20 +141,21 @@ parse_eawidths(char *path) table.width[(w+2)%3][c] = 0; } } - io·close(utf8); + io·close((io·Header*)&utf8); } -static -void +static void parse_emoji(char *path) { int at, w; int l, c, r; - io·Stream *utf8; - char *s, *field[2], line[1024]; + static io·Buffer utf8; + char *s, field[2][FieldLen]; - utf8 = io·open(path, "r"); - while((at=parse(utf8, arrlen(field), field, arrlen(line), line)) != ParseEOF){ + if(io·open(path, sys·ORead, &utf8)) + panicf("can't open %s\n", path); + + while((at=parse(&utf8, arrlen(field), field)) != ParseEOF){ if(at == ParseSkip) continue; @@ -178,7 +178,7 @@ parse_emoji(char *path) } } - io·close(utf8); + io·close((io·Header*)&utf8); } /* output functions */ @@ -322,4 +322,6 @@ main(int argc, char *argv[]) " return 0;\n" "}" ); + + return 0; } diff --git a/src/cmd/dwm/util.c b/src/cmd/dwm/util.c index 0db71cc..4bf5359 100644 --- a/src/cmd/dwm/util.c +++ b/src/cmd/dwm/util.c @@ -35,8 +35,8 @@ getparentprocess(pid_t p) uint v = 0; #if defined(__linux__) - io·Stream *f; - char buf[256]; + FILE *f; + char buf[256]; snprintf(buf, sizeof(buf) - 1, "/proc/%u/stat", (unsigned)p); if (!(f = fopen(buf, "r"))) diff --git a/src/cmd/rc/code.c b/src/cmd/rc/code.c index 47266e4..9c6316c 100644 --- a/src/cmd/rc/code.c +++ b/src/cmd/rc/code.c @@ -17,8 +17,7 @@ static struct Interpreter interpreter; #define emitf(x) ((void)(interpreter.i != interpreter.cap || grow()), interpreter.code[interpreter.i].f = (x), interpreter.i++) #define emits(x) ((void)(interpreter.i != interpreter.cap || grow()), interpreter.code[interpreter.i].s = (x), interpreter.i++) -static -int +static int grow(void) { interpreter.cap += 100; @@ -28,8 +27,7 @@ grow(void) return 0; } -static -void +static void storepc(int a) { if(interpreter.i <= a || a < 0) @@ -342,12 +340,17 @@ walk(Tree *node) storepc(addr2); emitf(Xpipewait); - break; -#if 0 case Tpipefd: -#endif + emitf(Xpipefd); + emiti(node->redir.type); + addr1 = emiti(0); + + walk(node->child[0]); + emitf(Xexit); + storepc(addr1); + break; case Tdup: if(node->redir.type == Rdupfd){ diff --git a/src/cmd/rc/exec.c b/src/cmd/rc/exec.c index bd68bf5..bdbc151 100644 --- a/src/cmd/rc/exec.c +++ b/src/cmd/rc/exec.c @@ -5,16 +5,20 @@ int yyparse(void); -struct Builtin{ +struct Builtin +{ char *name; void (*func)(void); }; -struct State { +#if 0 +struct State +{ int async; }; static struct State state; +#endif // ----------------------------------------------------------------------- // globals @@ -1415,6 +1419,54 @@ Xpipe(void) } void +Xpipefd(void) +{ + char name[40]; + Thread *orig = runner; + int pc, fd, pid, pfd[2], sidefd, mainfd; + + pc = runner->code.i; + if(pipe(pfd)<0){ + Xerror("can't get pipe"); + return; + } + + if(runner->code.exe[runner->code.i].i == Rread) + fd=1, sidefd=pfd[1], mainfd=pfd[0]; + else + fd=0, sidefd=pfd[0], mainfd=pfd[1]; + + switch(pid = fork()){ + case -1: + Xerror("try again"); + break; + case 0: + initchild(runner,1); + + /* child 0 (writer) forked process */ + run(runner->code.exe, pc+2, runner->local, 1); + + close(mainfd); + pushredir(Ropen, sidefd, fd); + runner->caller = nil; + break; + + default: + initparent(runner,pid,0); + + close(sidefd); + pushredir(Ropen, mainfd, mainfd); + + strcpy(name, "/dev/fd/"); + str·itoa(name+8, mainfd); + pushword(name); + + orig->code.i = orig->code.exe[pc+1].i; + break; + } +} + +void Xbasic(void) { Var *v; diff --git a/src/cmd/rc/exec.h b/src/cmd/rc/exec.h index 28cbd80..de3fdde 100644 --- a/src/cmd/rc/exec.h +++ b/src/cmd/rc/exec.h @@ -45,6 +45,7 @@ void Xpipe(void); void Xpipewait(void); void Xpopredir(void); void Xglob(void); +void Xpipefd(void); void Xreturn(void); void Xexit(void); diff --git a/src/cmd/rc/input.c b/src/cmd/rc/input.c index cc2383d..9771174 100644 --- a/src/cmd/rc/input.c +++ b/src/cmd/rc/input.c @@ -131,8 +131,7 @@ typedef struct typedef Position (*Noun)(struct TerminalState*, int);
typedef void (*Verb)(struct TerminalState*, Position);
-static
-int
+static int
runetype(rune r)
{
if(r<128)
@@ -147,23 +146,20 @@ runetype(rune r) return NonPrintable;
}
-static
-void
+static void
normalcursor(int fd)
{
write(fd,"\e[2 q",5);
}
-static
-void
+static void
insertcursor(int fd)
{
write(fd,"\e[6 q",5);
}
/* raw mode: 1960 magic shit. */
-static
-int
+static int
enterraw(int fd)
{
struct termios raw;
@@ -206,8 +202,7 @@ fatal: return 0;
}
-static
-void
+static void
exitraw(int fd)
{
/* don't even check the return value as it's too late. */
@@ -218,8 +213,7 @@ exitraw(int fd) /* use the esc [6n escape sequence to query the horizontal cursor position
* and return it. on error -1 is returned, on success the position of the
* cursor. */
-static
-int
+static int
cursorposition(int ifd, int ofd)
{
char buf[32];
@@ -250,8 +244,7 @@ cursorposition(int ifd, int ofd) }
/* try to get the number of columns in the current terminal, or assume 80 if it fails. */
-static
-int
+static int
columns(int ifd, int ofd)
{
struct winsize ws;
@@ -287,8 +280,7 @@ failed: return 80;
}
-static
-void
+static void
clear(void)
{
if(write(1,"\x1b[H\x1b[2J",7) <= 0)
@@ -297,8 +289,7 @@ clear(void) /* beep: used for completion when there is nothing to complete or when all
* the choices were already shown. */
-static
-void
+static void
beep(void)
{
fprintf(stderr, "\x7");
@@ -335,8 +326,7 @@ addhistory(char *line) return 1;
}
-static
-void
+static void
pophistory(void)
{
if(--history.top < history.entry)
@@ -346,8 +336,7 @@ pophistory(void) static void refreshline(struct TerminalState *);
-static
-char **
+static char **
currenthistory(struct TerminalState *term, intptr *size)
{
char **entry;
@@ -369,8 +358,7 @@ currenthistory(struct TerminalState *term, intptr *size) return entry;
}
-static
-void
+static void
usehistory(struct TerminalState *term, int d)
{
rune r;
@@ -423,16 +411,14 @@ struct Buffer char *b;
};
-static
-void
+static void
initbuffer(struct Buffer *ab)
{
ab->b = nil;
ab->len = 0;
}
-static
-void
+static void
append(struct Buffer *ab, const char *s, int len)
{
char *new = realloc(ab->b,ab->len+len);
@@ -443,8 +429,7 @@ append(struct Buffer *ab, const char *s, int len) ab->len += len;
}
-static
-void
+static void
freebuffer(struct Buffer *ab)
{
free(ab->b);
@@ -454,8 +439,7 @@ freebuffer(struct Buffer *ab) *
* rewrite the currently edited line accordingly to the buffer content,
* cursor position, and number of columns of the terminal. */
-static
-void
+static void
refreshsingleline(struct TerminalState *term)
{
char esc[64];
@@ -519,8 +503,7 @@ refreshsingleline(struct TerminalState *term) *
* Rewrite the currently edited line accordingly to the buffer content,
* cursor position, and number of columns of the terminal. */
-static
-void
+static void
refreshmultilines(struct TerminalState *term)
{
#if 0
@@ -603,8 +586,7 @@ refreshmultilines(struct TerminalState *term) /* Calls the two low level functions refreshSingleLine() or
* refreshMultiLine() according to the selected mode. */
-static
-void
+static void
refreshline(struct TerminalState *term)
{
if(mode.multiline)
@@ -695,16 +677,14 @@ insertbytes(struct TerminalState *term, int len, char *buf) /* modes */
-static
-void
+static void
normalmode(int fd)
{
mode.vi.insert = 0;
normalcursor(fd);
}
-static
-void
+static void
insertmode(int fd)
{
mode.vi.insert = 1;
@@ -713,8 +693,7 @@ insertmode(int fd) /* actions */
-static
-void
+static void
move(struct TerminalState *term, Position to)
{
if(to.buffer != term->edit.pos){
@@ -724,8 +703,7 @@ move(struct TerminalState *term, Position to) }
}
-static
-void
+static void
yank(struct TerminalState *term, Position to)
{
intptr len, off;
@@ -751,8 +729,7 @@ yank(struct TerminalState *term, Position to) term->yank.buf[len] = 0;
}
-static
-void
+static void
delete(struct TerminalState *term, Position to)
{
intptr diff;
@@ -790,8 +767,7 @@ refresh: #define CURRENT(term) (Position){ .buffer=(term)->edit.pos, .cursor=(term)->cursor.pos };
// move cursor to the left n boxes
-static
-Position
+static Position
left(struct TerminalState *term, int n)
{
rune r;
@@ -814,8 +790,7 @@ left(struct TerminalState *term, int n) }
// move cursor to the right n boxes
-static
-Position
+static Position
right(struct TerminalState *term, int n)
{
rune r;
@@ -839,8 +814,7 @@ right(struct TerminalState *term, int n) return pos;
}
-static
-Position
+static Position
prevword(struct TerminalState *term, int n)
{
rune r;
@@ -884,8 +858,7 @@ prevword(struct TerminalState *term, int n) return pos;
}
-static
-Position
+static Position
nextword(struct TerminalState *term, int n)
{
rune r;
@@ -932,8 +905,7 @@ nextword(struct TerminalState *term, int n) }
-static
-Position
+static Position
prevWord(struct TerminalState *term, int n)
{
rune r;
@@ -977,8 +949,7 @@ prevWord(struct TerminalState *term, int n) return pos;
}
-static
-Position
+static Position
nextWord(struct TerminalState *term, int n)
{
rune r;
@@ -1023,8 +994,7 @@ nextWord(struct TerminalState *term, int n) return pos;
}
-static
-Position
+static Position
nextend(struct TerminalState *term, int n)
{
rune r;
@@ -1067,8 +1037,7 @@ nextend(struct TerminalState *term, int n) return pos;
}
-static
-Position
+static Position
nextEnd(struct TerminalState *term, int n)
{
rune r;
@@ -1116,8 +1085,7 @@ nextEnd(struct TerminalState *term, int n) #define HOME(term) (Position){0}
#define END(term) (Position){(term)->edit.len, (term)->cursor.len}
-static
-int
+static int
vi(struct TerminalState *term, char c)
{
int n = 1;
@@ -1269,8 +1237,7 @@ action: #define END(term) (Position){(term).edit.len, (term).cursor.len}
-static
-int
+static int
size(char *s)
{
rune c;
@@ -1304,8 +1271,7 @@ size(char *s) * when ctrl+d is typed.
*
* the function returns the length of the current buffer. */
-static
-int
+static int
interact(int ifd, int ofd, char *buf, intptr len, char *prompt)
{
int n, aux;
@@ -1597,8 +1563,7 @@ printkeycode(void) /*
* this function calls the line editing function edit() using the stdin set in raw mode
*/
-static
-int
+static int
raw(char *buf, intptr len, char *prompt)
{
int n;
@@ -1622,8 +1587,7 @@ raw(char *buf, intptr len, char *prompt) * program is called in pipe or with a file redirected to its standard input
* in this case, we want to be able to return the line regardless of its length
*/
-static
-int
+static int
notty(void)
{
int c;
@@ -1670,8 +1634,7 @@ readline(char *prompt) }
/* At exit we'll try to fix the terminal to the initial conditions. */
-static
-void
+static void
doatexit(void)
{
exitraw(0);
diff --git a/src/cmd/rc/parse.c b/src/cmd/rc/parse.c index 42b69e4..af4608d 100644 --- a/src/cmd/rc/parse.c +++ b/src/cmd/rc/parse.c @@ -1,4 +1,4 @@ -/* A Bison parser, made by GNU Bison 3.8.2. */ +/* A Bison parser, made by GNU Bison 3.7.6. */ /* Bison implementation for Yacc-like parsers in C @@ -46,10 +46,10 @@ USER NAME SPACE" below. */ /* Identify Bison output, and Bison version. */ -#define YYBISON 30802 +#define YYBISON 30706 /* Bison version string. */ -#define YYBISON_VERSION "3.8.2" +#define YYBISON_VERSION "3.7.6" /* Skeleton name. */ #define YYSKELETON_NAME "yacc.c" @@ -120,52 +120,53 @@ enum yysymbol_kind_t YYSYMBOL_Tredir = 15, /* Tredir */ YYSYMBOL_Tdup = 16, /* Tdup */ YYSYMBOL_Tpipe = 17, /* Tpipe */ - YYSYMBOL_Tindex = 18, /* Tindex */ - YYSYMBOL_Tbasic = 19, /* Tbasic */ - YYSYMBOL_Targs = 20, /* Targs */ - YYSYMBOL_Tword = 21, /* Tword */ - YYSYMBOL_Twords = 22, /* Twords */ - YYSYMBOL_Tparen = 23, /* Tparen */ - YYSYMBOL_Tblock = 24, /* Tblock */ - YYSYMBOL_25_ = 25, /* ')' */ - YYSYMBOL_Tandand = 26, /* Tandand */ - YYSYMBOL_Toror = 27, /* Toror */ - YYSYMBOL_28_n_ = 28, /* '\n' */ - YYSYMBOL_29_ = 29, /* '^' */ - YYSYMBOL_30_ = 30, /* '$' */ - YYSYMBOL_Tcount = 31, /* Tcount */ - YYSYMBOL_Tjoin = 32, /* Tjoin */ - YYSYMBOL_33_ = 33, /* '(' */ - YYSYMBOL_34_ = 34, /* '{' */ - YYSYMBOL_35_ = 35, /* '}' */ - YYSYMBOL_36_ = 36, /* ';' */ - YYSYMBOL_37_ = 37, /* '&' */ - YYSYMBOL_38_ = 38, /* '=' */ - YYSYMBOL_39_ = 39, /* '`' */ - YYSYMBOL_YYACCEPT = 40, /* $accept */ - YYSYMBOL_rc = 41, /* rc */ - YYSYMBOL_line = 42, /* line */ - YYSYMBOL_body = 43, /* body */ - YYSYMBOL_paren = 44, /* paren */ - YYSYMBOL_block = 45, /* block */ - YYSYMBOL_cmds = 46, /* cmds */ - YYSYMBOL_cmdsln = 47, /* cmdsln */ - YYSYMBOL_ifbody = 48, /* ifbody */ - YYSYMBOL_case = 49, /* case */ - YYSYMBOL_casebody = 50, /* casebody */ - YYSYMBOL_assign = 51, /* assign */ - YYSYMBOL_redir = 52, /* redir */ - YYSYMBOL_epilog = 53, /* epilog */ - YYSYMBOL_cmd = 54, /* cmd */ - YYSYMBOL_basic = 55, /* basic */ - YYSYMBOL_atom = 56, /* atom */ - YYSYMBOL_word = 57, /* word */ - YYSYMBOL_executable = 58, /* executable */ - YYSYMBOL_nonkeyword = 59, /* nonkeyword */ - YYSYMBOL_keyword = 60, /* keyword */ - YYSYMBOL_words = 61, /* words */ - YYSYMBOL_wordsnl = 62, /* wordsnl */ - YYSYMBOL_nl = 63 /* nl */ + YYSYMBOL_Tpipefd = 18, /* Tpipefd */ + YYSYMBOL_Tindex = 19, /* Tindex */ + YYSYMBOL_Tbasic = 20, /* Tbasic */ + YYSYMBOL_Targs = 21, /* Targs */ + YYSYMBOL_Tword = 22, /* Tword */ + YYSYMBOL_Twords = 23, /* Twords */ + YYSYMBOL_Tparen = 24, /* Tparen */ + YYSYMBOL_Tblock = 25, /* Tblock */ + YYSYMBOL_26_ = 26, /* ')' */ + YYSYMBOL_Tandand = 27, /* Tandand */ + YYSYMBOL_Toror = 28, /* Toror */ + YYSYMBOL_29_n_ = 29, /* '\n' */ + YYSYMBOL_30_ = 30, /* '^' */ + YYSYMBOL_31_ = 31, /* '$' */ + YYSYMBOL_Tcount = 32, /* Tcount */ + YYSYMBOL_Tjoin = 33, /* Tjoin */ + YYSYMBOL_34_ = 34, /* '(' */ + YYSYMBOL_35_ = 35, /* '{' */ + YYSYMBOL_36_ = 36, /* '}' */ + YYSYMBOL_37_ = 37, /* ';' */ + YYSYMBOL_38_ = 38, /* '&' */ + YYSYMBOL_39_ = 39, /* '=' */ + YYSYMBOL_40_ = 40, /* '`' */ + YYSYMBOL_YYACCEPT = 41, /* $accept */ + YYSYMBOL_rc = 42, /* rc */ + YYSYMBOL_line = 43, /* line */ + YYSYMBOL_body = 44, /* body */ + YYSYMBOL_paren = 45, /* paren */ + YYSYMBOL_block = 46, /* block */ + YYSYMBOL_cmds = 47, /* cmds */ + YYSYMBOL_cmdsln = 48, /* cmdsln */ + YYSYMBOL_ifbody = 49, /* ifbody */ + YYSYMBOL_case = 50, /* case */ + YYSYMBOL_casebody = 51, /* casebody */ + YYSYMBOL_assign = 52, /* assign */ + YYSYMBOL_redir = 53, /* redir */ + YYSYMBOL_epilog = 54, /* epilog */ + YYSYMBOL_cmd = 55, /* cmd */ + YYSYMBOL_basic = 56, /* basic */ + YYSYMBOL_atom = 57, /* atom */ + YYSYMBOL_word = 58, /* word */ + YYSYMBOL_executable = 59, /* executable */ + YYSYMBOL_nonkeyword = 60, /* nonkeyword */ + YYSYMBOL_keyword = 61, /* keyword */ + YYSYMBOL_words = 62, /* words */ + YYSYMBOL_wordsnl = 63, /* wordsnl */ + YYSYMBOL_nl = 64 /* nl */ }; typedef enum yysymbol_kind_t yysymbol_kind_t; @@ -323,18 +324,12 @@ typedef int yy_state_fast_t; # define YY_USE(E) /* empty */ #endif +#if defined __GNUC__ && ! defined __ICC && 407 <= __GNUC__ * 100 + __GNUC_MINOR__ /* Suppress an incorrect diagnostic about yylval being uninitialized. */ -#if defined __GNUC__ && ! defined __ICC && 406 <= __GNUC__ * 100 + __GNUC_MINOR__ -# if __GNUC__ * 100 + __GNUC_MINOR__ < 407 -# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \ - _Pragma ("GCC diagnostic push") \ - _Pragma ("GCC diagnostic ignored \"-Wuninitialized\"") -# else -# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \ +# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \ _Pragma ("GCC diagnostic push") \ _Pragma ("GCC diagnostic ignored \"-Wuninitialized\"") \ _Pragma ("GCC diagnostic ignored \"-Wmaybe-uninitialized\"") -# endif # define YY_IGNORE_MAYBE_UNINITIALIZED_END \ _Pragma ("GCC diagnostic pop") #else @@ -491,21 +486,21 @@ union yyalloc #endif /* !YYCOPY_NEEDED */ /* YYFINAL -- State number of the termination state. */ -#define YYFINAL 61 +#define YYFINAL 63 /* YYLAST -- Last index in YYTABLE. */ -#define YYLAST 486 +#define YYLAST 479 /* YYNTOKENS -- Number of terminals. */ -#define YYNTOKENS 40 +#define YYNTOKENS 41 /* YYNNTS -- Number of nonterminals. */ #define YYNNTS 24 /* YYNRULES -- Number of rules. */ -#define YYNRULES 74 +#define YYNRULES 75 /* YYNSTATES -- Number of states. */ -#define YYNSTATES 136 +#define YYNSTATES 139 /* YYMAXUTOK -- Last valid token kind. */ -#define YYMAXUTOK 283 +#define YYMAXUTOK 284 /* YYTRANSLATE(TOKEN-NUM) -- Symbol number corresponding to TOKEN-NUM @@ -520,18 +515,18 @@ union yyalloc static const yytype_int8 yytranslate[] = { 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 28, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 29, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 30, 2, 37, 2, - 33, 25, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 36, - 2, 38, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 31, 2, 38, 2, + 34, 26, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 37, + 2, 39, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 29, 2, 39, 2, 2, 2, + 2, 2, 2, 2, 30, 2, 40, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 34, 2, 35, 2, 2, 2, 2, + 2, 2, 2, 35, 2, 36, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, @@ -547,11 +542,11 @@ static const yytype_int8 yytranslate[] = 2, 2, 2, 2, 2, 2, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, - 26, 27, 31, 32 + 25, 27, 28, 32, 33 }; #if YYDEBUG -/* YYRLINE[YYN] -- Source line where rule number YYN was defined. */ + /* YYRLINE[YYN] -- Source line where rule number YYN was defined. */ static const yytype_uint8 yyrline[] = { 0, 38, 38, 39, 42, 43, 46, 47, 50, 53, @@ -559,9 +554,9 @@ static const yytype_uint8 yyrline[] = 78, 79, 82, 83, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 105, 106, 107, 110, 111, 114, 115, 118, 119, - 122, 123, 124, 125, 126, 127, 128, 132, 132, 132, - 132, 132, 132, 132, 132, 132, 132, 132, 135, 136, - 139, 140, 141, 143, 145 + 122, 123, 124, 125, 126, 127, 128, 129, 132, 132, + 132, 132, 132, 132, 132, 132, 132, 132, 132, 135, + 136, 139, 140, 141, 143, 145 }; #endif @@ -579,10 +574,10 @@ static const char *const yytname[] = { "\"end of file\"", "error", "\"invalid token\"", "Tfor", "Tin", "Twhile", "Tif", "Telse", "Tswitch", "Tcase", "Tcasebody", "Ttwiddle", - "Tbang", "Tsubshell", "Tfunc", "Tredir", "Tdup", "Tpipe", "Tindex", - "Tbasic", "Targs", "Tword", "Twords", "Tparen", "Tblock", "')'", - "Tandand", "Toror", "'\\n'", "'^'", "'$'", "Tcount", "Tjoin", "'('", - "'{'", "'}'", "';'", "'&'", "'='", "'`'", "$accept", "rc", "line", + "Tbang", "Tsubshell", "Tfunc", "Tredir", "Tdup", "Tpipe", "Tpipefd", + "Tindex", "Tbasic", "Targs", "Tword", "Twords", "Tparen", "Tblock", + "')'", "Tandand", "Toror", "'\\n'", "'^'", "'$'", "Tcount", "Tjoin", + "'('", "'{'", "'}'", "';'", "'&'", "'='", "'`'", "$accept", "rc", "line", "body", "paren", "block", "cmds", "cmdsln", "ifbody", "case", "casebody", "assign", "redir", "epilog", "cmd", "basic", "atom", "word", "executable", "nonkeyword", "keyword", "words", "wordsnl", "nl", YY_NULLPTR @@ -595,6 +590,19 @@ yysymbol_name (yysymbol_kind_t yysymbol) } #endif +#ifdef YYPRINT +/* YYTOKNUM[NUM] -- (External) token number corresponding to the + (internal) symbol number NUM (which must be that of a token). */ +static const yytype_int16 yytoknum[] = +{ + 0, 256, 257, 258, 259, 260, 261, 262, 263, 264, + 265, 266, 267, 268, 269, 270, 271, 272, 273, 274, + 275, 276, 277, 278, 279, 280, 41, 281, 282, 10, + 94, 36, 283, 284, 40, 123, 125, 59, 38, 61, + 96 +}; +#endif + #define YYPACT_NINF (-44) #define yypact_value_is_default(Yyn) \ @@ -605,206 +613,204 @@ yysymbol_name (yysymbol_kind_t yysymbol) #define yytable_value_is_error(Yyn) \ 0 -/* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing - STATE-NUM. */ + /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing + STATE-NUM. */ static const yytype_int16 yypact[] = { - 124, -18, -16, -16, 19, 415, 447, 447, -44, 415, - -44, -44, 415, 415, 415, -44, 447, -9, 55, 36, - 56, 447, 447, 447, 73, 161, 15, -44, 415, 447, - -44, -44, 415, -44, -44, -44, -44, -44, -44, -44, - -44, -44, -44, -44, -44, 39, -44, -44, 59, 59, - 235, 39, 60, -44, -44, 198, 38, -44, 447, -8, - -44, -44, -44, 56, -44, -44, 59, 59, -44, -44, - -44, -44, -44, -44, 39, 415, 415, 12, 61, 267, - 267, 32, 415, 415, -44, 39, -44, -44, -44, 39, - -44, -44, -44, -44, 267, 267, 267, -44, 39, -44, - -44, -44, -44, 33, 51, -44, 33, -44, -44, 304, - -44, 59, 59, 341, 267, -44, 17, -44, -44, 33, - 267, -44, 267, 33, 5, 33, -44, 75, 52, 378, - -44, -44, -44, 267, -44, -8 + 127, -19, -17, -17, -9, 393, 439, 439, -44, 203, + -44, -44, 393, 393, 393, -44, 439, 32, 69, 45, + 50, 439, 439, 439, -8, 241, 15, -44, 393, 439, + -44, -44, 393, -44, -44, -44, -44, -44, -44, -44, + -44, -44, -44, -44, 32, -44, 42, -44, -44, 58, + 58, 203, -44, 42, 57, -44, -44, 165, 53, -44, + 439, 117, -44, -44, -44, 393, 50, -44, -44, 58, + 58, -44, -44, -44, -44, -44, -44, 42, 393, 393, + 10, 55, 406, 406, 2, 393, 393, -44, 42, -44, + -44, -44, 42, -44, -44, -44, -44, 406, 406, 406, + -44, 42, -44, -44, -44, -44, 43, 37, -44, 43, + -44, -44, 279, -44, 58, 58, 317, 406, -44, 28, + -44, -44, 43, 406, -44, 406, 43, 9, 43, -44, + 70, 54, 355, -44, -44, -44, 406, -44, 117 }; -/* YYDEFACT[STATE-NUM] -- Default reduction number in state STATE-NUM. - Performed when YYTABLE does not specify something else to do. Zero - means the default is an error. */ + /* YYDEFACT[STATE-NUM] -- Default reduction number in state STATE-NUM. + Performed when YYTABLE does not specify something else to do. Zero + means the default is an error. */ static const yytype_int8 yydefact[] = { - 24, 0, 0, 0, 0, 0, 24, 24, 68, 0, - 20, 50, 0, 0, 0, 70, 24, 0, 0, 0, + 24, 0, 0, 0, 0, 0, 24, 24, 69, 0, + 20, 50, 0, 0, 0, 71, 24, 0, 0, 0, 22, 24, 24, 24, 4, 25, 41, 48, 0, 24, - 73, 73, 0, 57, 58, 59, 60, 61, 62, 63, - 66, 64, 65, 67, 46, 68, 44, 45, 32, 33, - 0, 21, 51, 54, 55, 0, 0, 12, 24, 6, - 56, 1, 3, 22, 26, 5, 31, 30, 73, 73, - 73, 10, 11, 43, 42, 0, 0, 0, 0, 24, - 24, 0, 0, 34, 40, 69, 68, 53, 71, 72, - 9, 7, 13, 23, 24, 24, 24, 49, 19, 68, - 73, 8, 74, 37, 22, 38, 14, 73, 47, 0, - 27, 28, 29, 0, 24, 73, 0, 52, 73, 35, - 24, 73, 24, 15, 17, 36, 68, 17, 0, 0, - 18, 39, 73, 24, 16, 0 + 74, 74, 0, 58, 59, 60, 61, 62, 63, 64, + 67, 65, 66, 68, 0, 46, 69, 44, 45, 32, + 33, 0, 57, 21, 51, 54, 55, 0, 0, 12, + 24, 6, 56, 1, 3, 0, 22, 26, 5, 31, + 30, 74, 74, 74, 10, 11, 43, 42, 0, 0, + 0, 0, 24, 24, 0, 0, 34, 40, 70, 69, + 53, 72, 73, 9, 7, 13, 23, 24, 24, 24, + 49, 19, 69, 74, 8, 75, 37, 22, 38, 14, + 74, 47, 0, 27, 28, 29, 0, 24, 74, 0, + 52, 74, 35, 24, 74, 24, 15, 17, 36, 69, + 17, 0, 0, 18, 39, 74, 24, 16, 0 }; -/* YYPGOTO[NTERM-NUM]. */ + /* YYPGOTO[NTERM-NUM]. */ static const yytype_int8 yypgoto[] = { - -44, -44, 77, -26, 98, 13, 26, -28, -44, -44, - -24, -44, -15, 43, 0, -44, 22, 37, -44, -1, + -44, -44, 72, -27, 93, 17, 16, -35, -44, -44, + -28, -44, -15, 38, 0, -44, 35, 30, -44, -1, -44, -43, -44, -30 }; -/* YYDEFGOTO[NTERM-NUM]. */ + /* YYDEFGOTO[NTERM-NUM]. */ static const yytype_uint8 yydefgoto[] = { - 0, 18, 19, 56, 30, 20, 57, 58, 105, 127, - 128, 22, 23, 64, 59, 25, 44, 85, 26, 27, - 47, 50, 55, 79 + 0, 18, 19, 58, 30, 20, 59, 60, 108, 130, + 131, 22, 23, 67, 61, 25, 45, 88, 26, 27, + 48, 51, 57, 82 }; -/* YYTABLE[YYPACT[STATE-NUM]] -- What to do in state STATE-NUM. If - positive, shift that token. If negative, reduce the rule whose - number is the opposite. If YYTABLE_NINF, syntax error. */ + /* YYTABLE[YYPACT[STATE-NUM]] -- What to do in state STATE-NUM. If + positive, shift that token. If negative, reduce the rule whose + number is the opposite. If YYTABLE_NINF, syntax error. */ static const yytype_int16 yytable[] = { - 24, 80, 83, 78, 46, 63, 48, 49, 46, 68, - 73, 46, 46, 46, 126, 28, 99, 29, 69, 70, - 92, 24, 66, 67, 46, 16, 21, 46, 71, 72, - 60, 46, 91, 102, 52, 53, 54, 100, 94, 95, - 96, 82, 45, 109, 75, 102, 51, 21, 63, 46, - 68, 121, 32, 76, 46, 61, 113, 107, 115, 69, - 70, 82, 74, 84, 62, 77, 9, 10, 82, 81, - 114, 9, 10, 90, 46, 46, 68, 116, 86, 103, - 106, 46, 46, 129, 126, 120, 101, 131, 122, 63, - 68, 124, 89, 104, 110, 111, 112, 97, 65, 69, - 70, 31, 133, 130, 108, 134, 93, 0, 46, 71, - 72, 0, 46, 98, 119, 0, 0, 0, 0, 0, - 123, 0, 125, 0, -2, 0, 0, 1, 46, 2, - 3, 0, 4, 135, 0, 5, 6, 7, 8, 9, - 10, 0, 0, 0, 0, 11, 0, 0, 0, 0, + 24, 83, 81, 86, 47, 66, 49, 50, 47, 71, + 76, 47, 47, 47, 102, 28, 21, 29, 129, 72, + 73, 24, 69, 70, 47, 32, 52, 47, 110, 74, + 75, 47, 85, 94, 62, 46, 103, 21, 105, 53, + 85, 97, 98, 99, 118, 78, 112, 54, 55, 56, + 47, 66, 65, 10, 79, 77, 47, 105, 80, 116, + 71, 52, 84, 124, 47, 65, 10, 16, 87, 63, + 72, 73, 85, 117, 64, 71, 89, 47, 47, 129, + 119, 104, 106, 109, 47, 47, 132, 92, 123, 93, + 134, 125, 66, 68, 127, 53, 31, 113, 114, 115, + 107, 137, 133, 0, 96, 136, 0, 0, 0, 101, + 0, 47, 0, 100, 0, 47, 0, 122, 0, 0, + 111, 0, 0, 126, 0, 128, 0, -2, 0, 0, + 1, 47, 2, 3, 71, 4, 138, 0, 5, 6, + 7, 8, 9, 10, 72, 73, 95, 0, 0, 11, + 0, 0, 0, 0, 74, 75, 0, 0, 12, 13, + 14, 15, 16, 0, 0, 0, 0, 17, 33, 34, + 35, 36, 37, 38, 39, 0, 40, 41, 42, 43, + 44, 0, 0, 0, 0, 0, 0, 11, 0, 0, + 0, 90, 0, 0, 91, 0, 12, 13, 14, 15, + 0, 0, 0, 0, 0, 17, 33, 34, 35, 36, + 37, 38, 39, 0, 40, 41, 42, 43, 44, 0, + 0, 0, 0, 0, 0, 11, 0, 0, 0, 0, 0, 0, 0, 0, 12, 13, 14, 15, 16, 0, 0, 0, 0, 17, 33, 34, 35, 36, 37, 38, 39, 0, 40, 41, 42, 43, 9, 10, 0, 0, - 0, 0, 11, 0, 0, 0, 0, 0, 0, 0, - 0, 12, 13, 14, 15, 0, 0, 0, 0, 0, - 17, 33, 34, 35, 36, 37, 38, 39, 0, 40, - 41, 42, 43, 0, 0, 0, 0, 0, 0, 11, - 0, 0, 0, 87, 0, 0, 88, 0, 12, 13, + 0, 0, 0, 11, 0, 0, 0, 0, 0, 0, + 0, 0, 12, 13, 14, 15, 0, 0, 0, 0, + 0, 17, 33, 34, 35, 36, 37, 38, 39, 0, + 40, 41, 42, 43, 44, 0, 0, 0, 0, 0, + 0, 11, 0, 0, 0, 120, 0, 0, 0, 0, + 12, 13, 14, 15, 0, 0, 0, 0, 0, 17, + 33, 34, 35, 36, 37, 38, 39, 0, 40, 41, + 42, 43, 44, 0, 0, 0, 0, 0, 0, 11, + 0, 0, 0, 121, 0, 0, 0, 0, 12, 13, 14, 15, 0, 0, 0, 0, 0, 17, 33, 34, 35, 36, 37, 38, 39, 0, 40, 41, 42, 43, - 0, 0, 0, 0, 0, 0, 11, 0, 0, 0, - 0, 0, 0, 0, 0, 12, 13, 14, 15, 16, - 1, 0, 2, 3, 17, 4, 0, 0, 5, 6, - 7, 8, 9, 10, 0, 0, 0, 0, 11, 0, - 0, 0, 0, 0, 0, 102, 0, 12, 13, 14, - 15, 16, 0, 0, 0, 0, 17, 33, 34, 35, - 36, 37, 38, 39, 0, 40, 41, 42, 43, 0, - 0, 0, 0, 0, 0, 11, 0, 0, 0, 117, - 0, 0, 0, 0, 12, 13, 14, 15, 0, 0, - 0, 0, 0, 17, 33, 34, 35, 36, 37, 38, - 39, 0, 40, 41, 42, 43, 0, 0, 0, 0, - 0, 0, 11, 0, 0, 0, 118, 0, 0, 0, - 0, 12, 13, 14, 15, 0, 0, 0, 0, 0, - 17, 33, 34, 35, 36, 37, 38, 39, 0, 40, - 41, 42, 43, 0, 0, 0, 0, 0, 0, 11, - 0, 0, 0, 0, 0, 0, 0, 0, 12, 13, - 14, 15, 0, 0, 132, 0, 0, 17, 33, 34, - 35, 36, 37, 38, 39, 0, 40, 41, 42, 43, - 0, 0, 0, 0, 0, 0, 11, 0, 0, 0, - 0, 0, 0, 0, 0, 12, 13, 14, 15, 0, - 1, 0, 2, 3, 17, 4, 0, 0, 5, 6, - 7, 8, 9, 10, 0, 0, 0, 0, 11, 0, - 0, 0, 0, 0, 0, 0, 0, 12, 13, 14, - 15, 16, 0, 0, 0, 0, 17 + 44, 0, 0, 0, 0, 0, 0, 11, 0, 0, + 0, 0, 0, 0, 0, 0, 12, 13, 14, 15, + 0, 0, 135, 0, 0, 17, 33, 34, 35, 36, + 37, 38, 39, 0, 40, 41, 42, 43, 44, 1, + 0, 2, 3, 0, 4, 11, 0, 5, 6, 7, + 8, 9, 10, 0, 12, 13, 14, 15, 11, 0, + 0, 0, 0, 17, 0, 105, 0, 12, 13, 14, + 15, 16, 1, 0, 2, 3, 17, 4, 0, 0, + 5, 6, 7, 8, 9, 10, 0, 0, 0, 0, + 0, 11, 0, 0, 0, 0, 0, 0, 0, 0, + 12, 13, 14, 15, 16, 0, 0, 0, 0, 17 }; static const yytype_int16 yycheck[] = { - 0, 31, 45, 29, 5, 20, 6, 7, 9, 17, - 25, 12, 13, 14, 9, 33, 4, 33, 26, 27, - 28, 21, 22, 23, 25, 34, 0, 28, 36, 37, - 17, 32, 58, 28, 12, 13, 14, 25, 68, 69, - 70, 29, 5, 86, 29, 28, 9, 21, 63, 50, - 17, 34, 33, 38, 55, 0, 99, 25, 7, 26, - 27, 29, 25, 50, 28, 28, 15, 16, 29, 32, - 100, 15, 16, 35, 75, 76, 17, 107, 18, 79, - 80, 82, 83, 126, 9, 115, 25, 35, 118, 104, - 17, 121, 55, 80, 94, 95, 96, 75, 21, 26, - 27, 3, 132, 127, 82, 133, 63, -1, 109, 36, - 37, -1, 113, 76, 114, -1, -1, -1, -1, -1, - 120, -1, 122, -1, 0, -1, -1, 3, 129, 5, - 6, -1, 8, 133, -1, 11, 12, 13, 14, 15, - 16, -1, -1, -1, -1, 21, -1, -1, -1, -1, - -1, -1, -1, -1, 30, 31, 32, 33, 34, -1, - -1, -1, -1, 39, 3, 4, 5, 6, 7, 8, - 9, -1, 11, 12, 13, 14, 15, 16, -1, -1, - -1, -1, 21, -1, -1, -1, -1, -1, -1, -1, - -1, 30, 31, 32, 33, -1, -1, -1, -1, -1, - 39, 3, 4, 5, 6, 7, 8, 9, -1, 11, - 12, 13, 14, -1, -1, -1, -1, -1, -1, 21, - -1, -1, -1, 25, -1, -1, 28, -1, 30, 31, - 32, 33, -1, -1, -1, -1, -1, 39, 3, 4, + 0, 31, 29, 46, 5, 20, 6, 7, 9, 17, + 25, 12, 13, 14, 4, 34, 0, 34, 9, 27, + 28, 21, 22, 23, 25, 34, 9, 28, 26, 37, + 38, 32, 30, 60, 17, 5, 26, 21, 29, 9, + 30, 71, 72, 73, 7, 30, 89, 12, 13, 14, + 51, 66, 15, 16, 39, 25, 57, 29, 28, 102, + 17, 44, 32, 35, 65, 15, 16, 35, 51, 0, + 27, 28, 30, 103, 29, 17, 19, 78, 79, 9, + 110, 26, 82, 83, 85, 86, 129, 57, 118, 36, + 36, 121, 107, 21, 124, 65, 3, 97, 98, 99, + 83, 136, 130, -1, 66, 135, -1, -1, -1, 79, + -1, 112, -1, 78, -1, 116, -1, 117, -1, -1, + 85, -1, -1, 123, -1, 125, -1, 0, -1, -1, + 3, 132, 5, 6, 17, 8, 136, -1, 11, 12, + 13, 14, 15, 16, 27, 28, 29, -1, -1, 22, + -1, -1, -1, -1, 37, 38, -1, -1, 31, 32, + 33, 34, 35, -1, -1, -1, -1, 40, 3, 4, 5, 6, 7, 8, 9, -1, 11, 12, 13, 14, - -1, -1, -1, -1, -1, -1, 21, -1, -1, -1, - -1, -1, -1, -1, -1, 30, 31, 32, 33, 34, - 3, -1, 5, 6, 39, 8, -1, -1, 11, 12, - 13, 14, 15, 16, -1, -1, -1, -1, 21, -1, - -1, -1, -1, -1, -1, 28, -1, 30, 31, 32, - 33, 34, -1, -1, -1, -1, 39, 3, 4, 5, - 6, 7, 8, 9, -1, 11, 12, 13, 14, -1, - -1, -1, -1, -1, -1, 21, -1, -1, -1, 25, - -1, -1, -1, -1, 30, 31, 32, 33, -1, -1, - -1, -1, -1, 39, 3, 4, 5, 6, 7, 8, - 9, -1, 11, 12, 13, 14, -1, -1, -1, -1, - -1, -1, 21, -1, -1, -1, 25, -1, -1, -1, - -1, 30, 31, 32, 33, -1, -1, -1, -1, -1, - 39, 3, 4, 5, 6, 7, 8, 9, -1, 11, - 12, 13, 14, -1, -1, -1, -1, -1, -1, 21, - -1, -1, -1, -1, -1, -1, -1, -1, 30, 31, - 32, 33, -1, -1, 36, -1, -1, 39, 3, 4, + 15, -1, -1, -1, -1, -1, -1, 22, -1, -1, + -1, 26, -1, -1, 29, -1, 31, 32, 33, 34, + -1, -1, -1, -1, -1, 40, 3, 4, 5, 6, + 7, 8, 9, -1, 11, 12, 13, 14, 15, -1, + -1, -1, -1, -1, -1, 22, -1, -1, -1, -1, + -1, -1, -1, -1, 31, 32, 33, 34, 35, -1, + -1, -1, -1, 40, 3, 4, 5, 6, 7, 8, + 9, -1, 11, 12, 13, 14, 15, 16, -1, -1, + -1, -1, -1, 22, -1, -1, -1, -1, -1, -1, + -1, -1, 31, 32, 33, 34, -1, -1, -1, -1, + -1, 40, 3, 4, 5, 6, 7, 8, 9, -1, + 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, + -1, 22, -1, -1, -1, 26, -1, -1, -1, -1, + 31, 32, 33, 34, -1, -1, -1, -1, -1, 40, + 3, 4, 5, 6, 7, 8, 9, -1, 11, 12, + 13, 14, 15, -1, -1, -1, -1, -1, -1, 22, + -1, -1, -1, 26, -1, -1, -1, -1, 31, 32, + 33, 34, -1, -1, -1, -1, -1, 40, 3, 4, 5, 6, 7, 8, 9, -1, 11, 12, 13, 14, - -1, -1, -1, -1, -1, -1, 21, -1, -1, -1, - -1, -1, -1, -1, -1, 30, 31, 32, 33, -1, - 3, -1, 5, 6, 39, 8, -1, -1, 11, 12, - 13, 14, 15, 16, -1, -1, -1, -1, 21, -1, - -1, -1, -1, -1, -1, -1, -1, 30, 31, 32, - 33, 34, -1, -1, -1, -1, 39 + 15, -1, -1, -1, -1, -1, -1, 22, -1, -1, + -1, -1, -1, -1, -1, -1, 31, 32, 33, 34, + -1, -1, 37, -1, -1, 40, 3, 4, 5, 6, + 7, 8, 9, -1, 11, 12, 13, 14, 15, 3, + -1, 5, 6, -1, 8, 22, -1, 11, 12, 13, + 14, 15, 16, -1, 31, 32, 33, 34, 22, -1, + -1, -1, -1, 40, -1, 29, -1, 31, 32, 33, + 34, 35, 3, -1, 5, 6, 40, 8, -1, -1, + 11, 12, 13, 14, 15, 16, -1, -1, -1, -1, + -1, 22, -1, -1, -1, -1, -1, -1, -1, -1, + 31, 32, 33, 34, 35, -1, -1, -1, -1, 40 }; -/* YYSTOS[STATE-NUM] -- The symbol kind of the accessing symbol of - state STATE-NUM. */ + /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing + symbol of state STATE-NUM. */ static const yytype_int8 yystos[] = { 0, 3, 5, 6, 8, 11, 12, 13, 14, 15, - 16, 21, 30, 31, 32, 33, 34, 39, 41, 42, - 45, 46, 51, 52, 54, 55, 58, 59, 33, 33, - 44, 44, 33, 3, 4, 5, 6, 7, 8, 9, - 11, 12, 13, 14, 56, 57, 59, 60, 54, 54, - 61, 57, 56, 56, 56, 62, 43, 46, 47, 54, - 45, 0, 28, 52, 53, 42, 54, 54, 17, 26, - 27, 36, 37, 52, 57, 29, 38, 57, 43, 63, - 63, 57, 29, 61, 45, 57, 18, 25, 28, 57, - 35, 43, 28, 53, 63, 63, 63, 56, 57, 4, - 25, 25, 28, 54, 45, 48, 54, 25, 56, 61, - 54, 54, 54, 61, 63, 7, 63, 25, 25, 54, - 63, 34, 63, 54, 63, 54, 9, 49, 50, 61, - 50, 35, 36, 63, 47, 54 + 16, 22, 31, 32, 33, 34, 35, 40, 42, 43, + 46, 47, 52, 53, 55, 56, 59, 60, 34, 34, + 45, 45, 34, 3, 4, 5, 6, 7, 8, 9, + 11, 12, 13, 14, 15, 57, 58, 60, 61, 55, + 55, 62, 46, 58, 57, 57, 57, 63, 44, 47, + 48, 55, 46, 0, 29, 15, 53, 54, 43, 55, + 55, 17, 27, 28, 37, 38, 53, 58, 30, 39, + 58, 44, 64, 64, 58, 30, 62, 46, 58, 19, + 26, 29, 58, 36, 44, 29, 54, 64, 64, 64, + 57, 58, 4, 26, 26, 29, 55, 46, 49, 55, + 26, 57, 62, 55, 55, 55, 62, 64, 7, 64, + 26, 26, 55, 64, 35, 64, 55, 64, 55, 9, + 50, 51, 62, 51, 36, 37, 64, 48, 55 }; -/* YYR1[RULE-NUM] -- Symbol kind of the left-hand side of rule RULE-NUM. */ + /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */ static const yytype_int8 yyr1[] = { - 0, 40, 41, 41, 42, 42, 43, 43, 44, 45, - 46, 46, 47, 47, 48, 48, 49, 50, 50, 51, - 52, 52, 53, 53, 54, 54, 54, 54, 54, 54, - 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, - 54, 55, 55, 55, 56, 56, 57, 57, 58, 58, - 59, 59, 59, 59, 59, 59, 59, 60, 60, 60, + 0, 41, 42, 42, 43, 43, 44, 44, 45, 46, + 47, 47, 48, 48, 49, 49, 50, 51, 51, 52, + 53, 53, 54, 54, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 56, 56, 56, 57, 57, 58, 58, 59, 59, 60, 60, 60, 60, 60, 60, 60, 60, 61, 61, - 62, 62, 62, 63, 63 + 61, 61, 61, 61, 61, 61, 61, 61, 61, 62, + 62, 63, 63, 63, 64, 64 }; -/* YYR2[RULE-NUM] -- Number of symbols on the right-hand side of rule RULE-NUM. */ + /* YYR2[YYN] -- Number of symbols on the right hand side of rule YYN. */ static const yytype_int8 yyr2[] = { 0, 2, 0, 2, 1, 2, 1, 2, 3, 3, @@ -812,9 +818,9 @@ static const yytype_int8 yyr2[] = 1, 2, 0, 2, 0, 1, 2, 4, 4, 4, 2, 2, 2, 2, 3, 6, 8, 4, 4, 9, 3, 1, 2, 2, 1, 1, 1, 3, 1, 3, - 1, 2, 5, 3, 2, 2, 2, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 0, 2, - 0, 2, 2, 0, 2 + 1, 2, 5, 3, 2, 2, 2, 2, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, + 2, 0, 2, 2, 0, 2 }; @@ -826,7 +832,6 @@ enum { YYENOMEM = -2 }; #define YYACCEPT goto yyacceptlab #define YYABORT goto yyabortlab #define YYERROR goto yyerrorlab -#define YYNOMEM goto yyexhaustedlab #define YYRECOVERING() (!!yyerrstatus) @@ -867,7 +872,10 @@ do { \ YYFPRINTF Args; \ } while (0) - +/* This macro is provided for backward compatibility. */ +# ifndef YY_LOCATION_PRINT +# define YY_LOCATION_PRINT(File, Loc) ((void) 0) +# endif # define YY_SYMBOL_PRINT(Title, Kind, Value, Location) \ @@ -894,6 +902,10 @@ yy_symbol_value_print (FILE *yyo, YY_USE (yyoutput); if (!yyvaluep) return; +# ifdef YYPRINT + if (yykind < YYNTOKENS) + YYPRINT (yyo, yytoknum[yykind], *yyvaluep); +# endif YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN YY_USE (yykind); YY_IGNORE_MAYBE_UNINITIALIZED_END @@ -1348,7 +1360,6 @@ yyparse (void) YYDPRINTF ((stderr, "Starting parse\n")); yychar = YYEMPTY; /* Cause a token to be read. */ - goto yysetstate; @@ -1374,7 +1385,7 @@ yysetstate: if (yyss + yystacksize - 1 <= yyssp) #if !defined yyoverflow && !defined YYSTACK_RELOCATE - YYNOMEM; + goto yyexhaustedlab; #else { /* Get the current used size of the three stacks, in elements. */ @@ -1402,7 +1413,7 @@ yysetstate: # else /* defined YYSTACK_RELOCATE */ /* Extend the stack our own way. */ if (YYMAXDEPTH <= yystacksize) - YYNOMEM; + goto yyexhaustedlab; yystacksize *= 2; if (YYMAXDEPTH < yystacksize) yystacksize = YYMAXDEPTH; @@ -1413,7 +1424,7 @@ yysetstate: YY_CAST (union yyalloc *, YYSTACK_ALLOC (YY_CAST (YYSIZE_T, YYSTACK_BYTES (yystacksize)))); if (! yyptr) - YYNOMEM; + goto yyexhaustedlab; YYSTACK_RELOCATE (yyss_alloc, yyss); YYSTACK_RELOCATE (yyvs_alloc, yyvs); # undef YYSTACK_RELOCATE @@ -1435,7 +1446,6 @@ yysetstate: } #endif /* !defined yyoverflow && !defined YYSTACK_RELOCATE */ - if (yystate == YYFINAL) YYACCEPT; @@ -1550,293 +1560,299 @@ yyreduce: case 2: /* rc: %empty */ #line 38 "src/cmd/rc/syntax.y" { return 1; } -#line 1554 "src/cmd/rc/parse.c" +#line 1564 "src/cmd/rc/parse.c" break; case 3: /* rc: line '\n' */ #line 39 "src/cmd/rc/syntax.y" { return compile((yyvsp[-1].tree)); } -#line 1560 "src/cmd/rc/parse.c" +#line 1570 "src/cmd/rc/parse.c" break; case 5: /* line: cmds line */ #line 43 "src/cmd/rc/syntax.y" { (yyval.tree) = maketree2(';', (yyvsp[-1].tree), (yyvsp[0].tree)); } -#line 1566 "src/cmd/rc/parse.c" +#line 1576 "src/cmd/rc/parse.c" break; case 7: /* body: cmdsln body */ #line 47 "src/cmd/rc/syntax.y" { (yyval.tree) = maketree2(';', (yyvsp[-1].tree), (yyvsp[0].tree)); } -#line 1572 "src/cmd/rc/parse.c" +#line 1582 "src/cmd/rc/parse.c" break; case 8: /* paren: '(' body ')' */ #line 50 "src/cmd/rc/syntax.y" { (yyval.tree) = maketree1(Tparen, (yyvsp[-1].tree)); } -#line 1578 "src/cmd/rc/parse.c" +#line 1588 "src/cmd/rc/parse.c" break; case 9: /* block: '{' body '}' */ #line 53 "src/cmd/rc/syntax.y" { (yyval.tree) = maketree1(Tblock, (yyvsp[-1].tree)); } -#line 1584 "src/cmd/rc/parse.c" +#line 1594 "src/cmd/rc/parse.c" break; case 11: /* cmds: cmd '&' */ #line 57 "src/cmd/rc/syntax.y" { (yyval.tree) = maketree1('&', (yyvsp[-1].tree)); } -#line 1590 "src/cmd/rc/parse.c" +#line 1600 "src/cmd/rc/parse.c" break; case 14: /* ifbody: cmd */ #line 64 "src/cmd/rc/syntax.y" { (yyval.tree) = maketree2(Tif, nil, (yyvsp[0].tree)); } -#line 1596 "src/cmd/rc/parse.c" +#line 1606 "src/cmd/rc/parse.c" break; case 15: /* ifbody: block Telse nl cmd */ #line 65 "src/cmd/rc/syntax.y" { (yyval.tree) = maketree3(Tif, nil, (yyvsp[-3].tree), (yyvsp[-2].tree)); } -#line 1602 "src/cmd/rc/parse.c" +#line 1612 "src/cmd/rc/parse.c" break; case 16: /* case: Tcase words ';' nl cmdsln */ #line 68 "src/cmd/rc/syntax.y" { (yyval.tree) = hangchild2((yyvsp[-4].tree), (yyvsp[-3].tree), 0, (yyvsp[0].tree), 1);} -#line 1608 "src/cmd/rc/parse.c" +#line 1618 "src/cmd/rc/parse.c" break; case 17: /* casebody: %empty */ #line 71 "src/cmd/rc/syntax.y" { (yyval.tree) = nil; } -#line 1614 "src/cmd/rc/parse.c" +#line 1624 "src/cmd/rc/parse.c" break; case 18: /* casebody: case casebody */ #line 72 "src/cmd/rc/syntax.y" { (yyval.tree) = (!(yyvsp[0].tree)) ? (yyvsp[-1].tree) : maketree2(';', (yyvsp[-1].tree), (yyvsp[0].tree)); } -#line 1620 "src/cmd/rc/parse.c" +#line 1630 "src/cmd/rc/parse.c" break; case 19: /* assign: executable '=' word */ #line 75 "src/cmd/rc/syntax.y" { (yyval.tree) = maketree2('=', (yyvsp[-2].tree), (yyvsp[0].tree)); } -#line 1626 "src/cmd/rc/parse.c" +#line 1636 "src/cmd/rc/parse.c" break; case 21: /* redir: Tredir word */ #line 79 "src/cmd/rc/syntax.y" { (yyval.tree) = hangchild1((yyvsp[-1].tree), ((yyvsp[-1].tree)->redir.type == Rhere)?heredoc((yyvsp[0].tree)):(yyvsp[0].tree), 0); } -#line 1632 "src/cmd/rc/parse.c" +#line 1642 "src/cmd/rc/parse.c" break; case 22: /* epilog: %empty */ #line 82 "src/cmd/rc/syntax.y" { (yyval.tree) = nil; } -#line 1638 "src/cmd/rc/parse.c" +#line 1648 "src/cmd/rc/parse.c" break; case 23: /* epilog: redir epilog */ #line 83 "src/cmd/rc/syntax.y" { (yyval.tree) = hangchild1((yyvsp[-1].tree), (yyvsp[0].tree), 1); } -#line 1644 "src/cmd/rc/parse.c" +#line 1654 "src/cmd/rc/parse.c" break; case 24: /* cmd: %empty */ #line 86 "src/cmd/rc/syntax.y" { (yyval.tree) = nil; } -#line 1650 "src/cmd/rc/parse.c" +#line 1660 "src/cmd/rc/parse.c" break; case 25: /* cmd: basic */ #line 87 "src/cmd/rc/syntax.y" { (yyval.tree) = basictree((yyvsp[0].tree)); } -#line 1656 "src/cmd/rc/parse.c" +#line 1666 "src/cmd/rc/parse.c" break; case 26: /* cmd: block epilog */ #line 88 "src/cmd/rc/syntax.y" { (yyval.tree) = hangepilog((yyvsp[-1].tree), (yyvsp[0].tree)); } -#line 1662 "src/cmd/rc/parse.c" +#line 1672 "src/cmd/rc/parse.c" break; case 27: /* cmd: cmd Tpipe nl cmd */ #line 89 "src/cmd/rc/syntax.y" { (yyval.tree) = hangchild2((yyvsp[-2].tree), (yyvsp[-3].tree), 0, (yyvsp[0].tree), 1); } -#line 1668 "src/cmd/rc/parse.c" +#line 1678 "src/cmd/rc/parse.c" break; case 28: /* cmd: cmd Tandand nl cmd */ #line 90 "src/cmd/rc/syntax.y" { (yyval.tree) = maketree2(Tandand, (yyvsp[-3].tree), (yyvsp[0].tree)); } -#line 1674 "src/cmd/rc/parse.c" +#line 1684 "src/cmd/rc/parse.c" break; case 29: /* cmd: cmd Toror nl cmd */ #line 91 "src/cmd/rc/syntax.y" { (yyval.tree) = maketree2(Toror, (yyvsp[-3].tree), (yyvsp[0].tree)); } -#line 1680 "src/cmd/rc/parse.c" +#line 1690 "src/cmd/rc/parse.c" break; case 30: /* cmd: redir cmd */ #line 92 "src/cmd/rc/syntax.y" { (yyval.tree) = hangchild1((yyvsp[-1].tree), (yyvsp[0].tree), 1); } -#line 1686 "src/cmd/rc/parse.c" +#line 1696 "src/cmd/rc/parse.c" break; case 31: /* cmd: assign cmd */ #line 93 "src/cmd/rc/syntax.y" { (yyval.tree) = hangchild1((yyvsp[-1].tree), (yyvsp[0].tree), 2); } -#line 1692 "src/cmd/rc/parse.c" +#line 1702 "src/cmd/rc/parse.c" break; case 32: /* cmd: Tbang cmd */ #line 94 "src/cmd/rc/syntax.y" { (yyval.tree) = maketree1(Tbang, (yyvsp[0].tree)); } -#line 1698 "src/cmd/rc/parse.c" +#line 1708 "src/cmd/rc/parse.c" break; case 33: /* cmd: Tsubshell cmd */ #line 95 "src/cmd/rc/syntax.y" { (yyval.tree) = maketree1(Tsubshell, (yyvsp[0].tree)); } -#line 1704 "src/cmd/rc/parse.c" +#line 1714 "src/cmd/rc/parse.c" break; case 34: /* cmd: Ttwiddle word words */ #line 96 "src/cmd/rc/syntax.y" { (yyval.tree) = hangchild2((yyvsp[-2].tree), (yyvsp[-1].tree), 0, (yyvsp[0].tree), 1); } -#line 1710 "src/cmd/rc/parse.c" +#line 1720 "src/cmd/rc/parse.c" break; case 35: /* cmd: Tfor '(' word ')' nl cmd */ #line 97 "src/cmd/rc/syntax.y" { (yyval.tree) = hangchild3((yyvsp[-5].tree), (yyvsp[-3].tree), nil, (yyvsp[0].tree)); } -#line 1716 "src/cmd/rc/parse.c" +#line 1726 "src/cmd/rc/parse.c" break; case 36: /* cmd: Tfor '(' word Tin words ')' nl cmd */ #line 98 "src/cmd/rc/syntax.y" { (yyval.tree) = hangchild3((yyvsp[-7].tree), (yyvsp[-5].tree), (yyvsp[-3].tree), (yyvsp[0].tree)); } -#line 1722 "src/cmd/rc/parse.c" +#line 1732 "src/cmd/rc/parse.c" break; case 37: /* cmd: Twhile paren nl cmd */ #line 99 "src/cmd/rc/syntax.y" { (yyval.tree) = hangchild2((yyvsp[-3].tree), (yyvsp[-2].tree), 0, (yyvsp[0].tree), 1); } -#line 1728 "src/cmd/rc/parse.c" +#line 1738 "src/cmd/rc/parse.c" break; case 38: /* cmd: Tif paren nl ifbody */ #line 100 "src/cmd/rc/syntax.y" { (yyval.tree) = hangchild1((yyvsp[0].tree), (yyvsp[-2].tree), 0); } -#line 1734 "src/cmd/rc/parse.c" +#line 1744 "src/cmd/rc/parse.c" break; case 39: /* cmd: Tswitch '(' word ')' nl '{' nl casebody '}' */ #line 101 "src/cmd/rc/syntax.y" { (yyval.tree) = hangchild2((yyvsp[-8].tree), (yyvsp[-6].tree), 0, (yyvsp[-1].tree), 1); } -#line 1740 "src/cmd/rc/parse.c" +#line 1750 "src/cmd/rc/parse.c" break; case 40: /* cmd: Tfunc words block */ #line 102 "src/cmd/rc/syntax.y" { (yyval.tree) = hangchild2((yyvsp[-2].tree), (yyvsp[-1].tree), 0, (yyvsp[0].tree), 1); } -#line 1746 "src/cmd/rc/parse.c" +#line 1756 "src/cmd/rc/parse.c" break; case 42: /* basic: basic word */ #line 106 "src/cmd/rc/syntax.y" { (yyval.tree) = maketree2(Targs, (yyvsp[-1].tree), (yyvsp[0].tree)); } -#line 1752 "src/cmd/rc/parse.c" +#line 1762 "src/cmd/rc/parse.c" break; case 43: /* basic: basic redir */ #line 107 "src/cmd/rc/syntax.y" { (yyval.tree) = maketree2(Targs, (yyvsp[-1].tree), (yyvsp[0].tree)); } -#line 1758 "src/cmd/rc/parse.c" +#line 1768 "src/cmd/rc/parse.c" break; case 45: /* atom: keyword */ #line 111 "src/cmd/rc/syntax.y" { (yyval.tree) = maketree1(Tword, (yyvsp[0].tree)); } -#line 1764 "src/cmd/rc/parse.c" +#line 1774 "src/cmd/rc/parse.c" break; case 47: /* word: word '^' atom */ #line 115 "src/cmd/rc/syntax.y" { (yyval.tree) = maketree2('^', (yyvsp[-2].tree), (yyvsp[0].tree)); } -#line 1770 "src/cmd/rc/parse.c" +#line 1780 "src/cmd/rc/parse.c" break; case 49: /* executable: executable '^' atom */ #line 119 "src/cmd/rc/syntax.y" { (yyval.tree) = maketree2('^', (yyvsp[-2].tree), (yyvsp[0].tree)); } -#line 1776 "src/cmd/rc/parse.c" +#line 1786 "src/cmd/rc/parse.c" break; case 51: /* nonkeyword: '$' atom */ #line 123 "src/cmd/rc/syntax.y" { (yyval.tree) = maketree1('$', (yyvsp[0].tree)); } -#line 1782 "src/cmd/rc/parse.c" +#line 1792 "src/cmd/rc/parse.c" break; case 52: /* nonkeyword: '$' atom Tindex words ')' */ #line 124 "src/cmd/rc/syntax.y" { (yyval.tree) = maketree2(Tindex, (yyvsp[-3].tree), (yyvsp[-1].tree)); } -#line 1788 "src/cmd/rc/parse.c" +#line 1798 "src/cmd/rc/parse.c" break; case 53: /* nonkeyword: '(' wordsnl ')' */ #line 125 "src/cmd/rc/syntax.y" { (yyval.tree) = (yyvsp[-1].tree); } -#line 1794 "src/cmd/rc/parse.c" +#line 1804 "src/cmd/rc/parse.c" break; case 54: /* nonkeyword: Tcount atom */ #line 126 "src/cmd/rc/syntax.y" { (yyval.tree) = maketree1(Tcount, (yyvsp[0].tree)); } -#line 1800 "src/cmd/rc/parse.c" +#line 1810 "src/cmd/rc/parse.c" break; case 55: /* nonkeyword: Tjoin atom */ #line 127 "src/cmd/rc/syntax.y" { (yyval.tree) = maketree1(Tjoin, (yyvsp[0].tree)); } -#line 1806 "src/cmd/rc/parse.c" +#line 1816 "src/cmd/rc/parse.c" break; case 56: /* nonkeyword: '`' block */ #line 128 "src/cmd/rc/syntax.y" { (yyval.tree) = maketree1('`', (yyvsp[0].tree)); } -#line 1812 "src/cmd/rc/parse.c" +#line 1822 "src/cmd/rc/parse.c" + break; + + case 57: /* nonkeyword: Tredir block */ +#line 129 "src/cmd/rc/syntax.y" + { (yyval.tree) = hangchild1((yyvsp[-1].tree), (yyvsp[0].tree), 0); (yyval.tree)->type = Tpipefd; } +#line 1828 "src/cmd/rc/parse.c" break; - case 68: /* words: %empty */ + case 69: /* words: %empty */ #line 135 "src/cmd/rc/syntax.y" { (yyval.tree) = nil; } -#line 1818 "src/cmd/rc/parse.c" +#line 1834 "src/cmd/rc/parse.c" break; - case 69: /* words: words word */ + case 70: /* words: words word */ #line 136 "src/cmd/rc/syntax.y" { (yyval.tree) = maketree2(Twords, (yyvsp[-1].tree), (yyvsp[0].tree)); } -#line 1824 "src/cmd/rc/parse.c" +#line 1840 "src/cmd/rc/parse.c" break; - case 70: /* wordsnl: %empty */ + case 71: /* wordsnl: %empty */ #line 139 "src/cmd/rc/syntax.y" { (yyval.tree) = nil; } -#line 1830 "src/cmd/rc/parse.c" +#line 1846 "src/cmd/rc/parse.c" break; - case 72: /* wordsnl: wordsnl word */ + case 73: /* wordsnl: wordsnl word */ #line 141 "src/cmd/rc/syntax.y" {(yyval.tree) = (!(yyvsp[-1].tree)) ? ((!(yyvsp[0].tree)) ? nil : (yyvsp[0].tree)) : ((!(yyvsp[0].tree)) ? (yyvsp[-1].tree) : maketree2(Twords, (yyvsp[-1].tree), (yyvsp[0].tree))); } -#line 1836 "src/cmd/rc/parse.c" +#line 1852 "src/cmd/rc/parse.c" break; -#line 1840 "src/cmd/rc/parse.c" +#line 1856 "src/cmd/rc/parse.c" default: break; } @@ -1912,7 +1928,7 @@ yyerrlab: } yyerror (yymsgp); if (yysyntax_error_status == YYENOMEM) - YYNOMEM; + goto yyexhaustedlab; } } @@ -1948,7 +1964,6 @@ yyerrorlab: label yyerrorlab therefore never appears in user code. */ if (0) YYERROR; - ++yynerrs; /* Do not reclaim the symbols of the rule whose action triggered this YYERROR. */ @@ -2009,7 +2024,7 @@ yyerrlab1: `-------------------------------------*/ yyacceptlab: yyresult = 0; - goto yyreturnlab; + goto yyreturn; /*-----------------------------------. @@ -2017,22 +2032,24 @@ yyacceptlab: `-----------------------------------*/ yyabortlab: yyresult = 1; - goto yyreturnlab; + goto yyreturn; -/*-----------------------------------------------------------. -| yyexhaustedlab -- YYNOMEM (memory exhaustion) comes here. | -`-----------------------------------------------------------*/ +#if 1 +/*-------------------------------------------------. +| yyexhaustedlab -- memory exhaustion comes here. | +`-------------------------------------------------*/ yyexhaustedlab: yyerror (YY_("memory exhausted")); yyresult = 2; - goto yyreturnlab; + goto yyreturn; +#endif -/*----------------------------------------------------------. -| yyreturnlab -- parsing is finished, clean up and return. | -`----------------------------------------------------------*/ -yyreturnlab: +/*-------------------------------------------------------. +| yyreturn -- parsing is finished, clean up and return. | +`-------------------------------------------------------*/ +yyreturn: if (yychar != YYEMPTY) { /* Make sure we have latest lookahead translation. See comments at diff --git a/src/cmd/rc/parse.h b/src/cmd/rc/parse.h index 88859ea..ee56e0c 100644 --- a/src/cmd/rc/parse.h +++ b/src/cmd/rc/parse.h @@ -1,4 +1,4 @@ -/* A Bison parser, made by GNU Bison 3.8.2. */ +/* A Bison parser, made by GNU Bison 3.7.6. */ /* Bison interface for Yacc-like parsers in C @@ -39,7 +39,7 @@ # define YY_YY_SRC_CMD_RC_PARSE_H_INCLUDED /* Debug traces. */ #ifndef YYDEBUG -# define YYDEBUG 1 +# define YYDEBUG 0 #endif #if YYDEBUG extern int yydebug; @@ -69,17 +69,18 @@ extern int yydebug; Tredir = 270, /* Tredir */ Tdup = 271, /* Tdup */ Tpipe = 272, /* Tpipe */ - Tindex = 273, /* Tindex */ - Tbasic = 274, /* Tbasic */ - Targs = 275, /* Targs */ - Tword = 276, /* Tword */ - Twords = 277, /* Twords */ - Tparen = 278, /* Tparen */ - Tblock = 279, /* Tblock */ - Tandand = 280, /* Tandand */ - Toror = 281, /* Toror */ - Tcount = 282, /* Tcount */ - Tjoin = 283 /* Tjoin */ + Tpipefd = 273, /* Tpipefd */ + Tindex = 274, /* Tindex */ + Tbasic = 275, /* Tbasic */ + Targs = 276, /* Targs */ + Tword = 277, /* Tword */ + Twords = 278, /* Twords */ + Tparen = 279, /* Tparen */ + Tblock = 280, /* Tblock */ + Tandand = 281, /* Tandand */ + Toror = 282, /* Toror */ + Tcount = 283, /* Tcount */ + Tjoin = 284 /* Tjoin */ }; typedef enum yytokentype yytoken_kind_t; #endif @@ -92,7 +93,7 @@ union YYSTYPE struct Tree *tree; -#line 96 "src/cmd/rc/parse.h" +#line 97 "src/cmd/rc/parse.h" }; typedef union YYSTYPE YYSTYPE; @@ -103,8 +104,6 @@ typedef union YYSTYPE YYSTYPE; extern YYSTYPE yylval; - int yyparse (void); - #endif /* !YY_YY_SRC_CMD_RC_PARSE_H_INCLUDED */ diff --git a/src/cmd/rc/syntax.y b/src/cmd/rc/syntax.y index 3777710..dfd6e87 100644 --- a/src/cmd/rc/syntax.y +++ b/src/cmd/rc/syntax.y @@ -1,5 +1,5 @@ %token Tfor Tin Twhile Tif Telse Tswitch Tcase Tcasebody Ttwiddle Tbang Tsubshell Tfunc -%token Tredir Tdup Tpipe Tindex +%token Tredir Tdup Tpipe Tpipefd Tindex %token Tbasic Targs Tword Twords Tparen Tblock %define parse.error verbose @@ -126,7 +126,7 @@ nonkeyword: | Tcount atom { $$ = maketree1(Tcount, $2); } | Tjoin atom { $$ = maketree1(Tjoin, $2); } | '`' block { $$ = maketree1('`', $2); } -//| Tredir block { $$ = hangchild1($1, $2, 0); $$->type = Tpipefd; } +| Tredir block { $$ = hangchild1($1, $2, 0); $$->type = Tpipefd; } keyword: Tfor|Tin|Twhile|Tif|Telse|Tswitch|Tcase|Tbang|Tsubshell|Ttwiddle|Tfunc diff --git a/src/cmd/walk/walk.c b/src/cmd/walk/walk.c index c68d6e0..29a8600 100644 --- a/src/cmd/walk/walk.c +++ b/src/cmd/walk/walk.c @@ -3,8 +3,7 @@ static char buf[4*1024], *c = buf; /* should be greater or equal to PATH_MAX */ -static -void +static void flush(void) { *c = 0; @@ -12,9 +11,8 @@ flush(void) c = buf; } -static -int -print(void *data, char *rel, char *abs, io·Stat *info) +static int +print(void *data, char *rel, char *abs, struct stat *info) { copy: while (*abs && c < (arrend(buf)-2)) |