Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm
Precedence: bulk
X-No-Archive: yes
List-Id: Zsh Workers List <zsh-workers.zsh.org>
List-Post: <mailto:zsh-workers@zsh.org>
List-Help: <mailto:zsh-workers-help@zsh.org>
X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on f.primenet.com.au
X-Spam-Level: 
X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM
	autolearn=ham autolearn_force=no version=3.4.0
Subject: Re: Printf builtin missing v flag support
To: zsh-workers@zsh.org
References: <068ca8f5-315b-444c-b281-5f183e1daa8c@email.android.com>
 <151231104858.ZM24513@torch.brasslantern.com> <5686F643.1060707@gmx.com>
From: Eric Cook <llua@gmx.com>
Message-ID: <5686FA43.8070002@gmx.com>
Date: Fri, 1 Jan 2016 17:14:27 -0500
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101
 Thunderbird/38.5.0
MIME-Version: 1.0
In-Reply-To: <5686F643.1060707@gmx.com>
Content-Type: text/plain; charset=windows-1252
Content-Transfer-Encoding: 7bit
X-Provags-ID: V03:K0:xHzNr5Xr8s+uFYcrxHLU5axzSB/u5SYoLVYlsKvw1sm4ihexq+P
 6a7bJ6a+XAVe3p2f7o842RUdeVfFH2eFwSYw1wxb2diqLvX0TQuKhoYUsj4+ABR9VuW/32/
 H7j/9Ly45BLCov3HWJmz4iq15PoI428gdALXKcNMHdLf86xL7Yhh04RHJA7MeYUIDdtAJ4P
 Yh6y9W8QQ/7oz5BDXolgg==
X-UI-Out-Filterresults: notjunk:1;V01:K0:bZTOk6i/Zzw=:pGxwQWVF9CZtcPKv6jvrMi
 co5PnEN52Vw4J0HSD+APQG6p2hgxxDPcamVF/B4gAyPjU7eQsWTd1mDr+TNv+xp4qV9b246Me
 ahOdJtnavfa/nwghNgCciJJ+FEQJBS/gm8LszxvxFpJwDr/Rp/nO8XEfrzbZrSHDLbH+CIkc4
 nhowWm+IncoK9eTJg+qB2rzMpW0Evon9IZsRyYoO4OOQqB4FY97WSn5Zv1N2WELwRx+ymxeYI
 ucxh/OYIh2W4cBbwf2AWZxD+7ShkCX9VcwdhqQ1om81ZLZzfK3uEQ5FoV4BT+D7XYRgWT+Hcj
 JQhEhaYHrx7ZEdo0hvBkLk3FcoJNhHc6IWpDvcsmMgtdYjhR0VgFlLSum2SCZlD5uUDzbzLlb
 R9kTmrQZ9bThHrJMq1UHIy35sOsP7+V4dl0A+/uAycZ5tz/rIwplvz/kRA37flH68T5YKgfDF
 /k5JV3h/BnOXnw1Nf7kBhOcSbNJ0ef1rOlYJg/2b8DxxhipMLvTyvIYXAvfydh+gsjUQNxEOO
 N3XWBhg7ly+Rab1Z1kW4NbpZWMUp7Rj2ERUcOp80H8HRowS1rR1nj5tbd5LMd9n4YWKDgbF2N
 t5vlEjACBSxXZGn6ZIOQkOhCo8ttVOadx0y7sKsDxxAlKeY6kvWZ4J2EVxuuvbTExEylmUlyg
 mspB6G1YoHShQXDWs8svB9Uzmwcu2miQ7MADBlL1QpBT90wt7eW74ltaAoKOK+bOo7ev0hUpN
 qGjzs3NEss+K/meZKHY0dAGt95InOz0bbol5osm/Wr15B8cAcbhz98Be9XU2O0dGAjJU5nxU5
 UeP+4l4
X-Seq: zsh-workers 37482

On 01/01/2016 04:57 PM, Eric Cook wrote:
> On 12/31/2015 01:48 PM, Bart Schaefer wrote:
>> On Dec 31, 10:44am, Peter Stephenson wrote:
>> }
>> } The feature is obviously useful but the print implementation is
>> } a nightmare of special cases making it hard to change without
>> } considerable refactoring. That would probably be a Good Work, given
>> } enough test cases to check it, but is going to have to wait for a
>> } volunteer.
>> }
>> } I haven't checked whether -v is already in use in which case this is moot.
>>
>> -v is not in use, and the print implementation has already been refactored
>> to support the -z and -s options in printf, so this is actually rather
>> easy.
>>
>> I noticed that "print" uses metafy() on the aguments to -z and -s, but
>> "printf" did not, so I added metafy() for those cases.  Somebody holler
>> if this is wrong.
>>
>>
> 
> Could zsh error when an invalid parameter name is used?
> 
> % printf -v -- '%s' foo
> -v%
> % printf -v '%s' foo
> -v%
> % printf -v
> -v%
> 
> $ printf -v -- '%s' foo
> bash: printf: `--': not a valid identifier
> $ printf -v '%s' foo
> bash: printf: `%s': not a valid identifier
> $ printf -v
> bash: printf: -v: option requires an argument
> printf: usage: printf [-v var] format [arguments]
> 
> bash's printf -v can also assign to array elements, which isn't possible currently.
> 
> % typeset -A foo; printf -v 'foo[bar]' baz; typeset -p foo
> -vtypeset -A foo
> 
> % printf -v 'a[2+2]' foo; typeset -p a
> foo=( )
> 
> $ typeset -A foo; printf -v 'foo[bar]' baz; typeset -p foo
> declare -A foo='([bar]="baz" )'
> $ printf -v 'a[2+2]' foo; typeset -p a
> declare -a a='([4]="foo")'
> 
weeeeee, used the wrong version here, please ignore the email.

