Browse Source

Plan 9 from Bell Labs 2009-05-13

David du Colombier 15 years ago
parent
commit
2e78a9bf86
2 changed files with 17 additions and 6 deletions
  1. 8 0
      sys/src/cmd/rc/havefork.c
  2. 9 6
      sys/src/cmd/rc/io.c

+ 8 - 0
sys/src/cmd/rc/havefork.c

@@ -110,6 +110,14 @@ Xbackq(void)
 		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){

+ 9 - 6
sys/src/cmd/rc/io.c

@@ -12,15 +12,17 @@ pfmt(io *f, char *fmt, ...)
 {
 	va_list ap;
 	char err[ERRMAX];
+
 	va_start(ap, fmt);
 	pfmtnest++;
-	for(;*fmt;fmt++)
-		if(*fmt!='%')
+	for(;*fmt;fmt++) {
+		if(*fmt!='%') {
 			pchr(f, *fmt);
-		else switch(*++fmt){
-		case '\0':
-			va_end(ap);
-			return;
+			continue;
+		}
+		if(*++fmt == '\0')		/* "blah%"? */
+			break;
+		switch(*fmt){
 		case 'c':
 			pchr(f, va_arg(ap, int));
 			break;
@@ -55,6 +57,7 @@ pfmt(io *f, char *fmt, ...)
 			pchr(f, *fmt);
 			break;
 		}
+	}
 	va_end(ap);
 	if(--pfmtnest==0)
 		flush(f);