--- /sys/src/9/bcm/dat.h Wed Jan 9 11:05:35 2013 +++ /sys/src/9/bcm/dat.h Wed May 15 20:16:56 2013 @@ -179,7 +179,6 @@ int load; int intr; uvlong fastclock; /* last sampled value */ - uvlong inidle; /* time spent in idlehands() */ ulong spuriousintr; int lastintr; int ilockdepth; --- /sys/src/9/kw/dat.h Wed Sep 28 06:10:11 2011 +++ /sys/src/9/kw/dat.h Wed May 15 20:18:27 2013 @@ -159,13 +159,11 @@ int load; int intr; vlong fastclock; /* last sampled value */ - uvlong inidle; /* time spent in idlehands() */ ulong spuriousintr; int lastintr; int ilockdepth; Perf perf; /* performance counters */ -// int cpumhz; uvlong cpuhz; /* speed of cpu */ uvlong cyclefreq; /* Frequency of user readable cycle counter */ --- /sys/src/9/omap/dat.h Wed Sep 28 06:11:18 2011 +++ /sys/src/9/omap/dat.h Wed May 15 20:17:05 2013 @@ -182,7 +182,6 @@ int load; int intr; uvlong fastclock; /* last sampled value */ - uvlong inidle; /* time spent in idlehands() */ ulong spuriousintr; int lastintr; int ilockdepth; --- /sys/src/9/teg2/dat.h Fri Jan 25 01:34:11 2013 +++ /sys/src/9/teg2/dat.h Wed May 15 20:17:31 2013 @@ -198,7 +198,6 @@ int load; int intr; uvlong fastclock; /* last sampled value */ - uvlong inidle; /* time spent in idlehands() */ ulong spuriousintr; int lastintr; int ilockdepth; --- /sys/src/cmd/rc/havefork.c Fri Mar 1 23:25:27 2013 +++ /sys/src/cmd/rc/havefork.c Wed May 15 20:53:33 2013 @@ -3,6 +3,7 @@ #include "exec.h" #include "io.h" #include "fns.h" +#include int havefork = 1; @@ -74,16 +75,19 @@ /* * Who should wait for the exit from the fork? */ + void Xbackq(void) { - int c, pid; + int n, pid; int pfd[2]; - char wd[NTOK + 1]; - char *s, *ewd = &wd[NTOK], *stop; + char *stop; + char utf[UTFmax+1]; struct io *f; var *ifs = vlook("ifs"); word *v, *nextv; + Rune r; + String *word; stop = ifs->val? ifs->val->word: ""; if(pipe(pfd)<0){ @@ -106,30 +110,26 @@ addwaitpid(pid); close(pfd[PWR]); f = openfd(pfd[PRD]); - s = wd; - v = 0; - /* - * this isn't quite right for utf. stop could have utf - * in it, and we're processing the input as bytes, not - * utf encodings of runes. further, if we run out of - * room in wd, we can chop in the middle of a utf encoding - * (not to mention stepping on one of the bytes). - * presotto's Strings seem like the right data structure here. - */ - while((c = rchr(f))!=EOF){ - if(strchr(stop, c) || s==ewd){ - if(s!=wd){ - *s='\0'; - v = newword(wd, v); - s = wd; + word = s_new(); + v = nil; + /* rutf requires at least UTFmax+1 bytes in utf */ + while((n = rutf(f, utf, &r)) != EOF){ + utf[n] = '\0'; + if(utfutf(stop, utf) == nil) + s_nappend(word, utf, n); + else + /* + * utf/r is an ifs rune (e.g., \t, \n), thus + * ends the current word, if any. + */ + if(s_len(word) > 0){ + v = newword(s_to_c(word), v); + s_reset(word); } - } - else *s++=c; - } - if(s!=wd){ - *s='\0'; - v = newword(wd, v); } + if(s_len(word) > 0) + v = newword(s_to_c(word), v); + s_free(word); closeio(f); Waitfor(pid, 0); /* v points to reversed arglist -- reverse it onto argv */ --- /sys/src/cmd/rc/haventfork.c Wed Jun 27 06:27:14 2007 +++ /sys/src/cmd/rc/haventfork.c Wed May 15 00:06:03 2013 @@ -14,7 +14,7 @@ word *p; p = vlook("*")->val; - argv = malloc((count(p)+6)*sizeof(char*)); + argv = emalloc((count(p)+6)*sizeof(char*)); argc = 0; argv[argc++] = argv0; if(flag['e']) --- /sys/src/cmd/rc/here.c Wed Jun 27 06:28:53 2007 +++ /sys/src/cmd/rc/here.c Wed May 15 22:30:29 2013 @@ -2,10 +2,11 @@ #include "exec.h" #include "io.h" #include "fns.h" + struct here *here, **ehere; int ser = 0; -char tmp[]="/tmp/here0000.0000"; -char hex[]="0123456789abcdef"; +char tmp[] = "/tmp/here0000.0000"; +char hex[] = "0123456789abcdef"; void psubst(io*, uchar*); void pstrs(io*, word*); @@ -13,9 +14,9 @@ void hexnum(char *p, int n) { - *p++=hex[(n>>12)&0xF]; - *p++=hex[(n>>8)&0xF]; - *p++=hex[(n>>4)&0xF]; + *p++ = hex[(n>>12)&0xF]; + *p++ = hex[(n>>8)&0xF]; + *p++ = hex[(n>>4)&0xF]; *p = hex[n&0xF]; } @@ -23,20 +24,22 @@ heredoc(tree *tag) { struct here *h = new(struct here); - if(tag->type!=WORD) + + if(tag->type != WORD) yyerror("Bad here tag"); h->next = 0; if(here) *ehere = h; else here = h; - ehere=&h->next; + ehere = &h->next; h->tag = tag; hexnum(&tmp[9], getpid()); hexnum(&tmp[14], ser++); h->name = strdup(tmp); return token(tmp, WORD); } + /* * bug: lines longer than NLINE get split -- this can cause spurious * missubstitution, or a misrecognized EOF marker. @@ -46,36 +49,38 @@ void readhere(void) { - struct here *h, *nexth; - io *f; - char *s, *tag; int c, subst; + char *s, *tag; char line[NLINE+1]; - for(h = here;h;h = nexth){ - subst=!h->tag->quoted; + io *f; + struct here *h, *nexth; + + for(h = here; h; h = nexth){ + subst = !h->tag->quoted; tag = h->tag->str; c = Creat(h->name); - if(c<0) + if(c < 0) yyerror("can't create here document"); f = openfd(c); s = line; pprompt(); - while((c = rchr(runq->cmdfd))!=EOF){ - if(c=='\n' || s==&line[NLINE]){ - *s='\0'; - if(tag && strcmp(line, tag)==0) break; + while((c = rchr(runq->cmdfd)) != EOF){ + if(c == '\n' || s == &line[NLINE]){ + *s = '\0'; + if(tag && strcmp(line, tag) == 0) + break; if(subst) psubst(f, (uchar *)line); else pstr(f, line); s = line; - if(c=='\n'){ + if(c == '\n'){ pprompt(); pchr(f, c); - } - else *s++=c; - } - else *s++=c; + }else + *s++ = c; + }else + *s++ = c; } flush(f); closeio(f); @@ -92,45 +97,41 @@ { int savec, n; uchar *t, *u; + Rune r; word *star; + while(*s){ - if(*s!='$'){ - if(0xa0 <= *s && *s <= 0xf5){ - pchr(f, *s++); - if(*s=='\0') - break; - } - else if(0xf6 <= *s && *s <= 0xf7){ + if(*s != '$'){ /* copy plain text rune */ + if(*s < Runeself) pchr(f, *s++); - if(*s=='\0') - break; - pchr(f, *s++); - if(*s=='\0') - break; + else{ + n = chartorune(&r, (char *)s); + while(n-- > 0) + pchr(f, *s++); } - pchr(f, *s++); - } - else{ - t=++s; - if(*t=='$') + }else{ /* $something -- perform substitution */ + t = ++s; + if(*t == '$') pchr(f, *t++); else{ - while(*t && idchr(*t)) t++; - savec=*t; - *t='\0'; + while(*t && idchr(*t)) + t++; + savec = *t; + *t = '\0'; n = 0; - for(u = s;*u && '0'<=*u && *u<='9';u++) n = n*10+*u-'0'; - if(n && *u=='\0'){ + for(u = s; *u && '0' <= *u && *u <= '9'; u++) + n = n*10 + *u - '0'; + if(n && *u == '\0'){ star = vlook("*")->val; - if(star && 1<=n && n<=count(star)){ - while(--n) star = star->next; + if(star && 1 <= n && n <= count(star)){ + while(--n) + star = star->next; pstr(f, star->word); } - } - else + }else pstrs(f, vlook((char *)s)->val); *t = savec; - if(savec=='^') + if(savec == '^') t++; } s = t; --- /sys/src/cmd/rc/io.c Tue May 12 19:36:33 2009 +++ /sys/src/cmd/rc/io.c Wed May 15 00:30:51 2013 @@ -79,6 +79,35 @@ return *b->bufp++; } +int +rutf(io *b, char *buf, Rune *r) +{ + int n, i, c; + + c = rchr(b); + if(c == EOF) + return EOF; + *buf = c; + if(c < Runesync){ + *r = c; + return 1; + } + for(i = 1; (c = rchr(b)) != EOF; ){ + buf[i++] = c; + buf[i] = 0; + if(fullrune(buf, i)){ + n = chartorune(r, buf); + b->bufp -= i - n; /* push back unconsumed bytes */ + assert(b->fd == -1 || b->bufp > b->buf); + return n; + } + } + /* at eof */ + b->bufp -= i - 1; /* consume 1 byte */ + *r = Runeerror; + return runetochar(buf, r); +} + void pquo(io *f, char *s) { --- /sys/src/cmd/rc/io.h Wed Jun 27 02:57:25 2007 +++ /sys/src/cmd/rc/io.h Wed May 15 00:30:51 2013 @@ -12,6 +12,7 @@ int emptybuf(io*); void pchr(io*, int); int rchr(io*); +int rutf(io*, char*, Rune*); void closeio(io*); void flush(io*); int fullbuf(io*, int); --- /sys/src/cmd/rc/lex.c Wed Apr 24 01:15:45 2013 +++ /sys/src/cmd/rc/lex.c Wed May 15 23:10:33 2013 @@ -154,7 +154,7 @@ { if(p==0) return 0; - if(p==&tok[NTOK-1]){ + if(p >= &tok[NTOK]){ *p = 0; yyerror("token buffer too short"); return 0; @@ -170,7 +170,7 @@ int i; p = addtok(p, c); /* 1-byte UTF runes are special */ - if(onebyte(c)) + if(c < Runeself) return p; m = 0xc0; --- /sys/src/cmd/rc/rc.h Wed Apr 24 01:15:45 2013 +++ /sys/src/cmd/rc/rc.h Wed May 15 23:10:33 2013 @@ -79,7 +79,7 @@ #define NTOK 8192 /* maximum bytes in a word (token) */ -char tok[NTOK]; +char tok[NTOK + UTFmax]; #define APPEND 1 #define WRITE 2 @@ -110,8 +110,6 @@ void *Malloc(ulong); void efree(void *); -#define NOFILE 128 /* should come from on unix */ - struct here{ tree *tag; char *name; @@ -128,12 +126,6 @@ * GLOBGLOB matches GLOB */ #define GLOB ((char)0x01) - -/* - * onebyte(c) - * Is c the first character of a one-byte utf sequence? - */ -#define onebyte(c) ((c&0x80)==0x00) char **argp; char **args;