1 /*- 2 * Copyright (c) 1991, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * %sccs.include.redist.c% 6 */ 7 8 #ifndef lint 9 static char sccsid[] = "@(#)gfmt.c 8.4 (Berkeley) 03/28/94"; 10 #endif /* not lint */ 11 12 #include <sys/types.h> 13 14 #include <err.h> 15 #include <stdio.h> 16 #include <string.h> 17 18 #include "stty.h" 19 #include "extern.h" 20 21 static void gerr __P((char *)); 22 23 void 24 gprint(tp, wp, ldisc) 25 struct termios *tp; 26 struct winsize *wp; 27 int ldisc; 28 { 29 register struct cchar *cp; 30 31 (void)printf("gfmt1:cflag=%x:iflag=%x:lflag=%x:oflag=%x:", 32 tp->c_cflag, tp->c_iflag, tp->c_lflag, tp->c_oflag); 33 for (cp = cchars1; cp->name; ++cp) 34 (void)printf("%s=%x:", cp->name, tp->c_cc[cp->sub]); 35 (void)printf("ispeed=%d:ospeed=%d\n", cfgetispeed(tp), cfgetospeed(tp)); 36 } 37 38 void 39 gread(tp, s) 40 register struct termios *tp; 41 char *s; 42 { 43 register char *ep, *p; 44 register struct cchar *cp; 45 long tmp; 46 47 if ((s = strchr(s, ':')) == NULL) 48 gerr(NULL); 49 for (++s; s != NULL;) { 50 p = strsep(&s, ":\0"); 51 if (!p || !*p) 52 break; 53 if (!(ep = strchr(p, '='))) 54 gerr(p); 55 *ep++ = '\0'; 56 (void)sscanf(ep, "%lx", &tmp); 57 58 #define CHK(s) (*p == s[0] && !strcmp(p, s)) 59 if (CHK("cflag")) { 60 tp->c_cflag = tmp; 61 continue; 62 } 63 if (CHK("iflag")) { 64 tp->c_iflag = tmp; 65 continue; 66 } 67 if (CHK("ispeed")) { 68 (void)sscanf(ep, "%ld", &tmp); 69 tp->c_ispeed = tmp; 70 continue; 71 } 72 if (CHK("lflag")) { 73 tp->c_lflag = tmp; 74 continue; 75 } 76 if (CHK("oflag")) { 77 tp->c_oflag = tmp; 78 continue; 79 } 80 if (CHK("ospeed")) { 81 (void)sscanf(ep, "%ld", &tmp); 82 tp->c_ospeed = tmp; 83 continue; 84 } 85 for (cp = cchars1; cp->name != NULL; ++cp) 86 if (CHK(cp->name)) { 87 if (cp->sub == VMIN || cp->sub == VTIME) 88 (void)sscanf(ep, "%ld", &tmp); 89 tp->c_cc[cp->sub] = tmp; 90 break; 91 } 92 if (cp->name == NULL) 93 gerr(p); 94 } 95 } 96 97 static void 98 gerr(s) 99 char *s; 100 { 101 if (s) 102 errx(1, "illegal gfmt1 option -- %s", s); 103 else 104 errx(1, "illegal gfmt1 option"); 105 } 106