gfmt.c revision 8855
156043Syokota/*-
256043Syokota * Copyright (c) 1991, 1993, 1994
356043Syokota *	The Regents of the University of California.  All rights reserved.
456043Syokota *
556043Syokota * Redistribution and use in source and binary forms, with or without
656043Syokota * modification, are permitted provided that the following conditions
756043Syokota * are met:
856043Syokota * 1. Redistributions of source code must retain the above copyright
956043Syokota *    notice, this list of conditions and the following disclaimer.
1056043Syokota * 2. Redistributions in binary form must reproduce the above copyright
1156043Syokota *    notice, this list of conditions and the following disclaimer in the
1256043Syokota *    documentation and/or other materials provided with the distribution.
1356043Syokota * 3. All advertising materials mentioning features or use of this software
1456043Syokota *    must display the following acknowledgement:
1556043Syokota *	This product includes software developed by the University of
1656043Syokota *	California, Berkeley and its contributors.
1756043Syokota * 4. Neither the name of the University nor the names of its contributors
1856043Syokota *    may be used to endorse or promote products derived from this software
1956043Syokota *    without specific prior written permission.
2056043Syokota *
2156043Syokota * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2256043Syokota * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2356043Syokota * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2456043Syokota * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2556043Syokota * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2656043Syokota * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2756043Syokota * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2856043Syokota * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2956043Syokota * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
3056043Syokota * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3156043Syokota * SUCH DAMAGE.
3256043Syokota *
3356043Syokota *	$Id: gfmt.c,v 1.3 1995/03/19 13:29:23 joerg Exp $
3456043Syokota */
3556043Syokota
3656043Syokota#ifndef lint
3756043Syokotastatic char sccsid[] = "@(#)gfmt.c	8.6 (Berkeley) 4/2/94";
3856043Syokota#endif /* not lint */
3956043Syokota
4056043Syokota#include <sys/types.h>
4156043Syokota
4256043Syokota#include <err.h>
4356043Syokota#include <stdio.h>
4456043Syokota#include <string.h>
4556043Syokota
4656043Syokota#include "stty.h"
4756043Syokota#include "extern.h"
4856043Syokota
4956043Syokotastatic void
5056043Syokotagerr(s)
5156043Syokota	char *s;
5256043Syokota{
5356043Syokota	if (s)
5456043Syokota		errx(1, "illegal gfmt1 option -- %s", s);
5556043Syokota	else
5656043Syokota		errx(1, "illegal gfmt1 option");
5756043Syokota}
5856043Syokota
5956043Syokotavoid
6056043Syokotagprint(tp, wp, ldisc)
6156043Syokota	struct termios *tp;
6256043Syokota	struct winsize *wp;
6356043Syokota	int ldisc;
6456043Syokota{
6556043Syokota	struct cchar *cp;
6656043Syokota
6756043Syokota	(void)printf("gfmt1:cflag=%lx:iflag=%lx:lflag=%lx:oflag=%lx:",
6856043Syokota	    tp->c_cflag, tp->c_iflag, tp->c_lflag, tp->c_oflag);
6956043Syokota	for (cp = cchars1; cp->name; ++cp)
7056043Syokota		(void)printf("%s=%x:", cp->name, tp->c_cc[cp->sub]);
7156043Syokota	(void)printf("ispeed=%ld:ospeed=%ld\n", cfgetispeed(tp), cfgetospeed(tp));
7256043Syokota}
7356043Syokota
7456043Syokotavoid
7556043Syokotagread(tp, s)
7656043Syokota	struct termios *tp;
7756043Syokota	char *s;
7856043Syokota{
7956043Syokota	struct cchar *cp;
8056043Syokota	char *ep, *p;
8156043Syokota	long tmp;
8256043Syokota
8356043Syokota	if ((s = strchr(s, ':')) == NULL)
8456043Syokota		gerr(NULL);
8556043Syokota	for (++s; s != NULL;) {
8656043Syokota		p = strsep(&s, ":\0");
8756043Syokota		if (!p || !*p)
8856043Syokota			break;
8956043Syokota		if (!(ep = strchr(p, '=')))
9056043Syokota			gerr(p);
9156043Syokota		*ep++ = '\0';
9256043Syokota		(void)sscanf(ep, "%lx", &tmp);
9356043Syokota
9456043Syokota#define	CHK(s)	(*p == s[0] && !strcmp(p, s))
9556043Syokota		if (CHK("cflag")) {
9656043Syokota			tp->c_cflag = tmp;
9756043Syokota			continue;
9856043Syokota		}
9956043Syokota		if (CHK("iflag")) {
10056043Syokota			tp->c_iflag = tmp;
10156043Syokota			continue;
10256043Syokota		}
10356043Syokota		if (CHK("ispeed")) {
10456043Syokota			(void)sscanf(ep, "%ld", &tmp);
10556043Syokota			tp->c_ispeed = tmp;
10656043Syokota			continue;
10756043Syokota		}
10856043Syokota		if (CHK("lflag")) {
10956043Syokota			tp->c_lflag = tmp;
11056043Syokota			continue;
11156043Syokota		}
11256043Syokota		if (CHK("oflag")) {
11356043Syokota			tp->c_oflag = tmp;
11456043Syokota			continue;
11556043Syokota		}
11656043Syokota		if (CHK("ospeed")) {
11756043Syokota			(void)sscanf(ep, "%ld", &tmp);
11856043Syokota			tp->c_ospeed = tmp;
11956043Syokota			continue;
12056043Syokota		}
12156043Syokota		for (cp = cchars1; cp->name != NULL; ++cp)
12256043Syokota			if (CHK(cp->name)) {
12356043Syokota				if (cp->sub == VMIN || cp->sub == VTIME)
12456043Syokota					(void)sscanf(ep, "%ld", &tmp);
12556043Syokota				tp->c_cc[cp->sub] = tmp;
12656043Syokota				break;
12756043Syokota			}
12856043Syokota		if (cp->name == NULL)
12956043Syokota			gerr(p);
13056043Syokota	}
13156043Syokota}
13256043Syokota