Home | History | Annotate | Line # | Download | only in stty
gfmt.c revision 1.1
      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[] = "@(#)gfmt.c	5.4 (Berkeley) 6/10/91";
     36 #endif /* not lint */
     37 
     38 #include <sys/types.h>
     39 #include <stdio.h>
     40 #include <string.h>
     41 #include "stty.h"
     42 #include "extern.h"
     43 
     44 static void gerr __P((char *));
     45 
     46 void
     47 gprint(tp, wp, ldisc)
     48 	struct termios *tp;
     49 	struct winsize *wp;
     50 	int ldisc;
     51 {
     52 	register struct cchar *cp;
     53 
     54 	(void)printf("gfmt1:cflag=%x:iflag=%x:lflag=%x:oflag=%x:",
     55 	    tp->c_cflag, tp->c_iflag, tp->c_lflag, tp->c_oflag);
     56 	for (cp = cchars1; cp->name; ++cp)
     57 		(void)printf("%s=%x:", cp->name, tp->c_cc[cp->sub]);
     58 	(void)printf("ispeed=%d:ospeed=%d\n", cfgetispeed(tp), cfgetospeed(tp));
     59 }
     60 
     61 void
     62 gread(tp, s)
     63 	register struct termios *tp;
     64 	char *s;
     65 {
     66 	register char *ep, *p;
     67 	long tmp;
     68 
     69 #define	CHK(s)	(*p == s[0] && !strcmp(p, s))
     70 	if (!(s = index(s, ':')))
     71 		gerr(NULL);
     72 	for (++s; s;) {
     73 		p = strsep(&s, ":\0");
     74 		if (!p || !*p)
     75 			break;
     76 		if (!(ep = index(p, '=')))
     77 			gerr(p);
     78 		*ep++ = '\0';
     79 		(void)sscanf(ep, "%lx", &tmp);
     80 		if (CHK("cflag")) {
     81 			tp->c_cflag = tmp;
     82 			continue;
     83 		}
     84 		if (CHK("discard")) {
     85 			tp->c_cc[VDISCARD] = tmp;
     86 			continue;
     87 		}
     88 		if (CHK("dsusp")) {
     89 			tp->c_cc[VDSUSP] = tmp;
     90 			continue;
     91 		}
     92 		if (CHK("eof")) {
     93 			tp->c_cc[VEOF] = tmp;
     94 			continue;
     95 		}
     96 		if (CHK("eol")) {
     97 			tp->c_cc[VEOL] = tmp;
     98 			continue;
     99 		}
    100 		if (CHK("eol2")) {
    101 			tp->c_cc[VEOL2] = tmp;
    102 			continue;
    103 		}
    104 		if (CHK("erase")) {
    105 			tp->c_cc[VERASE] = tmp;
    106 			continue;
    107 		}
    108 		if (CHK("iflag")) {
    109 			tp->c_iflag = tmp;
    110 			continue;
    111 		}
    112 		if (CHK("intr")) {
    113 			tp->c_cc[VINTR] = tmp;
    114 			continue;
    115 		}
    116 		if (CHK("ispeed")) {
    117 			(void)sscanf(ep, "%ld", &tmp);
    118 			tp->c_ispeed = tmp;
    119 			continue;
    120 		}
    121 		if (CHK("kill")) {
    122 			tp->c_cc[VKILL] = tmp;
    123 			continue;
    124 		}
    125 		if (CHK("lflag")) {
    126 			tp->c_lflag = tmp;
    127 			continue;
    128 		}
    129 		if (CHK("lnext")) {
    130 			tp->c_cc[VLNEXT] = tmp;
    131 			continue;
    132 		}
    133 		if (CHK("oflag")) {
    134 			tp->c_oflag = tmp;
    135 			continue;
    136 		}
    137 		if (CHK("ospeed")) {
    138 			(void)sscanf(ep, "%ld", &tmp);
    139 			tp->c_ospeed = tmp;
    140 			continue;
    141 		}
    142 		if (CHK("quit")) {
    143 			tp->c_cc[VQUIT] = tmp;
    144 			continue;
    145 		}
    146 		if (CHK("reprint")) {
    147 			tp->c_cc[VREPRINT] = tmp;
    148 			continue;
    149 		}
    150 		if (CHK("start")) {
    151 			tp->c_cc[VSTART] = tmp;
    152 			continue;
    153 		}
    154 		if (CHK("status")) {
    155 			tp->c_cc[VSTATUS] = tmp;
    156 			continue;
    157 		}
    158 		if (CHK("stop")) {
    159 			tp->c_cc[VSTOP] = tmp;
    160 			continue;
    161 		}
    162 		if (CHK("susp")) {
    163 			tp->c_cc[VSUSP] = tmp;
    164 			continue;
    165 		}
    166 		if (CHK("werase")) {
    167 			tp->c_cc[VWERASE] = tmp;
    168 			continue;
    169 		}
    170 		gerr(p);
    171 	}
    172 }
    173 
    174 static void
    175 gerr(s)
    176 	char *s;
    177 {
    178 	if (s)
    179 		err("illegal gfmt1 option -- %s", s);
    180 	else
    181 		err("illegal gfmt1 option");
    182 }
    183