about summary refs log tree commit diff
diff options
context:
space:
mode:
authorPeter Stephenson <pws@users.sourceforge.net>2003-05-22 09:48:25 +0000
committerPeter Stephenson <pws@users.sourceforge.net>2003-05-22 09:48:25 +0000
commit1be7d4744d25d29b46f4a0b87a02cd9600ee6b74 (patch)
tree3cf7efa94211fea95f8175ea4f804816e954b40f
parentc7a2d2225e41e38f54ace2809fd61d3867fdd43b (diff)
downloadzsh-1be7d4744d25d29b46f4a0b87a02cd9600ee6b74.tar.gz
zsh-1be7d4744d25d29b46f4a0b87a02cd9600ee6b74.tar.xz
zsh-1be7d4744d25d29b46f4a0b87a02cd9600ee6b74.zip
18559, 18562: make modules use proper option arguments
-rw-r--r--ChangeLog9
-rw-r--r--Doc/Zsh/mod_socket.yo8
-rw-r--r--Doc/Zsh/mod_tcp.yo14
-rw-r--r--Doc/Zsh/zle.yo5
-rw-r--r--README13
-rw-r--r--Src/Modules/files.c8
-rw-r--r--Src/Modules/socket.c24
-rw-r--r--Src/Modules/tcp.c42
-rw-r--r--Src/Zle/zle_keymap.c6
-rw-r--r--Src/Zle/zle_main.c2
-rw-r--r--Src/zsh.h7
11 files changed, 72 insertions, 66 deletions
diff --git a/ChangeLog b/ChangeLog
index 43b251742..88090ffab 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2003-05-22  Peter Stephenson  <pws@csr.com>
+
+	* 18559, 18562: README, Doc/Zsh/mod_socket.yo, Doc/Zsh/mod_tcp.yo,
+	Doc/Zsh/zle.yo, Src/zsh.h, Src/Modules/files.c,
+	Src/Modules/socket.c, Src/Modules/tcp.c Src/Zle/zle_keymap.c
+	Src/Zle/zle_main.c: zsocket -d, ztcp -d, bindkey -M and
+	mkdir -m now take arguments of their own instead of swallowing the
+	first normal argument.  Also updgrade comment in README for 18512.
+
 2003-05-21  Peter Stephenson  <pws@csr.com>
 
 	* 18565: Src/subst.c, Test/D04parameter.ztst: when ${(u)...}
diff --git a/Doc/Zsh/mod_socket.yo b/Doc/Zsh/mod_socket.yo
index 993e3f6fe..d0ffc23cf 100644
--- a/Doc/Zsh/mod_socket.yo
+++ b/Doc/Zsh/mod_socket.yo
@@ -7,7 +7,7 @@ startitem()
 findex(zsocket)
 cindex(sockets)
 cindex(sockets, Unix domain)
