Home | History | Annotate | Line # | Download | only in stty
gfmt.c revision 1.6
      1 /*-
      2  * Copyright (c) 1991 The Regents of the University of California.
      3  * All rights reserved.
      4  *
      5  * Redistribution and use in source and binary forms, with or without
      6  * modification, are permitted provided that the following conditions
      7  * are met:
      8  * 1. Redistributions of source code must retain the above copyright
      9  *    notice, this list of conditions and the following disclaimer.
     10  * 2. Redistributions in binary form must reproduce the above copyright
     11  *    notice, this list of conditions and the following disclaimer in the
     12  *    documentation and/or other materials provided with the distribution.
     13  * 3. All advertising materials mentioning features or use of this software
     14  *    must display the following acknowledgement:
     15  *	This product includes software developed by the University of
     16  *	California, Berkeley and its contributors.
     17  * 4. Neither the name of the University nor the names of its contributors
     18  *    may be used to endorse or promote products derived from this software
     19  *    without specific prior written permission.
     20  *
     21  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     22  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     24  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     25  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     26  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     27  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     28  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     29  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     30  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     31  * SUCH DAMAGE.
     32  */
     33 
     34 #ifndef lint
     35 /*static char sccsid[] = "from: @(#)gfmt.c	5.4 (Berkeley) 6/10/91";*/
     36 static char rcsid[] = "$Id: gfmt.c,v 1.6 1994/03/23 04:05:28 mycroft Exp $";
     37 #endif /* not lint */
     38 
     39 #include <sys/types.h>
     40 #include <err.h>
     41 #include <stdio.h>
     42 #include <string.h>
     43 #include "stty.h"
     44 #include "extern.h"
     45 
     46 static void gerr __P((char *));
     47 
     48 void
     49 gprint(tp, wp, ldisc)
     50 	struct termios *tp;
     51 	struct winsize *wp;
     52 	int ldisc;
     53 {
     54 	register struct cchar *cp;
     55 
     56 	(void)printf("gfmt1:cflag=%x:iflag=%x:lflag=%x:oflag=%x:",
     57 	    tp->c_cflag, tp->c_iflag, tp->c_lflag, tp->c_oflag);
     58 	for (cp = cchars1; cp->name; ++cp)
     59 		(void)printf("%s=%x:", cp->name, tp->c_cc[cp->sub]);
     60 	(void)printf("ispeed=%d:ospeed=%d\n", cfgetispeed(tp), cfgetospeed(tp));
     61 }
     62 
     63 void
     64 gread(tp, s)
     65 	register struct termios *tp;
     66 	char *s;
     67 {
     68 	register char *ep, *p;
     69 	long tmp;
     70 
     71 #define	CHK(s)	(*p == s[0] && !strcmp(p, s))
     72 	if (!(s = index(s, ':')))
     73 		gerr(NULL);
     74 	for (++s; s;) {
     75 		p = strsep(&s, ":\0");
     76 		if (!p || !*p)
     77 			break;
     78 		if (!(ep = index(p, '=')))
     79 			gerr(p);
     80 		*ep++ = '\0';
     81 		(void)sscanf(ep, "%lx", &tmp);
     82 		if (CHK("cflag")) {
     83 			tp->c_cflag = tmp;
     84 			continue;
     85 		}
     86 		if (CHK("discard")) {
     87 			tp->c_cc[VDISCARD] = tmp;
     88 			continue;
     89 		}
     90 		if (CHK("dsusp")) {
     91 			tp->c_cc[VDSUSP] = tmp;
     92 			continue;
     93 		}
     94 		if (CHK("eof")) {
     95 			tp->c_cc[VEOF] = tmp;
     96 			continue;
     97 		}
     98 		if (CHK("eol")) {
     99 			tp->c_cc[VEOL] = tmp;
    100 			continue;
    101 		}
    102 		if (CHK("eol2")) {
    103 			tp->c_cc[VEOL2] = tmp;
    104 			continue;
    105 		}
    106 		if (CHK("erase")) {
    107 			tp->c_cc[VERASE] = tmp;
    108 			continue;
    109 		}
    110 		if (CHK("iflag")) {
    111 			tp->c_iflag = tmp;
    112 			continue;
    113 		}
    114 		if (CHK("intr")) {
    115 			tp->c_cc[VINTR] = tmp;
    116 			continue;
    117 		}
    118 		if (CHK("ispeed")) {
    119 			(void)sscanf(ep, "%ld", &tmp);
    120 			tp->c_ispeed = tmp;
    121 			continue;
    122 		}
    123 		if (CHK("kill")) {
    124 			tp->c_cc[VKILL] = tmp;
    125 			continue;
    126 		}
    127 		if (CHK("lflag")) {
    128 			tp->c_lflag = tmp;
    129 			continue;
    130 		}
    131 		if (CHK("lnext")) {
    132 			tp->c_cc[VLNEXT] = tmp;
    133 			continue;
    134 		}
    135 		if (CHK("min")) {
    136 			(void)sscanf(ep, "%ld", &tmp);
    137 			tp->c_cc[VMIN] = tmp;
    138 			continue;
    139 		}
    140 		if (CHK("oflag")) {
    141 			tp->c_oflag = tmp;
    142 			continue;
    143 		}
    144 		if (CHK("ospeed")) {
    145 			(void)sscanf(ep, "%ld", &tmp);
    146 			tp->c_ospeed = tmp;
    147 			continue;
    148 		}
    149 		if (CHK("quit")) {
    150 			tp->c_cc[VQUIT] = tmp;
    151 			continue;
    152 		}
    153 		if (CHK("reprint")) {
    154 			tp->c_cc[VREPRINT] = tmp;
    155 			continue;
    156 		}
    157 		if (CHK("start")) {
    158 			tp->c_cc[VSTART] = tmp;
    159 			continue;
    160 		}
    161 		if (CHK("status")) {
    162 			tp->c_cc[VSTATUS] = tmp;
    163 			continue;
    164 		}
    165 		if (CHK("stop")) {
    166 			tp->c_cc[VSTOP] = tmp;
    167 			continue;
    168 		}
    169 		if (CHK("susp")) {
    170 			tp->c_cc[VSUSP] = tmp;
    171 			continue;
    172 		}
    173 		if (CHK("time")) {
    174 			(void)sscanf(ep, "%ld", &tmp);
    175 			tp->c_cc[VTIME] = tmp;
    176 			continue;
    177 		}
    178 		if (CHK("werase")) {
    179 			tp->c_cc[VWERASE] = tmp;
    180 			continue;
    181 		}
    182 		gerr(p);
    183 	}
    184 }
    185 
    186 static void
    187 gerr(s)
    188 	char *s;
    189 {
    190 	if (s)
    191 		errx(1, "illegal gfmt1 option -- %s", s);
    192 	else
    193 		errx(1, "illegal gfmt1 option");
    194 }
    195