zsh-users
 help / color / mirror / code / Atom feed
* Backticks and                       other tricks
@ 2001-03-28  7:22 Mario Lang
  0 siblings, 0 replies; 6+ messages in thread
From: Mario Lang @ 2001-03-28  7:22 UTC (permalink / raw)
  To: zsh-users

Hi.

Can anyone cast some light on the following questions
regarding the code below:
1. Why does ${(P)...[...]} not work with subscripts of the
array? (in fucntion argsargs).
2. Why does the inclusion trick with backticks not
work (`argsargs filters`). Actually _arguments complains
about not being able to parse this option. 



#compdef ecasound

typeset -A filters
filters=(\
ef1 "Resonant bandpass filter":"center frequency":Hz:"width":Hz
ef3 "Resonant lowpass filter":"cutoff frequency":Hz:resonance::gain:
ef4 "Resonant lowpass filter (3rd-order, 36dB)":"cutoff frequency":Hz:resonance:
efa "Allpass filter":"delay":samples:"feedback":percents
efb "Bandpass filter":"center frequency":Hz:"width":Hz
efc "Comb filter":"delay":samples:"radius":0-1
efh "Highpass filter":"cutoff frequency":Hz
efi "Inverse comb filter":"delay":samples:"radius":0-1
efl "Lowpass filter":"cutoff frequency":Hz
efr "Bandreject filter":"center frequency":Hz:"width":Hz
efs "Resonator (resonating bandpass filter)":"center frequency":Hz:"width":Hz\
)

argsargs () {
  for i in ${(koP)1}; do
    print -- "'*-${i}[${(P)1[$i]%%:*}]: :->${i}' \\"
  done
}

_arguments \
  '-c[Start in interactive mode]' \
  '-d\:-[Debug level]:debug level' \
  '-D[Print all debug information to stderr]' \
  '-q[Quiet mode, no output]' \
  '--help[Show help]' \
  '--version[Show version information]' \
  '-n\:-[Set the name of chainsetup]:chainsetup name' \
  '-s\:-[Create a new chainsetup from file]:chainsetup file:_files' \
  '-sr\:-[Set internal sampling rate]:Internal sampling rate:(8000 11025 22050 44100 48000)' \
  '*-a\:-[Select active signal chains]:chain name' \
  '-b\:-[Sets the size of buffer in samples]:buffer size:(1 2 4 8 16 32 64 128 256 512 1024 2048 4096 8192 16384 32768 65536)' \
  '-m\:-[Force use of specified mix mode]:Mix mode:((auto\:Automatic simple\:Only\ one\ input/cain/output normal\:Normal\ single-threaded\ mode))' \
  '-r[Use realtime scheduling policy (SCHED_FIFO)]' \
  '-r\:-[Use realtime scheduling policy (SCHED_FIFO)]:sched_priority' \
  '-x[Truncate outputs]' \
  '*-z\:-[Enable feature]:feature:->z' \
  '-t\:-[Set processing time in seconds]:seconds (int/float)' \
  '-tl[Enable looping]' \
  '*-f\:-[Set sampling parameters for the following input/output files]: :->f' \
  '*-y\:-[Set starting position for last specified input/output]:seconds' \
  '*-i\:-[Specifies a new input source]:input source:->io' \
  '*-o\:-[Specifies a new output source]:output source:->io' \
  '*-Md\:-[Set the active MIDI-device]:device name:_files' \
  '*-Mms\:-[Send MMC start/stop to MIDI device-id]:device id' \
  '*-mss[Sends MIDI-sync to the selected MIDI-device]' \
  '*-pf\:-[Use the first preset found from file as chain operator]:preset file:_files -g *.epp' \
  '*-pn\:-[Find preset from global preset database]:preset name:->pn' \
  '*-ev[Analyze sample data to find max apm value without clipping]' \
  '*-ezf[Find the optimal value for DC-adjusting]' \
  '*-eS\:-[Audio stamp]:stamp-id (int)' \
  '*-ea\:-[Amplify signal]:amplification value (percent)' \
  '*-eac\:-[Amplify signal of channel]: :->eac' \
  '*-eaw\:-[Amplify singal (clipping)]: :->eaw' \
  '*-eal\:-[Limits audio level]:limit (percent)' \
  '*-ec\:-[Compressor (a simple one)]: :->ec' \
  '*-eca\:-[A more advanced compressor]: :->eca' \
  '*-enm\:-[Noise gate. (each channel is processes separately)]: :-enm' \
  '*-ei\:-[Pitch shifter (modifies audio pitch by altering its length)]:pitch-shift (percent)' \
  '*-epp\:-[Normal pan effect]:panning (0=left, 50=center, 100=right)' \
  '*-ezx\:-[Adjusts the signal DC (use -ezf to find optimal values)]: :-ezx' \
  '*-eemb\:-[Pulse gate]: :-eemb' \
  '*-eemp\:-[Pulse gate (hz)]: :->eemp' \
  '*-eemt\:-[Tremolo effect]: :->eemt' \
  `argsargs filters` \
  '*-erc\:-[Copy channel]: :->erc' \
  '*-erm\:-[Mix all channels to one channel]:to channel' \
  '*-etc\:-[Chorus]: :->etc' \
  '*-etd\:-[Delay effect]: :->etd' \
  '*-ete\:-[A more advanced reverb effect]: :-ete' \
  '*-etf\:-[Fake-stereo effect]:delay time (msec)' \
  '*-etl\:-[Flanger]: :->etl' \
  '*-etm\:-[Multitap delay]: :->etm' \
  '*-etp\:-[Phaser]: :->etp' \
  '*-etr\:-[Reverb effect]: :->etr' \
  '*-el\:-[LADSPA Plugin]: :->el' \
  '*-eli\:-[LADSPA Plugin]: :->el' \
  '*-gc\:-[Time crop gate]: :->gc' \
  '*-ge\:-[Threshold gate]: :->ge' \
  && return 0
