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