From ab400c0be5577cab2a66d242183887ebbd61717f Mon Sep 17 00:00:00 2001 From: Nicholas Date: Wed, 17 Nov 2021 08:22:03 -0800 Subject: checkin --- src/cmd/rc/main.c | 42 ++++++++++++++++++++++++++++++++++-------- 1 file changed, 34 insertions(+), 8 deletions(-) (limited to 'src/cmd/rc/main.c') diff --git a/src/cmd/rc/main.c b/src/cmd/rc/main.c index 81c7b8c..337470a 100644 --- a/src/cmd/rc/main.c +++ b/src/cmd/rc/main.c @@ -15,9 +15,9 @@ Shell shell = { 0 }; // functions void -initshell(void) +initshell(int *iflag) { - if((shell.interactive=0)){ //isatty(0))){ + if((*iflag=isatty(0))){ while(tcgetpgrp(0) != (shell.pid = getpgrp())) kill(-shell.pid, SIGTTIN); @@ -27,8 +27,7 @@ initshell(void) signal(SIGTSTP, SIG_IGN); signal(SIGTTIN, SIG_IGN); signal(SIGTTOU, SIG_IGN); - /* - * NOTE: if SIGCHLD is set to SIG_IGN then + /* NOTE: if SIGCHLD is set to SIG_IGN then * 1. children that terminate do not become zombies * 2. call a to wait() will block until all children have terminated * 3. the call to wait will fail with errno == ECHILD @@ -49,20 +48,47 @@ initshell(void) // ----------------------------------------------------------------------- // main point of entry +static void +usage(void) +{ + print(shell.err, "usage: %s [-cei] [file]", argv0); + exit(2); +} + int main(int argc, char *argv[]) { + int flag; + char *exe, *cmd = nil; shell.err = openfd(2); - /* yydebug=1; */ - initenv(); initpath(); initkeywords(); - initshell(); inithistory(); + initshell(&flag); + + ARGBEGIN{ + case 'e': shell.noerror = 1; break; + case 'i': shell.interactive = 1; break; + case 'I': shell.interactive = 0; break; + case 'c': + cmd = EARGF(usage()); + panicf("not implemented"); + break; + default: + usage(); + }ARGEND; + + if(!argc){ + shell.interactive |= flag; + exe = "/dev/stdin"; + }else + exe = *argv++, argc--; + + initlexer(shell.interactive); /* enablevi(); */ - xboot(argc, argv); + xboot(exe, argc, argv); /* unreachable */ } -- cgit v1.2.1