Annotation of src/lib/libcurses/curses_private.h, Revision 1.62
1.62 ! roy 1: /* $NetBSD: curses_private.h,v 1.61 2017/01/30 14:55:58 roy 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.40 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
1.46 wiz 38: * - Add a circular input character buffer in __screen to handle
39: * wide-character input (used in get_wch())
1.40 blymn 40: */
41:
1.44 roy 42: #include <term.h>
1.17 blymn 43: #include <termios.h>
44:
1.1 blymn 45: /* Private structure definitions for curses. */
1.18 blymn 46:
47: /* Termcap capabilities. */
1.40 blymn 48: #ifdef HAVE_WCHAR
49: /*
50: * Add a list of non-spacing characters to each spacing
51: * character in a singly linked list
52: */
53: typedef struct nschar_t {
54: wchar_t ch; /* Non-spacing character */
55: struct nschar_t *next; /* Next non-spacing character */
56: } nschar_t;
57: #endif /* HAVE_WCHAR */
58:
1.1 blymn 59: /*
1.42 jdc 60: * A window is an array of __LINE structures pointed to by the 'lines' pointer.
1.1 blymn 61: * A line is an array of __LDATA structures pointed to by the 'line' pointer.
62: *
63: * IMPORTANT: the __LDATA structure must NOT induce any padding, so if new
64: * fields are added -- padding fields with *constant values* should ensure
65: * that the compiler will not generate any padding when storing an array of
66: * __LDATA structures. This is to enable consistent use of memcmp, and memcpy
67: * for comparing and copying arrays.
68: */
69:
70: struct __ldata {
71: wchar_t ch; /* Character */
72: attr_t attr; /* Attributes */
1.40 blymn 73: #ifdef HAVE_WCHAR
74: nschar_t *nsp; /* Foreground non-spacing character pointer */
75: #endif /* HAVE_WCHAR */
1.1 blymn 76: };
77:
1.40 blymn 78: #ifdef HAVE_WCHAR
79: /* macros to extract the width of a wide character */
80: #define __WCWIDTH 0xfc000000
81: #define WCW_SHIFT 26
82: #define WCOL(wc) ((((unsigned) (wc).attr) >> WCW_SHIFT ) > MB_LEN_MAX ? ((int)(((unsigned) (wc).attr ) >> WCW_SHIFT )) - 64 : ((int)(((unsigned) (wc).attr ) >> WCW_SHIFT)))
83: #define SET_WCOL(c, w) do { \
84: ((c).attr) = ((((c).attr) & WA_ATTRIBUTES ) | ((w) << WCW_SHIFT )); \
85: } while(/*CONSTCOND*/0)
86: #define BGWCOL(wc) ((((wc).battr) >> WCW_SHIFT ) > MB_LEN_MAX ? (((wc).battr ) >> WCW_SHIFT ) - 64 : (((wc).battr ) >> WCW_SHIFT ))
87: #define SET_BGWCOL(c, w) do { \
88: ((c).battr) = ((((c).battr) & WA_ATTRIBUTES ) | ((w) << WCW_SHIFT )); \
89: } while(/*CONSTCOND*/0)
90: #endif /* HAVE_WCHAR */
91:
1.1 blymn 92: #define __LDATASIZE (sizeof(__LDATA))
93:
94: struct __line {
1.24 blymn 95: #ifdef DEBUG
96: #define SENTINEL_VALUE 0xaac0ffee
1.40 blymn 97:
1.24 blymn 98: unsigned int sentinel; /* try to catch line overflows */
99: #endif
1.1 blymn 100: #define __ISDIRTY 0x01 /* Line is dirty. */
101: #define __ISPASTEOL 0x02 /* Cursor is past end of line */
1.49 blymn 102: #define __ISFORCED 0x04 /* Force update, no optimisation */
1.1 blymn 103: unsigned int flags;
104: unsigned int hash; /* Hash value for the line. */
105: int *firstchp, *lastchp; /* First and last chngd columns ptrs */
106: int firstch, lastch; /* First and last changed columns. */
107: __LDATA *line; /* Pointer to the line text. */
108: };
109:
110: struct __window { /* Window structure. */
111: struct __window *nextp, *orig; /* Subwindows list and parent. */
112: int begy, begx; /* Window home. */
113: int cury, curx; /* Current x, y coordinates. */
114: int maxy, maxx; /* Maximum values for curx, cury. */
1.29 dsl 115: int reqy, reqx; /* Size requested when created */
116: int ch_off; /* x offset for firstch/lastch. */
1.43 roy 117: __LINE **alines; /* Array of pointers to the lines */
1.1 blymn 118: __LINE *lspace; /* line space (for cleanup) */
119: __LDATA *wspace; /* window space (for cleanup) */
120:
121: #define __ENDLINE 0x00000001 /* End of screen. */
122: #define __FLUSH 0x00000002 /* Fflush(stdout) after refresh. */
123: #define __FULLWIN 0x00000004 /* Window is a screen. */
124: #define __IDLINE 0x00000008 /* Insert/delete sequences. */
125: #define __SCROLLWIN 0x00000010 /* Last char will scroll window. */
126: #define __SCROLLOK 0x00000020 /* Scrolling ok. */
127: #define __CLEAROK 0x00000040 /* Clear on next refresh. */
128: #define __LEAVEOK 0x00000100 /* If cursor left */
129: #define __KEYPAD 0x00010000 /* If interpreting keypad codes */
130: #define __NOTIMEOUT 0x00020000 /* Wait indefinitely for func keys */
1.26 jdc 131: #define __IDCHAR 0x00040000 /* insert/delete char sequences */
132: #define __ISPAD 0x00080000 /* "window" is a pad */
1.50 blymn 133: #define __ISDERWIN 0x00100000 /* "window" is derived from parent */
1.54 roy 134: #define __IMMEDOK 0x00200000 /* refreshed when changed */
135: #define __SYNCOK 0x00400000 /* sync when changed */
1.1 blymn 136: unsigned int flags;
137: int delay; /* delay for getch() */
138: attr_t wattr; /* Character attributes */
1.5 jdc 139: wchar_t bch; /* Background character */
1.2 jdc 140: attr_t battr; /* Background attributes */
1.14 jdc 141: int scr_t, scr_b; /* Scrolling region top, bottom */
1.32 dsl 142: SCREEN *screen; /* Screen for this window */
1.36 jdc 143: int pbegy, pbegx,
144: sbegy, sbegx,
145: smaxy, smaxx; /* Saved prefresh() values */
1.50 blymn 146: int dery, derx; /* derived window coordinates
147: - top left corner of source
148: relative to parent win */
1.40 blymn 149: #ifdef HAVE_WCHAR
150: nschar_t *bnsp; /* Background non-spacing char list */
151: #endif /* HAVE_WCHAR */
1.51 christos 152: FILE *fp; /* for window formatted printf */
1.1 blymn 153: };
1.5 jdc 154:
155: /* Set of attributes unset by 'me' - 'mb', 'md', 'mh', 'mk', 'mp' and 'mr'. */
1.40 blymn 156: #ifndef HAVE_WCHAR
1.5 jdc 157: #define __TERMATTR \
158: (__REVERSE | __BLINK | __DIM | __BOLD | __BLANK | __PROTECT)
1.40 blymn 159: #else
160: #define __TERMATTR \
161: (__REVERSE | __BLINK | __DIM | __BOLD | __BLANK | __PROTECT \
162: | WA_TOP | WA_LOW | WA_LEFT | WA_RIGHT | WA_HORIZONTAL | WA_VERTICAL)
163: #endif /* HAVE_WCHAR */
1.2 jdc 164:
1.3 jdc 165: struct __winlist {
166: struct __window *winp; /* The window. */
167: struct __winlist *nextp; /* Next window. */
168: };
169:
1.17 blymn 170: struct __color {
171: short num;
172: short red;
173: short green;
174: short blue;
175: int flags;
176: };
177:
178: /* List of colour pairs */
179: struct __pair {
180: short fore;
181: short back;
182: int flags;
183: };
184:
185: /* Maximum colours */
1.55 roy 186: #define MAX_COLORS 256
1.17 blymn 187: /* Maximum colour pairs - determined by number of colour bits in attr_t */
1.25 jdc 188: #define MAX_PAIRS PAIR_NUMBER(__COLOR)
1.17 blymn 189:
190: typedef struct keymap keymap_t;
191:
1.60 roy 192: /* POSIX allows up to 8 columns in a label. */
193: #define MAX_SLK_COLS 8
194: #ifdef HAVE_WCHAR
195: #define MAX_SLK_LABEL sizeof(wchar_t) * MAX_SLK_COLS
196: #else
197: #define MAX_SLK_LABEL MAX_SLK_COLS
198: #endif
199: struct __slk_label {
200: char *text;
201: int justify;
202: #define SLK_JUSTIFY_LEFT 0
203: #define SLK_JUSTIFY_CENTER 1
204: #define SLK_JUSTIFY_RIGHT 2
205: char label[MAX_SLK_LABEL + 1];
206: int x;
207: };
1.59 roy 208:
209: #define MAX_RIPS 5
210: struct __ripoff {
211: int nlines;
212: WINDOW *win;
213: };
214:
1.17 blymn 215: /* this is the encapsulation of the terminal definition, one for
216: * each terminal that curses talks to.
217: */
218: struct __screen {
219: FILE *infd, *outfd; /* input and output file descriptors */
220: WINDOW *curscr; /* Current screen. */
221: WINDOW *stdscr; /* Standard screen. */
222: WINDOW *__virtscr; /* Virtual screen (for doupdate()). */
223: int curwin; /* current window for refresh */
1.29 dsl 224: int lx, ly; /* loop parameters for refresh */
1.17 blymn 225: int COLS; /* Columns on the screen. */
226: int LINES; /* Lines on the screen. */
1.59 roy 227: int nripped; /* Number of ripofflines. */
228: struct __ripoff ripped[MAX_RIPS]; /* ripofflines. */
1.56 roy 229: int ESCDELAY; /* Delay between keys in esc seq's. */
230: #define ESCDELAY_DEFAULT 300 /* milliseconds. */
1.48 roy 231: int TABSIZE; /* Size of a tab. */
1.56 roy 232: #define TABSIZE_DEFAULT 8 /* spaces. */
1.17 blymn 233: int COLORS; /* Maximum colors on the screen */
234: int COLOR_PAIRS; /* Maximum color pairs on the screen */
235: int My_term; /* Use Def_term regardless. */
236: char GT; /* Gtty indicates tabs. */
237: char NONL; /* Term can't hack LF doing a CR. */
238: char UPPERCASE; /* Terminal is uppercase only. */
239:
240: chtype acs_char[NUM_ACS];
1.40 blymn 241: #ifdef HAVE_WCHAR
242: cchar_t wacs_char[ NUM_ACS ];
243: #endif /* HAVE_WCHAR */
1.17 blymn 244: struct __color colours[MAX_COLORS];
245: struct __pair colour_pairs[MAX_PAIRS];
246: attr_t nca;
1.20 blymn 247:
1.17 blymn 248: /* Style of colour manipulation */
249: #define COLOR_NONE 0
250: #define COLOR_ANSI 1 /* ANSI/DEC-style colour manipulation */
251: #define COLOR_HP 2 /* HP-style colour manipulation */
252: #define COLOR_TEK 3 /* Tektronix-style colour manipulation */
253: #define COLOR_OTHER 4 /* None of the others but can set fore/back */
254: int color_type;
1.20 blymn 255:
1.17 blymn 256: attr_t mask_op;
257: attr_t mask_me;
258: attr_t mask_ue;
259: attr_t mask_se;
1.44 roy 260: TERMINAL *term;
1.17 blymn 261: int old_mode; /* old cursor visibility state for terminal */
262: keymap_t *base_keymap;
263: int echoit;
264: int pfast;
265: int rawmode;
1.30 jdc 266: int nl;
1.17 blymn 267: int noqch;
268: int clearok;
269: int useraw;
270: struct __winlist *winlistp;
271: struct termios cbreakt, rawt, *curt, save_termios;
272: struct termios orig_termios, baset, savedtty;
273: int ovmin;
274: int ovtime;
275: char *stdbuf;
276: unsigned int len;
277: int meta_state;
1.43 roy 278: char padchar;
1.17 blymn 279: int endwin;
1.22 itojun 280: int notty;
1.27 blymn 281: int half_delay;
1.35 jdc 282: int resized;
1.41 jdc 283: wchar_t *unget_list;
284: int unget_len, unget_pos;
1.52 roy 285: int filtered;
1.53 roy 286: int checkfd;
1.60 roy 287:
288: /* soft label key */
289: bool is_term_slk;
290: WINDOW *slk_window;
291: int slk_format;
292: #define SLK_FMT_3_2_3 0
293: #define SLK_FMT_4_4 1
294: int slk_nlabels;
295: int slk_label_len;
296: bool slk_hidden;
297: struct __slk_label *slk_labels;
298:
1.40 blymn 299: #ifdef HAVE_WCHAR
300: #define MB_LEN_MAX 8
301: #define MAX_CBUF_SIZE MB_LEN_MAX
302: int cbuf_head; /* header to cbuf */
303: int cbuf_tail; /* tail to cbuf */
304: int cbuf_cur; /* the current char in cbuf */
305: mbstate_t sp; /* wide char processing state */
306: char cbuf[ MAX_CBUF_SIZE ]; /* input character buffer */
307: #endif /* HAVE_WCHAR */
1.17 blymn 308: };
309:
310:
1.11 jdc 311: extern char __GT; /* Gtty indicates tabs. */
312: extern char __NONL; /* Term can't hack LF doing a CR. */
313: extern char __UPPERCASE; /* Terminal is uppercase only. */
314: extern int My_term; /* Use Def_term regardless. */
315: extern const char *Def_term; /* Default terminal type. */
1.17 blymn 316: extern SCREEN *_cursesi_screen; /* The current screen in use */
1.11 jdc 317:
1.39 jdc 318: /* Debugging options/functions. */
1.2 jdc 319: #ifdef DEBUG
1.39 jdc 320: #define __CTRACE_TSTAMP 0x00000001
321: #define __CTRACE_MISC 0x00000002
322: #define __CTRACE_INIT 0x00000004
323: #define __CTRACE_SCREEN 0x00000008
324: #define __CTRACE_WINDOW 0x00000010
325: #define __CTRACE_REFRESH 0x00000020
326: #define __CTRACE_COLOR 0x00000040
327: #define __CTRACE_INPUT 0x00000080
328: #define __CTRACE_OUTPUT 0x00000100
329: #define __CTRACE_LINE 0x00000200
330: #define __CTRACE_ATTR 0x00000400
331: #define __CTRACE_ERASE 0x00000800
1.42 jdc 332: #define __CTRACE_FILEIO 0x00001000
1.39 jdc 333: #define __CTRACE_ALL 0x7fffffff
334: void __CTRACE_init(void);
335: void __CTRACE(int, const char *, ...) __attribute__((__format__(__printf__, 2, 3)));
1.2 jdc 336: #endif
1.39 jdc 337:
338: /* Private functions. */
1.44 roy 339: int __cputchar_args(int, void *);
1.23 itojun 340: void _cursesi_free_keymap(keymap_t *);
341: int _cursesi_gettmode(SCREEN *);
342: void _cursesi_reset_acs(SCREEN *);
1.49 blymn 343: int _cursesi_addbyte(WINDOW *, __LINE **, int *, int *, int , attr_t, int);
344: int _cursesi_addwchar(WINDOW *, __LINE **, int *, int *, const cchar_t *,
345: int);
346: int _cursesi_waddbytes(WINDOW *, const char *, int, attr_t, int);
1.40 blymn 347: #ifdef HAVE_WCHAR
348: void _cursesi_reset_wacs(SCREEN *);
349: #endif /* HAVE_WCHAR */
1.23 itojun 350: void _cursesi_resetterm(SCREEN *);
351: int _cursesi_setterm(char *, SCREEN *);
1.4 blymn 352: int __delay(void);
1.57 roy 353: unsigned int __hash_more(const void *, size_t, unsigned int);
1.23 itojun 354: #define __hash(s, len) __hash_more((s), (len), 0u)
355: void __id_subwins(WINDOW *);
356: void __init_getch(SCREEN *);
357: void __init_acs(SCREEN *);
1.40 blymn 358: #ifdef HAVE_WCHAR
359: void __init_get_wch(SCREEN *);
360: void __init_wacs(SCREEN *);
1.44 roy 361: int __cputwchar_args( wchar_t, void * );
1.40 blymn 362: int _cursesi_copy_nsp(nschar_t *, struct __ldata *);
363: void __cursesi_free_nsp(nschar_t *);
364: void __cursesi_win_free_nsp(WINDOW *);
365: void __cursesi_putnsp(nschar_t *, const int, const int);
1.45 drochner 366: void __cursesi_chtype_to_cchar(chtype, cchar_t *);
1.40 blymn 367: #endif /* HAVE_WCHAR */
1.41 jdc 368: int __unget(wint_t);
1.23 itojun 369: int __mvcur(int, int, int, int, int);
1.26 jdc 370: WINDOW *__newwin(SCREEN *, int, int, int, int, int);
1.4 blymn 371: int __nodelay(void);
372: int __notimeout(void);
373: void __restartwin(void);
374: void __restore_colors(void);
1.6 blymn 375: void __restore_cursor_vis(void);
376: void __restore_meta_state(void);
1.4 blymn 377: void __restore_termios(void);
378: void __restore_stophandler(void);
1.35 jdc 379: void __restore_winchhandler(void);
1.59 roy 380: int __ripoffscreen(SCREEN *, int *);
381: void __ripoffresize(SCREEN *);
382: int __rippedlines(const SCREEN *);
1.4 blymn 383: void __save_termios(void);
1.25 jdc 384: void __set_color(WINDOW *win, attr_t attr);
1.4 blymn 385: void __set_stophandler(void);
1.35 jdc 386: void __set_winchhandler(void);
1.23 itojun 387: void __set_subwin(WINDOW *, WINDOW *);
1.60 roy 388: int __slk_init(SCREEN *);
389: void __slk_free(SCREEN *);
390: int __slk_resize(SCREEN *, int cols);
391: int __slk_noutrefresh(SCREEN *);
1.23 itojun 392: void __startwin(SCREEN *);
393: void __stop_signal_handler(int);
1.4 blymn 394: int __stopwin(void);
1.23 itojun 395: void __swflags(WINDOW *);
1.54 roy 396: void __sync(WINDOW *);
1.23 itojun 397: int __timeout(int);
398: int __touchline(WINDOW *, int, int, int);
399: int __touchwin(WINDOW *);
1.60 roy 400: int __unripoffline(int (*)(WINDOW *, int));
1.7 jdc 401: void __unsetattr(int);
1.25 jdc 402: void __unset_color(WINDOW *win);
1.23 itojun 403: int __waddch(WINDOW *, __LDATA *);
1.15 jdc 404: int __wgetnstr(WINDOW *, char *, int);
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>