Browse Source

Plan 9 from Bell Labs 2010-02-10

David du Colombier 14 years ago
parent
commit
82d16e1183
7 changed files with 94 additions and 43 deletions
  1. 1 0
      sys/include/avl.h
  2. 2 2
      sys/lib/plumb/basic
  3. 13 6
      sys/man/1/hget
  4. 27 0
      sys/man/2/avl
  5. 7 6
      sys/src/ape/cmd/uname.c
  6. 9 6
      sys/src/cmd/hget.c
  7. 35 23
      sys/src/libavl/avl.c

+ 1 - 0
sys/include/avl.h

@@ -23,3 +23,4 @@ void	endwalk(Avlwalk *walk);
 void	insertavl(Avltree *tree, Avl *new, Avl **oldp);
 Avl	*lookupavl(Avltree *tree, Avl *key);
 Avltree	*mkavltree(int(*cmp)(Avl*, Avl*));
+Avl*	searchavl(Avltree *tree, Avl *key, int neighbor);

+ 2 - 2
sys/lib/plumb/basic

@@ -73,10 +73,10 @@ attr add	addr=$3
 plumb to edit
 plumb client window $editor
 
-# .m files are looked up in /sys/module and passed to edit
+# .m files are looked up in /usr/inferno/module and passed to edit
 type is text
 data matches '([a-zA-Z¡-￿0-9]+\.m)('$addr')?'
-arg isfile	/sys/module/$1
+arg isfile	/usr/inferno/module/$1
 data set	$file
 attr add	addr=$3
 plumb to edit

+ 13 - 6
sys/man/1/hget

@@ -1,20 +1,22 @@
-.TH HGET 1 
+.TH HGET 1
 .SH NAME
-hget  \- retrieve a web page corresponding to a url
+hget \- retrieve a web page corresponding to a url
 .SH SYNOPSIS
-.PP
 .B hget
 [
 .B -dhv
-][
+] [
 .B -o
 .I ofile
-][
+] [
 .B -p
 .I body
-][
+] [
 .B -x
 .I netmntpt
+] [
+.B -r
+.I header
 ]
 .I url
 .SH DESCRIPTION
@@ -50,6 +52,11 @@ causes HTTP headers to be printed to standard output
 in addition to the transferred web page.
 .PP
 Option
+.B -r
+sends an arbitrary HTTP
+.IR header .
+.PP
+Option
 .B -d
 turns on debugging written to standard error.
 .PP

+ 27 - 0
sys/man/2/avl

@@ -24,6 +24,7 @@ void	deleteavl(Avltree *tree, Avl *key, Avl **oldp);
 void	endwalk(Avlwalk *walk);
 void	insertavl(Avltree *tree, Avl *new, Avl **oldp);
 Avl	*lookupavl(Avltree *tree, Avl *key);
+Avl	*searchavl(Avltree *tree, Avl *key, int neighbor);
 Avltree	*mkavltree(int(*cmp)(Avl*, Avl*));
 .EE
 .SH DESCRIPTION
@@ -60,6 +61,32 @@ comparison function,
 or
 .B nil
 if none.
+.PP
+.I Searchavl
+returns the
+.I tree
+node that matches
+.I key
+by
+.IR tree 's
+comparison function, if it exists.
+If it does not, and
+.I neighbor
+is positive, it returns the nearest node whose
+.I key
+is greater or
+.B nil
+if there is none and, if
+.I neighbor
+is negative, it returns the nearest node whose
+.I key
+is less or
+.B nil
+if there is none.
+It is an error to set
+.I neighbor
+to values other than \-1, 0, or +1.
+.PP
 .I Deleteavl
 removes the node matching
 .I key

+ 7 - 6
sys/src/ape/cmd/uname.c

@@ -28,24 +28,25 @@ main(int argc, char **argv)
 	}
 	ARGBEGIN {
 	case 'a':
-		printf("%s %s %s %s %s\n", u.sysname, u.nodename,
+		printf("%s %s %s %s %s ", u.sysname, u.nodename,
 			u.release, u.version, u.machine);
 		break;
 	case 'm':
-		printf("%s\n", u.machine);
+		printf("%s ", u.machine);
 		break;
 	case 'n':
-		printf("%s\n", u.nodename);
+		printf("%s ", u.nodename);
 		break;
 	case 'r':
-		printf("%s\n", u.release);
+		printf("%s ", u.release);
 		break;
 	case 's':
-		printf("%s\n", u.sysname);
+		printf("%s ", u.sysname);
 		break;
 	case 'v':
-		printf("%s\n", u.version);
+		printf("%s ", u.version);
 		break;
 	} ARGEND
+	printf("\n");
 	exit(0);
 }

