xref: /csrg-svn/bin/stty/gfmt.c (revision 66642)
148940Sbostic /*-
2*66642Spendry  * Copyright (c) 1991, 1993, 1994
360721Sbostic  *	The Regents of the University of California.  All rights reserved.
448940Sbostic  *
548940Sbostic  * %sccs.include.redist.c%
648940Sbostic  */
748940Sbostic 
848940Sbostic #ifndef lint
9*66642Spendry static char sccsid[] = "@(#)gfmt.c	8.6 (Berkeley) 04/02/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 
2166564Spendry static void
gerr(s)2266564Spendry gerr(s)
2366564Spendry 	char *s;
2466564Spendry {
2566564Spendry 	if (s)
2666564Spendry 		errx(1, "illegal gfmt1 option -- %s", s);
2766564Spendry 	else
2866564Spendry 		errx(1, "illegal gfmt1 option");
2966564Spendry }
3048940Sbostic 
3148940Sbostic void
gprint(tp,wp,ldisc)3248940Sbostic gprint(tp, wp, ldisc)
3348940Sbostic 	struct termios *tp;
3448940Sbostic 	struct winsize *wp;
3548940Sbostic 	int ldisc;
3648940Sbostic {
3766564Spendry 	struct cchar *cp;
3848940Sbostic 
3948940Sbostic 	(void)printf("gfmt1:cflag=%x:iflag=%x:lflag=%x:oflag=%x:",
4048940Sbostic 	    tp->c_cflag, tp->c_iflag, tp->c_lflag, tp->c_oflag);
4150041Sbostic 	for (cp = cchars1; cp->name; ++cp)
4248940Sbostic 		(void)printf("%s=%x:", cp->name, tp->c_cc[cp->sub]);
4348940Sbostic 	(void)printf("ispeed=%d:ospeed=%d\n", cfgetispeed(tp), cfgetospeed(tp));
4448940Sbostic }
4548940Sbostic 
4648940Sbostic void
gread(tp,s)4748940Sbostic gread(tp, s)
4866564Spendry 	struct termios *tp;
4948940Sbostic 	char *s;
5048940Sbostic {
5166564Spendry 	struct cchar *cp;
5266564Spendry 	char *ep, *p;
5348940Sbostic 	long tmp;
5448940Sbostic 
5566506Sbostic 	if ((s = strchr(s, ':')) == NULL)
5648940Sbostic 		gerr(NULL);
5766506Sbostic 	for (++s; s != NULL;) {
5848940Sbostic 		p = strsep(&s, ":\0");
5948940Sbostic 		if (!p || !*p)
6048940Sbostic 			break;
6159524Sbostic 		if (!(ep = strchr(p, '=')))
6248940Sbostic 			gerr(p);
6348940Sbostic 		*ep++ = '\0';
6448940Sbostic 		(void)sscanf(ep, "%lx", &tmp);
6566506Sbostic 
6666506Sbostic #define	CHK(s)	(*p == s[0] && !strcmp(p, s))
6748940Sbostic 		if (CHK("cflag")) {
6848940Sbostic 			tp->c_cflag = tmp;
6948940Sbostic 			continue;
7048940Sbostic 		}
7148940Sbostic 		if (CHK("iflag")) {
7248940Sbostic 			tp->c_iflag = tmp;
7348940Sbostic 			continue;
7448940Sbostic 		}
7548940Sbostic 		if (CHK("ispeed")) {
7648940Sbostic 			(void)sscanf(ep, "%ld", &tmp);
7748940Sbostic 			tp->c_ispeed = tmp;
7848940Sbostic 			continue;
7948940Sbostic 		}
8048940Sbostic 		if (CHK("lflag")) {
8148940Sbostic 			tp->c_lflag = tmp;
8248940Sbostic 			continue;
8348940Sbostic 		}
8448940Sbostic 		if (CHK("oflag")) {
8548940Sbostic 			tp->c_oflag = tmp;
8648940Sbostic 			continue;
8748940Sbostic 		}
8848940Sbostic 		if (CHK("ospeed")) {
8948940Sbostic 			(void)sscanf(ep, "%ld", &tmp);
9048940Sbostic 			tp->c_ospeed = tmp;
9148940Sbostic 			continue;
9248940Sbostic 		}
9366506Sbostic 		for (cp = cchars1; cp->name != NULL; ++cp)
9466506Sbostic 			if (CHK(cp->name)) {
9566506Sbostic 				if (cp->sub == VMIN || cp->sub == VTIME)
9666506Sbostic 					(void)sscanf(ep, "%ld", &tmp);
9766506Sbostic 				tp->c_cc[cp->sub] = tmp;
9866506Sbostic 				break;
9966506Sbostic 			}
10066506Sbostic 		if (cp->name == NULL)
10166506Sbostic 			gerr(p);
10248940Sbostic 	}
10348940Sbostic }
104