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 * 4. Neither the name of the University nor the names of its contributors 141556Srgrimes * may be used to endorse or promote products derived from this software 151556Srgrimes * without specific prior written permission. 161556Srgrimes * 171556Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 181556Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 191556Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 201556Srgrimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 211556Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 221556Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 231556Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 241556Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 251556Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 261556Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 271556Srgrimes * SUCH DAMAGE. 281556Srgrimes */ 291556Srgrimes 301556Srgrimes#ifndef lint 3136152Scharnier#if 0 3236152Scharnierstatic char sccsid[] = "@(#)gfmt.c 8.6 (Berkeley) 4/2/94"; 3336152Scharnier#endif 341556Srgrimes#endif /* not lint */ 3599110Sobrien#include <sys/cdefs.h> 3699110Sobrien__FBSDID("$FreeBSD$"); 371556Srgrimes 381556Srgrimes#include <sys/types.h> 391556Srgrimes 401556Srgrimes#include <err.h> 411556Srgrimes#include <stdio.h> 421556Srgrimes#include <string.h> 431556Srgrimes 441556Srgrimes#include "stty.h" 451556Srgrimes#include "extern.h" 461556Srgrimes 47181269Scpercivastatic void gerr(const char *s) __dead2; 4876810Skris 491556Srgrimesstatic void 5090111Simpgerr(const char *s) 511556Srgrimes{ 521556Srgrimes if (s) 531556Srgrimes errx(1, "illegal gfmt1 option -- %s", s); 541556Srgrimes else 551556Srgrimes errx(1, "illegal gfmt1 option"); 561556Srgrimes} 571556Srgrimes 581556Srgrimesvoid 5990111Simpgprint(struct termios *tp, struct winsize *wp __unused, int ldisc __unused) 601556Srgrimes{ 611556Srgrimes struct cchar *cp; 621556Srgrimes 637165Sjoerg (void)printf("gfmt1:cflag=%lx:iflag=%lx:lflag=%lx:oflag=%lx:", 6437230Sbde (u_long)tp->c_cflag, (u_long)tp->c_iflag, (u_long)tp->c_lflag, 6537230Sbde (u_long)tp->c_oflag); 661556Srgrimes for (cp = cchars1; cp->name; ++cp) 671556Srgrimes (void)printf("%s=%x:", cp->name, tp->c_cc[cp->sub]); 6859788Sache (void)printf("ispeed=%lu:ospeed=%lu\n", 6959788Sache (u_long)cfgetispeed(tp), (u_long)cfgetospeed(tp)); 701556Srgrimes} 711556Srgrimes 721556Srgrimesvoid 7390111Simpgread(struct termios *tp, char *s) 741556Srgrimes{ 751556Srgrimes struct cchar *cp; 761556Srgrimes char *ep, *p; 771556Srgrimes long tmp; 781556Srgrimes 791556Srgrimes if ((s = strchr(s, ':')) == NULL) 801556Srgrimes gerr(NULL); 811556Srgrimes for (++s; s != NULL;) { 821556Srgrimes p = strsep(&s, ":\0"); 831556Srgrimes if (!p || !*p) 841556Srgrimes break; 851556Srgrimes if (!(ep = strchr(p, '='))) 861556Srgrimes gerr(p); 871556Srgrimes *ep++ = '\0'; 88114576Smarkm (void)sscanf(ep, "%lx", (u_long *)&tmp); 891556Srgrimes 901556Srgrimes#define CHK(s) (*p == s[0] && !strcmp(p, s)) 911556Srgrimes if (CHK("cflag")) { 921556Srgrimes tp->c_cflag = tmp; 931556Srgrimes continue; 941556Srgrimes } 951556Srgrimes if (CHK("iflag")) { 961556Srgrimes tp->c_iflag = tmp; 971556Srgrimes continue; 981556Srgrimes } 991556Srgrimes if (CHK("ispeed")) { 1001556Srgrimes (void)sscanf(ep, "%ld", &tmp); 1011556Srgrimes tp->c_ispeed = tmp; 1021556Srgrimes continue; 1031556Srgrimes } 1041556Srgrimes if (CHK("lflag")) { 1051556Srgrimes tp->c_lflag = tmp; 1061556Srgrimes continue; 1071556Srgrimes } 1081556Srgrimes if (CHK("oflag")) { 1091556Srgrimes tp->c_oflag = tmp; 1101556Srgrimes continue; 1111556Srgrimes } 1121556Srgrimes if (CHK("ospeed")) { 1131556Srgrimes (void)sscanf(ep, "%ld", &tmp); 1141556Srgrimes tp->c_ospeed = tmp; 1151556Srgrimes continue; 1161556Srgrimes } 1171556Srgrimes for (cp = cchars1; cp->name != NULL; ++cp) 1181556Srgrimes if (CHK(cp->name)) { 1191556Srgrimes if (cp->sub == VMIN || cp->sub == VTIME) 1201556Srgrimes (void)sscanf(ep, "%ld", &tmp); 1211556Srgrimes tp->c_cc[cp->sub] = tmp; 1221556Srgrimes break; 1231556Srgrimes } 1241556Srgrimes if (cp->name == NULL) 1251556Srgrimes gerr(p); 1261556Srgrimes } 1271556Srgrimes} 128