148940Sbostic /*- 2*60721Sbostic * Copyright (c) 1991, 1993 3*60721Sbostic * The Regents of the University of California. All rights reserved. 448940Sbostic * 548940Sbostic * %sccs.include.redist.c% 648940Sbostic */ 748940Sbostic 848940Sbostic #ifndef lint 9*60721Sbostic static char sccsid[] = "@(#)gfmt.c 8.1 (Berkeley) 05/31/93"; 1048940Sbostic #endif /* not lint */ 1148940Sbostic 1248940Sbostic #include <sys/types.h> 1359524Sbostic 1459524Sbostic #include <err.h> 1548940Sbostic #include <stdio.h> 1648940Sbostic #include <string.h> 1759524Sbostic 1848940Sbostic #include "stty.h" 1948940Sbostic #include "extern.h" 2048940Sbostic 2148940Sbostic static void gerr __P((char *)); 2248940Sbostic 2348940Sbostic void 2448940Sbostic gprint(tp, wp, ldisc) 2548940Sbostic struct termios *tp; 2648940Sbostic struct winsize *wp; 2748940Sbostic int ldisc; 2848940Sbostic { 2948940Sbostic register struct cchar *cp; 3048940Sbostic 3148940Sbostic (void)printf("gfmt1:cflag=%x:iflag=%x:lflag=%x:oflag=%x:", 3248940Sbostic tp->c_cflag, tp->c_iflag, tp->c_lflag, tp->c_oflag); 3350041Sbostic for (cp = cchars1; cp->name; ++cp) 3448940Sbostic (void)printf("%s=%x:", cp->name, tp->c_cc[cp->sub]); 3548940Sbostic (void)printf("ispeed=%d:ospeed=%d\n", cfgetispeed(tp), cfgetospeed(tp)); 3648940Sbostic } 3748940Sbostic 3848940Sbostic void 3948940Sbostic gread(tp, s) 4048940Sbostic register struct termios *tp; 4148940Sbostic char *s; 4248940Sbostic { 4348940Sbostic register char *ep, *p; 4448940Sbostic long tmp; 4548940Sbostic 4648940Sbostic #define CHK(s) (*p == s[0] && !strcmp(p, s)) 4759524Sbostic if (!(s = strchr(s, ':'))) 4848940Sbostic gerr(NULL); 4948940Sbostic for (++s; s;) { 5048940Sbostic p = strsep(&s, ":\0"); 5148940Sbostic if (!p || !*p) 5248940Sbostic break; 5359524Sbostic if (!(ep = strchr(p, '='))) 5448940Sbostic gerr(p); 5548940Sbostic *ep++ = '\0'; 5648940Sbostic (void)sscanf(ep, "%lx", &tmp); 5748940Sbostic if (CHK("cflag")) { 5848940Sbostic tp->c_cflag = tmp; 5948940Sbostic continue; 6048940Sbostic } 6148940Sbostic if (CHK("discard")) { 6248940Sbostic tp->c_cc[VDISCARD] = tmp; 6348940Sbostic continue; 6448940Sbostic } 6548940Sbostic if (CHK("dsusp")) { 6648940Sbostic tp->c_cc[VDSUSP] = tmp; 6748940Sbostic continue; 6848940Sbostic } 6948940Sbostic if (CHK("eof")) { 7048940Sbostic tp->c_cc[VEOF] = tmp; 7148940Sbostic continue; 7248940Sbostic } 7348940Sbostic if (CHK("eol")) { 7448940Sbostic tp->c_cc[VEOL] = tmp; 7548940Sbostic continue; 7648940Sbostic } 7748940Sbostic if (CHK("eol2")) { 7848940Sbostic tp->c_cc[VEOL2] = tmp; 7948940Sbostic continue; 8048940Sbostic } 8148940Sbostic if (CHK("erase")) { 8248940Sbostic tp->c_cc[VERASE] = tmp; 8348940Sbostic continue; 8448940Sbostic } 8548940Sbostic if (CHK("iflag")) { 8648940Sbostic tp->c_iflag = tmp; 8748940Sbostic continue; 8848940Sbostic } 8948940Sbostic if (CHK("intr")) { 9048940Sbostic tp->c_cc[VINTR] = tmp; 9148940Sbostic continue; 9248940Sbostic } 9348940Sbostic if (CHK("ispeed")) { 9448940Sbostic (void)sscanf(ep, "%ld", &tmp); 9548940Sbostic tp->c_ispeed = tmp; 9648940Sbostic continue; 9748940Sbostic } 9848940Sbostic if (CHK("kill")) { 9948940Sbostic tp->c_cc[VKILL] = tmp; 10048940Sbostic continue; 10148940Sbostic } 10248940Sbostic if (CHK("lflag")) { 10348940Sbostic tp->c_lflag = tmp; 10448940Sbostic continue; 10548940Sbostic } 10648940Sbostic if (CHK("lnext")) { 10748940Sbostic tp->c_cc[VLNEXT] = tmp; 10848940Sbostic continue; 10948940Sbostic } 11048940Sbostic if (CHK("oflag")) { 11148940Sbostic tp->c_oflag = tmp; 11248940Sbostic continue; 11348940Sbostic } 11448940Sbostic if (CHK("ospeed")) { 11548940Sbostic (void)sscanf(ep, "%ld", &tmp); 11648940Sbostic tp->c_ospeed = tmp; 11748940Sbostic continue; 11848940Sbostic } 11948940Sbostic if (CHK("quit")) { 12048940Sbostic tp->c_cc[VQUIT] = tmp; 12148940Sbostic continue; 12248940Sbostic } 12348940Sbostic if (CHK("reprint")) { 12448940Sbostic tp->c_cc[VREPRINT] = tmp; 12548940Sbostic continue; 12648940Sbostic } 12748940Sbostic if (CHK("start")) { 12848940Sbostic tp->c_cc[VSTART] = tmp; 12948940Sbostic continue; 13048940Sbostic } 13148940Sbostic if (CHK("status")) { 13248940Sbostic tp->c_cc[VSTATUS] = tmp; 13348940Sbostic continue; 13448940Sbostic } 13548940Sbostic if (CHK("stop")) { 13648940Sbostic tp->c_cc[VSTOP] = tmp; 13748940Sbostic continue; 13848940Sbostic } 13948940Sbostic if (CHK("susp")) { 14048940Sbostic tp->c_cc[VSUSP] = tmp; 14148940Sbostic continue; 14248940Sbostic } 14348940Sbostic if (CHK("werase")) { 14448940Sbostic tp->c_cc[VWERASE] = tmp; 14548940Sbostic continue; 14648940Sbostic } 14748940Sbostic gerr(p); 14848940Sbostic } 14948940Sbostic } 15048940Sbostic 15148940Sbostic static void 15248940Sbostic gerr(s) 15348940Sbostic char *s; 15448940Sbostic { 15548940Sbostic if (s) 15659524Sbostic errx(1, "illegal gfmt1 option -- %s", s); 15748940Sbostic else 15859524Sbostic errx(1, "illegal gfmt1 option"); 15948940Sbostic } 160