int main(void) { int c; readline(); while ((c = get_c()) != '\n') { switch (c){ case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': unget_c(); readn(); break; case '+': case '-': /* 遇到加减法时,先读入下一组数字,再存入运算符号 */ readn(); pushstr(c); break; case '*': case '/': /* 遇到乘除法时,现把当前的预算符出栈,存入操作数,再存入乘除符号 */ pushtemp(popstr()); readn(); pushstr(c); pushstr(poptemp()); /* 原先的预算符号进栈 */ default: break; } } /* 输出逆波兰数序 */ pushstr('\0'); printf("%s\n", str); return 0; }
/* * service routines for `execute' */ short initio(struct ionod *iop, int save) { unsigned char *ion; int iof, fd; int ioufd; short lastfd; int newmode; lastfd = topfd; while (iop) { iof = iop->iofile; ion = mactrim(iop->ioname); ioufd = iof & IOUFD; if (*ion && (flags&noexec) == 0) { if (save) { fdmap[topfd].org_fd = ioufd; fdmap[topfd++].dup_fd = savefd(ioufd); } if (iof & IODOC) { struct tempblk tb; subst(chkopen(ion, 0), (fd = tmpfil(&tb))); /* * pushed in tmpfil() -- * bug fix for problem with * in-line scripts */ poptemp(); fd = chkopen(tmpout, 0); unlink((const char *)tmpout); } else if (iof & IOMOV) { if (eq(minus, ion)) { fd = -1; close(ioufd); } else if ((fd = stoi(ion)) >= USERIO) { failed(ion, badfile); } else fd = dup(fd); } else if (((iof & IOPUT) == 0) && ((iof & IORDW) == 0)) fd = chkopen(ion, 0); else if (iof & IORDW) /* For <> */ { newmode = O_RDWR|O_CREAT; fd = chkopen(ion, newmode); } else if (flags & rshflg) { failed(ion, restricted); } else if (iof & IOAPP && (fd = open((char *)ion, 1)) >= 0) { lseek(fd, (off_t)0, SEEK_END); } else { fd = create(ion); } if (fd >= 0) renamef(fd, ioufd); } iop = iop->ionxt; } return (lastfd); }
void copy(struct ionod *ioparg) { unsigned char *cline; unsigned char *clinep; struct ionod *iop; unsigned int c; unsigned char *ends; unsigned char *start; int fd; int i; int stripflg; unsigned char *pc; if (iop = ioparg) { struct tempblk tb; copy(iop->iolst); ends = mactrim(iop->ioname); stripflg = iop->iofile & IOSTRIP; if (nosubst) iop->iofile &= ~IODOC; fd = tmpfil(&tb); if (fndef) iop->ioname = (char *) make(tmpout); else iop->ioname = (char *) cpystak(tmpout); iop->iolst = iotemp; iotemp = iop; cline = clinep = start = locstak(); if (stripflg) { iop->iofile &= ~IOSTRIP; while (*ends == '\t') ends++; } for (;;) { chkpr(); if (nosubst) { c = readwc(); if (stripflg) while (c == '\t') c = readwc(); while (!eolchar(c)) { pc = readw(c); while (*pc) { if (clinep >= brkend) growstak(clinep); *clinep++ = *pc++; } c = readwc(); } }else{ c = nextwc(); if (stripflg) while (c == '\t') c = nextwc(); while (!eolchar(c)) { pc = readw(c); while (*pc) { if (clinep >= brkend) growstak(clinep); *clinep++ = *pc++; } if (c == '\\') { pc = readw(readwc()); /* *pc might be NULL */ if (*pc) { while (*pc) { if (clinep >= brkend) growstak(clinep); *clinep++ = *pc++; } } else { if (clinep >= brkend) growstak(clinep); *clinep++ = *pc; } } c = nextwc(); } } if (clinep >= brkend) growstak(clinep); *clinep = 0; if (eof || eq(cline, ends)) { if ((i = cline - start) > 0) write(fd, start, i); break; }else{ if (clinep >= brkend) growstak(clinep); *clinep++ = NL; } if ((i = clinep - start) < CPYSIZ) cline = clinep; else { write(fd, start, i); cline = clinep = start; } } poptemp(); /* * pushed in tmpfil -- bug fix for problem * deleting in-line scripts */ } }