+ tempv[1][0] = '\0';
+ tempv[1][1] = '\0';
+ tempv[1] = NULL;
+ for (tcp = *tempv; *tcp++;);
+ for (tcp--; tcp >= *tempv; tcp--)
+ tcp[1] = tcp[0];
+ *++tcp = '-';
+ argc--;
+ }
+ if (loginsh)
+ (void) time(&chktim);
+
+ AsciiOnly = 1;
+#ifdef NLS
+ (void) setlocale(LC_ALL, "");
+ {
+ int k;
+
+ for (k = 0200; k <= 0377 && !Isprint(k); k++);
+ AsciiOnly = k > 0377;
+ }
+#else
+ AsciiOnly = getenv("LANG") == NULL && getenv("LC_CTYPE") == NULL;
+#endif /* NLS */
+
+ /*
+ * Move the descriptors to safe places. The variable didfds is 0 while we
+ * have only FSH* to work with. When didfds is true, we have 0,1,2 and
+ * prefer to use these.
+ */
+ initdesc();
+
+ /*
+ * Initialize the shell variables. ARGV and PROMPT are initialized later.
+ * STATUS is also munged in several places. CHILD is munged when
+ * forking/waiting
+ */
+ set(STRstatus, Strsave(STR0));
+
+ if ((tcp = getenv("HOME")) != (char *) 0)
+ cp = SAVE(tcp);
+ else
+ cp = NULL;
+
+ if (cp == NULL)
+ fast = 1; /* No home -> can't read scripts */
+ else
+ set(STRhome, cp);
+ dinit(cp); /* dinit thinks that HOME == cwd in a login
+ * shell */
+ /*
+ * Grab other useful things from the environment. Should we grab
+ * everything??
+ */
+ if ((tcp = getenv("LOGNAME")) != (char *) 0 ||
+ (tcp = getenv("USER")) != (char *) 0)
+ set(STRuser, SAVE(tcp));
+ if ((tcp = getenv("TERM")) != (char *) 0)
+ set(STRterm, SAVE(tcp));
+
+ /*
+ * Re-initialize path if set in environment
+ */
+ if ((tcp = getenv("PATH")) == (char *) 0)
+ set1(STRpath, defaultpath(), &shvhed);
+ else
+ importpath(SAVE(tcp));
+
+ set(STRshell, Strsave(STR_SHELLPATH));
+
+ doldol = putn((int) getpid()); /* For $$ */
+ shtemp = Strspl(STRtmpsh, doldol); /* For << */
+
+ /*
+ * Record the interrupt states from the parent process. If the parent is
+ * non-interruptible our hand must be forced or we (and our children) won't
+ * be either. Our children inherit termination from our parent. We catch it
+ * only if we are the login shell.
+ */
+ /* parents interruptibility */
+ (void) sigvec(SIGINT, (struct sigvec *) 0, &osv);
+ parintr = (void (*) ()) osv.sv_handler;
+ (void) sigvec(SIGTERM, (struct sigvec *) 0, &osv);
+ parterm = (void (*) ()) osv.sv_handler;
+
+ if (loginsh) {
+ (void) signal(SIGHUP, phup); /* exit processing on HUP */
+ (void) signal(SIGXCPU, phup); /* ...and on XCPU */
+ (void) signal(SIGXFSZ, phup); /* ...and on XFSZ */
+ }
+
+ /*
+ * Process the arguments.
+ *
+ * Note that processing of -v/-x is actually delayed till after script
+ * processing.
+ *
+ * We set the first character of our name to be '-' if we are a shell running
+ * interruptible commands. Many programs which examine ps'es use this to
+ * filter such shells out.
+ */
+ argc--, tempv++;
+ while (argc > 0 && (tcp = tempv[0])[0] == '-' && *++tcp != '\0' && !batch) {
+ do
+ switch (*tcp++) {
+
+ case 0: /* - Interruptible, no prompt */
+ prompt = 0;
+ setintr = 1;
+ nofile = 1;
+ break;
+
+ case 'b': /* -b Next arg is input file */
+ batch = 1;
+ break;
+
+ case 'c': /* -c Command input from arg */
+ if (argc == 1)
+ xexit(0);
+ argc--, tempv++;
+ arginp = SAVE(tempv[0]);
+ prompt = 0;
+ nofile = 1;
+ break;