14b88c807SRodney W. Grimes /*- 24b88c807SRodney W. Grimes * Copyright (c) 1991, 1993, 1994 34b88c807SRodney W. Grimes * The Regents of the University of California. All rights reserved. 44b88c807SRodney W. Grimes * 54b88c807SRodney W. Grimes * Redistribution and use in source and binary forms, with or without 64b88c807SRodney W. Grimes * modification, are permitted provided that the following conditions 74b88c807SRodney W. Grimes * are met: 84b88c807SRodney W. Grimes * 1. Redistributions of source code must retain the above copyright 94b88c807SRodney W. Grimes * notice, this list of conditions and the following disclaimer. 104b88c807SRodney W. Grimes * 2. Redistributions in binary form must reproduce the above copyright 114b88c807SRodney W. Grimes * notice, this list of conditions and the following disclaimer in the 124b88c807SRodney W. Grimes * documentation and/or other materials provided with the distribution. 134b88c807SRodney W. Grimes * 3. All advertising materials mentioning features or use of this software 144b88c807SRodney W. Grimes * must display the following acknowledgement: 154b88c807SRodney W. Grimes * This product includes software developed by the University of 164b88c807SRodney W. Grimes * California, Berkeley and its contributors. 174b88c807SRodney W. Grimes * 4. Neither the name of the University nor the names of its contributors 184b88c807SRodney W. Grimes * may be used to endorse or promote products derived from this software 194b88c807SRodney W. Grimes * without specific prior written permission. 204b88c807SRodney W. Grimes * 214b88c807SRodney W. Grimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 224b88c807SRodney W. Grimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 234b88c807SRodney W. Grimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 244b88c807SRodney W. Grimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 254b88c807SRodney W. Grimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 264b88c807SRodney W. Grimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 274b88c807SRodney W. Grimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 284b88c807SRodney W. Grimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 294b88c807SRodney W. Grimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 304b88c807SRodney W. Grimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 314b88c807SRodney W. Grimes * SUCH DAMAGE. 3289730b29SDavid Greenman * 330fd510b7SJoerg Wunsch * $Id: gfmt.c,v 1.2 1994/09/24 02:58:57 davidg Exp $ 344b88c807SRodney W. Grimes */ 354b88c807SRodney W. Grimes 364b88c807SRodney W. Grimes #ifndef lint 374b88c807SRodney W. Grimes static char sccsid[] = "@(#)gfmt.c 8.6 (Berkeley) 4/2/94"; 384b88c807SRodney W. Grimes #endif /* not lint */ 394b88c807SRodney W. Grimes 404b88c807SRodney W. Grimes #include <sys/types.h> 414b88c807SRodney W. Grimes 424b88c807SRodney W. Grimes #include <err.h> 434b88c807SRodney W. Grimes #include <stdio.h> 444b88c807SRodney W. Grimes #include <string.h> 454b88c807SRodney W. Grimes 464b88c807SRodney W. Grimes #include "stty.h" 474b88c807SRodney W. Grimes #include "extern.h" 484b88c807SRodney W. Grimes 494b88c807SRodney W. Grimes static void 504b88c807SRodney W. Grimes gerr(s) 514b88c807SRodney W. Grimes char *s; 524b88c807SRodney W. Grimes { 534b88c807SRodney W. Grimes if (s) 544b88c807SRodney W. Grimes errx(1, "illegal gfmt1 option -- %s", s); 554b88c807SRodney W. Grimes else 564b88c807SRodney W. Grimes errx(1, "illegal gfmt1 option"); 574b88c807SRodney W. Grimes } 584b88c807SRodney W. Grimes 594b88c807SRodney W. Grimes void 604b88c807SRodney W. Grimes gprint(tp, wp, ldisc) 614b88c807SRodney W. Grimes struct termios *tp; 624b88c807SRodney W. Grimes struct winsize *wp; 634b88c807SRodney W. Grimes int ldisc; 644b88c807SRodney W. Grimes { 654b88c807SRodney W. Grimes struct cchar *cp; 664b88c807SRodney W. Grimes 670fd510b7SJoerg Wunsch (void)printf("gfmt1:cflag=%lx:iflag=%lx:lflag=%lx:oflag=%lx:", 684b88c807SRodney W. Grimes tp->c_cflag, tp->c_iflag, tp->c_lflag, tp->c_oflag); 694b88c807SRodney W. Grimes for (cp = cchars1; cp->name; ++cp) 704b88c807SRodney W. Grimes (void)printf("%s=%x:", cp->name, tp->c_cc[cp->sub]); 710fd510b7SJoerg Wunsch (void)printf("ispeed=%ld:ospeed=%ld\n", cfgetispeed(tp), cfgetospeed(tp)); 724b88c807SRodney W. Grimes } 734b88c807SRodney W. Grimes 744b88c807SRodney W. Grimes void 754b88c807SRodney W. Grimes gread(tp, s) 764b88c807SRodney W. Grimes struct termios *tp; 774b88c807SRodney W. Grimes char *s; 784b88c807SRodney W. Grimes { 794b88c807SRodney W. Grimes struct cchar *cp; 804b88c807SRodney W. Grimes char *ep, *p; 814b88c807SRodney W. Grimes long tmp; 824b88c807SRodney W. Grimes 834b88c807SRodney W. Grimes if ((s = strchr(s, ':')) == NULL) 844b88c807SRodney W. Grimes gerr(NULL); 854b88c807SRodney W. Grimes for (++s; s != NULL;) { 864b88c807SRodney W. Grimes p = strsep(&s, ":\0"); 874b88c807SRodney W. Grimes if (!p || !*p) 884b88c807SRodney W. Grimes break; 894b88c807SRodney W. Grimes if (!(ep = strchr(p, '='))) 904b88c807SRodney W. Grimes gerr(p); 914b88c807SRodney W. Grimes *ep++ = '\0'; 924b88c807SRodney W. Grimes (void)sscanf(ep, "%lx", &tmp); 934b88c807SRodney W. Grimes 944b88c807SRodney W. Grimes #define CHK(s) (*p == s[0] && !strcmp(p, s)) 954b88c807SRodney W. Grimes if (CHK("cflag")) { 964b88c807SRodney W. Grimes tp->c_cflag = tmp; 974b88c807SRodney W. Grimes continue; 984b88c807SRodney W. Grimes } 994b88c807SRodney W. Grimes if (CHK("iflag")) { 1004b88c807SRodney W. Grimes tp->c_iflag = tmp; 1014b88c807SRodney W. Grimes continue; 1024b88c807SRodney W. Grimes } 1034b88c807SRodney W. Grimes if (CHK("ispeed")) { 1044b88c807SRodney W. Grimes (void)sscanf(ep, "%ld", &tmp); 1054b88c807SRodney W. Grimes tp->c_ispeed = tmp; 1064b88c807SRodney W. Grimes continue; 1074b88c807SRodney W. Grimes } 1084b88c807SRodney W. Grimes if (CHK("lflag")) { 1094b88c807SRodney W. Grimes tp->c_lflag = tmp; 1104b88c807SRodney W. Grimes continue; 1114b88c807SRodney W. Grimes } 1124b88c807SRodney W. Grimes if (CHK("oflag")) { 1134b88c807SRodney W. Grimes tp->c_oflag = tmp; 1144b88c807SRodney W. Grimes continue; 1154b88c807SRodney W. Grimes } 1164b88c807SRodney W. Grimes if (CHK("ospeed")) { 1174b88c807SRodney W. Grimes (void)sscanf(ep, "%ld", &tmp); 1184b88c807SRodney W. Grimes tp->c_ospeed = tmp; 1194b88c807SRodney W. Grimes continue; 1204b88c807SRodney W. Grimes } 1214b88c807SRodney W. Grimes for (cp = cchars1; cp->name != NULL; ++cp) 1224b88c807SRodney W. Grimes if (CHK(cp->name)) { 1234b88c807SRodney W. Grimes if (cp->sub == VMIN || cp->sub == VTIME) 1244b88c807SRodney W. Grimes (void)sscanf(ep, "%ld", &tmp); 1254b88c807SRodney W. Grimes tp->c_cc[cp->sub] = tmp; 1264b88c807SRodney W. Grimes break; 1274b88c807SRodney W. Grimes } 1284b88c807SRodney W. Grimes if (cp->name == NULL) 1294b88c807SRodney W. Grimes gerr(p); 1304b88c807SRodney W. Grimes } 1314b88c807SRodney W. Grimes } 132