1*19907Sdist /* 2*19907Sdist * Copyright (c) 1980 Regents of the University of California. 3*19907Sdist * All rights reserved. The Berkeley software License Agreement 4*19907Sdist * specifies the terms and conditions for redistribution. 5*19907Sdist */ 6*19907Sdist 713073Ssam #ifndef lint 8*19907Sdist char copyright[] = 9*19907Sdist "@(#) Copyright (c) 1980 Regents of the University of California.\n\ 10*19907Sdist All rights reserved.\n"; 11*19907Sdist #endif not lint 12*19907Sdist 13*19907Sdist #ifndef lint 14*19907Sdist static char sccsid[] = "@(#)stty.c 5.1 (Berkeley) 05/02/85"; 15*19907Sdist #endif not lint 16*19907Sdist 171179Sbill /* 181179Sbill * set teletype modes 191179Sbill */ 201179Sbill 211179Sbill #include <stdio.h> 2218023Sbloom #include <sys/ioctl.h> 231179Sbill 2413073Ssam struct 2513073Ssam { 261179Sbill char *string; 271179Sbill int speed; 281179Sbill } speeds[] = { 2913073Ssam "0", B0, 3013073Ssam "50", B50, 3113073Ssam "75", B75, 3213073Ssam "110", B110, 3313073Ssam "134", B134, 3413073Ssam "134.5",B134, 3513073Ssam "150", B150, 3613073Ssam "200", B200, 3713073Ssam "300", B300, 3813073Ssam "600", B600, 3913073Ssam "1200", B1200, 4013073Ssam "1800", B1800, 4113073Ssam "2400", B2400, 4213073Ssam "4800", B4800, 4313073Ssam "9600", B9600, 4413073Ssam "exta", EXTA, 4513073Ssam "19200", EXTA, 4613073Ssam "extb", EXTB, 4713073Ssam "38400", EXTB, 4813073Ssam 0, 491179Sbill }; 5013073Ssam struct 5113073Ssam { 521179Sbill char *string; 5313073Ssam int set; 5413073Ssam int reset; 5513073Ssam int lset; 5613073Ssam int lreset; 571179Sbill } modes[] = { 5813073Ssam "even", EVENP, 0, 0, 0, 5913073Ssam "-even", 0, EVENP, 0, 0, 6013073Ssam "odd", ODDP, 0, 0, 0, 6113073Ssam "-odd", 0, ODDP, 0, 0, 6213073Ssam "raw", RAW, 0, 0, 0, 6313073Ssam "-raw", 0, RAW, 0, 0, 6413073Ssam "cooked", 0, RAW, 0, 0, 6513073Ssam "-nl", CRMOD, 0, 0, 0, 6613073Ssam "nl", 0, CRMOD, 0, 0, 6713073Ssam "echo", ECHO, 0, 0, 0, 6813073Ssam "-echo", 0, ECHO, 0, 0, 6913073Ssam "LCASE", LCASE, 0, 0, 0, 7013073Ssam "lcase", LCASE, 0, 0, 0, 7113073Ssam "-LCASE", 0, LCASE, 0, 0, 7213073Ssam "-lcase", 0, LCASE, 0, 0, 7313073Ssam "-tabs", XTABS, 0, 0, 0, 7413073Ssam "tabs", 0, XTABS, 0, 0, 7513073Ssam "tandem", TANDEM, 0, 0, 0, 7613073Ssam "-tandem", 0, TANDEM, 0, 0, 7713073Ssam "cbreak", CBREAK, 0, 0, 0, 7813073Ssam "-cbreak", 0, CBREAK, 0, 0, 7913073Ssam "cr0", CR0, CR3, 0, 0, 8013073Ssam "cr1", CR1, CR3, 0, 0, 8113073Ssam "cr2", CR2, CR3, 0, 0, 8213073Ssam "cr3", CR3, CR3, 0, 0, 8313073Ssam "tab0", TAB0, XTABS, 0, 0, 8413073Ssam "tab1", TAB1, XTABS, 0, 0, 8513073Ssam "tab2", TAB2, XTABS, 0, 0, 8613073Ssam "nl0", NL0, NL3, 0, 0, 8713073Ssam "nl1", NL1, NL3, 0, 0, 8813073Ssam "nl2", NL2, NL3, 0, 0, 8913073Ssam "nl3", NL3, NL3, 0, 0, 9013073Ssam "ff0", FF0, FF1, 0, 0, 9113073Ssam "ff1", FF1, FF1, 0, 0, 9213073Ssam "bs0", BS0, BS1, 0, 0, 9313073Ssam "bs1", BS1, BS1, 0, 0, 9413073Ssam "33", CR1, ALLDELAY, 0, 0, 9513073Ssam "tty33", CR1, ALLDELAY, 0, 0, 9613073Ssam "37", FF1+CR2+TAB1+NL1, ALLDELAY, 0, 0, 9713073Ssam "tty37", FF1+CR2+TAB1+NL1, ALLDELAY, 0, 0, 9813073Ssam "05", NL2, ALLDELAY, 0, 0, 9913073Ssam "vt05", NL2, ALLDELAY, 0, 0, 10013073Ssam "tn", CR1, ALLDELAY, 0, 0, 10113073Ssam "tn300", CR1, ALLDELAY, 0, 0, 10213073Ssam "ti", CR2, ALLDELAY, 0, 0, 10313073Ssam "ti700", CR2, ALLDELAY, 0, 0, 10413073Ssam "tek", FF1, ALLDELAY, 0, 0, 10513073Ssam "crtbs", 0, 0, LCRTBS, LPRTERA, 10613073Ssam "-crtbs", 0, 0, 0, LCRTBS, 10713073Ssam "prterase", 0, 0, LPRTERA, LCRTBS+LCRTKIL+LCRTERA, 10813073Ssam "-prterase", 0, 0, 0, LPRTERA, 10913073Ssam "crterase", 0, 0, LCRTERA, LPRTERA, 11013073Ssam "-crterase", 0, 0, 0, LCRTERA, 11113073Ssam "crtkill", 0, 0, LCRTKIL, LPRTERA, 11213073Ssam "-crtkill", 0, 0, 0, LCRTKIL, 11313073Ssam "tilde", 0, 0, LTILDE, 0, 11413073Ssam "-tilde", 0, 0, 0, LTILDE, 11513073Ssam "mdmbuf", 0, 0, LMDMBUF, 0, 11613073Ssam "-mdmbuf", 0, 0, 0, LMDMBUF, 11713073Ssam "litout", 0, 0, LLITOUT, 0, 11813073Ssam "-litout", 0, 0, 0, LLITOUT, 11913073Ssam "tostop", 0, 0, LTOSTOP, 0, 12013073Ssam "-tostop", 0, 0, 0, LTOSTOP, 12113073Ssam "flusho", 0, 0, LFLUSHO, 0, 12213073Ssam "-flusho", 0, 0, 0, LFLUSHO, 12313073Ssam "nohang", 0, 0, LNOHANG, 0, 12413073Ssam "-nohang", 0, 0, 0, LNOHANG, 1259853Ssam #ifdef notdef 12613073Ssam "etxack", 0, 0, LETXACK, 0, 12713073Ssam "-etxack", 0, 0, 0, LETXACK, 1289853Ssam #endif 12913073Ssam "ctlecho", 0, 0, LCTLECH, 0, 13013073Ssam "-ctlecho", 0, 0, 0, LCTLECH, 13113073Ssam "pendin", 0, 0, LPENDIN, 0, 13213073Ssam "-pendin", 0, 0, 0, LPENDIN, 13313073Ssam "decctlq", 0, 0, LDECCTQ, 0, 13413073Ssam "-decctlq", 0, 0, 0, LDECCTQ, 13513073Ssam "noflsh", 0, 0, LNOFLSH, 0, 13613073Ssam "-noflsh", 0, 0, 0, LNOFLSH, 13713073Ssam 0, 1381179Sbill }; 1391179Sbill 14013073Ssam struct tchars tc; 14113073Ssam struct ltchars ltc; 14213073Ssam struct sgttyb mode; 14318023Sbloom struct winsize win; 14413073Ssam int lmode; 1451179Sbill int oldisc, ldisc; 1461179Sbill 1471179Sbill struct special { 1481179Sbill char *name; 1491179Sbill char *cp; 1501179Sbill char def; 1511179Sbill } special[] = { 15213073Ssam "erase", &mode.sg_erase, CERASE, 15313073Ssam "kill", &mode.sg_kill, CKILL, 15413073Ssam "intr", &tc.t_intrc, CINTR, 15513073Ssam "quit", &tc.t_quitc, CQUIT, 15613073Ssam "start", &tc.t_startc, CSTART, 15713073Ssam "stop", &tc.t_stopc, CSTOP, 15813073Ssam "eof", &tc.t_eofc, CEOF, 15913073Ssam "brk", &tc.t_brkc, CBRK, 16013073Ssam "susp", <c.t_suspc, CSUSP, 16113073Ssam "dsusp", <c.t_dsuspc, CDSUSP, 16213073Ssam "rprnt", <c.t_rprntc, CRPRNT, 16313073Ssam "flush", <c.t_flushc, CFLUSH, 16413073Ssam "werase", <c.t_werasc, CWERASE, 16513073Ssam "lnext", <c.t_lnextc, CLNEXT, 1661179Sbill 0 1671179Sbill }; 1681179Sbill char *arg; 1691179Sbill 1701179Sbill int argc; 1711179Sbill char **argv; 1721179Sbill main(iargc, iargv) 17313073Ssam char **iargv; 1741179Sbill { 1751179Sbill int i; 1761179Sbill register struct special *sp; 1771179Sbill char obuf[BUFSIZ]; 1781179Sbill 1791179Sbill setbuf(stderr, obuf); 1801179Sbill argc = iargc; 1811179Sbill argv = iargv; 18213073Ssam ioctl(1, TIOCGETP, &mode); 1831179Sbill ioctl(1, TIOCGETD, &ldisc); 1841179Sbill oldisc = ldisc; 18513073Ssam ioctl(1, TIOCGETC, &tc); 18613073Ssam ioctl(1, TIOCLGET, &lmode); 18713073Ssam ioctl(1, TIOCGLTC, <c); 18818023Sbloom ioctl(1, TIOCGWINSZ, &win); 18913073Ssam if(argc == 1) { 1901179Sbill prmodes(0); 1911179Sbill exit(0); 1921179Sbill } 1931179Sbill if (argc == 2 && !strcmp(argv[1], "all")) { 1941179Sbill prmodes(1); 1951179Sbill exit(0); 1961179Sbill } 1971179Sbill if (argc == 2 && !strcmp(argv[1], "everything")) { 1981179Sbill prmodes(2); 1991179Sbill exit(0); 2001179Sbill } 20113073Ssam /* 20213073Ssam if (argc == 2 && !strcmp(argv[1], "all")) { 20313073Ssam prmodes(2); 20413073Ssam exit(0); 20513073Ssam } 20613073Ssam */ 20713073Ssam while(--argc > 0) { 2081179Sbill arg = *++argv; 20913073Ssam if (eq("ek")){ 21013073Ssam mode.sg_erase = '#'; 21113073Ssam mode.sg_kill = '@'; 2121179Sbill continue; 2131179Sbill } 21413073Ssam if (eq("new")){ 2151179Sbill ldisc = NTTYDISC; 21613073Ssam if (ioctl(1, TIOCSETD, &ldisc)<0) 2171179Sbill perror("ioctl"); 2181179Sbill continue; 2191179Sbill } 22013073Ssam if (eq("newcrt")){ 2211179Sbill ldisc = NTTYDISC; 22213073Ssam lmode &= ~LPRTERA; 22313073Ssam lmode |= LCRTBS|LCTLECH; 22413073Ssam if (mode.sg_ospeed >= B1200) 22513073Ssam lmode |= LCRTERA|LCRTKIL; 22613073Ssam if (ioctl(1, TIOCSETD, &ldisc)<0) 2271179Sbill perror("ioctl"); 2281179Sbill continue; 2291179Sbill } 23013073Ssam if (eq("crt")){ 23113073Ssam lmode &= ~LPRTERA; 23213073Ssam lmode |= LCRTBS|LCTLECH; 23313073Ssam if (mode.sg_ospeed >= B1200) 23413073Ssam lmode |= LCRTERA|LCRTKIL; 2351179Sbill continue; 2361179Sbill } 23713073Ssam if (eq("old")){ 23813073Ssam ldisc = 0; 23913073Ssam if (ioctl(1, TIOCSETD, &ldisc)<0) 2401179Sbill perror("ioctl"); 2411179Sbill continue; 2421179Sbill } 24313073Ssam if (eq("dec")){ 24413073Ssam mode.sg_erase = 0177; 24513073Ssam mode.sg_kill = CTRL(u); 24613073Ssam tc.t_intrc = CTRL(c); 2473797Sroot ldisc = NTTYDISC; 24813073Ssam lmode &= ~LPRTERA; 24913073Ssam lmode |= LCRTBS|LCTLECH|LDECCTQ; 25013073Ssam if (mode.sg_ospeed >= B1200) 25113073Ssam lmode |= LCRTERA|LCRTKIL; 25213073Ssam if (ioctl(1, TIOCSETD, &ldisc)<0) 2533797Sroot perror("ioctl"); 2543797Sroot continue; 2553797Sroot } 2561179Sbill for (sp = special; sp->name; sp++) 2571179Sbill if (eq(sp->name)) { 2581179Sbill if (--argc == 0) 2591179Sbill goto done; 2601179Sbill if (**++argv == 'u') 2611179Sbill *sp->cp = 0377; 2621179Sbill else if (**argv == '^') 2633955Sroot *sp->cp = ((*argv)[1] == '?') ? 2641179Sbill 0177 : (*argv)[1] & 037; 2651179Sbill else 2661179Sbill *sp->cp = **argv; 2671179Sbill goto cont; 2681179Sbill } 2691179Sbill if (eq("gspeed")) { 27013073Ssam mode.sg_ispeed = B300; 27113073Ssam mode.sg_ospeed = B9600; 2721179Sbill continue; 2731179Sbill } 2741179Sbill if (eq("hup")) { 27513073Ssam ioctl(1, TIOCHPCL, NULL); 2761179Sbill continue; 2771179Sbill } 27818023Sbloom if (eq("rows")) { 27918023Sbloom if (--argc == 0) 28018023Sbloom goto done; 28118023Sbloom win.ws_row = atoi(*++argv); 28218023Sbloom } 28318023Sbloom if (eq("columns")) { 28418023Sbloom if (--argc == 0) 28518023Sbloom goto done; 28618023Sbloom win.ws_col = atoi(*++argv); 28718023Sbloom } 28813073Ssam for(i=0; speeds[i].string; i++) 28913073Ssam if(eq(speeds[i].string)) { 29013073Ssam mode.sg_ispeed = mode.sg_ospeed = speeds[i].speed; 2911179Sbill goto cont; 2921179Sbill } 2931179Sbill if (eq("speed")) { 29413073Ssam ioctl(open("/dev/tty", 0), TIOCGETP, &mode); 29513073Ssam for(i=0; speeds[i].string; i++) 29613073Ssam if (mode.sg_ospeed == speeds[i].speed) { 2971179Sbill printf("%s\n", speeds[i].string); 2981179Sbill exit(0); 2991179Sbill } 3001179Sbill printf("unknown\n"); 3011179Sbill exit(1); 3021179Sbill } 30313073Ssam for(i=0; modes[i].string; i++) 30413073Ssam if(eq(modes[i].string)) { 30513073Ssam mode.sg_flags &= ~modes[i].reset; 30613073Ssam mode.sg_flags |= modes[i].set; 30713073Ssam lmode &= ~modes[i].lreset; 30813073Ssam lmode |= modes[i].lset; 3091179Sbill } 31013073Ssam if(arg) 3111179Sbill fprintf(stderr,"unknown mode: %s\n", arg); 3121179Sbill cont: 3131179Sbill ; 3141179Sbill } 3151179Sbill done: 31613073Ssam ioctl(1, TIOCSETN, &mode); 31713073Ssam ioctl(1, TIOCSETC, &tc); 31813073Ssam ioctl(1, TIOCSLTC, <c); 31913073Ssam ioctl(1, TIOCLSET, &lmode); 32018023Sbloom ioctl(1, TIOCSWINSZ, &win); 3211179Sbill } 3221179Sbill 3231179Sbill eq(string) 32413073Ssam char *string; 3251179Sbill { 3261179Sbill int i; 3271179Sbill 32813073Ssam if(!arg) 32913073Ssam return(0); 3301179Sbill i = 0; 3311179Sbill loop: 33213073Ssam if(arg[i] != string[i]) 3331179Sbill return(0); 33413073Ssam if(arg[i++] != '\0') 3351179Sbill goto loop; 3361179Sbill arg = 0; 33713073Ssam return(1); 3381179Sbill } 3391179Sbill 3401179Sbill prmodes(all) 3411179Sbill { 3421179Sbill register m; 3431179Sbill int any; 3441179Sbill 34513073Ssam if(ldisc==NETLDISC) 3461179Sbill fprintf(stderr, "net discipline, "); 34713073Ssam else if(ldisc==NTTYDISC) 3481179Sbill fprintf(stderr, "new tty, "); 34913073Ssam else if(all==2) 3501179Sbill fprintf(stderr, "old tty, "); 35113073Ssam if(mode.sg_ispeed != mode.sg_ospeed) { 35213073Ssam prspeed("input speed ", mode.sg_ispeed); 35313073Ssam prspeed("output speed ", mode.sg_ospeed); 3541179Sbill } else 35513073Ssam prspeed("speed ", mode.sg_ispeed); 35618023Sbloom if (all) 35718023Sbloom fprintf(stderr, ", %d rows, %d columns", win.ws_row, win.ws_col); 35813073Ssam fprintf(stderr, all==2 ? "\n" : "; "); 35913073Ssam m = mode.sg_flags; 36013073Ssam if(all==2 || (m&(EVENP|ODDP))!=(EVENP|ODDP)) { 36113073Ssam if(m & EVENP) fprintf(stderr,"even "); 36213073Ssam if(m & ODDP) fprintf(stderr,"odd "); 3631179Sbill } 36413073Ssam if(all==2 || m&RAW) 36513073Ssam fprintf(stderr,"-raw "+((m&RAW)!=0)); 36613073Ssam if(all==2 || (m&CRMOD)==0) 36713073Ssam fprintf(stderr,"-nl "+((m&CRMOD)==0)); 36813073Ssam if(all==2 || (m&ECHO)==0) 36913073Ssam fprintf(stderr,"-echo "+((m&ECHO)!=0)); 37013073Ssam if(all==2 || (m&LCASE)) 37113073Ssam fprintf(stderr,"-lcase "+((m&LCASE)!=0)); 37213073Ssam if(all==2 || (m&TANDEM)) 37313073Ssam fprintf(stderr,"-tandem "+((m&TANDEM)!=0)); 37413073Ssam fprintf(stderr,"-tabs "+((m&XTABS)!=XTABS)); 37513073Ssam if(all==2 || (m&CBREAK)) 37613073Ssam fprintf(stderr,"-cbreak "+((m&CBREAK)!=0)); 37713073Ssam if(all==2 || (m&NLDELAY)) 37813073Ssam delay((m&NLDELAY)/NL1, "nl"); 37913073Ssam if ((m&TBDELAY)!=XTABS) 38013073Ssam delay((m&TBDELAY)/TAB1, "tab"); 38113073Ssam if(all==2 || (m&CRDELAY)) 38213073Ssam delay((m&CRDELAY)/CR1, "cr"); 38313073Ssam if(all==2 || (m&VTDELAY)) 38413073Ssam delay((m&VTDELAY)/FF1, "ff"); 38513073Ssam if(all==2 || (m&BSDELAY)) 38613073Ssam delay((m&BSDELAY)/BS1, "bs"); 3871179Sbill if (all) 3881179Sbill fprintf(stderr,"\n"); 3891179Sbill #define lpit(what,str) \ 39013073Ssam if (all==2||(lmode&what)) { \ 39113073Ssam fprintf(stderr,str+((lmode&what)!=0)); any++; \ 3921179Sbill } 3931179Sbill if (ldisc == NTTYDISC) { 39413073Ssam int newcrt = (lmode&(LCTLECH|LCRTBS)) == (LCTLECH|LCRTBS) && 39513073Ssam (lmode&(LCRTERA|LCRTKIL)) == 39613073Ssam ((mode.sg_ospeed > B300) ? LCRTERA|LCRTKIL : 0); 39713817Ssam int nothing = 1; 3981179Sbill if (newcrt) { 39913073Ssam if (all==2) 40013073Ssam fprintf(stderr, "crt: (crtbs crterase crtkill ctlecho) "); 40113073Ssam else 40213073Ssam fprintf(stderr, "crt "); 4031179Sbill any++; 4041179Sbill } else { 40513073Ssam lpit(LCRTBS, "-crtbs "); 40613073Ssam lpit(LCRTERA, "-crterase "); 40713073Ssam lpit(LCRTKIL, "-crtkill "); 40813073Ssam lpit(LCTLECH, "-ctlecho "); 40913073Ssam lpit(LPRTERA, "-prterase "); 4101179Sbill } 41113073Ssam lpit(LTOSTOP, "-tostop "); 41213073Ssam if (all==2) { 4131179Sbill fprintf(stderr, "\n"); 4141179Sbill any = 0; 41513817Ssam nothing = 0; 4161179Sbill } 41713073Ssam lpit(LTILDE, "-tilde "); 41813073Ssam lpit(LFLUSHO, "-flusho "); 41913073Ssam lpit(LMDMBUF, "-mdmbuf "); 42013073Ssam lpit(LLITOUT, "-litout "); 42113073Ssam lpit(LNOHANG, "-nohang "); 4224017Sroot if (any) { 4234017Sroot fprintf(stderr,"\n"); 4244017Sroot any = 0; 42513817Ssam nothing = 0; 4264017Sroot } 4279853Ssam #ifdef notdef 42813073Ssam lpit(LETXACK, "-etxack "); 4299853Ssam #endif 43013073Ssam lpit(LPENDIN, "-pendin "); 43113073Ssam lpit(LDECCTQ, "-decctlq "); 43213073Ssam lpit(LNOFLSH, "-noflsh "); 43313817Ssam if (any || nothing) 4341179Sbill fprintf(stderr,"\n"); 4351179Sbill } else if (!all) 4361179Sbill fprintf(stderr,"\n"); 4371179Sbill if (all) { 4381179Sbill switch (ldisc) { 4391179Sbill 4401179Sbill case 0: 4411179Sbill fprintf(stderr,"\ 4421179Sbill erase kill intr quit stop eof\ 4431179Sbill \n"); 44413073Ssam pcol(mode.sg_erase, -1); 44513073Ssam pcol(mode.sg_kill, -1); 44613073Ssam pcol(tc.t_intrc, -1); 44713073Ssam pcol(tc.t_quitc, -1); 44813073Ssam pcol(tc.t_stopc, tc.t_startc); 44913073Ssam pcol(tc.t_eofc, tc.t_brkc); 4501179Sbill fprintf(stderr,"\n"); 4511179Sbill break; 4521179Sbill 4531179Sbill case NTTYDISC: 4541179Sbill fprintf(stderr,"\ 4551179Sbill erase kill werase rprnt flush lnext susp intr quit stop eof\ 4561179Sbill \n"); 45713073Ssam pcol(mode.sg_erase, -1); 45813073Ssam pcol(mode.sg_kill, -1); 45913073Ssam pcol(ltc.t_werasc, -1); 46013073Ssam pcol(ltc.t_rprntc, -1); 46113073Ssam pcol(ltc.t_flushc, -1); 46213073Ssam pcol(ltc.t_lnextc, -1); 46313073Ssam pcol(ltc.t_suspc, ltc.t_dsuspc); 46413073Ssam pcol(tc.t_intrc, -1); 46513073Ssam pcol(tc.t_quitc, -1); 46613073Ssam pcol(tc.t_stopc, tc.t_startc); 46713073Ssam pcol(tc.t_eofc, tc.t_brkc); 4681179Sbill fprintf(stderr,"\n"); 4691179Sbill break; 4701179Sbill } 4711179Sbill } else if (ldisc != NETLDISC) { 4721179Sbill register struct special *sp; 4731179Sbill int first = 1; 47413817Ssam 4751179Sbill for (sp = special; sp->name; sp++) { 4761179Sbill if ((*sp->cp&0377) != (sp->def&0377)) { 4771179Sbill pit(*sp->cp, sp->name, first ? "" : ", "); 4781179Sbill first = 0; 4791179Sbill }; 48013073Ssam if (sp->cp == &tc.t_brkc && ldisc == 0) 4811179Sbill break; 4821179Sbill } 48313817Ssam if (!first) 48413073Ssam fprintf(stderr, "\n"); 4851179Sbill } 4861179Sbill } 4871179Sbill 4881179Sbill pcol(ch1, ch2) 4891179Sbill int ch1, ch2; 4901179Sbill { 4911179Sbill int nout = 0; 4921179Sbill 4931179Sbill ch1 &= 0377; 4941179Sbill ch2 &= 0377; 4951179Sbill if (ch1 == ch2) 4961179Sbill ch2 = 0377; 4971179Sbill for (; ch1 != 0377 || ch2 != 0377; ch1 = ch2, ch2 = 0377) { 4981179Sbill if (ch1 == 0377) 4991179Sbill continue; 5001179Sbill if (ch1 & 0200) { 5011179Sbill fprintf(stderr, "M-"); 5021179Sbill nout += 2; 5031179Sbill ch1 &= ~ 0200; 5041179Sbill } 5051179Sbill if (ch1 == 0177) { 5061179Sbill fprintf(stderr, "^"); 5071179Sbill nout++; 5081179Sbill ch1 = '?'; 5091179Sbill } else if (ch1 < ' ') { 5101179Sbill fprintf(stderr, "^"); 5111179Sbill nout++; 5121179Sbill ch1 += '@'; 5131179Sbill } 5141179Sbill fprintf(stderr, "%c", ch1); 5151179Sbill nout++; 5161179Sbill if (ch2 != 0377) { 5171179Sbill fprintf(stderr, "/"); 5181179Sbill nout++; 5191179Sbill } 5201179Sbill } 5211179Sbill while (nout < 7) { 5221179Sbill fprintf(stderr, " "); 5231179Sbill nout++; 5241179Sbill } 5251179Sbill } 5261179Sbill 5271179Sbill pit(what, itsname, sep) 5281179Sbill unsigned what; 5291179Sbill char *itsname, *sep; 5301179Sbill { 5311179Sbill 5321179Sbill what &= 0377; 5331179Sbill fprintf(stderr, "%s%s", sep, itsname); 5341179Sbill if (what == 0377) { 5351179Sbill fprintf(stderr, " <undef>"); 5361179Sbill return; 5371179Sbill } 5381179Sbill fprintf(stderr, " = "); 5391179Sbill if (what & 0200) { 5401179Sbill fprintf(stderr, "M-"); 5411179Sbill what &= ~ 0200; 5421179Sbill } 5431179Sbill if (what == 0177) { 5441179Sbill fprintf(stderr, "^"); 5451179Sbill what = '?'; 5461179Sbill } else if (what < ' ') { 5471179Sbill fprintf(stderr, "^"); 5481179Sbill what += '@'; 5491179Sbill } 5501179Sbill fprintf(stderr, "%c", what); 5511179Sbill } 5521179Sbill 5531179Sbill delay(m, s) 55413073Ssam char *s; 5551179Sbill { 5561179Sbill 55713073Ssam if(m) 5581179Sbill fprintf(stderr,"%s%d ", s, m); 5591179Sbill } 5601179Sbill 5611179Sbill int speed[] = { 5626815Swnj 0,50,75,110,134,150,200,300,600,1200,1800,2400,4800,9600,19200,38400 5631179Sbill }; 5641179Sbill 5651179Sbill prspeed(c, s) 5661179Sbill char *c; 5671179Sbill { 5681179Sbill 5691179Sbill fprintf(stderr,"%s%d baud", c, speed[s]); 5701179Sbill } 571