1*5bb1ddccSjoerg /* $NetBSD: gfmt.c,v 1.17 2011/08/29 14:51:19 joerg Exp $ */
249f0ad86Scgd
361f28255Scgd /*-
4fe5a9095Smycroft * Copyright (c) 1991, 1993, 1994
5fe5a9095Smycroft * The Regents of the University of California. All rights reserved.
661f28255Scgd *
761f28255Scgd * Redistribution and use in source and binary forms, with or without
861f28255Scgd * modification, are permitted provided that the following conditions
961f28255Scgd * are met:
1061f28255Scgd * 1. Redistributions of source code must retain the above copyright
1161f28255Scgd * notice, this list of conditions and the following disclaimer.
1261f28255Scgd * 2. Redistributions in binary form must reproduce the above copyright
1361f28255Scgd * notice, this list of conditions and the following disclaimer in the
1461f28255Scgd * documentation and/or other materials provided with the distribution.
15b5b29542Sagc * 3. Neither the name of the University nor the names of its contributors
1661f28255Scgd * may be used to endorse or promote products derived from this software
1761f28255Scgd * without specific prior written permission.
1861f28255Scgd *
1961f28255Scgd * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2061f28255Scgd * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2161f28255Scgd * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2261f28255Scgd * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2361f28255Scgd * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2461f28255Scgd * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2561f28255Scgd * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2661f28255Scgd * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2761f28255Scgd * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2861f28255Scgd * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2961f28255Scgd * SUCH DAMAGE.
3061f28255Scgd */
3161f28255Scgd
32e028842eSchristos #include <sys/cdefs.h>
3361f28255Scgd #ifndef lint
3449f0ad86Scgd #if 0
3549f0ad86Scgd static char sccsid[] = "@(#)gfmt.c 8.6 (Berkeley) 4/2/94";
3649f0ad86Scgd #else
37*5bb1ddccSjoerg __RCSID("$NetBSD: gfmt.c,v 1.17 2011/08/29 14:51:19 joerg Exp $");
3849f0ad86Scgd #endif
3961f28255Scgd #endif /* not lint */
4061f28255Scgd
41017ff093Smrg #include <sys/param.h>
42fe5a9095Smycroft
4335723768Smycroft #include <err.h>
4461f28255Scgd #include <stdio.h>
4561f28255Scgd #include <string.h>
46fe5a9095Smycroft
4761f28255Scgd #include "stty.h"
4861f28255Scgd #include "extern.h"
4961f28255Scgd
50*5bb1ddccSjoerg __dead static void gerr(char *);
51e028842eSchristos
52fe5a9095Smycroft static void
gerr(char * s)5330b25d1cSperry gerr(char *s)
54fe5a9095Smycroft {
55fe5a9095Smycroft if (s)
56fe5a9095Smycroft errx(1, "illegal gfmt1 option -- %s", s);
57fe5a9095Smycroft else
58fe5a9095Smycroft errx(1, "illegal gfmt1 option");
59fe5a9095Smycroft }
6061f28255Scgd
6161f28255Scgd void
gprint(struct termios * tp)6230b25d1cSperry gprint(struct termios *tp)
6361f28255Scgd {
644f6f2f00Sjtc const struct cchar *cp;
6561f28255Scgd
6661f28255Scgd (void)printf("gfmt1:cflag=%x:iflag=%x:lflag=%x:oflag=%x:",
6761f28255Scgd tp->c_cflag, tp->c_iflag, tp->c_lflag, tp->c_oflag);
6861f28255Scgd for (cp = cchars1; cp->name; ++cp)
6961f28255Scgd (void)printf("%s=%x:", cp->name, tp->c_cc[cp->sub]);
7061f28255Scgd (void)printf("ispeed=%d:ospeed=%d\n", cfgetispeed(tp), cfgetospeed(tp));
7161f28255Scgd }
7261f28255Scgd
7361f28255Scgd void
gread(struct termios * tp,char * s)7430b25d1cSperry gread(struct termios *tp, char *s)
7561f28255Scgd {
764f6f2f00Sjtc const struct cchar *cp;
77fe5a9095Smycroft char *ep, *p;
7861f28255Scgd long tmp;
7961f28255Scgd
80fe5a9095Smycroft if ((s = strchr(s, ':')) == NULL)
8161f28255Scgd gerr(NULL);
82fe5a9095Smycroft for (++s; s != NULL;) {
8361f28255Scgd p = strsep(&s, ":\0");
8461f28255Scgd if (!p || !*p)
8561f28255Scgd break;
86fe5a9095Smycroft if (!(ep = strchr(p, '=')))
8761f28255Scgd gerr(p);
8861f28255Scgd *ep++ = '\0';
8961f28255Scgd (void)sscanf(ep, "%lx", &tmp);
90fe5a9095Smycroft
91fe5a9095Smycroft #define CHK(s) (*p == s[0] && !strcmp(p, s))
9261f28255Scgd if (CHK("cflag")) {
9361f28255Scgd tp->c_cflag = tmp;
9461f28255Scgd continue;
9561f28255Scgd }
9661f28255Scgd if (CHK("iflag")) {
9761f28255Scgd tp->c_iflag = tmp;
9861f28255Scgd continue;
9961f28255Scgd }
10032ee4be5Schristos #ifdef BSD4_4
10161f28255Scgd if (CHK("ispeed")) {
10261f28255Scgd (void)sscanf(ep, "%ld", &tmp);
10361f28255Scgd tp->c_ispeed = tmp;
10461f28255Scgd continue;
10561f28255Scgd }
10632ee4be5Schristos #endif
10761f28255Scgd if (CHK("lflag")) {
10861f28255Scgd tp->c_lflag = tmp;
10961f28255Scgd continue;
11061f28255Scgd }
11161f28255Scgd if (CHK("oflag")) {
11261f28255Scgd tp->c_oflag = tmp;
11361f28255Scgd continue;
11461f28255Scgd }
11532ee4be5Schristos #ifdef BSD4_4
11661f28255Scgd if (CHK("ospeed")) {
11761f28255Scgd (void)sscanf(ep, "%ld", &tmp);
11861f28255Scgd tp->c_ospeed = tmp;
11961f28255Scgd continue;
12061f28255Scgd }
12132ee4be5Schristos #endif
122fe5a9095Smycroft for (cp = cchars1; cp->name != NULL; ++cp)
123e1b53126Smycroft if (CHK(cp->name)) {
124e1b53126Smycroft if (cp->sub == VMIN || cp->sub == VTIME)
12535723768Smycroft (void)sscanf(ep, "%ld", &tmp);
126e1b53126Smycroft tp->c_cc[cp->sub] = tmp;
127e1b53126Smycroft break;
12835723768Smycroft }
129fe5a9095Smycroft if (cp->name == NULL)
13061f28255Scgd gerr(p);
13161f28255Scgd }
13261f28255Scgd }
133