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