Browse Source

Plan 9 from Bell Labs 2013-05-16

David du Colombier 11 years ago
parent
commit
3df5684d3b

+ 0 - 1
sys/src/9/bcm/dat.h

@@ -179,7 +179,6 @@ struct Mach
 	int	load;
 	int	intr;
 	uvlong	fastclock;		/* last sampled value */
-	uvlong	inidle;			/* time spent in idlehands() */
 	ulong	spuriousintr;
 	int	lastintr;
 	int	ilockdepth;

+ 0 - 2
sys/src/9/kw/dat.h

@@ -159,13 +159,11 @@ struct Mach
 	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 */
 

+ 0 - 1
sys/src/9/omap/dat.h

@@ -182,7 +182,6 @@ struct Mach
 	int	load;
 	int	intr;
 	uvlong	fastclock;		/* last sampled value */
-	uvlong	inidle;			/* time spent in idlehands() */
 	ulong	spuriousintr;
 	int	lastintr;
 	int	ilockdepth;

+ 0 - 1
sys/src/9/teg2/dat.h

@@ -198,7 +198,6 @@ struct Mach
 	int	load;
 	int	intr;
 	uvlong	fastclock;		/* last sampled value */
-	uvlong	inidle;			/* time spent in idlehands() */
 	ulong	spuriousintr;
 	int	lastintr;
 	int	ilockdepth;

+ 25 - 25
sys/src/cmd/rc/havefork.c

@@ -3,6 +3,7 @@
 #include "exec.h"
 #include "io.h"
 #include "fns.h"
+#include <String.h>
 
 int havefork = 1;
 
@@ -74,16 +75,19 @@ Xpipe(void)
 /*
  * 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 @@ Xbackq(void)
 		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 */

+ 50 - 49
sys/src/cmd/rc/here.c

@@ -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 pstrs(io*, word*);
 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 @@ tree*
 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 @@ heredoc(tree *tag)
 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 @@ psubst(io *f, uchar *s)
 {
 	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){
-				pchr(f, *s++);
-				if(*s=='\0')
-					break;
+		if(*s != '$'){		/* copy plain text rune */
+			if(*s < Runeself)
 				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;

+ 2 - 2
sys/src/cmd/rc/lex.c

@@ -154,7 +154,7 @@ addtok(char *p, int val)
 {
 	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 @@ addutf(char *p, int c)
 	int i;
 
 	p = addtok(p, c);	/* 1-byte UTF runes are special */
-	if(onebyte(c))
+	if(c < Runeself)
 		return p;
 
 	m = 0xc0;

+ 1 - 9
sys/src/cmd/rc/rc.h

@@ -79,7 +79,7 @@ int doprompt;
 
 #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 *emalloc(long);
 void *Malloc(ulong);
 void efree(void *);
 
-#define	NOFILE	128		/* should come from <sys/param.h> on unix */
-
 struct here{
 	tree	*tag;
 	char	*name;
@@ -129,12 +127,6 @@ int mypid;
  */
 #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;
 int nerror;		/* number of errors encountered during compilation */