...

-- 
CYa,
   Mario <mlang@delysid.org>
Homepage(s): http://delysid.org | http://piss.at/

"Who is General Failure and why is he reading my hard disk ?"
Microsoft spel chekar vor sail, worgs grate !!
(By leitner@inf.fu-berlin.de, Felix von Leitner)


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Backticks and                       other tricks
  2001-03-28 23:56     ` Andre Pang
@ 2001-03-29  3:57       ` Bart Schaefer
  0 siblings, 0 replies; 6+ messages in thread
From: Bart Schaefer @ 2001-03-29  3:57 UTC (permalink / raw)
  To: zsh-users

On Mar 29,  9:56am, Andre Pang wrote:
} 
} i wonder if Bart can write an obsfuscated DeCSS program in zsh ...

I think any DeCSS program written in zsh would be obfuscated, no matter
who wrote it.

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com

Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net   


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Backticks and                       other tricks
  2001-03-28 18:06   ` Thomas Köhler
@ 2001-03-28 23:56     ` Andre Pang
  2001-03-29  3:57       ` Bart Schaefer
  0 siblings, 1 reply; 6+ messages in thread
From: Andre Pang @ 2001-03-28 23:56 UTC (permalink / raw)
  To: Thomas Köhler, zsh-users

On Wed, Mar 28, 2001 at 08:06:19PM +0200, Thomas Köhler wrote:

> Bart Schaefer <schaefer@candle.brasslantern.com> wrote:
> [...]
> > 
> > One can always be creative:
> > 
> >     ${(kP)1}				gives an array of keys, so
> >     ${${(kP)1}[(i)$i]}		gives the index of the key;
> >     ${(vP)1}				gives an array of values, so
> >     ${${(vP)1}[${${(kP)1}[(i)$i]}]}	is the answer.
> 
> ..to the question "who wins the obfuscated zsh contest"? :-)

i wonder if Bart can write an obsfuscated DeCSS program in zsh ...


-- 
/ #ozone <andrep@cse.unsw.edu.au>; (mobile# 0411 882299)
                                   trust in love to save


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Backticks and                       other tricks
  2001-03-28 15:41 ` Bart Schaefer
@ 2001-03-28 18:06   ` Thomas Köhler
  2001-03-28 23:56     ` Andre Pang
  0 siblings, 1 reply; 6+ messages in thread
From: Thomas Köhler @ 2001-03-28 18:06 UTC (permalink / raw)
  To: zsh-users

[-- Attachment #1: Type: text/plain, Size: 719 bytes --]

On Wed, Mar 28, 2001 at 03:41:42PM +0000,
Bart Schaefer <schaefer@candle.brasslantern.com> wrote:
[...]
> 
> One can always be creative:
> 
>     ${(kP)1}				gives an array of keys, so
>     ${${(kP)1}[(i)$i]}		gives the index of the key;
>     ${(vP)1}				gives an array of values, so
>     ${${(vP)1}[${${(kP)1}[(i)$i]}]}	is the answer.

..to the question "who wins the obfuscated zsh contest"? :-)

SCNR,
Thomas

-- 
 Thomas Köhler Email:   jean-luc@picard.franken.de     | LCARS - Linux
     <><        WWW:     http://jeanluc-picard.de      | for Computers
                IRC:             jeanluc               | on All Real
               PGP public key available from Homepage! | Starships

