GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: lib/libcurses/trace/lib_tracebits.c Lines: 0 1 0.0 %
Date: 2017-11-07 Branches: 0 0 0.0 %

Line Branch Exec Source
1
/* $OpenBSD: lib_tracebits.c,v 1.10 2010/01/12 23:22:07 nicm Exp $ */
2
3
/****************************************************************************
4
 * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc.              *
5
 *                                                                          *
6
 * Permission is hereby granted, free of charge, to any person obtaining a  *
7
 * copy of this software and associated documentation files (the            *
8
 * "Software"), to deal in the Software without restriction, including      *
9
 * without limitation the rights to use, copy, modify, merge, publish,      *
10
 * distribute, distribute with modifications, sublicense, and/or sell       *
11
 * copies of the Software, and to permit persons to whom the Software is    *
12
 * furnished to do so, subject to the following conditions:                 *
13
 *                                                                          *
14
 * The above copyright notice and this permission notice shall be included  *
15
 * in all copies or substantial portions of the Software.                   *
16
 *                                                                          *
17
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS  *
18
 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF               *
19
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.   *
20
 * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,   *
21
 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR    *
22
 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR    *
23
 * THE USE OR OTHER DEALINGS IN THE SOFTWARE.                               *
24
 *                                                                          *
25
 * Except as contained in this notice, the name(s) of the above copyright   *
26
 * holders shall not be used in advertising or otherwise to promote the     *
27
 * sale, use or other dealings in this Software without prior written       *
28
 * authorization.                                                           *
29
 ****************************************************************************/
30
31
/****************************************************************************
32
 *  Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995               *
33
 *     and: Eric S. Raymond <esr@snark.thyrsus.com>                         *
34
 *     and: Thomas E. Dickey                        1996-on                 *
35
 ****************************************************************************/
