xref: /illumos-gate/usr/src/cmd/mdb/common/kmdb/kmdb_terminfo_skel.c (revision 628e3cbed6489fa1db545d8524a06cd6535af456)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /* BEGIN PROLOGUE */
23 
24 /*
25  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
26  * Use is subject to license terms.
27  */
28 
29 #pragma ident	"%Z%%M%	%I%	%E% SMI"
30 
31 /*
32  * kmdb_terminfo_skel.c is the skeleton used to generate
33  * kmdb_terminfo.c, which contains the kmdb-specific version
34  * of terminfo.
35  */
36 
37 #include <strings.h>
38 #include <unistd.h>
39 #include <curses.h>
40 
41 #include <mdb/mdb_io.h>
42 #include <mdb/mdb_debug.h>
43 #include <mdb/mdb.h>
44 
45 typedef enum {
46 	TIO_ATTR_REQSTR,
47 	TIO_ATTR_STR,
48 	TIO_ATTR_BOOL,
49 	TIO_ATTR_INT
50 } termio_attr_type_t;
51 
52 typedef struct {
53 	const char *ta_name;
54 	termio_attr_type_t ta_type;
55 	const void *ta_data;
56 } termio_attr_t;
57 
58 typedef struct {
59 	const char *td_name;
60 	const termio_attr_t *td_data;
61 } termio_desc_t;
62 
63 /* END PROLOGUE */
64 
65 /*
66  * tigen will insert the following definitions here:
67  *
68  *	<term>_attrs  (one per terminal type passed to tigen)
69  *	termio_db
70  */
71 
72 /* BEGIN EPILOGUE */
73 
74 static const termio_desc_t *tdp;
75 
76 /*ARGSUSED*/
77 int
78 setupterm(char *name, int fd, int *err)
79 {
80 	for (tdp = termio_db; tdp->td_name != NULL; tdp++) {
81 		if (strcmp(tdp->td_name, name) == 0)
82 			return (OK);
83 	}
84 
85 	*err = 0;
86 	return (ERR);
87 }
88 
89 int
90 restartterm(char *name, int fd, int *err)
91 {
92 	const termio_desc_t *otdp = tdp;
93 	int status;
94 
95 	if ((status = setupterm(name, fd, err)) != OK)
96 		tdp = otdp; /* restore old terminal settings */
97 
98 	return (status);
99 }
100 
101 const char *
102 tigetstr(const char *name)
103 {
104 	const termio_attr_t *tap;
105 
106 	for (tap = tdp->td_data; tap->ta_name != NULL; tap++) {
107 		if (strcmp(tap->ta_name, name) == 0) {
108 			if (tap->ta_type == TIO_ATTR_REQSTR ||
109 			    tap->ta_type == TIO_ATTR_STR)
110 				return (tap->ta_data);
111 			else
112 				return ((char *)-1);
113 		}
114 	}
115 
116 	return (NULL);
117 }
118 
119 int
120 tigetflag(const char *name)
121 {
122 	const termio_attr_t *tap;
123 
124 	for (tap = tdp->td_data; tap->ta_name != NULL; tap++) {
125 		if (strcmp(tap->ta_name, name) == 0) {
126 			if (tap->ta_type == TIO_ATTR_BOOL)
127 				return ((uintptr_t)tap->ta_data);
128 			else
129 				return (-1);
130 		}
131 	}
132 
133 	return (0);
134 }
135 
136 int
137 tigetnum(const char *name)
138 {
139 	const termio_attr_t *tap;
140 
141 	for (tap = tdp->td_data; tap->ta_name != NULL; tap++) {
142 		if (strcmp(tap->ta_name, name) == 0) {
143 			if (tap->ta_type == TIO_ATTR_INT)
144 				return ((uintptr_t)tap->ta_data);
145 			else
146 				return (-2);
147 		}
148 	}
149 
150 	return (-1);
151 }
152 
153 /* END EPILOGUE */
154