-item(tt(zsocket) [ tt(-adltv) ] [ var(args) ])(
+item(tt(zsocket) [ tt(-altv) ] [ tt(-d) var(fd) ] [ var(args) ])(
 tt(zsocket) is implemented as a builtin to allow full use of shell
 command line editing, file I/O, and job control mechanisms.
 
@@ -21,7 +21,7 @@ The shell parameter tt(REPLY) will be set to the file descriptor
 associated with that connection.  Currently, only stream connections
 are supported.
 
-If tt(-d) is specified, the first non-option argument
+If tt(-d) is specified, its argument
 will be taken as the target file descriptor for the
 connection.
 
@@ -38,7 +38,7 @@ tt(zsocket -l) will open a socket listening on var(filename).
 The shell parameter tt(REPLY) will be set to the file descriptor
 associated with that listener.
 
-If tt(-d) is specified, the first non-option argument
+If tt(-d) is specified, its argument
 will be taken as the target file descriptor for
 the connection.
 
@@ -51,7 +51,7 @@ The shell parameter tt(REPLY) will
 be set to the file descriptor associated with
 the inbound connection.
 
-If tt(-d) is specified, the first non-option argument
+If tt(-d) is specified, its argument
 will be taken as the target file descriptor for the
 connection.
 
diff --git a/Doc/Zsh/mod_tcp.yo b/Doc/Zsh/mod_tcp.yo
index b710a447a..bf17ec82a 100644
--- a/Doc/Zsh/mod_tcp.yo
+++ b/Doc/Zsh/mod_tcp.yo
@@ -7,7 +7,7 @@ startitem()
 findex(ztcp)
 cindex(TCP)
 cindex(sockets, TCP)
-item(tt(ztcp) [ tt(-acdflLtv) ] [ var(args) ])(
+item(tt(ztcp) [ tt(-acflLtv) ] [ tt(-d) var(fd) ] [ var(args) ])(
 tt(ztcp) is implemented as a builtin to allow full use of shell
 command line editing, file I/O, and job control mechanisms.
 
@@ -75,9 +75,8 @@ be added to the session table and the shell parameter
 tt(REPLY) will be set to the file descriptor associated
 with that connection.
 
-If tt(-d) is specified, the first non-option argument
-will be taken as the target file descriptor for the
-connection.
+If tt(-d) is specified, its argument will be taken as the target file
+descriptor for the connection.
 
 In order to elicit more verbose output, use tt(-v).
 )
@@ -94,9 +93,8 @@ session table and the shell parameter tt(REPLY)
 will be set to the file descriptor associated
 with that listener.
 
-If tt(-d) is specified, the first non-option argument
-will be taken as the target file descriptor for
-the connection.
+If tt(-d) is specified, its argument will be taken as the target file
+descriptor for the connection.
 
 In order to elicit more verbose output, use tt(-v).
 )
@@ -108,7 +106,7 @@ table and the shell parameter tt(REPLY) will
 be set to the file descriptor associated with
 the inbound connection.
 
-If tt(-d) is specified, the first non-option argument
+If tt(-d) is specified, its argument
 will be taken as the target file descriptor for the
 connection.
 
diff --git a/Doc/Zsh/zle.yo b/Doc/Zsh/zle.yo
index 705de2a03..085424ff0 100644
--- a/Doc/Zsh/zle.yo
+++ b/Doc/Zsh/zle.yo
@@ -134,9 +134,8 @@ Selects keymap `tt(viins)', and also links it to `tt(main)'.
 item(tt(-a))(
 Selects keymap `tt(vicmd)'.
 )
-item(tt(-M))(
-The first non-option argument is used as a keymap name,
-and does not otherwise count as an argument.
+item(tt(-M) var(keymap))(
+The var(keymap) specifies a keymap name.
 )
 enditem()
 
diff --git a/README b/README
index 53e50c4f3..9b8877a63 100644
--- a/README
+++ b/README
@@ -47,6 +47,19 @@ or not the expression occurs in double quotes.  For example:
   % foo=word/bird
   % print ${foo/\//-} "${foo/\//+}"
   word-bird word+bird
+Note also the following workaround which is valid in all versions of the
+shell that support this syntax:
+  % slash=/
+  % foo=word/bird
+  % print ${foo/$slash/-} "${foo/$slash/+}"
+
+In 4.0, the -M option to bindkey used the first non-option argument to
+specify the keymap, whereas it now uses an argument to the option.  Hence:
+  bindkey -M -R keymap a-z self-insert
+needs to be rewritten as
+  bindkey -M keymap -R a-z self-insert
+The following form works in both versions:
+  bindkey -R -M keymap a-z self-insert
 
 Documentation
 -------------
diff --git a/Src/Modules/files.c b/Src/Modules/files.c
index 51f362631..82429a986 100644
--- a/Src/Modules/files.c
+++ b/Src/Modules/files.c
@@ -74,12 +74,8 @@ bin_mkdir(char *nam, char **args, Options ops, int func)
 
     umask(oumask);
     if(OPT_ISSET(ops,'m')) {
-	char *str = *args++, *ptr;
+	char *str = OPT_ARG(ops,'m'), *ptr;
 
-	if(!*args) {
-	    zwarnnam(nam, "not enough arguments", NULL, 0);
-	    return 1;
-	}
 	mode = zstrtol(str, &ptr, 8);
 	if(!*str || *ptr) {
 	    zwarnnam(nam, "invalid mode `%s'", str, 0);
@@ -703,7 +699,7 @@ static struct builtin bintab[] = {
     BUILTIN("chgrp", 0, bin_chown, 2, -1, BIN_CHGRP, "Rs",    NULL),
     BUILTIN("chown", 0, bin_chown, 2, -1, BIN_CHOWN, "Rs",    NULL),
     BUILTIN("ln",    0, bin_ln,    1, -1, BIN_LN,    LN_OPTS, NULL),
-    BUILTIN("mkdir", 0, bin_mkdir, 1, -1, 0,         "pm",    NULL),
+    BUILTIN("mkdir", 0, bin_mkdir, 1, -1, 0,         "pm:",   NULL),
     BUILTIN("mv",    0, bin_ln,    2, -1, BIN_MV,    "fi",    NULL),
     BUILTIN("rm",    0, bin_rm,    1, -1, 0,         "dfirs", NULL),
     BUILTIN("rmdir", 0, bin_rmdir, 1, -1, 0,         NULL,    NULL),
diff --git a/Src/Modules/socket.c b/Src/Modules/socket.c
index 2b70eba6d..cca980845 100644
--- a/Src/Modules/socket.c
+++ b/Src/Modules/socket.c
@@ -62,7 +62,6 @@ bin_zsocket(char *nam, char **args, Options ops, int func)
 {
     int err=1, verbose=0, test=0, targetfd=0;
     SOCKLEN_T len;
-    char **dargs;
     struct sockaddr_un soun;
     int sfd;
 
@@ -73,26 +72,23 @@ bin_zsocket(char *nam, char **args, Options ops, int func)
 	test = 1;
 
     if (OPT_ISSET(ops,'d')) {
-	targetfd = atoi(args[0]);
-	dargs = args + 1;
+	targetfd = atoi(OPT_ARG(ops,'d'));
 	if (!targetfd) {
-	    zwarnnam(nam, "%s is an invalid argument to -d", args[0], 0);
+	    zwarnnam(nam, "%s is an invalid argument to -d",
+		     OPT_ARG(ops, 'd'), 0);
 	    return 1;
 	}
     }
-    else
-	dargs = args;
-
 
     if (OPT_ISSET(ops,'l')) {
 	char *localfn;
 
-	if (!dargs[0]) {
+	if (!args[0]) {
 	    zwarnnam(nam, "-l requires an argument", NULL, 0);
 	    return 1;
 	}
 
-	localfn = dargs[0];
+	localfn = args[0];
 
 	sfd = socket(PF_UNIX, SOCK_STREAM, 0);
 
@@ -139,12 +135,12 @@ bin_zsocket(char *nam, char **args, Options ops, int func)
     {
 	int lfd, rfd;
 
-	if (!dargs[0]) {
+	if (!args[0]) {
 	    zwarnnam(nam, "-a requires an argument", NULL, 0);
 	    return 1;
 	}
 
-	lfd = atoi(dargs[0]);
+	lfd = atoi(args[0]);
 
 	if (!lfd) {
 	    zwarnnam(nam, "invalid numerical argument", NULL, 0);
@@ -212,7 +208,7 @@ bin_zsocket(char *nam, char **args, Options ops, int func)
     }
     else
     {
-	if (!dargs[0]) {
+	if (!args[0]) {
 	    zwarnnam(nam, "zsocket requires an argument", NULL, 0);
 	    return 1;
 	}
@@ -225,7 +221,7 @@ bin_zsocket(char *nam, char **args, Options ops, int func)
 	}
 
 	soun.sun_family = AF_UNIX;
-	strncpy(soun.sun_path, dargs[0], UNIX_PATH_MAX);
+	strncpy(soun.sun_path, args[0], UNIX_PATH_MAX);
 	
 	if ((err = connect(sfd, (struct sockaddr *)&soun, sizeof(struct sockaddr_un)))) {
 	    zwarnnam(nam, "connection failed: %e", NULL, errno);
@@ -251,7 +247,7 @@ bin_zsocket(char *nam, char **args, Options ops, int func)
 }
 
 static struct builtin bintab[] = {
-    BUILTIN("zsocket", 0, bin_zsocket, 0, 3, 0, "adltv", NULL),
+    BUILTIN("zsocket", 0, bin_zsocket, 0, 3, 0, "ad:ltv", NULL),
 };
 
 /* The load/unload routines required by the zsh library interface */
diff --git a/Src/Modules/tcp.c b/Src/Modules/tcp.c
index cc591f6eb..2f3d0424d 100644
--- a/Src/Modules/tcp.c
+++ b/Src/Modules/tcp.c
@@ -341,7 +341,7 @@ bin_ztcp(char *nam, char **args, Options ops, int func)
 {
     int herrno, err=1, destport, force=0, verbose=0, test=0, targetfd=0;
     SOCKLEN_T  len;
-    char **addrp, *desthost, *localname, *remotename, **dargs;
+    char **addrp, *desthost, *localname, *remotename;
     struct hostent *zthost = NULL, *ztpeer = NULL;
     struct servent *srv;
     Tcp_session sess = NULL;
@@ -356,26 +356,24 @@ bin_ztcp(char *nam, char **args, Options ops, int func)
         test = 1;
 
     if (OPT_ISSET(ops,'d')) {
-	targetfd = atoi(args[0]);
-	dargs = args + 1;
+	targetfd = atoi(OPT_ARG(ops,'d'));
 	if (!targetfd) {
-	    zwarnnam(nam, "%s is an invalid argument to -d", args[0], 0);
+	    zwarnnam(nam, "%s is an invalid argument to -d",
+		     OPT_ARG(ops,'d'), 0);
 	    return 1;
 	}
     }
-    else
-	dargs = args;
 
 
     if (OPT_ISSET(ops,'c')) {
-	if (!dargs[0]) {
+	if (!args[0]) {
 	    tcp_cleanup();
 	}
 	else {
-	    targetfd = atoi(dargs[0]);
+	    targetfd = atoi(args[0]);
 	    sess = zts_byfd(targetfd);
 	    if(!targetfd) {
-		zwarnnam(nam, "%s is an invalid argument to -c", dargs[0], 0);
+		zwarnnam(nam, "%s is an invalid argument to -c", args[0], 0);
 		return 1;
 	    }
 
@@ -391,7 +389,7 @@ bin_ztcp(char *nam, char **args, Options ops, int func)
 	    }
 	    else
 	    {
-		zwarnnam(nam, "fd %s not found in tcp table", dargs[0], 0);
+		zwarnnam(nam, "fd %s not found in tcp table", args[0], 0);
 		return 1;
 	    }
 	}
@@ -399,16 +397,16 @@ bin_ztcp(char *nam, char **args, Options ops, int func)
     else if (OPT_ISSET(ops,'l')) {
 	int lport = 0;
 
-	if (!dargs[0]) {
+	if (!args[0]) {
 	    zwarnnam(nam, "-l requires an argument", NULL, 0);
 	    return 1;
 	}
 
-	srv = getservbyname(dargs[0], "tcp");
+	srv = getservbyname(args[0], "tcp");
 	if (srv)
 	    lport = srv->s_port;
 	else
-	    lport = htons(atoi(dargs[0]));
+	    lport = htons(atoi(args[0]));
 	if (!lport) { zwarnnam(nam, "bad service name or port number", NULL, 0);
 	return 1;
 	}
@@ -469,12 +467,12 @@ bin_ztcp(char *nam, char **args, Options ops, int func)
     {
 	int lfd, rfd;
 
-	if (!dargs[0]) {
+	if (!args[0]) {
 	    zwarnnam(nam, "-a requires an argument", NULL, 0);
 	    return 1;
 	}
 
-	lfd = atoi(dargs[0]);
+	lfd = atoi(args[0]);
 
 	if (!lfd) {
 	    zwarnnam(nam, "invalid numerical argument", NULL, 0);
@@ -483,7 +481,7 @@ bin_ztcp(char *nam, char **args, Options ops, int func)
 
 	sess = zts_byfd(lfd);
 	if (!sess) {
-	    zwarnnam(nam, "fd %s is not registered as a tcp connection", dargs[0], 0);
+	    zwarnnam(nam, "fd %s is not registered as a tcp connection", args[0], 0);
 	    return 1;
 	}
 
@@ -556,7 +554,7 @@ bin_ztcp(char *nam, char **args, Options ops, int func)
     }
     else
     {
-	if (!dargs[0]) {
+	if (!args[0]) {
 	    LinkNode node;
 	    for(node = firstnode(ztcp_sessions); node; incnode(node))
 	    {
@@ -601,19 +599,19 @@ bin_ztcp(char *nam, char **args, Options ops, int func)
 	    }
 	    return 0;
 	}
-	else if (!dargs[1]) {
+	else if (!args[1]) {
 	    destport = htons(23);
 	}
 	else {
 
-	    srv = getservbyname(dargs[1],"tcp");
+	    srv = getservbyname(args[1],"tcp");
 	    if (srv)
 		destport = srv->s_port;
 	    else
-		destport = htons(atoi(dargs[1]));
+		destport = htons(atoi(args[1]));
 	}
 	
-	desthost = ztrdup(dargs[0]);
+	desthost = ztrdup(args[0]);
 	
 	zthost = zsh_getipnodebyname(desthost, AF_INET, 0, &herrno);
 	if (!zthost || errflag) {
@@ -675,7 +673,7 @@ bin_ztcp(char *nam, char **args, Options ops, int func)
 }
 
 static struct builtin bintab[] = {
-    BUILTIN("ztcp", 0, bin_ztcp, 0, 3, 0, "acdflLtv", NULL),
+    BUILTIN("ztcp", 0, bin_ztcp, 0, 3, 0, "acd:flLtv", NULL),
 };
 
 /* The load/unload routines required by the zsh library interface */
diff --git a/Src/Zle/zle_keymap.c b/Src/Zle/zle_keymap.c
index 3a06bb632..58e5e2175 100644
--- a/Src/Zle/zle_keymap.c
+++ b/Src/Zle/zle_keymap.c
@@ -656,11 +656,7 @@ bin_bindkey(char *name, char **argv, Options ops, int func)
 	else if(OPT_ISSET(ops,'a'))
 	    kmname = "vicmd";
 	else if(OPT_ISSET(ops,'M')) {
-	    kmname = *argv++;
-	    if(!kmname) {
-		zwarnnam(name, "-M option requires a keymap argument", NULL, 0);
-		return 1;
-	    }
+	    kmname = OPT_ARG(ops,'M');
 	} else
 	    kmname = "main";
 	km = openkeymap(kmname);
diff --git a/Src/Zle/zle_main.c b/Src/Zle/zle_main.c
index 8daf60085..047aa3d12 100644
--- a/Src/Zle/zle_main.c
+++ b/Src/Zle/zle_main.c
@@ -1336,7 +1336,7 @@ zleaftertrap(Hookdef dummy, void *dat)
 }
 
 static struct builtin bintab[] = {
-    BUILTIN("bindkey", 0, bin_bindkey, 0, -1, 0, "evaMldDANmrsLRp", NULL),
+    BUILTIN("bindkey", 0, bin_bindkey, 0, -1, 0, "evaM:ldDANmrsLRp", NULL),
     BUILTIN("vared",   0, bin_vared,   1,  7, 0, NULL,             NULL),
     BUILTIN("zle",     0, bin_zle,     0, -1, 0, "aAcCDFgGIKlLmMNRU", NULL),
 };
diff --git a/Src/zsh.h b/Src/zsh.h
index 1733ce9bc..16558c3d3 100644
--- a/Src/zsh.h
+++ b/Src/zsh.h
@@ -955,10 +955,11 @@ struct funcwrap {
 /* Option was set as +X */
 #define OPT_PLUS(ops,c)		((ops)->ind[c] & 2)
 /*
- * Option was set any old how, maybe including an argument 
- * (cheap test when we don't care).
+ * Option was set any old how, maybe including an argument
+ * (cheap test when we don't care).  Some bits of code
+ * expect this to be 1 or 0.
  */
-#define OPT_ISSET(ops,c)	((ops)->ind[c])
+#define OPT_ISSET(ops,c)	((ops)->ind[c] != 0)
 /* Option has an argument */
 #define OPT_HASARG(ops,c)	((ops)->ind[c] > 3)
 /* The argument for the option; not safe if it doesn't have one */