* Copyright (c) 1991 The Regents of the University of California.
* This code is derived from software contributed to Berkeley by
* %sccs.include.redist.c%
"@(#) Copyright (c) 1991 The Regents of the University of California.\n\
static char sccsid
[] = "@(#)main.c 5.3 (Berkeley) %G%";
STATIC
union node
*curcmd
;
STATIC
union node
*prevcmd
;
short profile_buf
[16384];
STATIC
void read_profile(char *);
STATIC
void read_profile();
* Main routine. We initialize things, parse the arguments, execute
* profiles if we're a login shell, and then call cmdloop to execute
* commands. The setjmp call sets up the location to jump to when an
* exception occurs. When an exception occurs the variable "state"
* is used to figure out how far we had gotten.
main(argc
, argv
) char **argv
; {
monitor(4, etext
, profile_buf
, sizeof profile_buf
, 50);
if (setjmp(jmploc
.loc
)) {
* When a shell procedure is executed, we raise the
* exception EXSHELLPROC to clean up before executing
if (exception
== EXSHELLPROC
) {
} else if (state
== 0 || iflag
== 0 || ! rootshell
)
&& (! attyset() || equal(termval(), "emacs"))) {
if (exception
== EXINT
) {
FORCEINTON
; /* enable interrupts */
trputs("Shell args: "); trargs(argv
);
if (argv
[0] && argv
[0][0] == '-') {
read_profile("/etc/profile");
read_profile(".profile");
if ((sflag
|| minusc
) && (shinit
= lookupvar("ENV")) != NULL
&&
if (sflag
|| minusc
== NULL
) {
state4
: /* XXX ??? - why isn't this before the "if" statement */
* Read and execute commands. "Top" is nonzero for the top level command
* loop; it turns on prompting if the shell is interactive.
TRACE(("cmdloop(%d) called\n", top
));
if (Iflag
== 0 || !top
|| numeof
>= 50)
out2str("\nUse \"exit\" to leave shell.\n");
} else if (n
!= NULL
&& nflag
== 0) {
if (exitstatus
) /*DEBUG*/
outfmt(&errout
, "Exit status 0x%X\n", exitstatus
);
popstackmark(&smark
); /* unnecessary */
* Read /etc/profile or .profile. Return on error.
if ((fd
= open(name
, O_RDONLY
)) >= 0)
* Read a file containing shell functions.
if ((fd
= open(name
, O_RDONLY
)) >= 0)
error("Can't open %s", name
);
* Take commands from a file. To be compatable we should do a path
* search for the file, but a path search doesn't make any sense.
dotcmd(argc
, argv
) char **argv
; {
if (argc
>= 2) { /* That's what SVR2 does */
setinputfile(argv
[1], 1);
exitcmd(argc
, argv
) char **argv
; {
exitstatus
= number(argv
[1]);
lccmd(argc
, argv
) char **argv
; {
* Should never be called.