From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from euclid.skiles.gatech.edu (list@euclid.skiles.gatech.edu [130.207.146.50]) by melb.werple.net.au (8.7.5/8.7.3/2) with ESMTP id BAA05841 for ; Wed, 3 Jul 1996 01:47:12 +1000 (EST) Received: (from list@localhost) by euclid.skiles.gatech.edu (8.7.3/8.7.3) id LAA27234; Tue, 2 Jul 1996 11:39:21 -0400 (EDT) Resent-Date: Tue, 2 Jul 1996 11:39:21 -0400 (EDT) Message-Id: <199607021537.RAA16181@hydra.ifh.de> To: zsh-workers@math.gatech.edu (Zsh hackers list) Subject: Re: Tag functions with shell options? In-reply-to: "aheading@jpmorgan.com"'s message of "Tue, 02 Jul 1996 13:05:29 MET." <199607021205.NAA18450@gmp-etpres1.uk.jpmorgan.com> Date: Tue, 02 Jul 1996 17:37:58 +0200 From: Peter Stephenson Resent-Message-ID: <"sCUmE1.0.Sf6.eAKsn"@euclid> Resent-From: zsh-workers@math.gatech.edu X-Mailing-List: archive/latest/1506 X-Loop: zsh-workers@math.gatech.edu Precedence: list Resent-Sender: zsh-workers-request@math.gatech.edu aheading@jpmorgan.com wrote: > So I think I need some way of marking these functions to be interpreted with > SH_WORD_SPLIT turned on locally. Or have I missed something simple? This is definitely a weak point in compatibility. Perhaps in a future version we do want special ways of doing things like this. Some time ago, people were suggesting having hooks you could call when a function was called etc.; that would do the trick too. However, for the time being... I take it the problem is within the function, i.e. you don't actually have problems on the command line yourself? In that case it would be outside the scope of the function. Another problem arises if the functions get defined at arbitrary points during execution (err, like the sws_locate function below, in fact). In that case you're basically stuck without at the least a smart script to convert all functions defined inside in the appropriate manner. If they are playing fair, however, try this function. You need to call it with the names of all the functions you want to have run with sh_word_split turned on. They can be either already in memory or autoloadable: in the latter case, it assumes they are ksh-like autoloadable functions, i.e. the entire function definition is there including the `function foo { ... } bit.' It relies on the fact that `functions foo' returns an accurate representation of foo. I've been trying to ensure this over the years, but there almost certainly some things we've all missed. sws_fn () { # Convert a sh or ksh function to run under zsh by the addition of # some set of options. The function may already be defined, or be in # some autoload directory. # This is the text we\'d like added at the top of the function. local optline="setopt shwordsplit localoptions" local func body dir fnfile sws_locate() { # Find an autoload file. local dir for dir in $fpath; do if [[ -f $dir/$1 ]]; then fnfile=$dir/$1 return 0 fi done return 1 } for func; do if [[ "$(functions $func | head -1)" = *undefined* ]] && sws_locate $func; then # We're assuming these are ksh-like autoload functions, # i.e. they contain the full function include definition lines. . $fnfile fi body="$(functions $func 2>&1 | sed -e 1d -e '$d')" [[ -z $body ]] && print "No such function: $func" >&2 && continue eval "function $func { $optline $body }" done } -- Peter Stephenson Tel: +49 33762 77366 WWW: http://www.ifh.de/~pws/ Fax: +49 33762 77330 Deutches Electronen-Synchrotron --- Institut fuer Hochenergiephysik Zeuthen DESY-IfH, 15735 Zeuthen, Germany.