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. 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
29 * @(#)print.c 8.6 (Berkeley) 4/16/94
30 * $FreeBSD: src/bin/stty/print.c,v 1.12.2.2 2001/07/04 22:40:00 kris Exp $
33 #include <sys/types.h>
42 static void binit (const char *);
43 static void bput (const char *);
44 static const char *ccval (struct cchar *, int);
47 print(struct termios *tp, struct winsize *wp, int ldisc, enum FMT fmt)
52 int cnt, ispeed, ospeed;
53 char buf1[100], buf2[100];
57 /* Line discipline. */
58 if (ldisc != TTYDISC) {
61 cnt += printf("slip disc; ");
64 cnt += printf("ppp disc; ");
67 cnt += printf("#%d disc; ", ldisc);
73 ispeed = cfgetispeed(tp);
74 ospeed = cfgetospeed(tp);
77 printf("ispeed %d baud; ospeed %d baud;", ispeed, ospeed);
79 cnt += printf("speed %d baud;", ispeed);
81 cnt += printf(" %d rows; %d columns;", wp->ws_row, wp->ws_col);
85 #define on(f) ((tmp & (f)) != 0)
86 #define put(n, f, d) \
87 if (fmt >= BSD || on(f) != (d)) \
93 put("-icanon", ICANON, 1);
94 put("-isig", ISIG, 1);
95 put("-iexten", IEXTEN, 1);
96 put("-echo", ECHO, 1);
97 put("-echoe", ECHOE, 0);
98 put("-echok", ECHOK, 0);
99 put("-echoke", ECHOKE, 0);
100 put("-echonl", ECHONL, 0);
101 put("-echoctl", ECHOCTL, 0);
102 put("-echoprt", ECHOPRT, 0);
103 put("-altwerase", ALTWERASE, 0);
104 put("-noflsh", NOFLSH, 0);
105 put("-tostop", TOSTOP, 0);
106 put("-flusho", FLUSHO, 0);
107 put("-pendin", PENDIN, 0);
108 put("-nokerninfo", NOKERNINFO, 0);
109 put("-extproc", EXTPROC, 0);
114 put("-istrip", ISTRIP, 0);
115 put("-icrnl", ICRNL, 1);
116 put("-inlcr", INLCR, 0);
117 put("-igncr", IGNCR, 0);
118 put("-ixon", IXON, 1);
119 put("-ixoff", IXOFF, 0);
120 put("-ixany", IXANY, 1);
121 put("-imaxbel", IMAXBEL, 1);
122 put("-ignbrk", IGNBRK, 0);
123 put("-brkint", BRKINT, 1);
124 put("-inpck", INPCK, 0);
125 put("-ignpar", IGNPAR, 0);
126 put("-parmrk", PARMRK, 0);
131 put("-opost", OPOST, 1);
132 put("-onlcr", ONLCR, 1);
133 put("-ocrnl", OCRNL, 0);
134 put("-oxtabs", OXTABS, 1);
135 put("-onocr", OXTABS, 0);
136 put("-onlret", OXTABS, 0);
138 /* control flags (hardware state) */
141 put("-cread", CREAD, 1);
156 bput("-parenb" + on(PARENB));
157 put("-parodd", PARODD, 0);
158 put("-hupcl", HUPCL, 1);
159 put("-clocal", CLOCAL, 0);
160 put("-cstopb", CSTOPB, 0);
161 switch(tmp & (CCTS_OFLOW | CRTS_IFLOW)) {
169 put("-crtscts", CCTS_OFLOW | CRTS_IFLOW, 0);
172 put("-dsrflow", CDSR_OFLOW, 0);
173 put("-dtrflow", CDTR_IFLOW, 0);
174 put("-mdmbuf", MDMBUF, 0); /* XXX mdmbuf == dtrflow */
176 /* special control characters */
180 for (p = cchars1; p->name; ++p) {
181 snprintf(buf1, sizeof(buf1), "%s = %s;",
182 p->name, ccval(p, cc[p->sub]));
188 for (p = cchars1, cnt = 0; p->name; ++p) {
189 if (fmt != BSD && cc[p->sub] == p->def)
192 snprintf(buf1 + cnt * 8, sizeof(buf1) - cnt * 8,
194 snprintf(buf2 + cnt * 8, sizeof(buf2) - cnt * 8,
195 WD, ccval(p, cc[p->sub]));
196 if (++cnt == LINELENGTH / 8) {
198 printf("%s\n", buf1);
199 printf("%s\n", buf2);
203 printf("%s\n", buf1);
204 printf("%s\n", buf2);
210 static const char *label;
213 binit(const char *lb)
228 col = printf("%s: %s", label, s);
231 if ((col + strlen(s)) > LINELENGTH) {
233 col = printf("%s", s) + 8;
236 col += printf(" %s", s);
240 ccval(struct cchar *p, int c)
245 if (p->sub == VMIN || p->sub == VTIME) {
246 snprintf(buf, sizeof(buf), "%d", c);
249 if (c == _POSIX_VDISABLE)