From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 8769 invoked from network); 30 Jul 2000 09:35:11 -0000 Received: from sunsite.auc.dk (130.225.51.30) by ns1.primenet.com.au with SMTP; 30 Jul 2000 09:35:11 -0000 Received: (qmail 11215 invoked by alias); 30 Jul 2000 09:33:46 -0000 Mailing-List: contact zsh-workers-help@sunsite.auc.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 12432 Received: (qmail 12137 invoked from network); 29 Jul 2000 23:49:29 -0000 From: "Bart Schaefer" Message-Id: <1000729234923.ZM18609@candle.brasslantern.com> Date: Sat, 29 Jul 2000 23:49:23 +0000 In-Reply-To: Comments: In reply to Juhapekka Tolvanen "Re: Bug or feature?" (Jul 28, 8:45pm) References: X-Mailer: Z-Mail (5.0.0 30July97) To: Zsh hackers list Subject: PATCH (?): GNU-style long options for zsh MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii On Jul 28, 8:45pm, Juhapekka Tolvanen wrote: } } Is it too much work to teach zsh to understand long-options? Actually, it wasn't hard at all, for the shell itself (I'm not going to touch the builtin command option parser). It was fairly simple to make `--blahblahblah' mean the same as `-o blahblahblah', and then I just special-cased `--version'. (Normally I wouldn't use a goto, but given there was another already ...) This patch is not committed, pending a more thorough commentary from the rest of zsh-workers. The whole parseargs() loop could probably be written better than it is. Some things of note that result from code that I did NOT change: Zsh accepts `-opts-junk' where "opts" are any valid option letters and "junk" gets ignored. Thus `--sh-option-letters' and `-sh-option-letters' mean significantly different things .... Zsh accepts `+-' and `+b' as end of options; this is necessary for `+b' but not for `+-' (and could be changed by moving the `action' test in the patch up one `if' level). Also, therefore, `+opts-junk' turns off "opts" and ingores "junk". Index: Src/init.c =================================================================== @@ -34,6 +34,8 @@ #include "init.pro" +#include "version.h" + /**/ int noexitct = 0; @@ -207,13 +209,15 @@ while (*argv && (**argv == '-' || **argv == '+')) { char *args = *argv; action = (**argv == '-'); - if(!argv[0][1]) + if (!argv[0][1]) *argv = "--"; while (*++*argv) { /* The pseudo-option `--' signifies the end of options. * * `-b' does too, csh-style, unless we're emulating a * * Bourne style shell. */ if (**argv == '-' || (!bourne && **argv == 'b')) { + if (action && argv[0] == &args[1] && **argv == '-' && *++*argv) + goto longoptions; argv++; goto doneoptions; } @@ -230,7 +234,12 @@ zerr("string expected after -o", NULL, 0); exit(1); } - if(!(optno = optlookup(*argv))) + longoptions: + if (!strcmp(*argv, "version")) { + fprintf(stderr, "zsh %s (%s-%s-%s)\n", + ZSH_VERSION, MACHTYPE, VENDOR, OSTYPE); + exit(0); + } else if (!(optno = optlookup(*argv))) zerr("no such option: %s", *argv, 0); else if (optno == RESTRICTED) restricted = action; -- Bart Schaefer Brass Lantern Enterprises http://www.well.com/user/barts http://www.brasslantern.com Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net