From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) by finch.gentoo.org (Postfix) with ESMTP id 69A8F1381F3 for ; Mon, 17 Jun 2013 05:42:16 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 2EB4FE0839; Mon, 17 Jun 2013 05:42:11 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 24A7CE07ED for ; Mon, 17 Jun 2013 05:42:10 +0000 (UTC) Received: from vapier.localnet (localhost [127.0.0.1]) by smtp.gentoo.org (Postfix) with ESMTP id 5192133E4F8 for ; Mon, 17 Jun 2013 05:42:09 +0000 (UTC) From: Mike Frysinger Organization: wh0rd.org To: gentoo-dev@lists.gentoo.org Subject: Re: [gentoo-dev] Re: evar_push/pop helpers Date: Mon, 17 Jun 2013 01:42:15 -0400 User-Agent: KMail/1.13.7 (Linux/3.8.3; KDE/4.6.5; x86_64; ; ) References: <201306012303.21261.vapier@gentoo.org> <20130602173804.GA4280@rathaus.eclipse.co.uk> In-Reply-To: <20130602173804.GA4280@rathaus.eclipse.co.uk> Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-dev@lists.gentoo.org Reply-to: gentoo-dev@lists.gentoo.org MIME-Version: 1.0 Content-Type: multipart/signed; boundary="nextPart9146849.mXtM32AoL2"; protocol="application/pgp-signature"; micalg=pgp-sha1 Content-Transfer-Encoding: 7bit Message-Id: <201306170142.15784.vapier@gentoo.org> X-Archives-Salt: 2550a4a7-3c58-494e-a184-8720537c2c75 X-Archives-Hash: 60786aa9c5b2a495a23b8de00008481b --nextPart9146849.mXtM32AoL2 Content-Type: Text/Plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable On Sunday 02 June 2013 13:38:04 Steven J. Long wrote: > On Sat, Jun 01, 2013 at 11:03:20PM -0400, Mike Frysinger wrote: > > --- eutils.eclass 22 May 2013 05:10:29 -0000 1.421 > > +++ eutils.eclass 2 Jun 2013 03:00:46 -0000 > > @@ -146,6 +146,77 @@ estack_pop() { > > eval unset ${__estack_name}\[${__estack_i}\] > > } >=20 > Just in passing, one of the places you don't want nullglob messing things > up. not sure what you mean. that escapes the [] so that bash doesn't accidenta= lly=20 glob things. when the code actually executes, you don't need to escape=20 things. touch f i d x unset arr declare -A arr arr[f]=3D1234 arr[idx]=3D4321 echo "${arr[f]}" "${arr[idx]}" __estack_name=3Darr __estack_i=3Df eval unset ${__estack_name}\[${__estack_i}\] echo ${#arr[@]} __estack_i=3Didx eval unset ${__estack_name}\[${__estack_i}\] echo ${#arr[@]} seems to work > > +# is not specified, the var will be unset. > > +evar_push_set() { > > + local var=3D$1 > > + evar_push ${var} > > + case $# in > > + 1) unset ${var} ;; > > + 2) eval ${var}=3D\$2 ;; >=20 > I wish you wouldn't use eval for this. I know it's technically okay here, > or would be if you verified the parameter, but bash has printf -v for this > purpose: interesting, i hadn't seen that before ... looks new to bash-3.1. /me tuck= s=20 that into his tool belt. although it doesn't quite work in the edge case where the value is an empty= =20 string. consider: unset x printf -v x '' echo ${x+set} that should show "set", but it does not. i'll have to keep `eval ${var}=3D= `=20 when the value we're setting is empty. or just keep the eval code since i= =20 have to do eval anyways at that point. i'll report it upstream to the bash guys. > printf -v "$1" '%s' "$2" 2>/dev/null || die "unable to set: '$1' to: '$2'" >=20 > Note you should verify the variable name, ime, irrespective of a die on t= he > printf (or eval in sh.) It's much better feedback to the developer using > the routine. i don't think it's worth it. if you screw up the name, it tends to be a on= e- time cost, and the error shown is pretty clear as to where it's coming from. > printf -v also works with array members btw, if you do decide to extend in > that direction: i don't think i will, but i probably can convert the other core stack code = to=20 use this ... > > + : ${cnt:=3Dbad} > > + [[ -n ${cnt//[0-9]} ]] && die "${FUNCNAME}: first arg must be a > > number: $*" > > + ;; >=20 > Though a generic is_int function comes in much handier, ime. yeah, and we have other code that wants this (a simple grep for 0-9 in ecla= ss/=20 shows a bunch of hits) > > - # Some people like to make dirs of patches w/out suffixes (vim) > > + # We have to force sorting to C so that the wildcard expansion > > # is consistent #471666. > > + evar_push_set LC_COLLATE C > > + # Some people like to make dirs of patches w/out suffixes (vim). > > set -- "$1"/*${EPATCH_SUFFIX:+."${EPATCH_SUFFIX}"} > > + evar_pop >=20 > Have to say I'd just do this in a function adding to a locally-scoped > array, if it were me, eg local args; foo "$1" "$EPATCH_SUFFIX"; set -- > "${args[@]}"; unset args > foo() { > local LC_COLLATE=3DC > args=3D("$1"/*${2:+."$2"}) > } since i plan on using these funcs in other places, using the existing api=20 keeps things simple > though I'd prefer it if EPATCH_SUFFIX were allowed to be a list, > personally. wouldn't really make this any easier =2Dmike --nextPart9146849.mXtM32AoL2 Content-Type: application/pgp-signature; name=signature.asc Content-Description: This is a digitally signed message part. -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.17 (GNU/Linux) iQIcBAABAgAGBQJRvqG3AAoJEEFjO5/oN/WB+AAP/iuFqW7f+FMrLe7ZXQZg9ugQ 3VlDp/YdNsCjBb+gyaEy1unTXLQHdW2d0woFQBSkJYWsXHrxqwsWUHpv6QAnVyJr k7IEhbAjlzhR+pwfVRvgbBL3gPf6cDxpBgDDfaqRMwDsXBYNaL5L5BLuZKlrlqhz 10QzHqViua+KnlLofPsh0mhgeYx12b2/nbJA10bpAIESEsXzbh8Ksd64tBSk7rbF hpJs7cik0A1OKkYCHN4afxYNdQJrZrYlxkjwa9NtcBP/Hk/q2Bew9h1XinN4UWxo RrtU0L8Ds8Iz0Ni53eCYGDncl5bViYKZRY9Z8rGGGrOQXEM7vRj/z8HEM3bYjGsc ZQknvu0PbVuhLXAd3USqwwYUxAGsJEw3q3bjm2CfH5Tjausqy7tiiDTQyZZ51TMn ncUz+Y0+Sb+nAFWfyPnEqqZjDkLHbsPK0FWHyMiyay67tqIY+vMKSidZQvvecAJi DKyXQ1vO6ZsOKj7WUKXaI2KjdrPOvXX1IvKg4ePPQs3Bw1ecj3KKc7FtveE2/mIJ Owwh4/4rrCXCtwtxCB/+Dl4QW7ORlRY1rLaJ2Zq+wJXw1T2NGRkUguPpfjk5cWut As4Fw/wYv07avgVhMbA2ki125eWHXDU/hKoqBthRuPg0Yam47paLWWTBxpziRu/n q5ubgW77jB3bLTcxgSVi =JC+F -----END PGP SIGNATURE----- --nextPart9146849.mXtM32AoL2--