+ 9 - 6
sys/src/cmd/hget.c

@@ -17,6 +17,7 @@ struct URL
 	char	*redirect;
 	char	*postbody;
 	char	*cred;
+	char *rhead;
 	long	mtime;
 };
 
@@ -92,7 +93,7 @@ struct {
 void
 usage(void)
 {
-	fprint(2, "usage: %s [-dhv] [-o outfile] [-p body] [-x netmtpt] url\n", argv0);
+	fprint(2, "usage: %s [-dhv] [-o outfile] [-p body] [-x netmtpt] [-r header] url\n", argv0);
 	exits("usage");
 }
 
@@ -134,6 +135,9 @@ main(int argc, char **argv)
 	case 'x':
 		net = EARGF(usage());
 		break;
+	case 'r':
+		u.rhead = EARGF(usage());
+		break;
 	case 'p':
 		t = EARGF(usage());
 		if(p != postbody)
@@ -379,9 +383,6 @@ dohttp(URL *u, URL *px, Range *r, Out *out, long mtime)
 						"Pragma: no-cache\r\n",
 						u->host, u->page, u->host);
 			}
-			if(u->cred)
-				dfprint(fd,	"Authorization: Basic %s\r\n",
-						u->cred);
 		} else {
 			dfprint(fd,	"POST %s HTTP/1.0\r\n"
 					"Host: %s\r\n"
@@ -389,9 +390,11 @@ dohttp(URL *u, URL *px, Range *r, Out *out, long mtime)
 					"Content-length: %d\r\n"
 					"User-agent: Plan9/hget\r\n",
 					u->page, u->host, strlen(u->postbody));
-			if(u->cred)
-				dfprint(fd, "Authorization: Basic %s\r\n", u->cred);
 		}
+		if(u->cred)
+			dfprint(fd, "Authorization: Basic %s\r\n", u->cred);
+		if(u->rhead)
+			dfprint(fd, "%s\r\n", u->rhead);
 		if(r->start != 0){
 			dfprint(fd, "Range: bytes=%d-\n", r->start);
 			if(u->etag != nil){

+ 35 - 23
sys/src/libavl/avl.c

@@ -129,23 +129,6 @@ _insertavl(Avl **tp, Avl *p, Avl *r, int (*cmp)(Avl*,Avl*), Avl **rfree)
 	return 0;
 }
 
-static Avl*
-_lookupavl(Avl *t, Avl *r, int (*cmp)(Avl*,Avl*))
-{
-	int i;
-	Avl *p;
-
-	p = nil;
-	while(t != nil){
-		assert(t->p == p);
-		if((i = cmp(r, t)) == 0)
-			return t;
-		p = t;
-		t = t->n[(i+1)/2];
-	}
-	return nil;
-}
-
 static int
 successor(Avl **tp, Avl *p, Avl **r)
 {
@@ -257,12 +240,6 @@ insertavl(Avltree *t, Avl *new, Avl **oldp)
 	_insertavl(&t->root, nil, new, t->cmp, oldp);
 }
 
-Avl*
-lookupavl(Avltree *t, Avl *key)
-{
-	return _lookupavl(t->root, key, t->cmp);
-}
-
 static Avl*
 findpredecessor(Avl *a)
 {
@@ -301,6 +278,41 @@ findsuccessor(Avl *a)
 	}
 }
 
+static Avl*
+_lookupavl(Avl *t, Avl *r, int (*cmp)(Avl*,Avl*), int neighbor)
+{
+	int i;
+	Avl *p;
+
+	p = nil;
+	if(t == nil)
+		return nil;
+	do{
+		assert(t->p == p);
+		if((i = cmp(r, t)) == 0)
+			return t;
+		p = t;
+		t = t->n[(i+1)/2];
+	}while(t);
+	if(neighbor == 0)
+		return nil;
+	if(neighbor < 0)
+		return i > 0 ? p : findpredecessor(p);
+	return i < 0 ? p : findsuccessor(p);
+}
+
+Avl*
+searchavl(Avltree *t, Avl *key, int neighbor)
+{
+	return _lookupavl(t->root, key, t->cmp, neighbor);
+}
+
+Avl*
+lookupavl(Avltree *t, Avl *key)
+{
+	return _lookupavl(t->root, key, t->cmp, 0);
+}
+
 static void
 walkdel(Avl *a, void *v)
 {