From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from relay2.UU.NET ([137.39.1.7]) by hawkwind.utcs.toronto.edu with SMTP id <2751>; Thu, 25 Jun 1992 22:02:50 -0400 Received: from uunet.uu.net (via LOCALHOST.UU.NET) by relay2.UU.NET with SMTP (5.61/UUNET-internet-primary) id AA12653; Thu, 25 Jun 92 21:51:28 -0400 Received: from srg.UUCP by uunet.uu.net with UUCP/RMAIL (queueing-rmail) id 214959.6159; Thu, 25 Jun 1992 21:49:59 EDT Received: from ceres.srg.af.mil by srg.srg.af.mil id aa10803; Thu, 25 Jun 92 20:31:21 EDT From: culliton@srg.af.mil (Tom Culliton x2278) X-Mailer: SCO System V Mail (version 3.2) To: cks@hawkwind.utcs.toronto.edu, rc@hawkwind.utcs.toronto.edu Subject: Re: Another little challenge Date: Thu, 25 Jun 1992 20:31:25 -0400 Message-Id: <9206252031.aa11853@ceres.srg.af.mil> Excellent! It struck me that there had to be an elegant solution but I just couldn't see it. That little gem is already in my .rcrc file. :-) My recent rash of questions is prompted by converting a friend to rc and helping him solve the problems encountered. The other thing that reared it's head was the old "everything is exported" problem. Rich produced a partial solution back in May, but it required that you explicitly "unexport" things. I'm currently tinkering with a solution that looks like this: # This code can be fooled by really pathological cases involving embedded # newlines followed by either 'fn ' or '='. Fixing this is left as an # exercise for the reader. ;-) It's already slow enough for me. exported=() fn export { exported=($exported $*) } fn fns_n_vars { i=() tmp=() { fn_list=() var_list=() for (i in `` ($nl) {whatis}) if (~ $i 'fn '*) { tmp=`{echo $i} fn_list=($fn_list $tmp(2)) } else if (~ $i *'='*) { tmp=`` ('=') {echo $i} var_list=($var_list $tmp(1)) } }} fns_n_vars # pre-load should be done after all variable setting in .rcrc # Stuff run by clean_env will only see the exported variables. You can # also give this function multiple names for programs that choke on big # env's. Note that keeping fn_list and var_list up to date needs to be # improved. I thought about something like: # x=`` ($nl) {whatis} if (! ~ $#x $xcnt) { xcnt=$#x; fns_n_vars } # but it could be fooled pretty easily. Ideas? fn clean_env { i=() @{ if (~ $#fn_list 0 && ~ $#var_list 0) { fns_n_vars } for (i in $fn_list) { eval 'fn '^$i } for (i in $var_list) { if (! ~ $i $exported i exported) { eval $i^'=()' } } i=(); fn_list=(); var_list=(); exported=(); fn clean_env if (~ $0 clean_env) exec $* else exec $0 $* }}