gfmt.c revision 114576
11556Srgrimes/*- 21556Srgrimes * Copyright (c) 1991, 1993, 1994 31556Srgrimes * The Regents of the University of California. All rights reserved. 41556Srgrimes * 51556Srgrimes * Redistribution and use in source and binary forms, with or without 61556Srgrimes * modification, are permitted provided that the following conditions 71556Srgrimes * are met: 81556Srgrimes * 1. Redistributions of source code must retain the above copyright 91556Srgrimes * notice, this list of conditions and the following disclaimer. 101556Srgrimes * 2. Redistributions in binary form must reproduce the above copyright 111556Srgrimes * notice, this list of conditions and the following disclaimer in the 121556Srgrimes * documentation and/or other materials provided with the distribution. 131556Srgrimes * 3. All advertising materials mentioning features or use of this software 141556Srgrimes * must display the following acknowledgement: 151556Srgrimes * This product includes software developed by the University of 161556Srgrimes * California, Berkeley and its contributors. 171556Srgrimes * 4. Neither the name of the University nor the names of its contributors 181556Srgrimes * may be used to endorse or promote products derived from this software 191556Srgrimes * without specific prior written permission. 201556Srgrimes * 211556Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 221556Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 231556Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 241556Srgrimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 251556Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 261556Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 271556Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 281556Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 291556Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 301556Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 311556Srgrimes * SUCH DAMAGE. 321556Srgrimes */ 331556Srgrimes 341556Srgrimes#ifndef lint 3536152Scharnier#if 0 3636152Scharnierstatic char sccsid[] = "@(#)gfmt.c 8.6 (Berkeley) 4/2/94"; 3736152Scharnier#endif 381556Srgrimes#endif /* not lint */ 3999110Sobrien#include <sys/cdefs.h> 4099110Sobrien__FBSDID("$FreeBSD: head/bin/stty/gfmt.c 114576 2003-05-03 10:16:51Z markm $"); 411556Srgrimes 421556Srgrimes#include <sys/types.h> 431556Srgrimes 441556Srgrimes#include <err.h> 451556Srgrimes#include <stdio.h> 461556Srgrimes#include <string.h> 471556Srgrimes 481556Srgrimes#include "stty.h" 491556Srgrimes#include "extern.h" 501556Srgrimes 5190111Simpstatic void gerr(const char *s); 5276810Skris 531556Srgrimesstatic void 5490111Simpgerr(const char *s) 551556Srgrimes{ 561556Srgrimes if (s) 571556Srgrimes errx(1, "illegal gfmt1 option -- %s", s); 581556Srgrimes else 591556Srgrimes errx(1, "illegal gfmt1 option"); 601556Srgrimes} 611556Srgrimes 621556Srgrimesvoid 6390111Simpgprint(struct termios *tp, struct winsize *wp __unused, int ldisc __unused) 641556Srgrimes{ 651556Srgrimes struct cchar *cp; 661556Srgrimes 677165Sjoerg (void)printf("gfmt1:cflag=%lx:iflag=%lx:lflag=%lx:oflag=%lx:", 6837230Sbde (u_long)tp->c_cflag, (u_long)tp->c_iflag, (u_long)tp->c_lflag, 6937230Sbde (u_long)tp->c_oflag); 701556Srgrimes for (cp = cchars1; cp->name; ++cp) 711556Srgrimes (void)printf("%s=%x:", cp->name, tp->c_cc[cp->sub]); 7259788Sache (void)printf("ispeed=%lu:ospeed=%lu\n", 7359788Sache (u_long)cfgetispeed(tp), (u_long)cfgetospeed(tp)); 741556Srgrimes} 751556Srgrimes 761556Srgrimesvoid 7790111Simpgread(struct termios *tp, char *s) 781556Srgrimes{ 791556Srgrimes struct cchar *cp; 801556Srgrimes char *ep, *p; 811556Srgrimes long tmp; 821556Srgrimes 831556Srgrimes if ((s = strchr(s, ':')) == NULL) 841556Srgrimes gerr(NULL); 851556Srgrimes for (++s; s != NULL;) { 861556Srgrimes p = strsep(&s, ":\0"); 871556Srgrimes if (!p || !*p) 881556Srgrimes break; 891556Srgrimes if (!(ep = strchr(p, '='))) 901556Srgrimes gerr(p); 911556Srgrimes *ep++ = '\0'; 92114576Smarkm (void)sscanf(ep, "%lx", (u_long *)&tmp); 931556Srgrimes 941556Srgrimes#define CHK(s) (*p == s[0] && !strcmp(p, s)) 951556Srgrimes if (CHK("cflag")) { 961556Srgrimes tp->c_cflag = tmp; 971556Srgrimes continue; 981556Srgrimes } 991556Srgrimes if (CHK("iflag")) { 1001556Srgrimes tp->c_iflag = tmp; 1011556Srgrimes continue; 1021556Srgrimes } 1031556Srgrimes if (CHK("ispeed")) { 1041556Srgrimes (void)sscanf(ep, "%ld", &tmp); 1051556Srgrimes tp->c_ispeed = tmp; 1061556Srgrimes continue; 1071556Srgrimes } 1081556Srgrimes if (CHK("lflag")) { 1091556Srgrimes tp->c_lflag = tmp; 1101556Srgrimes continue; 1111556Srgrimes } 1121556Srgrimes if (CHK("oflag")) { 1131556Srgrimes tp->c_oflag = tmp; 1141556Srgrimes continue; 1151556Srgrimes } 1161556Srgrimes if (CHK("ospeed")) { 1171556Srgrimes (void)sscanf(ep, "%ld", &tmp); 1181556Srgrimes tp->c_ospeed = tmp; 1191556Srgrimes continue; 1201556Srgrimes } 1211556Srgrimes for (cp = cchars1; cp->name != NULL; ++cp) 1221556Srgrimes if (CHK(cp->name)) { 1231556Srgrimes if (cp->sub == VMIN || cp->sub == VTIME) 1241556Srgrimes (void)sscanf(ep, "%ld", &tmp); 1251556Srgrimes tp->c_cc[cp->sub] = tmp; 1261556Srgrimes break; 1271556Srgrimes } 1281556Srgrimes if (cp->name == NULL) 1291556Srgrimes gerr(p); 1301556Srgrimes } 1311556Srgrimes} 132