1: #include <stdio.h> 2: #include <ctype.h> 3: #include <sys/types.h> 4: #include <sys/stat.h> 5: #define fstat _fstat 6: 7: /* 8: * Gather -code file 9: * 10: * Code indicates the exit status. 11: * File is the primary file name. 12: * We don't deal with #include here. 13: */ 14: 15: char *pxerrs[] { 16: "NORMAL", 17: "CHR", 18: "DIVCHK", 19: "FDIVCHK", 20: "HALT", 21: "NILPTR", 22: "PASTEOF", 23: "SQRT", 24: "STKNEMP", 25: "SUBSCR", 26: "REFINAF", 27: "WRITE", 28: "CREATE", 29: "LN", 30: "BADOP", 31: "BADINUM", 32: "GOTO", 33: "CASE", 34: "SEEK", 35: "ALLOC", 36: "OUTOFMEM", 37: "CTTOT", 38: "TOODIGITS", 39: "MODCHK", 40: "BADFNUM", 41: "REMOVE", 42: "CLOSE", 43: "OPEN", 44: "ARGV", 45: "PACK", 46: "UNPACK", 47: "RANGE", 48: "ASRT", 49: "READIT", 50: "WRITEIT", 51: "BIGGIE", 52: "STLIM", 53: "STKOVFLO", 54: "INTR", 55: "FPOVFLO" 56: }; 57: 58: char *pierrs[] { 59: "AOK", 60: "ERRS", 61: "NOSTART", 62: "DIED" 63: }; 64: 65: char gatherdir[] = "/d/gather"; 66: #define GATHERID 7 67: 68: main(argc, argv) 69: int argc; 70: char *argv[]; 71: { 72: FILE *control; 73: long curtime; 74: register int c; 75: char namebuf[10]; 76: struct stat stbuf; 77: register char *cp; 78: 79: argc--, argv++; 80: if (argc != 2 || argv[0][0] != '-' || !digit(argv[0][1])) 81: exit(1); 82: if (strcmp(argv[1], "px") != 0 && freopen(argv[1], "r", stdin) == NULL) 83: exit(1); 84: if (chdir(gatherdir) < 0) 85: exit(1); 86: if (getname(getuid(), namebuf) < 0) 87: exit(1); 88: if (chdir(namebuf) < 0) 89: exit(1); 90: control = fopen("control", "a"); 91: if (control == NULL) 92: exit(1); 93: time(&curtime); 94: fstat(fileno(control), &stbuf); 95: fprintf(control, "%07D.p\t%s\t%s\t%s", stbuf.st_size, 96: decomp(argv[0], argv[1]), argv[1], ctime(&curtime)); 97: fflush(control); 98: fclose(control); 99: sprintf(namebuf, "%07D.p", stbuf.st_size); 100: if (strcmp(argv[0], "-0") == 0 || strcmp(argv[1], "px") == 0 || 101: strcmp(argv[0], "-2") == 0) 102: exit(1); 103: setuid(GATHERID); 104: if (freopen(namebuf, "w", stdout) == NULL) 105: exit(1); 106: for (;;) { 107: c = getc(stdin); 108: if (c < 0) 109: exit(0); 110: putchar(c); 111: if (ferror(stdout)) { 112: unlink(namebuf); 113: exit(1); 114: } 115: } 116: } 117: 118: any(c, cp) 119: int c; 120: char *cp; 121: { 122: 123: while (*cp) 124: if (c == *cp++) 125: return (1); 126: return (0); 127: } 128: 129: digit(c) 130: char c; 131: { 132: 133: return (c >= '0' && c <= '9'); 134: } 135: 136: decomp(cp, dp) 137: register char *cp; 138: char *dp; 139: { 140: register int i; 141: 142: if (*cp++ != '-') 143: return (--cp); 144: i = 0; 145: while (*cp) 146: i = i * 10 + *cp++ - '0'; 147: if (strcmp(dp, "px") == 0) { 148: if (i < 0 || i >= ((sizeof pxerrs) / (sizeof pxerrs[0]))) 149: return ("?????"); 150: return (pxerrs[i]); 151: } else { 152: if (i < 0 || i >= ((sizeof pierrs) / (sizeof pierrs[0]))) 153: return ("?????"); 154: return (pierrs[i]); 155: } 156: }