fix various and sundary little acid annoyances. in particular - don't assume 2 is clearly sizeof Rune, or that that always holds. - be careful with width and sign in print formats; fix B fmt. - don't mangle comments when in interactive mode - increase max procs debugged to 400. close all those fds, too. Reference: /n/patches.lsub.org/patch/acid1 Date: Tue Jun 5 07:14:16 CES 2012 Signed-off-by: quanstro@quanstro.net --- /sys/src/cmd/acid/acid.h Thu Apr 12 12:25:21 2012 +++ /sys/src/cmd/acid/acid.h Tue Jun 5 06:11:49 2012 @@ -5,8 +5,8 @@ Strsize = 4096, Hashsize = 128, Maxarg = 512, - NFD = 100, - Maxproc = 50, + Maxproc = 400, + NFD = Maxproc+20, Maxval = 10, Mempergc = 1024*1024, }; @@ -243,6 +243,10 @@ void yyerror(char*, ...); int yylex(void); int yyparse(void); + +#pragma varargck argpos error 1 +#pragma varargck argpos fatal 1 +#pragma varargck argpos yyerror 1 enum { --- /sys/src/cmd/acid/builtin.c Thu Apr 12 12:25:21 2012 +++ /sys/src/cmd/acid/builtin.c Tue Nov 15 20:32:31 2011 @@ -40,8 +40,8 @@ void include(Node*, Node*); void regexp(Node*, Node*); void dosysr1(Node*, Node*); -void fmtof(Node*, Node*) ; -void dofmtsize(Node*, Node*) ; +void fmtof(Node*, Node*); +void dofmtsize(Node*, Node*); typedef struct Btab Btab; struct Btab @@ -861,7 +861,7 @@ } } -void +void flatten(Node **av, Node *n) { if(n == 0) @@ -969,7 +969,6 @@ void patom(char type, Store *res) { - int i; char buf[512]; extern char *typenames[]; @@ -984,20 +983,13 @@ Bprint(bout, "%3c", (int)res->ival); break; case 'r': - Bprint(bout, "%C", (int)res->ival); + Bprint(bout, "%C", (uint)res->ival); break; case 'B': - memset(buf, '0', 34); - buf[1] = 'b'; - for(i = 0; i < 32; i++) { - if(res->ival & (1<ival); break; case 'b': - Bprint(bout, "%.2x", (int)res->ival&0xff); + Bprint(bout, "%.2x", (uint)res->ival&0xff); break; case 'X': Bprint(bout, "%.8lux", (ulong)res->ival); @@ -1009,10 +1001,10 @@ Bprint(bout, "%d", (int)res->ival); break; case 'd': - Bprint(bout, "%d", (ushort)res->ival); + Bprint(bout, "%hd", (short)res->ival); break; case 'u': - Bprint(bout, "%d", (int)res->ival&0xffff); + Bprint(bout, "%hud", (uint)res->ival&0xffff); break; case 'U': Bprint(bout, "%lud", (ulong)res->ival); @@ -1030,13 +1022,13 @@ Bprint(bout, "%.16llux", res->ival); break; case 'o': - Bprint(bout, "0%.11uo", (int)res->ival&0xffff); + Bprint(bout, "0%.11uo", (uint)res->ival&0xffff); break; case 'O': Bprint(bout, "0%.6uo", (int)res->ival); break; case 'q': - Bprint(bout, "0%.11o", (short)(res->ival&0xffff)); + Bprint(bout, "0%.11ho", (short)(res->ival&0xffff)); break; case 'Q': Bprint(bout, "0%.6o", (int)res->ival); @@ -1270,7 +1262,8 @@ r->ival = strtol(p+1, 0, 0); } -void fmtof(Node *r, Node *args) +void +fmtof(Node *r, Node *args) { Node *av[Maxarg]; Node res; @@ -1280,36 +1273,36 @@ if(na < 1) error("fmtof(obj): no argument"); if(na > 1) - error("fmtof(obj): too many arguments") ; + error("fmtof(obj): too many arguments"); expr(av[0], &res); r->op = OCONST; - r->type = TINT ; - r->ival = res.fmt ; + r->type = TINT; + r->ival = res.fmt; r->fmt = 'c'; } -void dofmtsize(Node *r, Node *args) +void +dofmtsize(Node *r, Node *args) { - Node *av[Maxarg]; - Node res; - Store * s ; - Value v ; + Node *av[Maxarg], res; + Store *s; + Value v; na = 0; flatten(av, args); if(na < 1) error("fmtsize(obj): no argument"); if(na > 1) - error("fmtsize(obj): too many arguments") ; + error("fmtsize(obj): too many arguments"); expr(av[0], &res); - v.type = res.type ; - s = &v.Store ; - *s = res ; + v.type = res.type; + s = &v.Store; + *s = res; r->op = OCONST; - r->type = TINT ; - r->ival = fmtsize(&v) ; + r->type = TINT; + r->ival = fmtsize(&v); r->fmt = 'D'; } --- /sys/src/cmd/acid/exec.c Thu Apr 12 12:25:21 2012 +++ /sys/src/cmd/acid/exec.c Sun Sep 4 18:54:39 2011 @@ -205,7 +205,7 @@ void indir(Map *m, uvlong addr, char fmt, Node *r) { - int i; + int i, j, k; ulong lval; uvlong uvval; int ret; @@ -286,16 +286,19 @@ break; case 'R': r->type = TSTRING; - for(i = 0; i < sizeof(buf)-2; i += 2) { - ret = get1(m, addr, (uchar*)&buf[i], 2); + for(i = 0; i < sizeof(buf)-sizeof(Rune); i += sizeof(Rune)) { + ret = get1(m, addr, (uchar*)&buf[i], sizeof(Rune)); if (ret < 0) error("indir: %r"); - addr += 2; - if(buf[i] == 0 && buf[i+1] == 0) + addr += sizeof(Rune); + k = 0; + for(j = 0; j < sizeof(Rune); j++) + k |= buf[i+j]; + if(k == 0) break; } - buf[i++] = 0; - buf[i] = 0; + for(j = 0; j < sizeof(Rune); j++) + buf[i++] = 0; r->string = runenode((Rune*)buf); break; case 'i': --- /sys/src/cmd/acid/expr.c Thu Apr 12 12:25:21 2012 +++ /sys/src/cmd/acid/expr.c Sun Sep 4 16:55:57 2011 @@ -537,7 +537,7 @@ res->op = OCONST; res->type = TINT; if(l.type != TINT || r.type != TINT) - error("bad expr type %"); + error("bad expr type %%"); res->ival = l.ival%r.ival; } --- /sys/src/cmd/acid/lex.c Thu Apr 12 12:25:21 2012 +++ /sys/src/cmd/acid/lex.c Sun Sep 4 06:37:21 2011 @@ -329,6 +329,14 @@ case '\t': goto loop; + case '/': + c = lexc(); + if(c != '/'){ + unlexc(c); + return '/'; + } + eatnl(); + case '\n': line++; if(interactive == 0) @@ -390,15 +398,6 @@ return Tinc; unlexc(c); return '+'; - - case '/': - c = lexc(); - if(c == '/') { - eatnl(); - goto loop; - } - unlexc(c); - return '/'; case '\'': c = lexc(); --- /sys/src/cmd/acid/main.c Thu Apr 12 12:25:21 2012 +++ /sys/src/cmd/acid/main.c Sun Sep 4 17:01:50 2011 @@ -172,7 +172,7 @@ text = open(aout, OREAD); if(text < 0) - error("%s: can't open %s: %r\n", argv0, aout); + error("%s: can't open %s: %r", argv0, aout); readtext(aout); } if(pid) /* pid given */ --- /sys/src/cmd/acid/proc.c Thu Apr 12 12:25:21 2012 +++ /sys/src/cmd/acid/proc.c Tue Jun 5 06:10:45 2012 @@ -77,17 +77,14 @@ write(fd, "hang", 4); close(fd); - close(0); - close(1); - close(2); - for(i = 3; i < NFD; i++) + for(i = 0; i < NFD; i++) close(i); open("/dev/cons", OREAD); open("/dev/cons", OWRITE); open("/dev/cons", OWRITE); exec(argv[0], argv); - fatal("new: exec %s: %r"); + fatal("new: exec %s: %r", argv[0]); default: install(pid); msg(pid, "waitstop"); --- /sys/src/cmd/acid/util.c Thu Apr 12 12:25:21 2012 +++ /sys/src/cmd/acid/util.c Sun Sep 4 17:01:50 2011 @@ -203,7 +203,7 @@ break; } if(ret < 0) - error("can't get register %s: %r\n", reg); + error("can't get register %s: %r", reg); return v; }