[-- Attachment #2: Type: application/pgp-signature, Size: 232 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Backticks and                       other tricks
  2001-03-28  9:00 Sven Wischnowsky
@ 2001-03-28 15:41 ` Bart Schaefer
  2001-03-28 18:06   ` Thomas Köhler
  0 siblings, 1 reply; 6+ messages in thread
From: Bart Schaefer @ 2001-03-28 15:41 UTC (permalink / raw)
  To: zsh-users

On Mar 28, 11:00am, Sven Wischnowsky wrote:
} 
} Mario Lang wrote:
} 
} > Can anyone cast some light on the following questions
} > regarding the code below:
} > 1. Why does ${(P)...[...]} not work with subscripts of the
} > array? (in fucntion argsargs).
} 
} `array', that's the point.  The ${(P)1} yields an array (a *normal*
} array, not an associative array).

That's not directly the problem ... directly, the problem is that
${(P)1[$i]} first computes ${1[$i]} and then applies (P) to it.

If you get around THAT problem by using ${${(P)1}[$i]}, THEN you get
the problem Sven describes.

Given the relative precedence of flags and subscripts, there's no simple
workaround for this.  We're just going to have to implement ksh namerefs
(not for 4.0.1).

} Currently I don't see a solution other than just not using an
} associative array at all

One can always be creative:

    ${(kP)1}				gives an array of keys, so
    ${${(kP)1}[(i)$i]}			gives the index of the key;
    ${(vP)1}				gives an array of values, so
    ${${(vP)1}[${${(kP)1}[(i)$i]}]}	is the answer.


-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com

Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net   


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Backticks and                       other tricks
@ 2001-03-28  9:00 Sven Wischnowsky
  2001-03-28 15:41 ` Bart Schaefer
  0 siblings, 1 reply; 6+ messages in thread
From: Sven Wischnowsky @ 2001-03-28  9:00 UTC (permalink / raw)
  To: zsh-users


Mario Lang wrote:

> Can anyone cast some light on the following questions
> regarding the code below:
> 1. Why does ${(P)...[...]} not work with subscripts of the
> array? (in fucntion argsargs).

`array', that's the point.  The ${(P)1} yields an array (a *normal*
array, not an associative array).  On normal arrays the subscripts of
`[ef1]' etc. are used as mathematical expressions and since there
aren't any variables with those names, mathematical evaluation gives
the value `0' (zero) as subscripts, so one always gets the first
element in the array.

Currently I don't see a solution other than just not using an
associative array at all, e.g. by prepending the `keys' to the
strings:

  # No need for backslashes here...

  filters=(
    ef1:"Resonant bandpass filter":"center frequency":Hz:"width":Hz
    ef3:"Resonant lowpass filter":"cutoff frequency":Hz:resonance::gain:
    ef4:"Resonant lowpass filter (3rd-order, 36dB)":"cutoff frequency":Hz:resonance:
    efa:"Allpass filter":"delay":samples:"feedback":percents
    efb:"Bandpass filter":"center frequency":Hz:"width":Hz
    efc:"Comb filter":"delay":samples:"radius":0-1
    efh:"Highpass filter":"cutoff frequency":Hz
    efi:"Inverse comb filter":"delay":samples:"radius":0-1
    efl:"Lowpass filter":"cutoff frequency":Hz
    efr:"Bandreject filter":"center frequency":Hz:"width":Hz
    efs:"Resonator (resonating bandpass filter)":"center frequency":Hz:"width":Hz\
  )

  argsargs () {
    for i in ${(P)1}; do
      print -- "*-${i%%:*}[${${i#*:}%%:*}]: :->${i%%:*}"
    done
  }

> 2. Why does the inclusion trick with backticks not
> work (`argsargs filters`). Actually _arguments complains
> about not being able to parse this option. 

The backticks make the words in the output of argsargs be split at
white spaces.  One solution would be to set IFS (deprecated) or use
the standard expression for splitting process outputs into lines:

  ${(f)"$(argsargs filters)"}

The quoting around the $(..) makes it return the complete output as
one (unaltered) string.  The (f) flag splits that at newlines into
array elements.


But anyway I would suggest not using process substitution if it can be 
avoided (always an extra process).  And since the options don't change 
it can be cached without any harm.  E.g.:

  if (( ! $+_ecasound_opts )); then
    local filters i

    filters=(
      ...
    )

    _ecasound_opts=()
    for i in $filters; do
      _ecasound_opts=($_ecasound_opts "*-${i%%:*}[${${i#*:}%%:*}]: :->${i%%:*}")
    done
  fi

  _arguments \
    $_ecasound_opts \
    ...                # other options



To -workers: that the ${(P)1} thing doesn't work is ugly, isn't it?

Bye
 Sven


--
Sven Wischnowsky                         wischnow@informatik.hu-berlin.de


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2001-03-29  3:58 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-03-28  7:22 Backticks and other tricks Mario Lang
2001-03-28  9:00 Sven Wischnowsky
2001-03-28 15:41 ` Bart Schaefer
2001-03-28 18:06   ` Thomas Köhler
2001-03-28 23:56     ` Andre Pang
2001-03-29  3:57       ` Bart Schaefer

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).