// run theorem prover on a file int runatp(const List<Tuple<String, String> > &expandedfiles) { // check phases if (!phases[EXPANDFILE] || !phases[PARSEFILE]) { cout << endl; cout << "Skipping parsing ..." << endl; } // run prover on expanded files ListIterator<Tuple<String, String> > xfIter(expandedfiles); for ( ; !xfIter.done(); xfIter++) { // get input and expanded file names String infile(xfIter().key); String exfile(xfIter().data); cout << endl; cout << "Parsing input file ... " << infile << endl; if (verbose) { cout << "Parsing expanded file ... " << exfile << endl; } programstatistics[TotalFilesRead] += 1; // reset syntax errors counter for this file syntaxErrors = 0; // open file to read if ((yyin = fopen((const char *)exfile, "r")) == NULL) { ERRORD("unable to read.", exfile, errno); return(NOTOK); } // check syntax of program if (yyparse() != OK) { ERRORD(String("yyparse failed for ...")+infile, syntaxErrors, errno); fclose(yyin); yyin = NULL; return(NOTOK); } // close file. fclose(yyin); yyin = NULL; // clear out semantic structures scope.clear(); symbols.clear(); ptrees.clear(); } // all done return(OK); }
int sh_source(Shell_t *shp, Sfio_t *iop, const char *file) { char* oid; char* nid; int fd; if (!file || !*file || (fd = path_open(shp,file, PATHCOMP)) < 0) { REGRESS(source, "sh_source", ("%s:ENOENT", file)); return 0; } oid = error_info.id; nid = error_info.id = strdup(file); shp->st.filename = path_fullname(shp,stakptr(PATH_OFFSET)); REGRESS(source, "sh_source", ("%s", file)); exfile(shp, iop, fd); error_info.id = oid; free(nid); return 1; }
void commands(void) { int *a1, c, temp; char lastsep; Dir *d; for(;;) { if(pflag) { pflag = 0; addr1 = addr2 = dot; printcom(); } c = '\n'; for(addr1 = 0;;) { lastsep = c; a1 = address(); c = getchr(); if(c != ',' && c != ';') break; if(lastsep == ',') error(Q); if(a1 == 0) { a1 = zero+1; if(a1 > dol) a1--; } addr1 = a1; if(c == ';') dot = a1; } if(lastsep != '\n' && a1 == 0) a1 = dol; if((addr2=a1) == 0) { given = 0; addr2 = dot; } else given = 1; if(addr1 == 0) addr1 = addr2; switch(c) { case 'a': add(0); continue; case 'b': nonzero(); browse(); continue; case 'c': nonzero(); newline(); rdelete(addr1, addr2); append(gettty, addr1-1); continue; case 'd': nonzero(); newline(); rdelete(addr1, addr2); continue; case 'E': fchange = 0; c = 'e'; case 'e': setnoaddr(); if(vflag && fchange) { fchange = 0; error(Q); } filename(c); init(); addr2 = zero; goto caseread; case 'f': setnoaddr(); filename(c); putst(savedfile); continue; case 'g': global(1); continue; case 'i': add(-1); continue; case 'j': if(!given) addr2++; newline(); join(); continue; case 'k': nonzero(); c = getchr(); if(c < 'a' || c > 'z') error(Q); newline(); names[c-'a'] = *addr2 & ~01; anymarks |= 01; continue; case 'm': move(0); continue; case 'n': listn++; newline(); printcom(); continue; case '\n': if(a1==0) { a1 = dot+1; addr2 = a1; addr1 = a1; } if(lastsep==';') addr1 = a1; printcom(); continue; case 'l': listf++; case 'p': case 'P': newline(); printcom(); continue; case 'Q': fchange = 0; case 'q': setnoaddr(); newline(); quit(); case 'r': filename(c); caseread: if((io=open(file, OREAD)) < 0) { lastc = '\n'; error(file); } if((d = dirfstat(io)) != nil){ if(d->mode & DMAPPEND) print("warning: %s is append only\n", file); free(d); } Binit(&iobuf, io, OREAD); setwide(); squeeze(0); c = zero != dol; append(getfile, addr2); exfile(OREAD); fchange = c; continue; case 's': nonzero(); substitute(globp != 0); continue; case 't': move(1); continue; case 'u': nonzero(); newline(); if((*addr2&~01) != subnewa) error(Q); *addr2 = subolda; dot = addr2; continue; case 'v': global(0); continue; case 'W': wrapp++; case 'w': setwide(); squeeze(dol>zero); temp = getchr(); if(temp != 'q' && temp != 'Q') { peekc = temp; temp = 0; } filename(c); if(!wrapp || ((io = open(file, OWRITE)) == -1) || ((seek(io, 0L, 2)) == -1)) if((io = create(file, OWRITE, 0666)) < 0) error(file); Binit(&iobuf, io, OWRITE); wrapp = 0; if(dol > zero) putfile(); exfile(OWRITE); if(addr1<=zero+1 && addr2==dol) fchange = 0; if(temp == 'Q') fchange = 0; if(temp) quit(); continue; case '=': setwide(); squeeze(0); newline(); count = addr2 - zero; putd(); putchr('\n'); continue; case '!': callunix(); continue; case EOF: return; } error(Q); } }
int main(int c, char *v[], char *e[]) { int rflag = ttyflg; int rsflag = 1; /* local restricted flag */ unsigned char *flagc = flagadr; struct namnod *n; mypid = getpid(); mypgid = getpgid(mypid); mysid = getsid(mypid); /* * Do locale processing only if /usr is mounted. */ localedir_exists = (access(localedir, F_OK) == 0); /* * initialize storage allocation */ if (stakbot == 0) { addblok((unsigned)0); } /* * If the first character of the last path element of v[0] is "-" * (ex. -sh, or /bin/-sh), this is a login shell */ if (*simple(v[0]) == '-') { signal(SIGXCPU, SIG_DFL); signal(SIGXFSZ, SIG_DFL); /* * As the previous comment states, this is a login shell. * Therefore, we set the login_shell flag to explicitly * indicate this condition. */ login_shell = TRUE; } stdsigs(); /* * set names from userenv */ setup_env(); /* * LC_MESSAGES is set here so that early error messages will * come out in the right style. * Note that LC_CTYPE is done later on and is *not* * taken from the previous environ */ /* * Do locale processing only if /usr is mounted. */ if (localedir_exists) (void) setlocale(LC_ALL, ""); #if !defined(TEXT_DOMAIN) /* Should be defined by cc -D */ #define TEXT_DOMAIN "SYS_TEST" /* Use this only if it weren't */ #endif (void) textdomain(TEXT_DOMAIN); /* * 'rsflag' is zero if SHELL variable is * set in environment and * the simple file part of the value. * is rsh */ if (n = findnam("SHELL")) { if (eq("rsh", simple(n->namval))) rsflag = 0; } /* * a shell is also restricted if the simple name of argv(0) is * rsh or -rsh in its simple name */ #ifndef RES if (c > 0 && (eq("rsh", simple(*v)) || eq("-rsh", simple(*v)))) rflag = 0; #endif if (eq("jsh", simple(*v)) || eq("-jsh", simple(*v))) flags |= monitorflg; hcreate(); set_dotpath(); /* * look for options * dolc is $# */ dolc = options(c, v); if (dolc < 2) { flags |= stdflg; { while (*flagc) flagc++; *flagc++ = STDFLG; *flagc = 0; } } if ((flags & stdflg) == 0) dolc--; if ((flags & privflg) == 0) { uid_t euid; gid_t egid; uid_t ruid; gid_t rgid; /* * Determine all of the user's id #'s for this process and * then decide if this shell is being entered as a result * of a fork/exec. * If the effective uid/gid do NOT match and the euid/egid * is < 100 and the egid is NOT 1, reset the uid and gid to * the user originally calling this process. */ euid = geteuid(); ruid = getuid(); egid = getegid(); rgid = getgid(); if ((euid != ruid) && (euid < 100)) setuid(ruid); /* reset the uid to the orig user */ if ((egid != rgid) && ((egid < 100) && (egid != 1))) setgid(rgid); /* reset the gid to the orig user */ } dolv = (unsigned char **)v + c - dolc; dolc--; /* * return here for shell file execution * but not for parenthesis subshells */ if (setjmp(subshell)) { freejobs(); flags |= subsh; } /* * number of positional parameters */ replace(&cmdadr, dolv[0]); /* cmdadr is $0 */ /* * set pidname '$$' */ assnum(&pidadr, (long)mypid); /* * set up temp file names */ settmp(); /* * default internal field separators * Do not allow importing of IFS from parent shell. * setup_env() may have set anything from parent shell to IFS. * Always set the default ifs to IFS. */ assign(&ifsnod, (unsigned char *)sptbnl); dfault(&mchknod, MAILCHECK); mailchk = stoi(mchknod.namval); /* initialize OPTIND for getopt */ n = lookup("OPTIND"); assign(n, (unsigned char *)"1"); /* * make sure that option parsing starts * at first character */ _sp = 1; if ((beenhere++) == FALSE) /* ? profile */ { if ((login_shell == TRUE) && (flags & privflg) == 0) { /* system profile */ #ifndef RES if ((input = pathopen(nullstr, sysprofile)) >= 0) exfile(rflag); /* file exists */ #endif /* user profile */ if ((input = pathopen(homenod.namval, profile)) >= 0) { exfile(rflag); flags &= ~ttyflg; } } if (rsflag == 0 || rflag == 0) { if ((flags & rshflg) == 0) { while (*flagc) flagc++; *flagc++ = 'r'; *flagc = '\0'; } flags |= rshflg; } /* * open input file if specified */ if (comdiv) { estabf(comdiv); input = -1; } else { if (flags & stdflg) { input = 0; } else { /* * If the command file specified by 'cmdadr' * doesn't exist, chkopen() will fail calling * exitsh(). If this is a login shell and * the $HOME/.profile file does not exist, the * above statement "flags &= ~ttyflg" does not * get executed and this makes exitsh() call * longjmp() instead of exiting. longjmp() will * return to the location specified by the last * active jmpbuffer, which is the one set up in * the function exfile() called after the system * profile file is executed (see lines above). * This would cause an infinite loop, because * chkopen() will continue to fail and exitsh() * to call longjmp(). To make exitsh() exit instead * of calling longjmp(), we then set the flag forcexit * at this stage. */ flags |= forcexit; input = chkopen(cmdadr, 0); flags &= ~forcexit; } #ifdef ACCT if (input != 0) preacct(cmdadr); #endif comdiv--; } } #ifdef pdp11 else *execargs = (char *)dolv; /* for `ps' cmd */ #endif exfile(0); done(0); }
static void commands(void) { register Line_t* a1; register int c; register int n; char* s; int lastsep; for (;;) { trap(); if (ed.print & (REG_SUB_LIST|REG_SUB_NUMBER|REG_SUB_PRINT)) { ed.addr1 = ed.addr2 = ed.dot; print(); } if (!ed.global) { ed.evented = 0; if (ed.prompt > 0) sfputr(ed.msg, sfstrbase(ed.buffer.prompt), -1); } if ((c = getchr()) == ',' || c == ';') { ed.given = 1; ed.addr1 = (lastsep = c) == ',' ? ed.zero + 1 : ed.dot; a1 = ed.dol; c = getchr(); } else { ed.addr1 = 0; ed.peekc = c; c = '\n'; for (;;) { lastsep = c; a1 = address(); c = getchr(); if (c != ',' && c != ';') break; if (lastsep == ',') error(2, "invalid address"); if (!a1) { a1 = ed.zero + 1; if (a1 > ed.dol) a1--; } ed.addr1 = a1; if (c == ';') ed.dot = a1; } if (lastsep != '\n' && !a1) a1 = ed.dol; } if (!(ed.addr2 = a1)) { ed.given = 0; ed.addr2 = ed.dot; } else ed.given = 1; if (!ed.addr1) ed.addr1 = ed.addr2; switch (c) { case 'a': add(0); continue; case 'c': nonzero(); newline(); rdelete(ed.addr1, ed.addr2); append(getline, ed.addr1 - 1, NiL); continue; case 'd': nonzero(); newline(); rdelete(ed.addr1, ed.addr2); continue; case 'E': ed.modified = 0; c = 'e'; /*FALLTHROUGH*/ case 'e': setnoaddr(); if (ed.verbose && ed.modified) { ed.modified = 0; error(2, "modified data not written"); } /*FALLTHROUGH*/ case 'r': filename(c); setwide(); squeeze(0); c = ed.zero != ed.dol; append(getfile, ed.addr2, NiL); ed.modified = c; exfile(); continue; case 'f': setnoaddr(); filename(c); putrec(sfstrbase(ed.buffer.file)); continue; case 'G': global(1, 1); continue; case 'g': global(1, 0); continue; case 'H': ed.help = !ed.help; /*FALLTHROUGH*/ case 'h': setnoaddr(); newline(); if (ed.help || c == 'h') sfputr(ed.msg, sfstrbase(ed.buffer.help), '\n'); continue; case 'i': add(-1); continue; case 'j': if (!ed.given) ed.addr2++; newline(); join(); continue; case 'k': nonzero(); if ((c = getchr()) == EOF || (c -= MARK_MIN) < 0 || c >= elementsof(ed.marks)) error(2, "invalid mark"); newline(); ed.addr2->offset |= LINE_MARKED; ed.marks[c] = ed.addr2->offset & ~LINE_GLOBAL; ed.marked = 1; continue; case 'm': move(0); continue; case 'n': ed.print |= REG_SUB_NUMBER; newline(); print(); continue; case '\n': if (!a1) { a1 = ed.dot + 1; ed.addr2 = a1; ed.addr1 = a1; } if (lastsep == ';') ed.addr1 = a1; print(); continue; case 'l': ed.print |= REG_SUB_LIST; /*FALLTHROUGH*/ case 'p': newline(); print(); continue; case 'P': setnoaddr(); s = getrec(ed.buffer.line, '\n', 0); if (*s || !(ed.prompt = -ed.prompt) && (s = "*")) { sfstrseek(ed.buffer.prompt, 0, SEEK_SET); sfputr(ed.buffer.prompt, s, 0); ed.prompt = 1; } continue; case 'Q': ed.modified = 0; /*FALLTHROUGH*/ case 'q': setnoaddr(); newline(); quit(0); continue; case 'S': setnoaddr(); newline(); s = strchr(usage, '\n') + 5; sfprintf(ed.msg, "file=\"%s\"%s%s%s prompt=\"%s\" tmp=%lu%s event=%lu version=\"%-.*s\"\n", sfstrbase(ed.buffer.file), ed.modified ? " modified" : "", ed.help ? " help" : "", ed.verbose ? " verbose" : "", sfstrbase(ed.buffer.prompt), ed.tmpoff, ed.tmpoff > BLOCK_TMP ? "[file]" : "", ed.event, strchr(s, '\n') - s, s); continue; case 's': nonzero(); substitute(ed.global != 0); continue; case 't': move(1); continue; case 'u': setnoaddr(); newline(); undo(); continue; case 'V': global(0, 1); continue; case 'v': global(0, 0); continue; case 'W': case 'w': setwide(); squeeze(ed.dol > ed.zero); if ((n = getchr()) != 'q' && n != 'Q') { ed.peekc = n; n = 0; } filename(c); if (ed.dol > ed.zero) putfile(); exfile(); if (n == 'Q' || ed.addr1 <= ed.zero + 1 && ed.addr2 == ed.dol) ed.modified = 0; if (n) quit(0); continue; case 'z': nonzero(); page(); continue; case '=': setwide(); squeeze(0); newline(); sfprintf(ed.msg, "%d\n", ed.addr2 - ed.zero); continue; case '!': if (ed.restricted) error(2, "%c: restricted command", c); shell(); continue; case '#': setnoaddr(); getrec(ed.buffer.line, '\n', REC_IGNORE); continue; case EOF: return; } error(2, "unknown command"); } }
static void shell(void) { register char* s; register char* f = 0; register int c; if (ed.given) squeeze(ed.dol > ed.zero); s = getrec(ed.buffer.line, '\n', 0); if (s[0] == '!' && !s[1]) { if (!*sfstrbase(ed.buffer.shell)) error(2, "no saved shell command"); f = sfstrbase(ed.buffer.file); } else if (!s[0]) error(2, "empty shell command"); else SWP(ed.buffer.shell, ed.buffer.line); s = sfstrbase(ed.buffer.shell); sfstrseek(ed.buffer.line, 0, SEEK_SET); sfputc(ed.buffer.line, '!'); while (c = *s++) { if (c == '\\') { if (*s != '%') sfputc(ed.buffer.line, c); sfputc(ed.buffer.line, *s++); } else if (c == '%') sfputr(ed.buffer.line, f = sfstrbase(ed.buffer.file), -1); else sfputc(ed.buffer.line, c); } if (ed.given) { if (!ed.tmpfile && !(ed.tmpfile = pathtemp(NiL, 0, NiL, error_info.id, NiL))) error(ERROR_SYSTEM|2, "cannot generate temp file name"); if (!(ed.iop = sfopen(NiL, ed.tmpfile, "w"))) error(ERROR_SYSTEM|2, "%s: cannot create temp file", ed.tmpfile); error_info.file = ed.tmpfile; if (ed.dol > ed.zero) putfile(); exfile(); ed.bytes = 0; ed.lines = 0; sfprintf(ed.buffer.line, " < %s", ed.tmpfile); if (!(s = sfstruse(ed.buffer.line))) error(ERROR_SYSTEM|3, "out of space"); if (!(ed.iop = sfpopen(NiL, s + 1, "r"))) error(ERROR_SYSTEM|2, "%s: cannot execute shell command", s); error_info.file = s; rdelete(ed.addr1, ed.addr2); append(getfile, ed.dot, NiL); exfile(); remove(ed.tmpfile); } else { if (!(s = sfstruse(ed.buffer.line))) error(ERROR_SYSTEM|3, "out of space"); s++; if (f) putrec(s); if (!(ed.iop = sfpopen(NiL, s, ""))) error(ERROR_SYSTEM|2, "%s: cannot execute shell command", s); if (sfclose(ed.iop)) { ed.iop = 0; error(ERROR_SYSTEM|2, "%s: shell command exit error", s); } if (ed.verbose) putrec("!"); } }
int main(int c, const char *v[]) { register int rflag = ttyflg; /* initialise storage allocation */ blokinit(); stdsigs(); setbrk(BRKINCR); addblok((POS) 0); /* set names from userenv */ sh_getenv(); /* look for restricted */ /* if(c>0 && any('r', *v) ) { rflag=0 ;} */ /* look for options */ dolc = options(c, v); if (dolc < 2) flags |= stdflg; if ((flags & stdflg) == 0) dolc--; dolv = v + c - dolc; dolc--; /* return here for shell file execution */ setjmp(subshell); /* number of positional parameters */ assnum(&dolladr, dolc); cmdadr = (char *)dolv[0]; /* set pidname */ assnum(&pidadr, getpid()); /* set up temp file names */ settmp(); /* default ifs */ dfault(&ifsnod, sptbnl); if ((beenhere++) == FALSE) { /* ? profile */ if (*cmdadr == '-' && (input = pathopen(nullstr, profile)) >= 0) { exfile(rflag); flags &= ~ttyflg; ; } if (rflag == 0) { flags |= rshflg; } /* open input file if specified */ if (comdiv) { estabf(comdiv); input = -1; } else { input = ((flags & stdflg) ? 0 : chkopen(cmdadr)); comdiv--; ; } // } else { *execargs=(char *)dolv; /* for `ps' cmd */ ; } exfile(0); done(); }