xref: /illumos-gate/usr/src/cmd/mdb/common/kmdb/kmdb_terminfo_skel.c (revision 9164a50bf932130cbb5097a16f6986873ce0e6e5)
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 /*
30  * kmdb_terminfo_skel.c is the skeleton used to generate
31  * kmdb_terminfo.c, which contains the kmdb-specific version
32  * of terminfo.
33  */
34 
35 #include <strings.h>
36 #include <unistd.h>
37 #include <curses.h>
38 
39 #include <mdb/mdb_io.h>
40 #include <mdb/mdb_debug.h>
41 #include <mdb/mdb.h>
42 
43 typedef enum {
44 	TIO_ATTR_REQSTR,
45 	TIO_ATTR_STR,
46 	TIO_ATTR_BOOL,
47 	TIO_ATTR_INT
48 } termio_attr_type_t;
49 
50 typedef struct {
51 	const char *ta_name;
52 	termio_attr_type_t ta_type;
53 	const void *ta_data;
54 } termio_attr_t;
55 
56 typedef struct {
57 	const char *td_name;
58 	const termio_attr_t *td_data;
59 } termio_desc_t;
60 
61 /* END PROLOGUE */
62 
63 /*
64  * tigen will insert the following definitions here:
65  *
66  *	<term>_attrs  (one per terminal type passed to tigen)
67  *	termio_db
68  */
69 
70 /* BEGIN EPILOGUE */
71 
72 static const termio_desc_t *tdp;
73 
74 /*ARGSUSED*/
75 int
76 setupterm(char *name, int fd, int *err)
77 {
78 	for (tdp = termio_db; tdp->td_name != NULL; tdp++) {
79 		if (strcmp(tdp->td_name, name) == 0)
80 			return (OK);
81 	}
82 
83 	*err = 0;
84 	return (ERR);
85 }
86 
87 int
88 restartterm(char *name, int fd, int *err)
89 {
90 	const termio_desc_t *otdp = tdp;
91 	int status;
92 
93 	if ((status = setupterm(name, fd, err)) != OK)
94 		tdp = otdp; /* restore old terminal settings */
95 
96 	return (status);
97 }
98 
99 const char *
100 tigetstr(const char *name)
101 {
102 	const termio_attr_t *tap;
103 
104 	for (tap = tdp->td_data; tap->ta_name != NULL; tap++) {
105 		if (strcmp(tap->ta_name, name) == 0) {
106 			if (tap->ta_type == TIO_ATTR_REQSTR ||
107 			    tap->ta_type == TIO_ATTR_STR)
108 				return (tap->ta_data);
109 			else
110 				return ((char *)-1);
111 		}
112 	}
113 
114 	return (NULL);
115 }
116 
117 int
118 tigetflag(const char *name)
119 {
120 	const termio_attr_t *tap;
121 
122 	for (tap = tdp->td_data; tap->ta_name != NULL; tap++) {
123 		if (strcmp(tap->ta_name, name) == 0) {
124 			if (tap->ta_type == TIO_ATTR_BOOL)
125 				return ((uintptr_t)tap->ta_data);
126 			else
127 				return (-1);
128 		}
129 	}
130 
131 	return (0);
132 }
133 
134 int
135 tigetnum(const char *name)
136 {
137 	const termio_attr_t *tap;
138 
139 	for (tap = tdp->td_data; tap->ta_name != NULL; tap++) {
140 		if (strcmp(tap->ta_name, name) == 0) {
141 			if (tap->ta_type == TIO_ATTR_INT)
142 				return ((uintptr_t)tap->ta_data);
143 			else
144 				return (-2);
145 		}
146 	}
147 
148 	return (-1);
149 }
150 
151 /* END EPILOGUE */
152