From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 2906 invoked from network); 14 May 2003 10:23:15 -0000 Received: from sunsite.dk (130.225.247.90) by ns1.primenet.com.au with SMTP; 14 May 2003 10:23:15 -0000 Received: (qmail 23082 invoked by alias); 14 May 2003 10:23:05 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 18530 Received: (qmail 23067 invoked from network); 14 May 2003 10:23:05 -0000 Received: from localhost (HELO sunsite.dk) (127.0.0.1) by localhost with SMTP; 14 May 2003 10:23:05 -0000 X-MessageWall-Score: 0 (sunsite.dk) Received: from [212.125.75.4] by sunsite.dk (MessageWall 1.0.8) with SMTP; 14 May 2003 10:23:4 -0000 Received: (qmail 6494 invoked from network); 14 May 2003 10:14:02 -0000 Received: from iris.logica.co.uk (158.234.9.163) by server-21.tower-1.messagelabs.com with SMTP; 14 May 2003 10:14:02 -0000 Received: from gmcs3.local ([158.234.142.61]) by iris.logica.co.uk (8.9.3/8.9.3/Debian 8.9.3-21) with ESMTP id LAA30035 for ; Wed, 14 May 2003 11:14:02 +0100 X-Authentication-Warning: iris.logica.co.uk: Host [158.234.142.61] claimed to be gmcs3.local Received: from gmcs3.local (localhost [127.0.0.1]) by gmcs3.local (8.11.6/8.11.6/SuSE Linux 0.5) with ESMTP id h4EAEMx02616 for ; Wed, 14 May 2003 12:14:22 +0200 X-VirusChecked: Checked From: Oliver Kiddle To: Zsh workers Subject: PATCH: listing options with set -o/+o Date: Wed, 14 May 2003 12:14:22 +0200 Message-ID: <2614.1052907262@gmcs3.local> The most recent POSIX shell definition, states that `set -o' should "write the current settings of the options to standard output in an unspecified format" and `set +o' should "write the current option settings to standard output in a format that is suitable for reinput to the shell as commands that achieve the same options settings" There are a few possibilities with respect to the exact format the output should take. I've done what I think is best but it is very easy to change so feel free to make other suggestions. For set -o, I've duplicated what you get from setopt with the kshoptionprint option. For set +o, it only prints those options that are in their non-default state (which is what ksh93 and pdksh do but not bash). Oliver Index: Doc/Zsh/builtins.yo =================================================================== RCS file: /cvsroot/zsh/zsh/Doc/Zsh/builtins.yo,v retrieving revision 1.60 diff -u -r1.60 builtins.yo --- Doc/Zsh/builtins.yo 3 Apr 2003 09:55:48 -0000 1.60 +++ Doc/Zsh/builtins.yo 14 May 2003 10:11:09 -0000 @@ -973,7 +973,7 @@ cindex(parameters, setting array) cindex(array parameters, setting) pindex(KSH_ARRAYS, use of) -item(tt(set) [ {tt(PLUS())|tt(-)}var(options) | {tt(PLUS())|tt(-)}tt(o) var(option_name) ] ... [ {tt(PLUS())|tt(-)}tt(A) [ var(name) ] ] [ var(arg) ... ])( +item(tt(set) [ {tt(PLUS())|tt(-)}var(options) | {tt(PLUS())|tt(-)}tt(o) [ var(option_name) ] ] ... [ {tt(PLUS())|tt(-)}tt(A) [ var(name) ] ] [ var(arg) ... ])( Set the options for the shell and/or set the positional parameters, or declare and set an array. If the tt(-s) option is given, it causes the specified arguments to be sorted before assigning them to the positional @@ -981,7 +981,10 @@ sort arguments in descending order. For the meaning of the other flags, see ifzman(zmanref(zshoptions))\ ifnzman(noderef(Options))\ -. Flags may be specified by name using the tt(-o) option. +. Flags may be specified by name using the tt(-o) option. If no option +name is supplied with tt(-o), the current option states are printed. +With tt(PLUS()o) they are printed in a form that can be used as input +to the shell. If the tt(-A) flag is specified, var(name) is set to an array containing the given var(arg)s; if no var(name) is specified, all arrays are printed Index: Src/builtin.c =================================================================== RCS file: /cvsroot/zsh/zsh/Src/builtin.c,v retrieving revision 1.100 diff -u -r1.100 builtin.c --- Src/builtin.c 4 Apr 2003 16:47:02 -0000 1.100 +++ Src/builtin.c 14 May 2003 10:11:10 -0000 @@ -562,9 +562,9 @@ if (!*++*args) args++; if (!*args) { - zwarnnam(nam, "string expected after -o", NULL, 0); + printoptionstates(hadplus); inittyptab(); - return 1; + return 0; } if(!(optno = optlookup(*args))) zwarnnam(nam, "no such option: %s", *args, 0); Index: Src/options.c =================================================================== RCS file: /cvsroot/zsh/zsh/Src/options.c,v retrieving revision 1.14 diff -u -r1.14 options.c --- Src/options.c 4 Dec 2002 13:57:51 -0000 1.14 +++ Src/options.c 14 May 2003 10:11:10 -0000 @@ -705,6 +705,33 @@ return buf; } +/* print options for set -o/+o */ + +/**/ +void +printoptionstates(int hadplus) +{ + scanhashtable(optiontab, 1, 0, OPT_ALIAS, printoptionnodestate, hadplus); +} + +/**/ +static void +printoptionnodestate(HashNode hn, int hadplus) +{ + Optname on = (Optname) hn; + int optno = on->optno; + + if (hadplus) { + if (defset(on) != isset(optno)) + printf("set -o %s%s\n", defset(on) ? "no" : "", on->nam); + } else { + if (defset(on)) + printf("no%-19s %s\n", on->nam, isset(optno) ? "off" : "on"); + else + printf("%-21s %s\n", on->nam, isset(optno) ? "on" : "off"); + } +} + /* Print option list for --help */ /**/