From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 4072 invoked by alias); 22 Feb 2015 03:53:32 -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: 34602 Received: (qmail 12466 invoked from network); 22 Feb 2015 03:53:30 -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=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.2 X-CMAE-Score: 0 X-CMAE-Analysis: v=2.1 cv=QtXpBu2Y c=1 sm=1 tr=0 a=FT8er97JFeGWzr5TCOCO5w==:117 a=kj9zAlcOel0A:10 a=q2GGsy2AAAAA:8 a=oR5dmqMzAAAA:8 a=-9mUelKeXuEA:10 a=0HtSIViG9nkA:10 a=qJsOZcF2TG8SJrAshAcA:9 a=CjuIK1q_8ugA:10 From: Bart Schaefer Message-id: <150221195321.ZM23717@torch.brasslantern.com> Date: Sat, 21 Feb 2015 19:53:21 -0800 In-reply-to: <150221163922.ZM23297@torch.brasslantern.com> Comments: In reply to Bart Schaefer "Re: Builtin strftime and TZ assignments" (Feb 21, 4:39pm) References: <150221102305.ZM26540@torch.brasslantern.com> <150221124546.ZM8579@torch.brasslantern.com> <20150221222712.49d49b88@ntlworld.com> <150221145441.ZM23213@torch.brasslantern.com> <20150221231614.3b871425@ntlworld.com> <150221163922.ZM23297@torch.brasslantern.com> X-Mailer: OpenZMail Classic (0.9.2 24April2005) To: zsh-workers@zsh.org Subject: Re: Builtin strftime and TZ assignments MIME-version: 1.0 Content-type: text/plain; charset=us-ascii On Feb 21, 4:39pm, Bart Schaefer wrote: } } On Feb 21, 11:16pm, Peter Stephenson wrote: } } } } That wouldn't work because a level is only assigned if you "typeset" or } } equivalent --- a normal assignment creates a global parameter. But I'd } } expect it to work with locallevel instead of locallevel+1. It does in fact work with locallevel. } } I don't understand the difference if createparam() isn't there. It } } should always be called by any function that needs to create a parameter. } } If you just call setsparam("TZ", ...), it will eventually go through } createparam() and the right thing happens with locallevel Apparently I was confused about that too -- it's the use of the TZ=UTC prefix which creates and removes again the parameter, not the use of the parameter scope in bin_strftime(). } Also I now suspect my patch breaks strftime -s, I didn't test that. Which it does not. Except for one special case: "strftime -s TZ ..." doesn't change the value of TZ. Here's a revised patch. Question: How does one know when to metafy() the value passed to setsparam()? It doesn't appear that getsparam() performs an unmetafy(), so I presume I can pass directly back to setsparam(). diff --git a/Src/Modules/datetime.c b/Src/Modules/datetime.c index 00ebd2b..63a04dc 100644 --- a/Src/Modules/datetime.c +++ b/Src/Modules/datetime.c @@ -94,7 +94,7 @@ reverse_strftime(char *nam, char **argv, char *scalar, int quiet) } static int -bin_strftime(char *nam, char **argv, Options ops, UNUSED(int func)) +output_strftime(char *nam, char **argv, Options ops, UNUSED(int func)) { int bufsize, x; char *endptr = NULL, *scalar = NULL, *buffer; @@ -145,6 +145,25 @@ bin_strftime(char *nam, char **argv, Options ops, UNUSED(int func)) return 0; } +static int +bin_strftime(char *nam, char **argv, Options ops, int func) +{ + int result = 1; + char *tz = getsparam("TZ"); + + startparamscope(); + if (tz && *tz) { + Param pm = createparam("TZ", PM_LOCAL|PM_SCALAR|PM_EXPORTED); + if (pm) + pm->level = locallevel; /* because createparam() doesn't */ + setsparam("TZ", ztrdup(tz)); + } + result = output_strftime(nam, argv, ops, func); + endparamscope(); + + return result; +} + static zlong getcurrentsecs(UNUSED(Param pm)) {