Browse Source

Plan 9 from Bell Labs 2004-02-09

David du Colombier 21 years ago
parent
commit
4828036a4b

+ 4 - 4
dist/replica/plan9.db

@@ -3390,7 +3390,7 @@ sys/include/authsrv.h - 664 sys sys 1014929062 4542
 sys/include/bin.h - 664 sys sys 1014929062 215
 sys/include/bio.h - 664 sys sys 1014929062 1854
 sys/include/bootexec.h - 664 sys sys 1014929062 3144
-sys/include/complete.h - 664 sys sys 1072904891 517
+sys/include/complete.h - 664 sys sys 1076276516 562
 sys/include/control.h - 664 sys sys 1045419238 4801
 sys/include/ctype.h - 664 sys sys 1014929062 951
 sys/include/cursor.h - 664 sys sys 1014929062 102
@@ -4766,7 +4766,7 @@ sys/man/2/cachechars - 664 sys sys 944959696 7061
 sys/man/2/chdir - 664 sys sys 944959694 552
 sys/man/2/cleanname - 664 sys sys 950593488 709
 sys/man/2/color - 664 sys sys 944959697 1335
-sys/man/2/complete - 664 sys sys 1072905221 2175
+sys/man/2/complete - 664 sys sys 1076276513 2396
 sys/man/2/control - 664 sys sys 1037465511 42782
 sys/man/2/cputime - 664 sys sys 1015091518 713
 sys/man/2/ctime - 664 sys sys 954378853 2547
@@ -10209,7 +10209,7 @@ sys/src/cmd/rio/scrl.c - 664 sys sys 1014926357 3245
 sys/src/cmd/rio/time.c - 664 sys sys 1014926357 1829
 sys/src/cmd/rio/util.c - 664 sys sys 1014926357 2061
 sys/src/cmd/rio/wctl.c - 664 sys sys 1023206837 8808
-sys/src/cmd/rio/wind.c - 664 sys sys 1073268477 32704
+sys/src/cmd/rio/wind.c - 664 sys sys 1076276532 32785
 sys/src/cmd/rio/xfid.c - 664 sys sys 1032061723 17424
 sys/src/cmd/rm.c - 664 sys sys 1014926615 1563
 sys/src/cmd/rx.c - 664 sys sys 1071155928 4188
@@ -11748,7 +11748,7 @@ sys/src/libc/sparc/tas.s - 664 sys sys 944961721 67
 sys/src/libc/sparc/vlop.s - 664 sys sys 944961720 2423
 sys/src/libc/sparc/vlrt.c - 664 sys sys 1067723054 9066
 sys/src/libcomplete - 20000000775 sys sys 1072904881 0
-sys/src/libcomplete/complete.c - 664 sys sys 1072904881 2673
+sys/src/libcomplete/complete.c - 664 sys sys 1076276513 2697
 sys/src/libcomplete/mkfile - 664 sys sys 1072904881 208
 sys/src/libcontrol - 20000000775 sys sys 1016857569 0
 sys/src/libcontrol/box.c - 664 sys sys 1015095043 3276

+ 4 - 0
dist/replica/plan9.log

@@ -13798,3 +13798,7 @@
 1075689090 0 c sys/games/lib/fortunes - 664 sys sys 1075688069 247488
 1076130039 0 c sys/src/cmd/vac/fs.c - 664 sys sys 1076129457 2934
 1076176846 0 c sys/src/cmd/upas/pop3/pop3.c - 664 sys sys 1076176207 14301
+1076277660 0 c sys/include/complete.h - 664 sys sys 1076276516 562
+1076277660 1 c sys/man/2/complete - 664 sys sys 1076276513 2396
+1076277660 2 c sys/src/cmd/rio/wind.c - 664 sys sys 1076276532 32785
+1076277660 3 c sys/src/libcomplete/complete.c - 664 sys sys 1076276513 2697

+ 2 - 1
sys/include/complete.h

@@ -7,7 +7,8 @@ struct Completion{
 	uchar advance;		/* whether forward progress has been made */
 	uchar complete;	/* whether the completion now represents a file or directory */
 	char *string;		/* the string to advance, suffixed " " or "/" for file or directory */
-	int nfile;			/* number of files that matched */
+	int nmatch;		/* number of files that matched */
+	int nfile;			/* number of files returned */
 	char **filename;	/* their names */
 };
 

+ 13 - 2
sys/man/2/complete

@@ -16,7 +16,8 @@ struct Completion{
 	uchar advance;		/* whether forward progress has been made */
 	uchar complete;	/* whether the completion now represents a file or directory */
 	char *string;		/* the string to advance, suffixed " " or "/" for file or directory */
-	int nfile;			/* number of files that matched */
+	int nmatch;		/* number of files that matched */
+	int nfile;			/* number of files returned */
 	char **filename;	/* their names */
 };
 
