|
|
1.1 ! root 1: #include "hdr.h" ! 2: ! 3: int debug; ! 4: int vfd; ! 5: int incmd; ! 6: int logfd; ! 7: char **inptr, *inpptr; ! 8: extern int yydebug; ! 9: extern tfn(), Tfn(); ! 10: ! 11: main(int argc, char **argv) ! 12: { ! 13: #pragma ref argc ! 14: int quiet = 0; ! 15: char *remote = "/cs/dk!2500rem"; ! 16: ! 17: fmtinstall('t', tfn); ! 18: fmtinstall('T', Tfn); ! 19: logfd = open("/dev/null", 1); ! 20: for(argv++; argv[0][0] == '-'; argv++) ! 21: switch(argv[0][1]) ! 22: { ! 23: case 'l': ! 24: logfd = creat("2500.log", 0666); break; ! 25: case 'D': ! 26: ++debug; break; ! 27: case 'q': ! 28: quiet = 1; break; ! 29: } ! 30: if(*argv){ ! 31: incmd = 1; ! 32: inptr = argv; ! 33: inpptr = *inptr; ! 34: } else ! 35: incmd = 0; ! 36: if(debug){ ! 37: vfd = open("/dev/null", 2); ! 38: } else { ! 39: if((vfd = ipcopen(remote, "light")) < 0){ ! 40: Fprint(2, "can't open %s\n", remote); ! 41: exit(1); ! 42: } ! 43: /* ioctl(vfd, TIOCFLUSH, (char *)0);*/ ! 44: } ! 45: if(!quiet){ ! 46: locenable(); ! 47: status(0); ! 48: frame(0xFF); ! 49: } ! 50: while(yyparse()) ! 51: fprint(2, "parse errors!\n"); ! 52: exit(0); ! 53: } ! 54: ! 55: cmd(int cnt, char *str, char *res, char *fmt, int args) ! 56: { ! 57: static char buf[64]; ! 58: char *out; ! 59: register i, sum; ! 60: int cm, n; ! 61: int rn; ! 62: extern char *doprint(); ! 63: ! 64: out = doprint(buf, fmt, (char *)&args); ! 65: n = out-buf; ! 66: buf[0] &= 0xf0; ! 67: buf[0] |= n-2; ! 68: cm = buf[0]; ! 69: for(i = sum = 0; i < n; i++) ! 70: sum += buf[i]; ! 71: if(n < 2){ ! 72: fprint(2, "%ux: cmd too small[%d]\n", cm, n); ! 73: return(-1); ! 74: } ! 75: if(n > 17){ ! 76: fprint(2, "%ux: cmd too big[%d]\n", cm, n); ! 77: return(-1); ! 78: } ! 79: buf[n++] = sum; ! 80: if(write(vfd, buf, n) != n){ ! 81: perror("write"); ! 82: return(-1); ! 83: } ! 84: if(res == 0) ! 85: res = buf; ! 86: if(!debug){ ! 87: i = read(vfd, res, 64); ! 88: if(i < 0){ ! 89: perror("XTTY read"); ! 90: return(-1); ! 91: } ! 92: rn = (res[0]&0xF)+3; ! 93: while(i < rn){ ! 94: int j; ! 95: j = read(vfd, &res[i], rn-i); ! 96: if(j < 0) break; ! 97: i += j; ! 98: } ! 99: if((res[0] == 0x10) && (res[1] == 0x01) && (res[2] == 0x11)){ /* ack */ ! 100: if(cnt){ ! 101: fprint(2, "%s: got ack, expected %d data bytes\n", cnt); ! 102: return(-1); ! 103: } ! 104: } else if((res[0] == 0x11) && (res[1] == 0x12)){ ! 105: fprint(2, "%s: NAK on cmd %2.2ux:", str, cm); ! 106: if(res[2]&0x80) fprint(2, " timeout"); ! 107: if(res[2]&0x40) fprint(2, " framing"); ! 108: if(res[2]&0x20) fprint(2, " overrun"); ! 109: if(res[2]&0x10) fprint(2, " parity"); ! 110: if(res[2]&0x04) fprint(2, " checksum"); ! 111: if(res[2]&0x01) fprint(2, " undefined command"); ! 112: fprint(2, "\n"); ! 113: return(-1); ! 114: } else if(i != (cnt+3)){ ! 115: fprint(2, "%s: got %d data bytes, expected %d\n", str, i-3, cnt); ! 116: return(-1); ! 117: } ! 118: if(i != (res[0]&0xF)+3){ ! 119: fprint(2, "%s: urk! got %d bytes, pkt says %d:", str, ! 120: i, (res[0]&0xF)+3); ! 121: for(n = 0; n < i; n++) fprint(2, " 0x%2.2x", res[n]&0xFF); ! 122: fprint(2, "\n"); ! 123: return(-1); ! 124: } ! 125: } ! 126: return(0); ! 127: } ! 128: ! 129: getc() ! 130: { ! 131: register c; ! 132: ! 133: if(incmd){ ! 134: if(inpptr == 0) ! 135: return(-1); ! 136: if((c = *inpptr++) == 0){ ! 137: c = '\n'; ! 138: inpptr = *++inptr; ! 139: } ! 140: } else ! 141: c = Fgetc(0); ! 142: if(c >= 0) ! 143: Fputc(logfd, c); ! 144: else ! 145: Fprint(logfd, "<<EOF>>\n"); ! 146: return(c); ! 147: } ! 148: ! 149: tfn(t, f1, f2, f3) ! 150: Time *t; ! 151: { ! 152: #pragma ref f2 ! 153: #pragma ref f3 ! 154: #define T(x) BYTE(((x)&0xFF)/10, ((x)&0xFF)%10) ! 155: ! 156: chconv(T(t->f), f1); ! 157: chconv(T(t->s), f1); ! 158: chconv(T(t->m), f1); ! 159: chconv(T(t->h), f1); ! 160: return(sizeof *t); ! 161: } ! 162: ! 163: Tfn(t, f1, f2, f3) ! 164: Time *t; ! 165: { ! 166: #pragma ref f3 ! 167: char buf[20]; ! 168: ! 169: sprint(buf, "%d.%d.%d.%d", t->h, t->m, t->s, t->f); ! 170: strconv(buf, f1, f2); ! 171: return(sizeof *t); ! 172: } ! 173: ! 174: help() ! 175: { ! 176: extern char *helpstrs[]; ! 177: char **h; ! 178: ! 179: for(h = helpstrs; *h; h++) ! 180: Fprint(1, "%s\n", *h); ! 181: Fprint(1, "!unix cmd\n"); ! 182: Fprint(1, "\ttimes are s|s.f|m.s.f|h.m.s.f\n"); ! 183: Fprint(1, "\tchannels are one or more of audio[123]|video\n"); ! 184: Fprint(1, "\tall input is lower case; comments start with #; cmds sep by ;|\\n\n"); ! 185: Fflush(1); ! 186: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.