From: culliton@srg.af.mil (Tom Culliton x2278)
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 [thread overview]
Message-ID: <9206252031.aa11853@ceres.srg.af.mil> (raw)
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 $*
}}
next reply other threads:[~1992-06-26 2:02 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
1992-06-26 0:31 Tom Culliton x2278 [this message]
1992-06-26 2:34 ` Scott Schwartz
-- strict thread matches above, loose matches on Subject: below --
1992-06-25 22:29 Tom Culliton x2278
1992-06-25 23:35 ` Chris Siebenmann
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=9206252031.aa11853@ceres.srg.af.mil \
--to=culliton@srg.af.mil \
--cc=cks@hawkwind.utcs.toronto.edu \
--cc=rc@hawkwind.utcs.toronto.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).