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 * 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.
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
33 * @(#)print.c 8.6 (Berkeley) 4/16/94
34 * $FreeBSD: src/bin/stty/print.c,v 1.12.2.2 2001/07/04 22:40:00 kris Exp $
35 * $DragonFly: src/bin/stty/print.c,v 1.5 2004/11/07 20:54:52 eirikn Exp $
38 #include <sys/types.h>
47 #include <sys/ioctl_compat.h> /* XXX NTTYDISC is too well hidden */
49 static void binit (const char *);
50 static void bput (const char *);
51 static const char *ccval (struct cchar *, int);
54 print(struct termios *tp, struct winsize *wp, int ldisc, enum FMT fmt)
59 int cnt, ispeed, ospeed;
60 char buf1[100], buf2[100];
64 /* Line discipline. */
65 if (ldisc != TTYDISC) {
68 cnt += printf("new tty disc; ");
71 cnt += printf("slip disc; ");
74 cnt += printf("ppp disc; ");
77 cnt += printf("#%d disc; ", ldisc);
83 ispeed = cfgetispeed(tp);
84 ospeed = cfgetospeed(tp);
87 printf("ispeed %d baud; ospeed %d baud;", ispeed, ospeed);
89 cnt += printf("speed %d baud;", ispeed);
91 cnt += printf(" %d rows; %d columns;", wp->ws_row, wp->ws_col);
95 #define on(f) ((tmp & (f)) != 0)
96 #define put(n, f, d) \
97 if (fmt >= BSD || on(f) != (d)) \
103 put("-icanon", ICANON, 1);
104 put("-isig", ISIG, 1);
105 put("-iexten", IEXTEN, 1);
106 put("-echo", ECHO, 1);
107 put("-echoe", ECHOE, 0);
108 put("-echok", ECHOK, 0);
109 put("-echoke", ECHOKE, 0);
110 put("-echonl", ECHONL, 0);
111 put("-echoctl", ECHOCTL, 0);
112 put("-echoprt", ECHOPRT, 0);
113 put("-altwerase", ALTWERASE, 0);
114 put("-noflsh", NOFLSH, 0);
115 put("-tostop", TOSTOP, 0);
116 put("-flusho", FLUSHO, 0);
117 put("-pendin", PENDIN, 0);
118 put("-nokerninfo", NOKERNINFO, 0);
119 put("-extproc", EXTPROC, 0);
124 put("-istrip", ISTRIP, 0);
125 put("-icrnl", ICRNL, 1);
126 put("-inlcr", INLCR, 0);
127 put("-igncr", IGNCR, 0);
128 put("-ixon", IXON, 1);
129 put("-ixoff", IXOFF, 0);
130 put("-ixany", IXANY, 1);
131 put("-imaxbel", IMAXBEL, 1);
132 put("-ignbrk", IGNBRK, 0);
133 put("-brkint", BRKINT, 1);
134 put("-inpck", INPCK, 0);
135 put("-ignpar", IGNPAR, 0);
136 put("-parmrk", PARMRK, 0);
141 put("-opost", OPOST, 1);
142 put("-onlcr", ONLCR, 1);
143 put("-ocrnl", OCRNL, 0);
144 put("-oxtabs", OXTABS, 1);
145 put("-onocr", OXTABS, 0);
146 put("-onlret", OXTABS, 0);
148 /* control flags (hardware state) */
151 put("-cread", CREAD, 1);
166 bput("-parenb" + on(PARENB));
167 put("-parodd", PARODD, 0);
168 put("-hupcl", HUPCL, 1);
169 put("-clocal", CLOCAL, 0);
170 put("-cstopb", CSTOPB, 0);
171 switch(tmp & (CCTS_OFLOW | CRTS_IFLOW)) {
179 put("-crtscts", CCTS_OFLOW | CRTS_IFLOW, 0);
182 put("-dsrflow", CDSR_OFLOW, 0);
183 put("-dtrflow", CDTR_IFLOW, 0);
184 put("-mdmbuf", MDMBUF, 0); /* XXX mdmbuf == dtrflow */
186 /* special control characters */
190 for (p = cchars1; p->name; ++p) {
191 snprintf(buf1, sizeof(buf1), "%s = %s;",
192 p->name, ccval(p, cc[p->sub]));
198 for (p = cchars1, cnt = 0; p->name; ++p) {
199 if (fmt != BSD && cc[p->sub] == p->def)
202 snprintf(buf1 + cnt * 8, sizeof(buf1) - cnt * 8,
204 snprintf(buf2 + cnt * 8, sizeof(buf2) - cnt * 8,
205 WD, ccval(p, cc[p->sub]));
206 if (++cnt == LINELENGTH / 8) {
208 printf("%s\n", buf1);
209 printf("%s\n", buf2);
213 printf("%s\n", buf1);
214 printf("%s\n", buf2);
220 static const char *label;
223 binit(const char *lb)
238 col = printf("%s: %s", label, s);
241 if ((col + strlen(s)) > LINELENGTH) {
243 col = printf("%s", s) + 8;
246 col += printf(" %s", s);
250 ccval(struct cchar *p, int c)
255 if (p->sub == VMIN || p->sub == VTIME) {
256 snprintf(buf, sizeof(buf), "%d", c);
259 if (c == _POSIX_VDISABLE)