Annotation of src/lib/libcurses/curses_private.h, Revision 1.38.6.5
1.38.6.5! blymn 1: /* $NetBSD: curses_private.h,v 1.38.6.4 2007/02/26 09:49:29 blymn Exp $ */
1.1 blymn 2:
3: /*-
4: * Copyright (c) 1998-2000 Brett Lymn
5: * (blymn@baea.com.au, brett_lymn@yahoo.com.au)
6: * All rights reserved.
7: *
8: * This code has been donated to The NetBSD Foundation by the Author.
9: *
10: * Redistribution and use in source and binary forms, with or without
11: * modification, are permitted provided that the following conditions
12: * are met:
13: * 1. Redistributions of source code must retain the above copyright
14: * notice, this list of conditions and the following disclaimer.
15: * 2. The name of the author may not be used to endorse or promote products
1.16 wiz 16: * derived from this software without specific prior written permission
1.1 blymn 17: *
18: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19: * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21: * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22: * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23: * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27: * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28: *
29: *
30: */
31:
1.38.6.1 blymn 32: /* Modified by Ruibiao Qiu <ruibiao@arl.wustl.edu,ruibiao@gmail.com>
33: * to add support for wide characters
34: * Changes:
35: * - Add a compiler variable HAVE_WCHAR for wide character only code
36: * - Add a pointer to liked list of non-spacing characters in __ldata
37: * and the macro to access the width field in the attribute field
38: * - Add a circular input character buffer in __screen to handle wide
39: * character input (used in get_wch())
40: */
41:
1.17 blymn 42: #include <termios.h>
43:
1.1 blymn 44: /* Private structure definitions for curses. */
1.18 blymn 45:
46: /* Termcap capabilities. */
47: extern char __tc_am, __tc_bs, __tc_cc, __tc_da, __tc_eo,
48: __tc_hc, __tc_hl, __tc_in, __tc_mi, __tc_ms,
49: __tc_nc, __tc_ns, __tc_os, __tc_ul, __tc_ut,
50: __tc_xb, __tc_xn, __tc_xt, __tc_xs, __tc_xx;
51: extern char __CA;
52: extern int __tc_pa, __tc_Co, __tc_NC;
53: extern char *__tc_ac, *__tc_AB, *__tc_ae, *__tc_AF, *__tc_AL,
54: *__tc_al, *__tc_as, *__tc_bc, *__tc_bl, *__tc_bt,
55: *__tc_cd, *__tc_ce, *__tc_cl, *__tc_cm, *__tc_cr,
56: *__tc_cs, *__tc_dc, *__tc_DL, *__tc_dl, *__tc_dm,
57: *__tc_DO, *__tc_do, *__tc_eA, *__tc_ed, *__tc_ei,
58: *__tc_ho, *__tc_Ic, *__tc_ic, *__tc_im, *__tc_Ip,
59: *__tc_ip, *__tc_k0, *__tc_k1, *__tc_k2, *__tc_k3,
60: *__tc_k4, *__tc_k5, *__tc_k6, *__tc_k7, *__tc_k8,
61: *__tc_k9, *__tc_kd, *__tc_ke, *__tc_kh, *__tc_kl,
62: *__tc_kr, *__tc_ks, *__tc_ku, *__tc_LE, *__tc_ll,
63: *__tc_ma, *__tc_mb, *__tc_md, *__tc_me, *__tc_mh,
64: *__tc_mk, *__tc_mm, *__tc_mo, *__tc_mp, *__tc_mr,
65: *__tc_nd, *__tc_nl, *__tc_oc, *__tc_op,
66: *__tc_rc, *__tc_RI, *__tc_Sb, *__tc_sc, *__tc_se,
67: *__tc_SF, *__tc_Sf, *__tc_sf, *__tc_so, *__tc_sp,
68: *__tc_SR, *__tc_sr, *__tc_ta, *__tc_te, *__tc_ti,
69: *__tc_uc, *__tc_ue, *__tc_UP, *__tc_up, *__tc_us,
70: *__tc_vb, *__tc_ve, *__tc_vi, *__tc_vs;
71:
1.38.6.1 blymn 72: #ifdef HAVE_WCHAR
73: extern char *__tc_Xh, *__tc_Xl, *__tc_Xo, *__tc_Xr, *__tc_Xt,
74: *__tc_Xv;
75: /*
76: * Add a list of non-spacing characters to each spacing
77: * character in a singly linked list
78: */
79: typedef struct nschar_t {
80: wchar_t ch; /* Non-spacing character */
81: struct nschar_t *next; /* Next non-spacing character */
82: } nschar_t;
83: #endif /* HAVE_WCHAR */
84:
1.1 blymn 85: /*
86: * A window an array of __LINE structures pointed to by the 'lines' pointer.
87: * A line is an array of __LDATA structures pointed to by the 'line' pointer.
88: *
89: * IMPORTANT: the __LDATA structure must NOT induce any padding, so if new
90: * fields are added -- padding fields with *constant values* should ensure
91: * that the compiler will not generate any padding when storing an array of
92: * __LDATA structures. This is to enable consistent use of memcmp, and memcpy
93: * for comparing and copying arrays.
94: */
95:
96: struct __ldata {
97: wchar_t ch; /* Character */
98: attr_t attr; /* Attributes */
1.38.6.1 blymn 99: #ifdef HAVE_WCHAR
100: nschar_t *nsp; /* Foreground non-spacing character pointer */
101: #endif /* HAVE_WCHAR */
1.1 blymn 102: };
103:
1.38.6.1 blymn 104: #ifdef HAVE_WCHAR
105: /* macros to extract the width of a wide character */
106: #define __WCWIDTH 0xfc000000
107: #define WCW_SHIFT 26
108: #define WCOL(wc) ((((unsigned) (wc).attr) >> WCW_SHIFT ) > MB_LEN_MAX ? ((int)(((unsigned) (wc).attr ) >> WCW_SHIFT )) - 64 : ((int)(((unsigned) (wc).attr ) >> WCW_SHIFT)))
109: #define SET_WCOL(c, w) do { \
110: ((c).attr) = ((((c).attr) & WA_ATTRIBUTES ) | ((w) << WCW_SHIFT )); \
111: } while(/*CONSTCOND*/0)
112: #define BGWCOL(wc) ((((wc).battr) >> WCW_SHIFT ) > MB_LEN_MAX ? (((wc).battr ) >> WCW_SHIFT ) - 64 : (((wc).battr ) >> WCW_SHIFT ))
113: #define SET_BGWCOL(c, w) do { \
114: ((c).battr) = ((((c).battr) & WA_ATTRIBUTES ) | ((w) << WCW_SHIFT )); \
115: } while(/*CONSTCOND*/0)
116: #endif /* HAVE_WCHAR */
117:
1.1 blymn 118: #define __LDATASIZE (sizeof(__LDATA))
119:
120: struct __line {
1.24 blymn 121: #ifdef DEBUG
122: #define SENTINEL_VALUE 0xaac0ffee
1.38.6.1 blymn 123:
1.24 blymn 124: unsigned int sentinel; /* try to catch line overflows */
125: #endif
1.1 blymn 126: #define __ISDIRTY 0x01 /* Line is dirty. */
127: #define __ISPASTEOL 0x02 /* Cursor is past end of line */
128: unsigned int flags;
129: unsigned int hash; /* Hash value for the line. */
130: int *firstchp, *lastchp; /* First and last chngd columns ptrs */
131: int firstch, lastch; /* First and last changed columns. */
132: __LDATA *line; /* Pointer to the line text. */
133: };
134:
135: struct __window { /* Window structure. */
136: struct __window *nextp, *orig; /* Subwindows list and parent. */
137: int begy, begx; /* Window home. */
138: int cury, curx; /* Current x, y coordinates. */
139: int maxy, maxx; /* Maximum values for curx, cury. */
1.29 dsl 140: int reqy, reqx; /* Size requested when created */
141: int ch_off; /* x offset for firstch/lastch. */
1.1 blymn 142: __LINE **lines; /* Array of pointers to the lines */
143: __LINE *lspace; /* line space (for cleanup) */
144: __LDATA *wspace; /* window space (for cleanup) */
145:
146: #define __ENDLINE 0x00000001 /* End of screen. */
147: #define __FLUSH 0x00000002 /* Fflush(stdout) after refresh. */
148: #define __FULLWIN 0x00000004 /* Window is a screen. */
149: #define __IDLINE 0x00000008 /* Insert/delete sequences. */
150: #define __SCROLLWIN 0x00000010 /* Last char will scroll window. */
151: #define __SCROLLOK 0x00000020 /* Scrolling ok. */
152: #define __CLEAROK 0x00000040 /* Clear on next refresh. */
153: #define __LEAVEOK 0x00000100 /* If cursor left */
154: #define __KEYPAD 0x00010000 /* If interpreting keypad codes */
155: #define __NOTIMEOUT 0x00020000 /* Wait indefinitely for func keys */
1.26 jdc 156: #define __IDCHAR 0x00040000 /* insert/delete char sequences */
157: #define __ISPAD 0x00080000 /* "window" is a pad */
1.1 blymn 158: unsigned int flags;
159: int delay; /* delay for getch() */
160: attr_t wattr; /* Character attributes */
1.5 jdc 161: wchar_t bch; /* Background character */
1.2 jdc 162: attr_t battr; /* Background attributes */
1.14 jdc 163: int scr_t, scr_b; /* Scrolling region top, bottom */
1.32 dsl 164: SCREEN *screen; /* Screen for this window */
1.36 jdc 165: int pbegy, pbegx,
166: sbegy, sbegx,
167: smaxy, smaxx; /* Saved prefresh() values */
1.38.6.1 blymn 168: #ifdef HAVE_WCHAR
169: nschar_t *bnsp; /* Background non-spacing char list */
170: #endif /* HAVE_WCHAR */
1.1 blymn 171: };
1.5 jdc 172:
173: /* Set of attributes unset by 'me' - 'mb', 'md', 'mh', 'mk', 'mp' and 'mr'. */
1.38.6.1 blymn 174: #ifndef HAVE_WCHAR
1.5 jdc 175: #define __TERMATTR \
176: (__REVERSE | __BLINK | __DIM | __BOLD | __BLANK | __PROTECT)
1.38.6.1 blymn 177: #else
178: #define __TERMATTR \
179: (__REVERSE | __BLINK | __DIM | __BOLD | __BLANK | __PROTECT \
180: | WA_TOP | WA_LOW | WA_LEFT | WA_RIGHT | WA_HORIZONTAL | WA_VERTICAL)
181: #endif /* HAVE_WCHAR */
1.2 jdc 182:
1.3 jdc 183: struct __winlist {
184: struct __window *winp; /* The window. */
185: struct __winlist *nextp; /* Next window. */
186: };
187:
1.17 blymn 188: struct __color {
189: short num;
190: short red;
191: short green;
192: short blue;
193: int flags;
194: };
195:
196: /* List of colour pairs */
197: struct __pair {
198: short fore;
199: short back;
200: int flags;
201: };
202:
203: /* Maximum colours */
204: #define MAX_COLORS 64
205: /* Maximum colour pairs - determined by number of colour bits in attr_t */
1.25 jdc 206: #define MAX_PAIRS PAIR_NUMBER(__COLOR)
1.17 blymn 207:
208: typedef struct keymap keymap_t;
209:
210: /* this is the encapsulation of the terminal definition, one for
211: * each terminal that curses talks to.
212: */
213: struct __screen {
214: FILE *infd, *outfd; /* input and output file descriptors */
215: WINDOW *curscr; /* Current screen. */
216: WINDOW *stdscr; /* Standard screen. */
217: WINDOW *__virtscr; /* Virtual screen (for doupdate()). */
218: int curwin; /* current window for refresh */
1.29 dsl 219: int lx, ly; /* loop parameters for refresh */
1.17 blymn 220: int COLS; /* Columns on the screen. */
221: int LINES; /* Lines on the screen. */
222: int COLORS; /* Maximum colors on the screen */
223: int COLOR_PAIRS; /* Maximum color pairs on the screen */
224: int My_term; /* Use Def_term regardless. */
225: char GT; /* Gtty indicates tabs. */
226: char NONL; /* Term can't hack LF doing a CR. */
227: char UPPERCASE; /* Terminal is uppercase only. */
228:
229: /* BEWARE!!! The order of the following terminal capabilities */
230: /* (tc_foo) is important - do not update without fixing the zap */
231: /* function in setterm.c */
232: char tc_am, tc_bs, tc_cc, tc_da, tc_eo, tc_hc, tc_hl, tc_in, tc_mi,
233: tc_ms, tc_nc, tc_ns, tc_os, tc_ul, tc_ut, tc_xb, tc_xn, tc_xt,
234: tc_xs, tc_xx;
235: int flag_count;
236: int tc_pa, tc_Co, tc_NC;
237: int int_count;
238: char *tc_AB, *tc_ac, *tc_ae, *tc_AF, *tc_AL,
239: *tc_al, *tc_as, *tc_bc, *tc_bl, *tc_bt,
240: *tc_cd, *tc_ce, *tc_cl, *tc_cm, *tc_cr,
241: *tc_cs, *tc_dc, *tc_DL, *tc_dl, *tc_dm,
242: *tc_DO, *tc_do, *tc_eA, *tc_ed, *tc_ei,
243: *tc_ho, *tc_Ic, *tc_ic, *tc_im, *tc_Ip,
244: *tc_ip, *tc_k0, *tc_k1, *tc_k2, *tc_k3,
245: *tc_k4, *tc_k5, *tc_k6, *tc_k7, *tc_k8,
246: *tc_k9, *tc_kd, *tc_ke, *tc_kh, *tc_kl,
247: *tc_kr, *tc_ks, *tc_ku, *tc_LE, *tc_ll,
248: *tc_ma, *tc_mb, *tc_md, *tc_me, *tc_mh,
249: *tc_mk, *tc_mm, *tc_mo, *tc_mp, *tc_mr,
250: *tc_nd, *tc_nl, *tc_oc, *tc_op, *tc_pc,
251: *tc_rc, *tc_RI, *tc_Sb, *tc_sc, *tc_se,
252: *tc_SF, *tc_Sf, *tc_sf, *tc_so, *tc_sp,
253: *tc_SR, *tc_sr, *tc_ta, *tc_te, *tc_ti,
254: *tc_uc, *tc_ue, *tc_UP, *tc_up, *tc_us,
1.38.6.1 blymn 255: #ifndef HAVE_WCHAR
1.17 blymn 256: *tc_vb, *tc_ve, *tc_vi, *tc_vs;
1.38.6.1 blymn 257: #else
258: *tc_vb, *tc_ve, *tc_vi, *tc_vs, *tc_Xh,
259: *tc_Xl, *tc_Xo, *tc_Xr, *tc_Xt, *tc_Xv;
260: #endif /* HAVE_WCHAR */
1.17 blymn 261: char CA;
262: int str_count;
263: chtype acs_char[NUM_ACS];
1.38.6.1 blymn 264: #ifdef HAVE_WCHAR
265: cchar_t wacs_char[ NUM_ACS ];
266: #endif /* HAVE_WCHAR */
1.17 blymn 267: struct __color colours[MAX_COLORS];
268: struct __pair colour_pairs[MAX_PAIRS];
269: attr_t nca;
1.20 blymn 270:
1.17 blymn 271: /* Style of colour manipulation */
272: #define COLOR_NONE 0
273: #define COLOR_ANSI 1 /* ANSI/DEC-style colour manipulation */
274: #define COLOR_HP 2 /* HP-style colour manipulation */
275: #define COLOR_TEK 3 /* Tektronix-style colour manipulation */
276: #define COLOR_OTHER 4 /* None of the others but can set fore/back */
277: int color_type;
1.20 blymn 278:
1.17 blymn 279: attr_t mask_op;
280: attr_t mask_me;
281: attr_t mask_ue;
282: attr_t mask_se;
283: struct tinfo *cursesi_genbuf;
284: int old_mode; /* old cursor visibility state for terminal */
285: keymap_t *base_keymap;
286: int echoit;
287: int pfast;
288: int rawmode;
1.30 jdc 289: int nl;
1.17 blymn 290: int noqch;
291: int clearok;
292: int useraw;
293: struct __winlist *winlistp;
294: struct termios cbreakt, rawt, *curt, save_termios;
295: struct termios orig_termios, baset, savedtty;
296: int ovmin;
297: int ovtime;
298: char *stdbuf;
299: unsigned int len;
300: int meta_state;
301: char pad_char;
1.21 christos 302: char ttytype[128];
1.17 blymn 303: int endwin;
1.22 itojun 304: int notty;
1.27 blymn 305: int half_delay;
1.35 jdc 306: int resized;
1.38.6.1 blymn 307: #ifdef HAVE_WCHAR
308: #define MB_LEN_MAX 8
309: #define MAX_CBUF_SIZE MB_LEN_MAX
310: int cbuf_head; /* header to cbuf */
311: int cbuf_tail; /* tail to cbuf */
312: int cbuf_cur; /* the current char in cbuf */
313: mbstate_t sp; /* wide char processing state */
314: char cbuf[ MAX_CBUF_SIZE ]; /* input character buffer */
315: #endif /* HAVE_WCHAR */
1.17 blymn 316: };
317:
318:
1.11 jdc 319: extern char __GT; /* Gtty indicates tabs. */
320: extern char __NONL; /* Term can't hack LF doing a CR. */
321: extern char __UPPERCASE; /* Terminal is uppercase only. */
322: extern int My_term; /* Use Def_term regardless. */
323: extern const char *Def_term; /* Default terminal type. */
1.17 blymn 324: extern SCREEN *_cursesi_screen; /* The current screen in use */
1.11 jdc 325:
1.38.6.2 jdc 326: /* Debugging options/functions. */
1.2 jdc 327: #ifdef DEBUG
1.38.6.2 jdc 328: #define __CTRACE_TSTAMP 0x00000001
329: #define __CTRACE_MISC 0x00000002
330: #define __CTRACE_INIT 0x00000004
331: #define __CTRACE_SCREEN 0x00000008
332: #define __CTRACE_WINDOW 0x00000010
333: #define __CTRACE_REFRESH 0x00000020
334: #define __CTRACE_COLOR 0x00000040
335: #define __CTRACE_INPUT 0x00000080
336: #define __CTRACE_OUTPUT 0x00000100
337: #define __CTRACE_LINE 0x00000200
338: #define __CTRACE_ATTR 0x00000400
339: #define __CTRACE_ERASE 0x00000800
340: #define __CTRACE_ALL 0x7fffffff
341: void __CTRACE_init(void);
342: void __CTRACE(int, const char *, ...) __attribute__((__format__(__printf__, 2, 3)));
1.2 jdc 343: #endif
1.38.6.2 jdc 344:
345: /* Private functions. */
1.23 itojun 346: void __cputchar_args(char, void *);
347: void _cursesi_free_keymap(keymap_t *);
348: int _cursesi_gettmode(SCREEN *);
349: void _cursesi_reset_acs(SCREEN *);
1.38.6.4 blymn 350: int _cursesi_addbyte(WINDOW *, __LINE **, int *, int *, int , attr_t);
351: int _cursesi_addwchar(WINDOW *, __LINE **, int *, int *, const cchar_t *);
1.38.6.1 blymn 352: #ifdef HAVE_WCHAR
353: void _cursesi_reset_wacs(SCREEN *);
354: #endif /* HAVE_WCHAR */
1.23 itojun 355: void _cursesi_resetterm(SCREEN *);
356: int _cursesi_setterm(char *, SCREEN *);
1.4 blymn 357: int __delay(void);
1.37 dsl 358: u_int __hash_more(const void *, size_t, u_int);
1.23 itojun 359: #define __hash(s, len) __hash_more((s), (len), 0u)
360: void __id_subwins(WINDOW *);
361: void __init_getch(SCREEN *);
362: void __init_acs(SCREEN *);
1.38.6.1 blymn 363: #ifdef HAVE_WCHAR
364: void __init_get_wch(SCREEN *);
365: void __init_wacs(SCREEN *);
1.38.6.3 blymn 366: void __cputwchar_args( wchar_t, void * );
367: int _cursesi_copy_nsp(nschar_t *, struct __ldata *);
368: void __cursesi_free_nsp(nschar_t *);
369: void __cursesi_win_free_nsp(WINDOW *);
1.38.6.5! blymn 370: void __cursesi_putnsp(nschar_t *, const int, const int);
1.38.6.1 blymn 371: #endif /* HAVE_WCHAR */
1.23 itojun 372: char *__longname(char *, char *); /* Original BSD version */
373: int __mvcur(int, int, int, int, int);
1.26 jdc 374: WINDOW *__newwin(SCREEN *, int, int, int, int, int);
1.4 blymn 375: int __nodelay(void);
376: int __notimeout(void);
377: char *__parse_cap(const char *, ...);
378: void __restartwin(void);
379: void __restore_colors(void);
1.6 blymn 380: void __restore_cursor_vis(void);
381: void __restore_meta_state(void);
1.4 blymn 382: void __restore_termios(void);
383: void __restore_stophandler(void);
1.35 jdc 384: void __restore_winchhandler(void);
1.4 blymn 385: void __save_termios(void);
1.25 jdc 386: void __set_color(WINDOW *win, attr_t attr);
1.4 blymn 387: void __set_stophandler(void);
1.35 jdc 388: void __set_winchhandler(void);
1.23 itojun 389: void __set_subwin(WINDOW *, WINDOW *);
390: void __startwin(SCREEN *);
391: void __stop_signal_handler(int);
1.4 blymn 392: int __stopwin(void);
1.23 itojun 393: void __swflags(WINDOW *);
394: int __timeout(int);
395: int __touchline(WINDOW *, int, int, int);
396: int __touchwin(WINDOW *);
397: char *__tscroll(const char *, int, int);
1.7 jdc 398: void __unsetattr(int);
1.25 jdc 399: void __unset_color(WINDOW *win);
1.23 itojun 400: int __waddch(WINDOW *, __LDATA *);
1.15 jdc 401: int __wgetnstr(WINDOW *, char *, int);
1.38.6.1 blymn 402: #ifdef HAVE_WCHAR
403: int __wgetn_wstr(WINDOW *, wchar_t *, int);
404: #endif /* HAVE_WCHAR */
1.35 jdc 405: void __winch_signal_handler(int);
1.2 jdc 406:
407: /* Private #defines. */
1.23 itojun 408: #define min(a,b) ((a) < (b) ? (a) : (b))
409: #define max(a,b) ((a) > (b) ? (a ): (b))
1.2 jdc 410:
411: /* Private externs. */
1.3 jdc 412: extern int __echoit;
413: extern int __endwin;
414: extern int __pfast;
415: extern int __rawmode;
416: extern int __noqch;
1.11 jdc 417: extern attr_t __mask_op, __mask_me, __mask_ue, __mask_se;
1.7 jdc 418: extern WINDOW *__virtscr;
1.25 jdc 419: extern int __using_color;
420: extern attr_t __default_color;
CVSweb <webmaster@jp.NetBSD.org>