xref: /illumos-gate/usr/src/lib/libxcurses2/src/libc/xcurses/private.h (revision 1da57d551424de5a9d469760be7c4b4d4f10a755)
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 /*
23  * Copyright (c) 1996-1999 by Sun Microsystems, Inc.
24  * All rights reserved.
25  */
26 
27 /*
28  * private.h
29  *
30  * XCurses Library
31  *
32  * Copyright 1990, 1995 by Mortice Kern Systems Inc.  All rights reserved.
33  *
34  */
35 
36 #include <sys/isa_defs.h>
37 #include <mks.h>
38 #include <curses.h>
39 #include <termios.h>
40 #include <unctrl.h>
41 
42 #define	M_TERM_NAME		"unknown"
43 
44 /*
45  * Interbyte timer value used for processing multibyte function keys.
46  */
47 #ifndef M_CURSES_INTERBYTE_TIME
48 #define	M_CURSES_INTERBYTE_TIME		10
49 #endif
50 
51 /*
52  * Maximum number of lines that can be ripped off.
53  */
54 #ifndef M_CURSES_MAX_RIPOFFLINE
55 #define	M_CURSES_MAX_RIPOFFLINE		5
56 #endif
57 
58 /*
59  * See copywin() and wrefresh() case 4.  It is unclear whether XPG4 V2
60  * disallows supporting case 4 (expanding characters straddling a window
61  * boundary).
62  */
63 #define	M_CURSES_SENSIBLE_WINDOWS
64 
65 /*
66  * Enable typeahead() support.
67  */
68 /* using unget buffer as typeahead buffer too */
69 #define	M_TYPEAHEAD_SIZE	200
70 
71 /*
72  * END OF CONFIGURABLE SECTION
73  */
74 
75 /*
76  * Constant WINDOW definition attributes.
77  */
78 #define	W_IS_PAD	0x0001	/* Window is a pad. */
79 #define	W_END_LINE	0x0002	/* End of line is the margin. */
80 #define	W_FULL_LINE	0x0004	/* Line spans screen width. */
81 #define	W_FULL_WINDOW	0x0008	/* Window is full screen. */
82 #define	W_SCROLL_WINDOW	0x0010	/* Touches bottom-right corner */
83 
84 /*
85  * WINDOW state.
86  */
87 #define	W_CLEAR_WINDOW	0x0020	/* clearok() clear screen next update. */
88 #define	W_REDRAW_WINDOW 0x0040	/* wredrawln() use simple() next update. */
89 
90 /*
91  * Configurable WINDOW options.
92  */
93 #define	W_FLUSH		0x0080	/* immedok() update when window changes. */
94 #define	W_CAN_SCROLL	0x0100	/* scrollok() window can software scroll. */
95 #define	W_LEAVE_CURSOR	0x0200	/* leaveok() don't fuss with the cursor. */
96 #define	W_SYNC_UP	0x0400	/* syncok() update ancestors when changed. */
97 #define	W_USE_KEYPAD	0x0800	/* keypad() enbles KEY_ processing. */
98 #define	W_USE_TIMEOUT	0x1000	/* notimeout() disables the interbyte timer. */
99 #define	W_CONFIG_MASK	0x1f80 	/* Mask of configurable flags. */
100 
101 /*
102  * Flags used in SCREEN.
103  */
104 #define	S_ECHO		0x0001	/* Software echo enbled. */
105 #define	S_ENDWIN	0x0002	/* Curses is in "shell" mode. */
106 #define	S_INS_DEL_CHAR	0x0004	/* idcok() enabled for terminal (future). */
107 #define	S_INS_DEL_LINE	0x0008	/* idlok() enabled for terminal. */
108 #define	S_ISATTY	0x0010	/* _kfd is a terminal. */
109 #define	S_USE_META	0x0020	/* meta() enabled. */
110 #define	S_TYPEAHEAD_OK	0x0040	/* typeahead flag */
111 
112 typedef struct t_decode {
113 	struct t_decode	*sibling;
114 	struct t_decode	*child;
115 	short	key;			/* KEY_ value or 0. */
116 	int	ch;		/* Character found by this node. */
117 } t_decode;
118 
119 typedef struct {
120 	int	top;			/* # of lines off the top. */
121 	int	bottom;			/* # of lines off the bottom (-ve). */
122 	struct {
123 		int	dy;		/* Distance from screen top/bottom. */
124 		int	(*init)(WINDOW *, int);	/* Init. function for window. */
125 		int	created;
126 	} line[M_CURSES_MAX_RIPOFFLINE];
127 } t_rip;
128 
129 extern SCREEN	*__m_screen;
130 extern int	__m_slk_format;
131 extern int	__m_slk_labels_on;
132 extern const short	__m_keyindex[][2];
133 
134 extern const char	*boolnames[];
135 extern const char	*boolcodes[];
136 extern const char	*boolfnames[];
137 extern const char	*numnames[];
138 extern const char	*numcodes[];
139 extern const char	*numfnames[];
140 extern const char	*strnames[];
141 extern const char	*strcodes[];
142 extern const char	*strfnames[];
143 
144 #define	ATTR_STATE	cur_term->_at
145 
146 #define	PTERMIOS(x)	((struct termios *)(cur_term->x))
147 
148 #define	__m_cc_width(cc)	wcwidth((cc)->_wc[0])
149 
150 #define	TPUTS(a, b, c)			tputs(a, b, c)
151 
152 extern int	__m_wc_cc(wint_t, cchar_t *);
153 extern int	__m_mbs_cc(const char *, attr_t, short, cchar_t *);
154 extern int	__m_wcs_cc(const wchar_t *, attr_t, short, cchar_t *);
155 extern int	__m_acs_cc(chtype, cchar_t *);
156 extern int	__m_wacs_cc(const cchar_t *, cchar_t *);
157 extern int	__m_cc_mbs(const cchar_t *, char *, int);
158 
159 extern int	__m_cc_sort(cchar_t *);
160 extern int	__m_cc_write(const cchar_t *);
161 extern int	__m_cc_first(WINDOW *, int, int);
162 extern int	__m_cc_next(WINDOW *, int, int);
163 extern int	__m_cc_islast(WINDOW *, int, int);
164 extern int	__m_cc_expand(WINDOW *, int, int, int);
165 extern int	__m_cc_erase(WINDOW *, int, int, int, int);
166 extern int	__m_cc_compare(const cchar_t *, const cchar_t *, int);
167 extern int	__m_cc_replace(WINDOW *, int, int, const cchar_t *, int);
168 extern int	__m_cc_add(WINDOW *, int, int, const cchar_t *, int,
169 	int *, int *);
170 #if defined(_LP64)
171 extern void	__m_cc_hash(WINDOW *, unsigned int *, int);
172 #else
173 extern void	__m_cc_hash(WINDOW *, unsigned long *, int);
174 #endif
175 
176 extern int	__m_set_echo(int);
177 extern int	__m_tty_get(struct termios *);
178 extern int	__m_tty_set(struct termios *);
179 extern int	__m_decode_init(t_decode **);
180 extern void	__m_decode_free(t_decode **);
181 extern int	__m_do_scroll(WINDOW *, int, int, int *, int *);
182 extern int	__m_ptr_move(void **, unsigned, unsigned, unsigned, unsigned);
183 
184 extern int	__m_doupdate_init(void);
185 extern int	__m_wins_wch(WINDOW *, int, int, const cchar_t *, int *, int *);
186 extern int	__m_cc_ins(WINDOW *, int, int, const cchar_t *);
187 extern void	__m_mvcur_cost(void);
188 
189 extern int	__m_cc_modify(WINDOW *, int, int, const cchar_t *);
190 extern int	__m_tty_set_prog_mode(void);
191 extern int	__m_tputs(const char *, int, int (*)(int));
192 extern int	__m_slk_clear(int);
193 extern int	__m_cc_add_k(WINDOW *, int, int, const cchar_t *,
194 	int, int *, int *);
195 extern int	__m_cc_equal(const cchar_t *, const cchar_t *);
196 extern void	__m_touch_locs(WINDOW *, int, int, int);
197 extern int	__m_wadd_wch(WINDOW *, const cchar_t *);
198 extern void	__m_slk_doupdate(void);
199 extern int	__m_outc(int);
200 extern int	__m_tty_wc(int, wchar_t *);
201 extern int	__m_chtype_cc(chtype, cchar_t *);
202 extern chtype	__m_cc_chtype(const cchar_t *);
203 extern int	__m_copywin(const WINDOW *, WINDOW *, int);
204 extern WINDOW	*__m_newwin(WINDOW *, int, int, int, int);
205 extern int	__m_putchar(int);
206 extern int	__m_mvcur(int, int, int, int, int (*)(int));
207 extern int	__m_read_terminfo(const char *, TERMINAL *);
208 extern int	__m_setupterm(char *, int, int, int *);
209 
210 extern int	pollTypeahead(void);
211 extern int	wistombs(char *, const wint_t *, int);
212 extern int	wistowcs(wchar_t *, const wint_t *, int);
213 
214 extern void	wtouchln_hard(WINDOW *, int, int);
215 
216 /*
217  * Unique callback functions to initialize a SCREEN's wide_io_t structure,
218  * which is used by __m_wio_get().   The __xc_ denotes XCurses and is used
219  * instead of __m_ to avoid possible name conflicts else-where in MKS
220  * libraries and applications.  Note that wgetch() is used for the get
221  * function.
222  */
223 extern int	__xc_feof(void *);
224 extern int	__xc_ferror(void *);
225 extern void	__xc_clearerr(void *);
226 extern int	__xc_ungetc(int, void *);
227 
228 /*
229  * Input stack macros replaced by these functions.
230  */
231 extern void	iqAdd(unsigned int ch);
232 extern void	iqPush(unsigned int ch);
233 extern int	iqIsEmpty(void);
234 extern void	iqReset(void);
235 extern int	iqPull(void);
236 
237 #define	WSYNC(w)	\
238 	if ((w)->_flags & W_SYNC_UP) {\
239 		wsyncup(w);\
240 	}
241 #define	WFLUSH(w)	(((w)->_flags & W_FLUSH) ? wrefresh(w) : OK)
242 
243 /* end */
244