/*-1* Copyright (c) 1991, 1993, 19942* The Regents of the University of California. All rights reserved.3*4* Redistribution and use in source and binary forms, with or without5* modification, are permitted provided that the following conditions6* are met:7* 1. Redistributions of source code must retain the above copyright8* notice, this list of conditions and the following disclaimer.9* 2. Redistributions in binary form must reproduce the above copyright10* notice, this list of conditions and the following disclaimer in the11* documentation and/or other materials provided with the distribution.12* 3. Neither the name of the University nor the names of its contributors13* may be used to endorse or promote products derived from this software14* without specific prior written permission.15*16* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND17* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE18* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE19* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE20* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL21* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS22* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)23* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT24* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY25* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF26* SUCH DAMAGE.27*/2829#include <sys/types.h>3031#include <err.h>32#include <stdio.h>33#include <stdlib.h>34#include <string.h>3536#include "stty.h"37#include "extern.h"3839static void gerr(const char *s) __dead2;4041static void42gerr(const char *s)43{44if (s)45errx(1, "illegal gfmt1 option -- %s", s);46else47errx(1, "illegal gfmt1 option");48}4950void51gprint(struct termios *tp, struct winsize *wp __unused, int ldisc __unused)52{53struct cchar *cp;5455(void)printf("gfmt1:cflag=%lx:iflag=%lx:lflag=%lx:oflag=%lx:",56(u_long)tp->c_cflag, (u_long)tp->c_iflag, (u_long)tp->c_lflag,57(u_long)tp->c_oflag);58for (cp = cchars1; cp->name; ++cp)59(void)printf("%s=%x:", cp->name, tp->c_cc[cp->sub]);60(void)printf("ispeed=%lu:ospeed=%lu\n",61(u_long)cfgetispeed(tp), (u_long)cfgetospeed(tp));62}6364void65gread(struct termios *tp, char *s)66{67struct cchar *cp;68char *ep, *p;69long tmp;7071if ((s = strchr(s, ':')) == NULL)72gerr(NULL);73for (++s; s != NULL;) {74p = strsep(&s, ":\0");75if (!p || !*p)76break;77if (!(ep = strchr(p, '=')))78gerr(p);79*ep++ = '\0';80tmp = strtoul(ep, NULL, 0x10);8182#define CHK(s) (*p == s[0] && !strcmp(p, s))83if (CHK("cflag")) {84tp->c_cflag = tmp;85continue;86}87if (CHK("iflag")) {88tp->c_iflag = tmp;89continue;90}91if (CHK("ispeed")) {92tmp = strtoul(ep, NULL, 10);93tp->c_ispeed = tmp;94continue;95}96if (CHK("lflag")) {97tp->c_lflag = tmp;98continue;99}100if (CHK("oflag")) {101tp->c_oflag = tmp;102continue;103}104if (CHK("ospeed")) {105tmp = strtoul(ep, NULL, 10);106tp->c_ospeed = tmp;107continue;108}109for (cp = cchars1; cp->name != NULL; ++cp)110if (CHK(cp->name)) {111if (cp->sub == VMIN || cp->sub == VTIME)112tmp = strtoul(ep, NULL, 10);113tp->c_cc[cp->sub] = tmp;114break;115}116if (cp->name == NULL)117gerr(p);118}119}120121122