use C library err/warn routines, index->strchr, etc.
[unix-history] / usr / src / bin / stty / gfmt.c
CommitLineData
d5b6f44e
KB
1/*-
2 * Copyright (c) 1991 The Regents of the University of California.
3 * All rights reserved.
4 *
5 * %sccs.include.redist.c%
6 */
7
8#ifndef lint
80c32590 9static char sccsid[] = "@(#)gfmt.c 5.5 (Berkeley) %G%";
d5b6f44e
KB
10#endif /* not lint */
11
12#include <sys/types.h>
80c32590
KB
13
14#include <err.h>
d5b6f44e
KB
15#include <stdio.h>
16#include <string.h>
80c32590 17
d5b6f44e
KB
18#include "stty.h"
19#include "extern.h"
20
21static void gerr __P((char *));
22
23void
24gprint(tp, wp, ldisc)
25 struct termios *tp;
26 struct winsize *wp;
27 int ldisc;
28{
d5b6f44e
KB
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);
3ac03562 33 for (cp = cchars1; cp->name; ++cp)
d5b6f44e
KB
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
38void
39gread(tp, s)
40 register struct termios *tp;
41 char *s;
42{
43 register char *ep, *p;
44 long tmp;
45
46#define CHK(s) (*p == s[0] && !strcmp(p, s))
80c32590 47 if (!(s = strchr(s, ':')))
d5b6f44e
KB
48 gerr(NULL);
49 for (++s; s;) {
50 p = strsep(&s, ":\0");
51 if (!p || !*p)
52 break;
80c32590 53 if (!(ep = strchr(p, '=')))
d5b6f44e
KB
54 gerr(p);
55 *ep++ = '\0';
56 (void)sscanf(ep, "%lx", &tmp);
57 if (CHK("cflag")) {
58 tp->c_cflag = tmp;
59 continue;
60 }
61 if (CHK("discard")) {
62 tp->c_cc[VDISCARD] = tmp;
63 continue;
64 }
65 if (CHK("dsusp")) {
66 tp->c_cc[VDSUSP] = tmp;
67 continue;
68 }
69 if (CHK("eof")) {
70 tp->c_cc[VEOF] = tmp;
71 continue;
72 }
73 if (CHK("eol")) {
74 tp->c_cc[VEOL] = tmp;
75 continue;
76 }
77 if (CHK("eol2")) {
78 tp->c_cc[VEOL2] = tmp;
79 continue;
80 }
81 if (CHK("erase")) {
82 tp->c_cc[VERASE] = tmp;
83 continue;
84 }
85 if (CHK("iflag")) {
86 tp->c_iflag = tmp;
87 continue;
88 }
89 if (CHK("intr")) {
90 tp->c_cc[VINTR] = tmp;
91 continue;
92 }
93 if (CHK("ispeed")) {
94 (void)sscanf(ep, "%ld", &tmp);
95 tp->c_ispeed = tmp;
96 continue;
97 }
98 if (CHK("kill")) {
99 tp->c_cc[VKILL] = tmp;
100 continue;
101 }
102 if (CHK("lflag")) {
103 tp->c_lflag = tmp;
104 continue;
105 }
106 if (CHK("lnext")) {
107 tp->c_cc[VLNEXT] = tmp;
108 continue;
109 }
110 if (CHK("oflag")) {
111 tp->c_oflag = tmp;
112 continue;
113 }
114 if (CHK("ospeed")) {
115 (void)sscanf(ep, "%ld", &tmp);
116 tp->c_ospeed = tmp;
117 continue;
118 }
119 if (CHK("quit")) {
120 tp->c_cc[VQUIT] = tmp;
121 continue;
122 }
123 if (CHK("reprint")) {
124 tp->c_cc[VREPRINT] = tmp;
125 continue;
126 }
127 if (CHK("start")) {
128 tp->c_cc[VSTART] = tmp;
129 continue;
130 }
131 if (CHK("status")) {
132 tp->c_cc[VSTATUS] = tmp;
133 continue;
134 }
135 if (CHK("stop")) {
136 tp->c_cc[VSTOP] = tmp;
137 continue;
138 }
139 if (CHK("susp")) {
140 tp->c_cc[VSUSP] = tmp;
141 continue;
142 }
143 if (CHK("werase")) {
144 tp->c_cc[VWERASE] = tmp;
145 continue;
146 }
147 gerr(p);
148 }
149}
150
151static void
152gerr(s)
153 char *s;
154{
155 if (s)
80c32590 156 errx(1, "illegal gfmt1 option -- %s", s);
d5b6f44e 157 else
80c32590 158 errx(1, "illegal gfmt1 option");
d5b6f44e 159}