2 * Copyright (c) 1991, 1993, 1994
3 * The Regents of the University of California. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
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 * 4. Neither the name of the University nor the names of its contributors
14 * may be used to endorse or promote products derived from this software
15 * without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 static char sccsid[] = "@(#)print.c 8.6 (Berkeley) 4/16/94";
35 #include <sys/cdefs.h>
36 __FBSDID("$FreeBSD$");
38 #include <sys/types.h>
47 static void binit(const char *);
48 static void bput(const char *);
49 static const char *ccval(struct cchar *, int);
52 print(struct termios *tp, struct winsize *wp, int ldisc, enum FMT fmt)
57 int cnt, ispeed, ospeed;
58 char buf1[100], buf2[100];
62 /* Line discipline. */
63 if (ldisc != TTYDISC) {
66 cnt += printf("slip disc; ");
69 cnt += printf("ppp disc; ");
72 cnt += printf("#%d disc; ", ldisc);
78 ispeed = cfgetispeed(tp);
79 ospeed = cfgetospeed(tp);
82 printf("ispeed %d baud; ospeed %d baud;", ispeed, ospeed);
84 cnt += printf("speed %d baud;", ispeed);
86 cnt += printf(" %d rows; %d columns;", wp->ws_row, wp->ws_col);
90 #define on(f) ((tmp & (f)) != 0)
91 #define put(n, f, d) \
92 if (fmt >= BSD || on(f) != (d)) \
98 put("-icanon", ICANON, 1);
99 put("-isig", ISIG, 1);
100 put("-iexten", IEXTEN, 1);
101 put("-echo", ECHO, 1);
102 put("-echoe", ECHOE, 0);
103 put("-echok", ECHOK, 0);
104 put("-echoke", ECHOKE, 0);
105 put("-echonl", ECHONL, 0);
106 put("-echoctl", ECHOCTL, 0);
107 put("-echoprt", ECHOPRT, 0);
108 put("-altwerase", ALTWERASE, 0);
109 put("-noflsh", NOFLSH, 0);
110 put("-tostop", TOSTOP, 0);
111 put("-flusho", FLUSHO, 0);
112 put("-pendin", PENDIN, 0);
113 put("-nokerninfo", NOKERNINFO, 0);
114 put("-extproc", EXTPROC, 0);
119 put("-istrip", ISTRIP, 0);
120 put("-icrnl", ICRNL, 1);
121 put("-inlcr", INLCR, 0);
122 put("-igncr", IGNCR, 0);
123 put("-ixon", IXON, 1);
124 put("-ixoff", IXOFF, 0);
125 put("-ixany", IXANY, 1);
126 put("-imaxbel", IMAXBEL, 1);
127 put("-ignbrk", IGNBRK, 0);
128 put("-brkint", BRKINT, 1);
129 put("-inpck", INPCK, 0);
130 put("-ignpar", IGNPAR, 0);
131 put("-parmrk", PARMRK, 0);
136 put("-opost", OPOST, 1);
137 put("-onlcr", ONLCR, 1);
138 put("-ocrnl", OCRNL, 0);
147 put("-onocr", ONOCR, 0);
148 put("-onlret", ONLRET, 0);
150 /* control flags (hardware state) */
153 put("-cread", CREAD, 1);
168 bput("-parenb" + on(PARENB));
169 put("-parodd", PARODD, 0);
170 put("-hupcl", HUPCL, 1);
171 put("-clocal", CLOCAL, 0);
172 put("-cstopb", CSTOPB, 0);
173 switch(tmp & (CCTS_OFLOW | CRTS_IFLOW)) {
181 put("-crtscts", CCTS_OFLOW | CRTS_IFLOW, 0);
184 put("-dsrflow", CDSR_OFLOW, 0);
185 put("-dtrflow", CDTR_IFLOW, 0);
186 put("-mdmbuf", MDMBUF, 0); /* XXX mdmbuf == dtrflow */
188 /* special control characters */
192 for (p = cchars1; p->name; ++p) {
193 (void)snprintf(buf1, sizeof(buf1), "%s = %s;",
194 p->name, ccval(p, cc[p->sub]));
200 for (p = cchars1, cnt = 0; p->name; ++p) {
201 if (fmt != BSD && cc[p->sub] == p->def)
204 (void)snprintf(buf1 + cnt * 8, sizeof(buf1) - cnt * 8,
206 (void)snprintf(buf2 + cnt * 8, sizeof(buf2) - cnt * 8,
207 WD, ccval(p, cc[p->sub]));
208 if (++cnt == LINELENGTH / 8) {
210 (void)printf("%s\n", buf1);
211 (void)printf("%s\n", buf2);
215 (void)printf("%s\n", buf1);
216 (void)printf("%s\n", buf2);
222 static const char *label;
225 binit(const char *lb)
240 col = printf("%s: %s", label, s);
243 if ((col + strlen(s)) > LINELENGTH) {
244 (void)printf("\n\t");
245 col = printf("%s", s) + 8;
248 col += printf(" %s", s);
252 ccval(struct cchar *p, int c)
257 if (p->sub == VMIN || p->sub == VTIME) {
258 (void)snprintf(buf, sizeof(buf), "%d", c);
261 if (c == _POSIX_VDISABLE)