static void comsubst(void) { /* command substn */ FILEBLK cb; register char d; register STKPTR savptr = fixstak(); usestak(); while ((d = readc()) != SQUOTE && d) pushstak(d); { register char *argc; trim(argc = fixstak()); push(&cb); estabf(argc); } { register TREPTR t = makefork(FPOU, cmd(EOFSYM, MTFLG | NLFLG)); int pv[2]; /* this is done like this so that the pipe * is open only when needed */ chkpipe(pv); initf(pv[INPIPE]); execute(t, 0, 0, pv); close(pv[OTPIPE]); } tdystak(savptr); staktop = movstr(savptr, stakbot); while (d = readc()) pushstak(d | quote); await(0); while (stakbot != staktop) { if ((*--staktop & STRIP) != NL) { ++staktop; break; } } pop(); }
static void exfile(int prof) { time_t mailtime = 0; /* Must not be a register variable */ time_t curtime = 0; /* * move input */ if (input > 0) { Ldup(input, INIO); input = INIO; } setmode(prof); if (setjmp(errshell) && prof) { close(input); (void) endjobs(0); return; } /* * error return here */ loopcnt = peekc = peekn = 0; fndef = 0; nohash = 0; iopend = 0; if (input >= 0) initf(input); /* * command loop */ for (;;) { tdystak(0); stakchk(); /* may reduce sbrk */ exitset(); if ((flags & prompt) && standin->fstak == 0 && !eof) { if (mailp) { time(&curtime); if ((curtime - mailtime) >= mailchk) { chkmail(); mailtime = curtime; } } /* necessary to print jobs in a timely manner */ if (trapnote & TRAPSET) chktrap(); prs(ps1nod.namval); #ifdef TIME_OUT alarm(TIMEOUT); #endif } trapnote = 0; peekc = readwc(); if (eof) { if (endjobs(JOB_STOPPED)) return; eof = 0; } #ifdef TIME_OUT alarm(0); #endif { struct trenod *t; t = cmd(NL, MTFLG); if (t == NULL && flags & ttyflg) freejobs(); else execute(t, 0, eflag); } eof |= (flags & oneflg); } }
static void exfile(BOOL prof) { register L_INT mailtime = 0; register int userid; struct stat statb; /* move input */ if (input > 0) { Ldup(input, INIO); input = INIO; } /* move output to safe place */ if (output == 2) { Ldup(dup(2), OTIO); output = OTIO; } userid = getuid(); /* decide whether interactive */ if ((flags & intflg) || ((flags & oneflg) == 0 && isatty(output) && isatty(input))) { dfault(&ps1nod, (userid ? stdprompt : supprompt)); dfault(&ps2nod, readmsg); flags |= ttyflg | prompt; ignsig(KILL); } else { flags |= prof; flags &= ~prompt; } if (setjmp(errshell) && prof) { close(input); return; } /* error return here */ loopcnt = breakcnt = peekc = 0; iopend = 0; if (input >= 0) initf(input); /* command loop */ for (;;) { tdystak(0); stakchk(); /* may reduce sbrk */ exitset(); if ((flags & prompt) && standin->fstak == 0 && !eof) { if (mailnod.namval && stat(mailnod.namval, &statb) >= 0 && statb.st_size && (statb.st_mtime != mailtime) && mailtime) { prs(mailmsg); } mailtime = statb.st_mtime; prs(ps1nod.namval); alarm(TIMEOUT); flags |= waiting; } trapnote = 0; peekc = readc(); if (eof) return; alarm(0); flags &= ~waiting; execute(cmd(NL, MTFLG), 0, NULL, NULL); eof |= (flags & oneflg); } }