rc-list - mailing list for the rc(1) shell
 help / color / mirror / Atom feed
* Re: Another little challenge
@ 1992-06-26  0:31 Tom Culliton x2278
  1992-06-26  2:34 ` Scott Schwartz
  0 siblings, 1 reply; 4+ messages in thread
From: Tom Culliton x2278 @ 1992-06-26  0:31 UTC (permalink / raw)
  To: cks, rc

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 $*
}}


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

* Re: Another little challenge
  1992-06-26  0:31 Another little challenge Tom Culliton x2278
@ 1992-06-26  2:34 ` Scott Schwartz
  0 siblings, 0 replies; 4+ messages in thread
From: Scott Schwartz @ 1992-06-26  2:34 UTC (permalink / raw)
  To: Tom Culliton x2278; +Cc: rc


| # 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.

Here's where Unix really loses: malappropriate delimiters all over the
place.  If "whatis" would print an \0 between entries, you could use
that to split them.  That assumes ifs can deal with \0, and that \0
won't otherwise appear in the output from whatis. (ifs='' seems to work;
probably as a side effect of nul terminated strings.)  Lisp really wins
because the read primative can properly interpret whatever the write
primative generates.


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

* Re: Another little challenge
  1992-06-25 22:29 Tom Culliton x2278
@ 1992-06-25 23:35 ` Chris Siebenmann
  0 siblings, 0 replies; 4+ messages in thread
From: Chris Siebenmann @ 1992-06-25 23:35 UTC (permalink / raw)
  To: rc

 You can't run something on every subshell, but you can run something
on every interactive subshell. For the people who weren't around for
my discovery process of this last year:
	fn prompt { if (! ~ $cpid $pid) {cpid=$pid; ... } }
This will let you run something every time a new interactive shell
starts up and runs prompt.

	- cks


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

* Another little challenge
@ 1992-06-25 22:29 Tom Culliton x2278
  1992-06-25 23:35 ` Chris Siebenmann
  0 siblings, 1 reply; 4+ messages in thread
From: Tom Culliton x2278 @ 1992-06-25 22:29 UTC (permalink / raw)
  To: rc

While I've got your brains working it seems like a good time to re-ask
a question that never got answered before.

There is no hook in rc to have something done when a child shell is
started.  (like ksh's ENV variable)  Has anyone come up with a way to
do something like this?  What inspired this is firing off a new xterm
running rc and wanting to set certain things.  (stty, etc.)  You can do
some of the stty type stuff, but not all of it, using command line
options, or you can make every xterm call rc as a login shell which has
other problems.  It seems like this is something which needs a good
general purpose solution.  Any ideas?

Tom


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

end of thread, other threads:[~1992-06-26  2:35 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1992-06-26  0:31 Another little challenge Tom Culliton x2278
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

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).