xref: /csrg-svn/bin/stty/gfmt.c (revision 66506)
148940Sbostic /*-
260721Sbostic  * Copyright (c) 1991, 1993
360721Sbostic  *	The Regents of the University of California.  All rights reserved.
448940Sbostic  *
548940Sbostic  * %sccs.include.redist.c%
648940Sbostic  */
748940Sbostic 
848940Sbostic #ifndef lint
9*66506Sbostic static char sccsid[] = "@(#)gfmt.c	8.4 (Berkeley) 03/28/94";
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;
44*66506Sbostic 	register struct cchar *cp;
4548940Sbostic 	long tmp;
4648940Sbostic 
47*66506Sbostic 	if ((s = strchr(s, ':')) == NULL)
4848940Sbostic 		gerr(NULL);
49*66506Sbostic 	for (++s; s != NULL;) {
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);
57*66506Sbostic 
58*66506Sbostic #define	CHK(s)	(*p == s[0] && !strcmp(p, s))
5948940Sbostic 		if (CHK("cflag")) {
6048940Sbostic 			tp->c_cflag = tmp;
6148940Sbostic 			continue;
6248940Sbostic 		}
6348940Sbostic 		if (CHK("iflag")) {
6448940Sbostic 			tp->c_iflag = tmp;
6548940Sbostic 			continue;
6648940Sbostic 		}
6748940Sbostic 		if (CHK("ispeed")) {
6848940Sbostic 			(void)sscanf(ep, "%ld", &tmp);
6948940Sbostic 			tp->c_ispeed = tmp;
7048940Sbostic 			continue;
7148940Sbostic 		}
7248940Sbostic 		if (CHK("lflag")) {
7348940Sbostic 			tp->c_lflag = tmp;
7448940Sbostic 			continue;
7548940Sbostic 		}
7648940Sbostic 		if (CHK("oflag")) {
7748940Sbostic 			tp->c_oflag = tmp;
7848940Sbostic 			continue;
7948940Sbostic 		}
8048940Sbostic 		if (CHK("ospeed")) {
8148940Sbostic 			(void)sscanf(ep, "%ld", &tmp);
8248940Sbostic 			tp->c_ospeed = tmp;
8348940Sbostic 			continue;
8448940Sbostic 		}
85*66506Sbostic 		for (cp = cchars1; cp->name != NULL; ++cp)
86*66506Sbostic 			if (CHK(cp->name)) {
87*66506Sbostic 				if (cp->sub == VMIN || cp->sub == VTIME)
88*66506Sbostic 					(void)sscanf(ep, "%ld", &tmp);
89*66506Sbostic 				tp->c_cc[cp->sub] = tmp;
90*66506Sbostic 				break;
91*66506Sbostic 			}
92*66506Sbostic 		if (cp->name == NULL)
93*66506Sbostic 			gerr(p);
9448940Sbostic 	}
9548940Sbostic }
9648940Sbostic 
9748940Sbostic static void
9848940Sbostic gerr(s)
9948940Sbostic 	char *s;
10048940Sbostic {
10148940Sbostic 	if (s)
10259524Sbostic 		errx(1, "illegal gfmt1 option -- %s", s);
10348940Sbostic 	else
10459524Sbostic 		errx(1, "illegal gfmt1 option");
10548940Sbostic }
106