@@ -41,13 +42,23 @@ and a string
 .IR s ,
 it returns an analysis of the file names in that directory that begin with the string
 .IR s .
-The field
+The fields
+.B nmatch
+and
 .B nfile
 will be set to the number of files that match the prefix and
 .B filename
 will be filled in with their names.
 If the file named is a directory, a slash character will be appended to it.
 .PP
+If no files match the string,
+.B nmatch
+will be zero, but
+.I complete
+will return the full set of files in the directory, with
+.I nfile
+set to their number.
+.PP
 The flag
 .B advance
 reports whether the string

+ 7 - 2
sys/src/cmd/rio/wind.c

@@ -467,12 +467,17 @@ showcandidates(Window *w, Completion *c)
 	Fmt f;
 	Rune *rp;
 	uint nr, qline, q0;
+	char *s;
 
 	runefmtstrinit(&f);
+	if (c->nmatch == 0)
+		s = "[no matches in ";
+	else
+		s = "[";
 	if(c->nfile > 32)
-		fmtprint(&f, "[%d files]\n", c->nfile);
+		fmtprint(&f, "%s%d files]\n", s, c->nfile);
 	else{
-		fmtprint(&f, "[");
+		fmtprint(&f, "%s", s);
 		for(i=0; i<c->nfile; i++){
 			if(i > 0)
 				fmtprint(&f, " ");

+ 16 - 14
sys/src/libcomplete/complete.c

@@ -41,7 +41,7 @@ strpcmp(const void *va, const void *vb)
 Completion*
 complete(char *dir, char *s)
 {
-	long i, l, n, nmatch, len, nbytes;
+	long i, l, n, nfile, len, nbytes;
 	int fd, minlen;
 	Dir *dirp;
 	char **name, *p;
@@ -78,49 +78,51 @@ complete(char *dir, char *s)
 
 	/* find the matches */
 	len = strlen(s);
-	nmatch = 0;
+	nfile = 0;
 	minlen = 1000000;
 	for(i=0; i<n; i++)
 		if(strncmp(s, dirp[i].name, len) == 0){
-			name[nmatch] = dirp[i].name;
-			mode[nmatch] = dirp[i].mode;
+			name[nfile] = dirp[i].name;
+			mode[nfile] = dirp[i].mode;
 			if(minlen > strlen(dirp[i].name))
 				minlen = strlen(dirp[i].name);
-			nmatch++;
+			nfile++;
 		}
 
-	if(nmatch > 0) {
+	if(nfile > 0) {
 		/* report interesting results */
 		/* trim length back to longest common initial string */
-		for(i=1; i<nmatch; i++)
+		for(i=1; i<nfile; i++)
 			minlen = longestprefixlength(name[0], name[i], minlen);
 
 		/* build the answer */
-		c->complete = (nmatch == 1);
+		c->complete = (nfile == 1);
 		c->advance = c->complete || (minlen > len);
 		c->string = (char*)(c+1);
 		memmove(c->string, name[0]+len, minlen-len);
 		if(c->complete)
 			c->string[minlen++ - len] = (mode[0]&DMDIR)? '/' : ' ';
 		c->string[minlen - len] = '\0';
+		c->nmatch = nfile;
 	} else {
 		/* no match, so return all possible strings */
 		for(i=0; i<n; i++){
 			name[i] = dirp[i].name;
 			mode[i] = dirp[i].mode;
 		}
-		nmatch = n;
+		nfile = n;
+		c->nmatch = 0;
 	}
 
 	/* attach list of names */
-	nbytes = nmatch * sizeof(char*);
-	for(i=0; i<nmatch; i++)
+	nbytes = nfile * sizeof(char*);
+	for(i=0; i<nfile; i++)
 		nbytes += strlen(name[i]) + 1 + 1;
 	c->filename = malloc(nbytes);
 	if(c->filename == nil)
 		goto Return;
-	p = (char*)(c->filename + nmatch);
-	for(i=0; i<nmatch; i++){
+	p = (char*)(c->filename + nfile);
+	for(i=0; i<nfile; i++){
 		c->filename[i] = p;
 		strcpy(p, name[i]);
 		p += strlen(p);
@@ -128,7 +130,7 @@ complete(char *dir, char *s)
 			*p++ = '/';
 		*p++ = '\0';
 	}
-	c->nfile = nmatch;
+	c->nfile = nfile;
 	qsort(c->filename, c->nfile, sizeof(c->filename[0]), strpcmp);
 
   Return: