1: # 2: /* 3: * set teletype modes 4: */ 5: 6: /* 7: * tty flags 8: */ 9: #define HUPCL 01 10: #define XTABS 02 11: #define LCASE 04 12: #define ECHO 010 13: #define CRMOD 020 14: #define RAW 040 15: #define ODDP 0100 16: #define EVENP 0200 17: #define ANYP 0300 18: 19: /* 20: * Delay algorithms 21: */ 22: #define CR0 0 23: #define CR1 010000 24: #define CR2 020000 25: #define CR3 030000 26: #define NL0 0 27: #define NL1 000400 28: #define NL2 001000 29: #define NL3 001400 30: #define TAB0 0 31: #define TAB1 002000 32: #define TAB2 004000 33: #define TAB3 006000 34: #define FF0 0 35: #define FF1 040000 36: #define BS0 0 37: #define BS1 0100000 38: #define ALL 0177400 39: 40: struct 41: { 42: char *string; 43: int speed; 44: } speeds[] 45: { 46: "0", (0<<8)|0, 47: "50", (1<<8)|1, 48: "75", (2<<8)|2, 49: "110", (3<<8)|3, 50: "134", (4<<8)|4, 51: "134.5",(4<<8)|4, 52: "150", (5<<8)|5, 53: "200", (6<<8)|6, 54: "300", (7<<8)|7, 55: "600", (8<<8)|8, 56: "1200", (9<<8)|9, 57: "1800", (10<<8)|10, 58: "2400", (11<<8)|11, 59: "4800", (12<<8)|12, 60: "9600", (13<<8)|13, 61: "exta", (14<<8)|14, 62: "extb", (15<<8)|15, 63: 0, 64: }; 65: struct 66: { 67: char *string; 68: int set; 69: int reset; 70: } modes[] 71: { 72: "even", 73: EVENP, 0, 74: 75: "-even", 76: 0, EVENP, 77: 78: "odd", 79: ODDP, 0, 80: 81: "-odd", 82: 0, ODDP, 83: 84: "raw", 85: RAW, 0, 86: 87: "-raw", 88: 0, RAW, 89: 90: "cooked", 91: 0, RAW, 92: 93: "-nl", 94: CRMOD, 0, 95: 96: "nl", 97: 0, CRMOD, 98: 99: "echo", 100: ECHO, 0, 101: 102: "-echo", 103: 0, ECHO, 104: 105: "LCASE", 106: LCASE, 0, 107: 108: "lcase", 109: LCASE, 0, 110: 111: "-LCASE", 112: 0, LCASE, 113: 114: "-lcase", 115: 0, LCASE, 116: 117: "-tabs", 118: XTABS, 0, 119: 120: "tabs", 121: 0, XTABS, 122: 123: "hup", 124: HUPCL, 0, 125: 126: "-hup", 127: 0, HUPCL, 128: 129: "cr0", 130: CR0, CR3, 131: 132: "cr1", 133: CR1, CR3, 134: 135: "cr2", 136: CR2, CR3, 137: 138: "cr3", 139: CR3, CR3, 140: 141: "tab0", 142: TAB0, TAB3, 143: 144: "tab1", 145: TAB1, TAB3, 146: 147: "tab2", 148: TAB2, TAB3, 149: 150: "tab3", 151: TAB3, TAB3, 152: 153: "nl0", 154: NL0, NL3, 155: 156: "nl1", 157: NL1, NL3, 158: 159: "nl2", 160: NL2, NL3, 161: 162: "nl3", 163: NL3, NL3, 164: 165: "ff0", 166: FF0, FF1, 167: 168: "ff1", 169: FF1, FF1, 170: 171: "bs0", 172: BS0, BS1, 173: 174: "bs1", 175: BS1, BS1, 176: 177: "33", 178: CR1, ALL, 179: 180: "tty33", 181: CR1, ALL, 182: 183: "37", 184: FF1+CR2+TAB1+NL1, ALL, 185: 186: "tty37", 187: FF1+CR2+TAB1+NL1, ALL, 188: 189: "05", 190: NL2, ALL, 191: 192: "vt05", 193: NL2, ALL, 194: 195: "tn", 196: CR1, ALL, 197: 198: "tn300", 199: CR1, ALL, 200: 201: "ti", 202: CR2, ALL, 203: 204: "ti700", 205: CR2, ALL, 206: 207: "tek", 208: FF1, ALL, 209: 210: 0, 211: }; 212: 213: char *arg; 214: int mode[3]; 215: 216: struct { char lobyte, hibyte; }; 217: 218: main(argc, argv) 219: char *argv[]; 220: { 221: int i; 222: 223: gtty(1, mode); 224: if(argc == 1) { 225: prmodes(); 226: exit(0); 227: } 228: while(--argc > 0) { 229: 230: arg = *++argv; 231: if (eq("ek")) 232: mode[1] = '#@'; 233: if (eq("erase")) { 234: mode[1].lobyte = **++argv; 235: argc--; 236: } 237: if (eq("kill")) { 238: mode[1].hibyte = **++argv; 239: argc--; 240: } 241: for(i=0; speeds[i].string; i++) 242: if(eq(speeds[i].string)) 243: mode[0] = speeds[i].speed; 244: for(i=0; modes[i].string; i++) 245: if(eq(modes[i].string)) { 246: mode[2] =& ~modes[i].reset; 247: mode[2] =| modes[i].set; 248: } 249: if(arg) 250: printf("unknown mode: %s\n", arg); 251: } 252: stty(1,mode); 253: } 254: 255: eq(string) 256: char *string; 257: { 258: int i; 259: 260: if(!arg) 261: return(0); 262: i = 0; 263: loop: 264: if(arg[i] != string[i]) 265: return(0); 266: if(arg[i++] != '\0') 267: goto loop; 268: arg = 0; 269: return(1); 270: } 271: 272: prmodes() 273: { 274: register m; 275: 276: if(mode[0].lobyte != mode[0].hibyte) { 277: prspeed("input speed ", mode[0].lobyte); 278: prspeed("output speed ", mode[0].hibyte); 279: } else 280: prspeed("speed ", mode[0].lobyte); 281: printf("erase = '%c'; kill = '%c'\n", mode[1].lobyte, mode[1].hibyte); 282: m = mode[2]; 283: if(m & 0200) printf("even "); 284: if(m & 0100) printf("odd "); 285: if(m & 040) printf("raw "); 286: if(m & 020) printf("-nl "); 287: if(m & 010) printf("echo "); 288: if(m & 04) printf("lcase "); 289: if(m & 02) printf("-tabs "); 290: if(m & 01) printf("hup "); 291: delay(m>>8, "nl"); 292: delay(m>>10, "tab"); 293: delay(m>>12, "cr"); 294: delay((m>>14)&1, "ff"); 295: delay((m>>15)&1, "bs"); 296: printf("\n"); 297: } 298: 299: delay(m, s) 300: char *s; 301: { 302: 303: if(m =& 3) 304: printf("%s%d ", s, m); 305: } 306: 307: int speed[] 308: { 309: 0,50,75,110,134,150,200,300,600,1200,1800,2400,4800,9600,0,0 310: }; 311: 312: prspeed(c, s) 313: { 314: 315: printf("%s%d baud\n", c, speed[s]); 316: } 317: 318: putchar(c) 319: { 320: 321: write(2, &c, 1); 322: }