2010/9/11 "Paweł Hajdan, Jr." <phajdan.jr@gentoo.org>
On 9/11/10 11:03 AM, Jonathan Callen wrote:
> Just as a proof-of-concept, here's one implementation of such a
> function, allowing for an arbitrary number of arguments:
>
> use_echo() {
> Â* Â* Â* while [[ $# -gt 1 ]]; do
> Â* Â* Â* Â* Â* Â* Â* if use "$1"; then
> Â* Â* Â* Â* Â* Â* Â* Â* Â* Â* Â* echo "$2"
> Â* Â* Â* Â* Â* Â* Â* Â* Â* Â* Â* return
> Â* Â* Â* Â* Â* Â* Â* fi
> Â* Â* Â* Â* Â* Â* Â* shift 2
> Â* Â* Â* done
> Â* Â* Â* [[ $# -eq 1 ]] && echo "$1"
> }
Looks good to me. If it doesn't get included in any eclass, I will just
paste it to the chromium ebuilds.
Paweł
I don't count but sometimes I do still read ebuilds, the function proposed look a bit^W unreadable to me,Â*may I suggest to aggregate use and echo, separating them with a comma ",".
The first element with an empty "use" always echo and return.
See implementation and example below
use_case() {Â*Â* Â* Â* Â*local uÂ*Â* Â* Â* Â*local c
Â*Â* Â* Â* Â*while [[ $# -gt 0 ]]Â*Â* Â* Â* Â*doÂ*Â* Â* Â* Â* Â* Â* Â* Â*u=${1%%,*}Â*Â* Â* Â* Â* Â* Â* Â* Â*c=${1#*,}Â*Â* Â* Â* Â* Â* Â* Â* Â*if [[ ${u} == "" ]] || use $uÂ*Â* Â* Â* Â* Â* Â* Â* Â*then Â*Â*
Â*Â* Â* Â* Â* Â* Â* Â* Â* Â* Â* Â* Â*echo ${c}Â*Â* Â* Â* Â* Â* Â* Â* Â* Â* Â* Â* Â*breakÂ*Â* Â* Â* Â* Â* Â* Â* Â*fiÂ*Â* Â* Â* Â* Â* Â* Â* Â*shiftÂ*Â* Â* Â* Â*done}
echo $(use_case useA,echoA useB,echoB ,echoC)