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