2003-08-07 13:05:01 +04:00
|
|
|
/* $NetBSD: gfmt.c,v 1.16 2003/08/07 09:05:41 agc Exp $ */
|
1995-03-21 12:01:59 +03:00
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
/*-
|
1994-09-20 08:52:02 +04:00
|
|
|
* Copyright (c) 1991, 1993, 1994
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
1993-03-21 12:45:37 +03:00
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
2003-08-07 13:05:01 +04:00
|
|
|
* 3. Neither the name of the University nor the names of its contributors
|
1993-03-21 12:45:37 +03:00
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
1997-07-21 01:28:26 +04:00
|
|
|
#include <sys/cdefs.h>
|
1993-03-21 12:45:37 +03:00
|
|
|
#ifndef lint
|
1995-03-21 12:01:59 +03:00
|
|
|
#if 0
|
|
|
|
static char sccsid[] = "@(#)gfmt.c 8.6 (Berkeley) 4/2/94";
|
|
|
|
#else
|
2003-08-07 13:05:01 +04:00
|
|
|
__RCSID("$NetBSD: gfmt.c,v 1.16 2003/08/07 09:05:41 agc Exp $");
|
1995-03-21 12:01:59 +03:00
|
|
|
#endif
|
1993-03-21 12:45:37 +03:00
|
|
|
#endif /* not lint */
|
|
|
|
|
1999-06-10 18:59:50 +04:00
|
|
|
#include <sys/param.h>
|
1994-09-20 08:52:02 +04:00
|
|
|
|
1994-03-23 07:05:23 +03:00
|
|
|
#include <err.h>
|
1993-03-21 12:45:37 +03:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
1994-09-20 08:52:02 +04:00
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
#include "stty.h"
|
|
|
|
#include "extern.h"
|
|
|
|
|
2003-06-16 21:22:00 +04:00
|
|
|
static void gerr(char *);
|
1997-07-21 01:28:26 +04:00
|
|
|
|
1994-09-20 08:52:02 +04:00
|
|
|
static void
|
2003-06-16 21:22:00 +04:00
|
|
|
gerr(char *s)
|
1994-09-20 08:52:02 +04:00
|
|
|
{
|
|
|
|
if (s)
|
|
|
|
errx(1, "illegal gfmt1 option -- %s", s);
|
|
|
|
else
|
|
|
|
errx(1, "illegal gfmt1 option");
|
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
void
|
2003-06-16 21:22:00 +04:00
|
|
|
gprint(struct termios *tp)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1996-05-07 22:20:05 +04:00
|
|
|
const struct cchar *cp;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
(void)printf("gfmt1:cflag=%x:iflag=%x:lflag=%x:oflag=%x:",
|
|
|
|
tp->c_cflag, tp->c_iflag, tp->c_lflag, tp->c_oflag);
|
|
|
|
for (cp = cchars1; cp->name; ++cp)
|
|
|
|
(void)printf("%s=%x:", cp->name, tp->c_cc[cp->sub]);
|
|
|
|
(void)printf("ispeed=%d:ospeed=%d\n", cfgetispeed(tp), cfgetospeed(tp));
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2003-06-16 21:22:00 +04:00
|
|
|
gread(struct termios *tp, char *s)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1996-05-07 22:20:05 +04:00
|
|
|
const struct cchar *cp;
|
1994-09-20 08:52:02 +04:00
|
|
|
char *ep, *p;
|
1993-03-21 12:45:37 +03:00
|
|
|
long tmp;
|
|
|
|
|
1994-09-20 08:52:02 +04:00
|
|
|
if ((s = strchr(s, ':')) == NULL)
|
1993-03-21 12:45:37 +03:00
|
|
|
gerr(NULL);
|
1994-09-20 08:52:02 +04:00
|
|
|
for (++s; s != NULL;) {
|
1993-03-21 12:45:37 +03:00
|
|
|
p = strsep(&s, ":\0");
|
|
|
|
if (!p || !*p)
|
|
|
|
break;
|
1994-09-20 08:52:02 +04:00
|
|
|
if (!(ep = strchr(p, '=')))
|
1993-03-21 12:45:37 +03:00
|
|
|
gerr(p);
|
|
|
|
*ep++ = '\0';
|
|
|
|
(void)sscanf(ep, "%lx", &tmp);
|
1994-09-20 08:52:02 +04:00
|
|
|
|
|
|
|
#define CHK(s) (*p == s[0] && !strcmp(p, s))
|
1993-03-21 12:45:37 +03:00
|
|
|
if (CHK("cflag")) {
|
|
|
|
tp->c_cflag = tmp;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (CHK("iflag")) {
|
|
|
|
tp->c_iflag = tmp;
|
|
|
|
continue;
|
|
|
|
}
|
1999-03-02 20:27:03 +03:00
|
|
|
#ifdef BSD4_4
|
1993-03-21 12:45:37 +03:00
|
|
|
if (CHK("ispeed")) {
|
|
|
|
(void)sscanf(ep, "%ld", &tmp);
|
|
|
|
tp->c_ispeed = tmp;
|
|
|
|
continue;
|
|
|
|
}
|
1999-03-02 20:27:03 +03:00
|
|
|
#endif
|
1993-03-21 12:45:37 +03:00
|
|
|
if (CHK("lflag")) {
|
|
|
|
tp->c_lflag = tmp;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (CHK("oflag")) {
|
|
|
|
tp->c_oflag = tmp;
|
|
|
|
continue;
|
|
|
|
}
|
1999-03-02 20:27:03 +03:00
|
|
|
#ifdef BSD4_4
|
1993-03-21 12:45:37 +03:00
|
|
|
if (CHK("ospeed")) {
|
|
|
|
(void)sscanf(ep, "%ld", &tmp);
|
|
|
|
tp->c_ospeed = tmp;
|
|
|
|
continue;
|
|
|
|
}
|
1999-03-02 20:27:03 +03:00
|
|
|
#endif
|
1994-09-20 08:52:02 +04:00
|
|
|
for (cp = cchars1; cp->name != NULL; ++cp)
|
1994-03-23 08:05:30 +03:00
|
|
|
if (CHK(cp->name)) {
|
|
|
|
if (cp->sub == VMIN || cp->sub == VTIME)
|
|
|
|
(void)sscanf(ep, "%ld", &tmp);
|
|
|
|
tp->c_cc[cp->sub] = tmp;
|
|
|
|
break;
|
|
|
|
}
|
1994-09-20 08:52:02 +04:00
|
|
|
if (cp->name == NULL)
|
1994-03-23 08:05:30 +03:00
|
|
|
gerr(p);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
}
|