36
37
#include <curses.priv.h>
38
#include <term.h>		/* cur_term */
39
40
MODULE_ID("$Id: lib_tracebits.c,v 1.10 2010/01/12 23:22:07 nicm Exp $")
41
42
#if SVR4_TERMIO && !defined(_POSIX_SOURCE)
43
#define _POSIX_SOURCE
44
#endif
45
46
#if HAVE_SYS_TERMIO_H
47
#include <sys/termio.h>		/* needed for ISC */
48
#endif
49
50
#ifdef __EMX__
51
#include <io.h>
52
#endif
53
54
/* may be undefined if we're using termio.h */
55
#ifndef TOSTOP
56
#define TOSTOP 0
57
#endif
58
59
#ifndef IEXTEN
60
#define IEXTEN 0
61
#endif
62
63
#ifndef ONLCR
64
#define ONLCR 0
65
#endif
66
67
#ifndef OCRNL
68
#define OCRNL 0
69
#endif
70
71
#ifndef ONOCR
72
#define ONOCR 0
73
#endif
74
75
#ifndef ONLRET
76
#define ONLRET 0
77
#endif
78
79
#ifdef TRACE
80
81
typedef struct {
82
    unsigned int val;
83
    const char *name;
84
} BITNAMES;
85
86
static void
87
lookup_bits(char *buf, size_t bufsize, const BITNAMES * table, const char *label, unsigned int val)
88
{
89
    const BITNAMES *sp;
90
91
    (void) strlcat(buf, label, bufsize);
92
    (void) strlcat(buf, ": {", bufsize);
93
    for (sp = table; sp->name; sp++)
94
	if (sp->val != 0
95
	    && (val & sp->val) == sp->val) {
96
	    (void) strlcat(buf, sp->name, bufsize);
97
	    (void) strlcat(buf, ", ", bufsize);
98
	}
99
    if (buf[strlen(buf) - 2] == ',')
100
	buf[strlen(buf) - 2] = '\0';
101
    (void) strlcat(buf, "} ", bufsize);
102
}
103
104
NCURSES_EXPORT(char *)
105
_nc_trace_ttymode(TTY * tty)
106
/* describe the state of the terminal control bits exactly */
107
{
108
    char *buf;
109
    size_t bufsize;
110
111
#ifdef TERMIOS
112
    static const BITNAMES iflags[] =
113
    {
114
	{BRKINT, "BRKINT"},
115
	{IGNBRK, "IGNBRK"},
116
	{IGNPAR, "IGNPAR"},
117
	{PARMRK, "PARMRK"},
118
	{INPCK, "INPCK"},
119
	{ISTRIP, "ISTRIP"},
120
	{INLCR, "INLCR"},
121
	{IGNCR, "IGNC"},
122
	{ICRNL, "ICRNL"},
123
	{IXON, "IXON"},
124
	{IXOFF, "IXOFF"},
125
	{0, NULL}
126
#define ALLIN	(BRKINT|IGNBRK|IGNPAR|PARMRK|INPCK|ISTRIP|INLCR|IGNCR|ICRNL|IXON|IXOFF)
127
    }, oflags[] =
128
    {
129
	{OPOST, "OPOST"},
130
	{OFLAGS_TABS, "XTABS"},
131
	{ONLCR, "ONLCR"},
132
	{OCRNL, "OCRNL"},
133
	{ONOCR, "ONOCR"},
134
	{ONLRET, "ONLRET"},
135
	{0, NULL}
136
#define ALLOUT	(OPOST|OFLAGS_TABS|ONLCR|OCRNL|ONOCR|ONLRET)
137
    }, cflags[] =
138
    {
139
	{CLOCAL, "CLOCAL"},
140
	{CREAD, "CREAD"},
141
	{CSTOPB, "CSTOPB"},
142
#if !defined(CS5) || !defined(CS8)
143
	{CSIZE, "CSIZE"},
144
#endif
145
	{HUPCL, "HUPCL"},
146
	{PARENB, "PARENB"},
147
	{PARODD | PARENB, "PARODD"},	/* concession to readability */
148
	{0, NULL}
149
#define ALLCTRL	(CLOCAL|CREAD|CSIZE|CSTOPB|HUPCL|PARENB|PARODD)
150
    }, lflags[] =
151
    {
152
	{ECHO, "ECHO"},
153
	{ECHOE | ECHO, "ECHOE"},	/* concession to readability */
154
	{ECHOK | ECHO, "ECHOK"},	/* concession to readability */
155
	{ECHONL, "ECHONL"},
156
	{ICANON, "ICANON"},
157
	{ISIG, "ISIG"},
158
	{NOFLSH, "NOFLSH"},
159
	{TOSTOP, "TOSTOP"},
160
	{IEXTEN, "IEXTEN"},
161
	{0, NULL}
162
#define ALLLOCAL	(ECHO|ECHONL|ICANON|ISIG|NOFLSH|TOSTOP|IEXTEN)
163
    };
164
165
    bufsize = 8 + sizeof(iflags) + 8 + sizeof(oflags) + 8 + sizeof(cflags) +
166
	8 + sizeof(lflags) + 8;
167
    buf = _nc_trace_buf(0, bufsize);
168
169
    if (buf != 0) {
170
171
	if (tty->c_iflag & ALLIN)
172
	    lookup_bits(buf, bufsize, iflags, "iflags", tty->c_iflag);
173
174
	if (tty->c_oflag & ALLOUT)
175
	    lookup_bits(buf, bufsize, oflags, "oflags", tty->c_oflag);
176
177
	if (tty->c_cflag & ALLCTRL)
178
	    lookup_bits(buf, bufsize, cflags, "cflags", tty->c_cflag);
179
180
#if defined(CS5) && defined(CS8)
181
	{
182
	    static struct {
183
		int value;
184
		const char *name;
185
	    } csizes[] = {
186
#define CS_DATA(name) { name, #name " " }
187
		CS_DATA(CS5),
188
#ifdef CS6
189
		    CS_DATA(CS6),
190
#endif
191
#ifdef CS7
192
		    CS_DATA(CS7),
193
#endif
194
		    CS_DATA(CS8),
195
	    };
196
	    const char *result = "CSIZE? ";
197
	    int value = (tty->c_cflag & CSIZE);
198
	    unsigned n;
199
200
	    if (value != 0) {
201
		for (n = 0; n < SIZEOF(csizes); n++) {
202
		    if (csizes[n].value == value) {
203
			result = csizes[n].name;
204
			break;
205
		    }
206
		}
207
	    }
208
	    strlcat(buf, result, bufsize);
209
	}
210
#endif
211
212
	if (tty->c_lflag & ALLLOCAL)
213
	    lookup_bits(buf, bufsize, lflags, "lflags", tty->c_lflag);
214
    }
215
#else
216
    /* reference: ttcompat(4M) on SunOS 4.1 */
217
#ifndef EVENP
218
#define EVENP 0
219
#endif
220
#ifndef LCASE
221
#define LCASE 0
222
#endif
223
#ifndef LLITOUT
224
#define LLITOUT 0
225
#endif
226
#ifndef ODDP
227
#define ODDP 0
228
#endif
229
#ifndef TANDEM
230
#define TANDEM 0
231
#endif
232
233
    static const BITNAMES cflags[] =
234
    {
235
	{CBREAK, "CBREAK"},
236
	{CRMOD, "CRMOD"},
237
	{ECHO, "ECHO"},
238
	{EVENP, "EVENP"},
239
	{LCASE, "LCASE"},
240
	{LLITOUT, "LLITOUT"},
241
	{ODDP, "ODDP"},
242
	{RAW, "RAW"},
243
	{TANDEM, "TANDEM"},
244
	{XTABS, "XTABS"},
245
	{0, NULL}
246
#define ALLCTRL	(CBREAK|CRMOD|ECHO|EVENP|LCASE|LLITOUT|ODDP|RAW|TANDEM|XTABS)
247
    };
248
249
    buf = _nc_trace_buf(0,
250
			8 + sizeof(cflags));
251
    if (buf != 0) {
252
	if (tty->sg_flags & ALLCTRL) {
253
	    lookup_bits(buf, cflags, "cflags", tty->sg_flags);
254
	}
255
    }
256
#endif
257
    return (buf);
258
}
259
260
NCURSES_EXPORT(char *)
261
_nc_tracebits(void)
262
{
263
    return _nc_trace_ttymode(&(cur_term->Nttyb));
264
}
265
#else
266
NCURSES_EXPORT(char *)
267
_nc_tracebits(void)
268
{
269
	return NULL;
270
}
271
#endif /* TRACE */