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 * 4. Neither the name of the University nor the names of its contributors 144b88c807SRodney W. Grimes * may be used to endorse or promote products derived from this software 154b88c807SRodney W. Grimes * without specific prior written permission. 164b88c807SRodney W. Grimes * 174b88c807SRodney W. Grimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 184b88c807SRodney W. Grimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 194b88c807SRodney W. Grimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 204b88c807SRodney W. Grimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 214b88c807SRodney W. Grimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 224b88c807SRodney W. Grimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 234b88c807SRodney W. Grimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 244b88c807SRodney W. Grimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 254b88c807SRodney W. Grimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 264b88c807SRodney W. Grimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 274b88c807SRodney W. Grimes * SUCH DAMAGE. 284b88c807SRodney W. Grimes */ 294b88c807SRodney W. Grimes 304b88c807SRodney W. Grimes #ifndef lint 319ba8bd65SPhilippe Charnier #if 0 329ba8bd65SPhilippe Charnier static char sccsid[] = "@(#)gfmt.c 8.6 (Berkeley) 4/2/94"; 339ba8bd65SPhilippe Charnier #endif 344b88c807SRodney W. Grimes #endif /* not lint */ 352749b141SDavid E. O'Brien #include <sys/cdefs.h> 362749b141SDavid E. O'Brien __FBSDID("$FreeBSD$"); 374b88c807SRodney W. Grimes 384b88c807SRodney W. Grimes #include <sys/types.h> 394b88c807SRodney W. Grimes 404b88c807SRodney W. Grimes #include <err.h> 414b88c807SRodney W. Grimes #include <stdio.h> 424b88c807SRodney W. Grimes #include <string.h> 434b88c807SRodney W. Grimes 444b88c807SRodney W. Grimes #include "stty.h" 454b88c807SRodney W. Grimes #include "extern.h" 464b88c807SRodney W. Grimes 47f9bcf9caSColin Percival static void gerr(const char *s) __dead2; 485e5a5667SKris Kennaway 494b88c807SRodney W. Grimes static void 505134c3f7SWarner Losh gerr(const char *s) 514b88c807SRodney W. Grimes { 524b88c807SRodney W. Grimes if (s) 534b88c807SRodney W. Grimes errx(1, "illegal gfmt1 option -- %s", s); 544b88c807SRodney W. Grimes else 554b88c807SRodney W. Grimes errx(1, "illegal gfmt1 option"); 564b88c807SRodney W. Grimes } 574b88c807SRodney W. Grimes 584b88c807SRodney W. Grimes void 595134c3f7SWarner Losh gprint(struct termios *tp, struct winsize *wp __unused, int ldisc __unused) 604b88c807SRodney W. Grimes { 614b88c807SRodney W. Grimes struct cchar *cp; 624b88c807SRodney W. Grimes 630fd510b7SJoerg Wunsch (void)printf("gfmt1:cflag=%lx:iflag=%lx:lflag=%lx:oflag=%lx:", 640eb7b1caSBruce Evans (u_long)tp->c_cflag, (u_long)tp->c_iflag, (u_long)tp->c_lflag, 650eb7b1caSBruce Evans (u_long)tp->c_oflag); 664b88c807SRodney W. Grimes for (cp = cchars1; cp->name; ++cp) 674b88c807SRodney W. Grimes (void)printf("%s=%x:", cp->name, tp->c_cc[cp->sub]); 68df41cfeeSAndrey A. Chernov (void)printf("ispeed=%lu:ospeed=%lu\n", 69df41cfeeSAndrey A. Chernov (u_long)cfgetispeed(tp), (u_long)cfgetospeed(tp)); 704b88c807SRodney W. Grimes } 714b88c807SRodney W. Grimes 724b88c807SRodney W. Grimes void 735134c3f7SWarner Losh gread(struct termios *tp, char *s) 744b88c807SRodney W. Grimes { 754b88c807SRodney W. Grimes struct cchar *cp; 764b88c807SRodney W. Grimes char *ep, *p; 774b88c807SRodney W. Grimes long tmp; 784b88c807SRodney W. Grimes 794b88c807SRodney W. Grimes if ((s = strchr(s, ':')) == NULL) 804b88c807SRodney W. Grimes gerr(NULL); 814b88c807SRodney W. Grimes for (++s; s != NULL;) { 824b88c807SRodney W. Grimes p = strsep(&s, ":\0"); 834b88c807SRodney W. Grimes if (!p || !*p) 844b88c807SRodney W. Grimes break; 854b88c807SRodney W. Grimes if (!(ep = strchr(p, '='))) 864b88c807SRodney W. Grimes gerr(p); 874b88c807SRodney W. Grimes *ep++ = '\0'; 8897daf7ecSMark Murray (void)sscanf(ep, "%lx", (u_long *)&tmp); 894b88c807SRodney W. Grimes 904b88c807SRodney W. Grimes #define CHK(s) (*p == s[0] && !strcmp(p, s)) 914b88c807SRodney W. Grimes if (CHK("cflag")) { 924b88c807SRodney W. Grimes tp->c_cflag = tmp; 934b88c807SRodney W. Grimes continue; 944b88c807SRodney W. Grimes } 954b88c807SRodney W. Grimes if (CHK("iflag")) { 964b88c807SRodney W. Grimes tp->c_iflag = tmp; 974b88c807SRodney W. Grimes continue; 984b88c807SRodney W. Grimes } 994b88c807SRodney W. Grimes if (CHK("ispeed")) { 1004b88c807SRodney W. Grimes (void)sscanf(ep, "%ld", &tmp); 1014b88c807SRodney W. Grimes tp->c_ispeed = tmp; 1024b88c807SRodney W. Grimes continue; 1034b88c807SRodney W. Grimes } 1044b88c807SRodney W. Grimes if (CHK("lflag")) { 1054b88c807SRodney W. Grimes tp->c_lflag = tmp; 1064b88c807SRodney W. Grimes continue; 1074b88c807SRodney W. Grimes } 1084b88c807SRodney W. Grimes if (CHK("oflag")) { 1094b88c807SRodney W. Grimes tp->c_oflag = tmp; 1104b88c807SRodney W. Grimes continue; 1114b88c807SRodney W. Grimes } 1124b88c807SRodney W. Grimes if (CHK("ospeed")) { 1134b88c807SRodney W. Grimes (void)sscanf(ep, "%ld", &tmp); 1144b88c807SRodney W. Grimes tp->c_ospeed = tmp; 115d0834e7fSAndrey A. Chernov continue; 116d0834e7fSAndrey A. Chernov } 1174b88c807SRodney W. Grimes for (cp = cchars1; cp->name != NULL; ++cp) 1184b88c807SRodney W. Grimes if (CHK(cp->name)) { 1194b88c807SRodney W. Grimes if (cp->sub == VMIN || cp->sub == VTIME) 1204b88c807SRodney W. Grimes (void)sscanf(ep, "%ld", &tmp); 1214b88c807SRodney W. Grimes tp->c_cc[cp->sub] = tmp; 1224b88c807SRodney W. Grimes break; 1234b88c807SRodney W. Grimes } 1244b88c807SRodney W. Grimes if (cp->name == NULL) 1254b88c807SRodney W. Grimes gerr(p); 1264b88c807SRodney W. Grimes } 1274b88c807SRodney W. Grimes } 128