ash internals: evalstring() calls

Alex Martelli alex at am.sublink.org
Wed Mar 27 07:26:22 AEST 1991


dfenyes at thesis1.med.uth.tmc.edu (David Fenyes) writes:
:Ash is certainly an undersold shell;  for its power and flexibility,
I fully agree...

:I added a command line editor & history.  I want to be able to expand
:variables in PS1, and also execute the contents of the variable EVERY
:befor each prompt.  To do this, I call the function evalstring in eval.c.
:This works perfectly for valid expressions, but if there is a syntax error,
:the shell goes into an infinite loop, reporting the error endlessly.

Here's the relevant portion from mash, my own ash dialect:

		handler = &jmploc;
		TRACE(("putprompt(%s)\n", prompter));
		if (setjmp(jmploc.loc)) {
			TRACE(("putprompt error recovery\n"));
			popstackmark(&smark);
			popfile();
			p = 0;
		} else {
			setstackmark(&smark);
			evalstring(prompter);
			popstackmark(&smark);
			p = lookupvar("__P");
		}

where "prompter" is a string I build up by catting __P=" in front of
lookupvar("PS1"), and " after that.
BTW, as a reminder for others, ash and atty are available in volume 19
of comp.sources.unix, and are very interesting to study as a possibly
optimal design point in the complexity/function tradeoff for shells.
Just a pity that atty ain't easy to integrate into most Unices... so
we all build history and line editing into each of our shells and
interactive programs... hafta look into shared libraries one day...:-)
-- 
Alex Martelli - (home snailmail:) v. Barontini 27, 40138 Bologna, ITALIA
Email: (work:) martelli at cadlab.sublink.org, (home:) alex at am.sublink.org
Phone: (work:) ++39 (51) 371099, (home:) ++39 (51) 250434; 
Fax: ++39 (51) 366964 (work only), Fidonet: 332/401.3 (home only).



More information about the Comp.unix.shell mailing list