From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 19410 invoked by alias); 7 May 2015 09:46:33 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 35054 Received: (qmail 10899 invoked from network); 7 May 2015 09:46:31 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_HI, SPF_HELO_PASS,T_HDRS_LCASE,T_MANY_HDRS_LCASE autolearn=ham version=3.3.2 X-AuditID: cbfec7f5-f794b6d000001495-68-554b3218a800 Date: Thu, 07 May 2015 10:35:51 +0100 From: Peter Stephenson To: Zsh Hackers' List Subject: PATCH: readonly -p with POSIX_BUILTINS Message-id: <20150507103551.58d52ef0@pwslap01u.europe.root.pri> Organization: Samsung Cambridge Solution Centre X-Mailer: Claws Mail 3.7.9 (GTK+ 2.22.0; i386-redhat-linux-gnu) MIME-version: 1.0 Content-type: text/plain; charset=US-ASCII Content-transfer-encoding: 7bit X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrJLMWRmVeSWpSXmKPExsVy+t/xK7oSRt6hBpdW81kcbH7I5MDoserg B6YAxigum5TUnMyy1CJ9uwSujJvzLjAVXBKqmPR5DWsD4wG+LkYODgkBE4mmLyZdjJxAppjE hXvr2boYuTiEBJYySrS2LWGEcGYwSTw+cJEZpEpIYCujxJKtxSA2i4CqxJ3T65lAbDYBQ4mp m2YzggwVEdCWaP8oBhIWFtCXOLp/EyOIzStgL9E9axGYzQ8Uv/r3ExPEYnuJmVfOQNUISvyY fI8FxGYW0JLYvK2JFcKWl9i85i3UCeoSN+7uZp/AKDALScssJC2zkLQsYGRexSiaWppcUJyU nmukV5yYW1yal66XnJ+7iRESgF93MC49ZnWIUYCDUYmHN6DKM1SINbGsuDL3EKMEB7OSCK+R oXeoEG9KYmVValF+fFFpTmrxIUZpDhYlcd6Zu96HCAmkJ5akZqemFqQWwWSZODilGhj3NwTt M7ubf0viN0PT0Ukedtv3sD9rr9l6Jv3LtRSxdy1xMxR6fy8++k/x/SefXY/3nRQ1eHcxJcXI akvOi8xdfRf0HPt8jKM+bJTdqaHOJLF57ZqzZ++cneCpkHqpc05lfGSnxspzl7438K5ca1A/ ddPC/H8sS2a/9f/6OLH0y8unwW/4r9cUK7EUZyQaajEXFScCAEdXT1o8AgAA This fixes the POSIX_BUILTINS aspect of "readonly -p" output, i.e. it needs to show unset variables (the standard is explicit about this). It doesn't fix the non-POSIX_BUILTINS aspect of "readonly -p" output, i.e. "er, this output is all a bit broken, isn't it?" The object of "readonly -p" is to have a set of commands to restore the current state: that means it should work without complaint on a new shell (I don't think it can possibly be required to work once you've already run it as POSIX doesn't allow you to remove the readonly attribute). I think that means not printing values for readonly specials. Feel free to argue it shouldn't show readonly specials at all --- if you ran a script so generated immediately on starting a shell and it included a readonly special that was loaded from a module, then I think you'd be screwed. I'm vaguely inclining that way myself; you don't use the -p option if you're just listing things for information. diff --git a/Src/params.c b/Src/params.c index d53b6ca..9eab51a 100644 --- a/Src/params.c +++ b/Src/params.c @@ -5039,8 +5039,19 @@ printparamnode(HashNode hn, int printflags) Param p = (Param) hn; char *t, **u; - if (p->node.flags & PM_UNSET) - return; + if (p->node.flags & PM_UNSET) { + if (isset(POSIXBUILTINS) && (p->node.flags & PM_READONLY) && + (printflags & PRINT_TYPESET)) + { + /* + * Special POSIX rules: show the parameter as readonly + * even though it's unset, but with no value. + */ + printflags |= PRINT_NAMEONLY; + } + else + return; + } if (printflags & PRINT_TYPESET) printf("typeset "); diff --git a/Test/B02typeset.ztst b/Test/B02typeset.ztst index f4fb8ec..2edbb0b 100644 --- a/Test/B02typeset.ztst +++ b/Test/B02typeset.ztst @@ -475,13 +475,15 @@ print ${+pbro} >&2 (typeset pbro=3) (pbro=4) + readonly -p | grep pbro >&2 # shows up as "readonly" although unset typeset -r pbro # idempotent (no error)... print ${+pbro} >&2 # ...so still readonly... typeset +r pbro # ...can't turn it off ) -1:Readonly with POSIX_BUILTINS +1:readonly with POSIX_BUILTINS ?0 ?(eval):5: read-only variable: pbro ?(eval):6: read-only variable: pbro +?typeset -r pbro ?0 -?(eval):9: read-only variable: pbro +?(eval):10: read-only variable: pbro