int tmpfil(struct tempblk *tb) { int fd; int len; size_t size_left = TMPOUTSZ - tmpout_offset; /* make sure tmp file does not already exist. */ do { len = snprintf((char *)&tmpout[tmpout_offset], size_left, "%u", serial); fd = open((char *)tmpout, O_RDWR|O_CREAT|O_EXCL, 0600); serial++; if ((serial >= UINT_MAX) || (len >= size_left)) { /* * We've already cycled through all the possible * numbers or the tmp file name is being * truncated anyway (although TMPOUTSZ should be * big enough), so start over. */ serial = 0; break; } } while ((fd == -1) && (errno == EEXIST)); if (fd != -1) { pushtemp(fd, tb); return (fd); } else failed(tmpout, badcreate); }
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; }