1 /****************************************************************************
2 * Copyright (c) 1998 Free Software Foundation, Inc. *
4 * Permission is hereby granted, free of charge, to any person obtaining a *
5 * copy of this software and associated documentation files (the *
6 * "Software"), to deal in the Software without restriction, including *
7 * without limitation the rights to use, copy, modify, merge, publish, *
8 * distribute, distribute with modifications, sublicense, and/or sell *
9 * copies of the Software, and to permit persons to whom the Software is *
10 * furnished to do so, subject to the following conditions: *
12 * The above copyright notice and this permission notice shall be included *
13 * in all copies or substantial portions of the Software. *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
16 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
18 * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
21 * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
23 * Except as contained in this notice, the name(s) of the above copyright *
24 * holders shall not be used in advertising or otherwise to promote the *
25 * sale, use or other dealings in this Software without prior written *
27 ****************************************************************************/
29 /****************************************************************************
30 * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 *
31 * and: Eric S. Raymond <esr@snark.thyrsus.com> *
32 ****************************************************************************/
36 * $Id: curses.priv.h,v 1.101 1998/02/11 12:13:57 tom Exp $
40 * Header file for curses library objects which are private to
46 #define CURSES_PRIV_H 1
52 #include <ncurses_cfg.h>
55 #define MODULE_ID(id) static const char Ident[] = id;
57 #define MODULE_ID(id) /*nothing*/
62 #include <sys/types.h>
68 #if HAVE_SYS_BSDTYPES_H
69 #include <sys/bsdtypes.h> /* needed for ISC */
74 #elif HAVE_SYS_PARAM_H
75 # include <sys/param.h>
79 # if defined(_POSIX_PATH_MAX)
80 # define PATH_MAX _POSIX_PATH_MAX
81 # elif defined(MAXPATHLEN)
82 # define PATH_MAX MAXPATHLEN
84 # define PATH_MAX 255 /* the Posix minimum path-size */
99 /* Some systems have a broken 'select()', but workable 'poll()'. Use that */
100 #if HAVE_POLL && HAVE_SYS_STROPTS_H && HAVE_POLL_H
101 #define USE_FUNC_POLL 1
103 #define USE_FUNC_POLL 0
106 /* Alessandro Rubini's GPM (general-purpose mouse) */
107 #if HAVE_LIBGPM && HAVE_GPM_H
108 #define USE_GPM_SUPPORT 1
110 #define USE_GPM_SUPPORT 0
113 /* QNX mouse support */
114 #if defined(__QNX__) && !defined(__QNXNTO__)
115 #define USE_QNX_MOUSE 1
117 #define USE_QNX_MOUSE 0
120 #define DEFAULT_MAXCLICK 166
121 #define EV_MAX 8 /* size of mouse circular event queue */
124 * If we don't have signals to support it, don't add a sigwinch handler.
125 * In any case, resizing is an extended feature. Use it if we've got it.
127 #ifndef NCURSES_EXT_FUNCS
128 #undef HAVE_SIZECHANGE
132 #define USE_SIZECHANGE 1
138 * As currently coded, hashmap relies on the scroll-hints logic.
140 #if !USE_SCROLL_HINTS
142 #define USE_SCROLL_HINTS 1
144 #define USE_SCROLL_HINTS 0
149 #define if_USE_SCROLL_HINTS(stmt) stmt
151 #define if_USE_SCROLL_HINTS(stmt) /*nothing*/
155 * Note: ht/cbt expansion flakes out randomly under Linux 1.1.47, but only
156 * when we're throwing control codes at the screen at high volume. To see
157 * this, re-enable USE_HARD_TABS and run worm for a while. Other systems
158 * probably don't want to define this either due to uncertainties about tab
159 * delays and expansion in raw mode.
163 struct tries *child; /* ptr to child. NULL if none */
164 struct tries *sibling; /* ptr to sibling. NULL if none */
165 unsigned char ch; /* character at this node */
166 unsigned short value; /* code of string so far. 0 if none. */
170 * Definitions for color pairs
172 #define C_SHIFT 8 /* we need more bits than there are colors */
173 #define C_MASK ((1 << C_SHIFT) - 1)
175 #define PAIR_OF(fg, bg) ((((fg) & C_MASK) << C_SHIFT) | ((bg) & C_MASK))
178 * Structure for palette tables
183 short red, green, blue;
187 #define MAXCOLUMNS 135
189 #define FIFO_SIZE MAXCOLUMNS+2 /* for nocbreak mode input */
193 #define WINDOWLIST struct _win_list
195 #include <curses.h> /* we'll use -Ipath directive to get the right one! */
198 * Structure for soft labels.
203 char *text; /* text for the label */
204 char *form_text; /* formatted text (left/center/...) */
205 int x; /* x coordinate of this field */
206 char dirty; /* this label has changed */
207 char visible; /* field is visible */
211 char dirty; /* all labels have changed */
212 char hidden; /* soft labels are hidden */
215 char* buffer; /* buffer for labels */
216 short maxlab; /* number of available labels */
217 short labcnt; /* number of allocated labels */
218 short maxlen; /* length of labels */
219 chtype attr; /* soft label attribute */
223 int _ifd; /* input file ptr for screen */
224 FILE *_ofp; /* output file ptr for screen */
225 char *_setbuf; /* buffered I/O for output */
226 int _checkfd; /* filedesc for typeahead check */
227 struct term *_term; /* terminal type information */
228 short _lines; /* screen lines */
229 short _columns; /* screen columns */
230 short _lines_avail; /* lines available for stdscr */
231 short _topstolen; /* lines stolen from top */
233 WINDOW *_curscr; /* current screen */
234 WINDOW *_newscr; /* virtual screen to be updated to */
235 WINDOW *_stdscr; /* screen's full-window context */
237 struct tries *_keytry; /* "Try" for use with keypad mode */
238 struct tries *_key_ok; /* Disabled keys via keyok(,FALSE) */
239 int _tried; /* keypad mode was initialized */
241 unsigned int _fifo[FIFO_SIZE]; /* input push-back buffer */
242 short _fifohead, /* head of fifo queue */
243 _fifotail, /* tail of fifo queue */
244 _fifopeek, /* where to peek for next char */
245 _fifohold; /* set if breakout marked */
247 int _endwin; /* are we out of window mode? */
248 unsigned long _current_attr; /* terminal attribute current set */
249 int _coloron; /* is color enabled? */
250 int _cursor; /* visibility of the cursor */
251 int _cursrow; /* physical cursor row */
252 int _curscol; /* physical cursor column */
253 int _nl; /* True if NL -> CR/NL is on */
254 int _raw; /* True if in raw mode */
255 int _cbreak; /* 1 if in cbreak mode */
256 /* > 1 if in halfdelay mode */
257 int _echo; /* True if echo on */
258 int _use_meta; /* use the meta key? */
259 SLK *_slk; /* ptr to soft key struct / NULL */
261 /* cursor movement costs; units are 10ths of milliseconds */
262 int _char_padding; /* cost of character put */
263 int _cr_cost; /* cost of (carriage_return) */
264 int _cup_cost; /* cost of (cursor_address) */
265 int _home_cost; /* cost of (cursor_home) */
266 int _ll_cost; /* cost of (cursor_to_ll) */
268 int _ht_cost; /* cost of (tab) */
269 int _cbt_cost; /* cost of (backtab) */
270 #endif /* USE_HARD_TABS */
271 int _cub1_cost; /* cost of (cursor_left) */
272 int _cuf1_cost; /* cost of (cursor_right) */
273 int _cud1_cost; /* cost of (cursor_down) */
274 int _cuu1_cost; /* cost of (cursor_up) */
275 int _cub_cost; /* cost of (parm_cursor_left) */
276 int _cuf_cost; /* cost of (parm_cursor_right) */
277 int _cud_cost; /* cost of (parm_cursor_down) */
278 int _cuu_cost; /* cost of (parm_cursor_up) */
279 int _hpa_cost; /* cost of (column_address) */
280 int _vpa_cost; /* cost of (row_address) */
281 /* used in lib_doupdate.c, must be chars */
282 int _ed_cost; /* cost of (clr_eos) */
283 int _el_cost; /* cost of (clr_eol) */
284 int _el1_cost; /* cost of (clr_bol) */
285 int _dch1_cost; /* cost of (delete_character) */
286 int _ich1_cost; /* cost of (insert_character) */
287 int _dch_cost; /* cost of (parm_dch) */
288 int _ich_cost; /* cost of (parm_ich) */
289 int _ech_cost; /* cost of (erase_chars) */
290 int _rep_cost; /* cost of (repeat_char) */
291 int _hpa_ch_cost; /* cost of (column_address) */
292 int _cup_ch_cost; /* cost of (cursor_address) */
293 /* used in lib_mvcur.c */
294 char * _address_cursor;
295 int _carriage_return_length;
296 int _cursor_home_length;
297 int _cursor_to_ll_length;
298 int _scrolling; /* 1 if terminal's smart enough to */
300 /* used in lib_color.c */
301 color_t *_color_table; /* screen's color palette */
302 int _color_count; /* count of colors in palette */
303 unsigned short *_color_pairs; /* screen's color pair list */
304 int _pair_count; /* count of color pairs */
305 int _default_color; /* use default colors */
306 chtype _xmc_suppress; /* attributes to suppress if xmc */
307 chtype _xmc_triggers; /* attributes to process if xmc */
308 chtype _acs_map[ACS_LEN];
311 * These data correspond to the state of the idcok() and idlok()
312 * functions. A caveat is in order here: the XSI and SVr4
313 * documentation specify that these functions apply to the window which
314 * is given as an argument. However, ncurses implements this logic
315 * only for the newscr/curscr update process, _not_ per-window.
319 #define _nc_idlok SP->_nc_sp_idlok
320 #define _nc_idcok SP->_nc_sp_idcok
323 * These are the data that support the mouse interface.
326 bool (*_mouse_event) (SCREEN *);
327 bool (*_mouse_inline)(SCREEN *);
328 bool (*_mouse_parse) (int);
329 void (*_mouse_resume)(SCREEN *);
330 void (*_mouse_wrap) (SCREEN *);
331 int _mouse_fd; /* file-descriptor, if any */
334 * This supports automatic resizing
337 int (*_resize)(int,int);
341 * These are data that support the proper handling of the panel stack on an
344 struct panelhook _panelHook;
346 * Linked-list of all windows, to support '_nc_resizeall()' and
349 WINDOWLIST *_nc_sp_windows;
350 #define _nc_windows SP->_nc_sp_windows
353 SCREEN *_next_screen;
356 extern SCREEN *_nc_screen_chain;
358 #ifdef NCURSES_NOMACROS
359 #include <nomacros.h>
368 int line; /* lines to take, < 0 => from bottom*/
369 int (*hook)(struct _win_st *, int); /* callback for user */
370 struct _win_st *w; /* maybe we need this for cleanup */
373 /* The terminfo source is assumed to be 7-bit ASCII */
374 #define is7bits(c) ((unsigned)(c) < 128)
377 #define min(a,b) ((a) > (b) ? (b) : (a))
381 #define max(a,b) ((a) < (b) ? (b) : (a))
384 /* usually in <unistd.h> */
385 #ifndef STDOUT_FILENO
386 #define STDOUT_FILENO 1
389 #ifndef STDERR_FILENO
390 #define STDERR_FILENO 2
394 #define EXIT_SUCCESS 0
398 #define EXIT_FAILURE 1
402 #define R_OK 4 /* Test for read permission. */
405 #define W_OK 2 /* Test for write permission. */
408 #define X_OK 1 /* Test for execute permission. */
411 #define F_OK 0 /* Test for existence. */
414 #define TextOf(c) ((c) & (chtype)A_CHARTEXT)
415 #define AttrOf(c) ((c) & (chtype)A_ATTRIBUTES)
417 #define BLANK (' '|A_NORMAL)
421 #define SIZEOF(v) (sizeof(v)/sizeof(v[0]))
422 #define typeCalloc(type,elts) (type *)calloc(elts,sizeof(type))
423 #define FreeIfNeeded(p) if(p != 0) free(p)
424 #define FreeAndNull(p) free(p); p = 0
426 #include <nc_alloc.h>
429 * Prefixes for call/return points of library function traces. We use these to
430 * instrument the public functions so that the traces can be easily transformed
431 * into regression scripts.
433 #define T_CALLED(fmt) "called " fmt
434 #define T_CREATE(fmt) "create " fmt
435 #define T_RETURN(fmt) "return " fmt
438 #define TR(n, a) if (_nc_tracing & (n)) _tracef a
439 #define T(a) TR(TRACE_CALLS, a)
440 #define TPUTS_TRACE(s) _nc_tputs_trace = s;
441 #define TRACE_RETURN(value,type) return _nc_retrace_##type(value)
442 #define returnAttr(code) TRACE_RETURN(code,attr_t)
443 #define returnCode(code) TRACE_RETURN(code,int)
444 #define returnPtr(code) TRACE_RETURN(code,ptr)
445 #define returnVoid T((T_RETURN(""))); return
446 #define returnWin(code) TRACE_RETURN(code,win)
447 extern unsigned _nc_tracing;
448 extern WINDOW * _nc_retrace_win(WINDOW *);
449 extern attr_t _nc_retrace_attr_t(attr_t);
450 extern char *_nc_retrace_ptr(char *);
451 extern const char *_nc_tputs_trace;
452 extern const char *_nc_visbuf(const char *);
453 extern const char *_nc_visbuf2(int, const char *);
454 extern int _nc_retrace_int(int);
455 extern long _nc_outchars;
456 extern void _nc_fifo_dump(void);
460 #define TPUTS_TRACE(s)
461 #define returnAttr(code) return code
462 #define returnCode(code) return code
463 #define returnPtr(code) return code
464 #define returnVoid return
465 #define returnWin(code) return code
468 #define _trace_key(ch) ((ch > KEY_MIN) ? keyname(ch) : _tracechar((unsigned char)ch))
470 #define ALL_BUT_COLOR ((chtype)~(A_COLOR))
471 #define IGNORE_COLOR_OFF FALSE
472 #define NONBLANK_ATTR (A_BOLD|A_DIM|A_BLINK)
473 #define XMC_CHANGES(c) ((c) & SP->_xmc_suppress)
476 #define toggle_attr_on(S,at) \
477 if (PAIR_NUMBER(at) > 0)\
478 (S) = ((S) & ALL_BUT_COLOR) | (at);\
481 T(("new attribute is %s", _traceattr((S))))
484 #define toggle_attr_off(S,at) \
485 if (IGNORE_COLOR_OFF == TRUE) {\
486 if (PAIR_NUMBER(at) == 0xff) /* turn off color */\
488 else /* leave color alone */\
489 (S) &= ~((at)&ALL_BUT_COLOR);\
491 if (PAIR_NUMBER(at) > 0x00) /* turn off color */\
492 (S) &= ~(at|A_COLOR);\
493 else /* leave color alone */\
496 T(("new attribute is %s", _traceattr((S))));
498 #define DelCharCost(count) \
501 : ((delete_character != 0) \
502 ? (SP->_dch1_cost * count) \
505 #define InsCharCost(count) \
508 : ((insert_character != 0) \
509 ? (SP->_ich1_cost * count) \
513 #define UpdateAttrs(c) if (SP->_current_attr != AttrOf(c)) { \
514 attr_t chg = SP->_current_attr; \
515 vidattr(AttrOf(c)); \
516 if (magic_cookie_glitch > 0 \
517 && XMC_CHANGES((chg ^ SP->_current_attr))) { \
518 T(("%s @%d before glitch %d,%d", \
519 __FILE__, __LINE__, \
522 _nc_do_xmc_glitch(chg); \
526 #define UpdateAttrs(c) if (SP->_current_attr != AttrOf(c)) \
531 * Check whether the given character can be output by clearing commands. This
532 * includes test for being a space and not including any 'bad' attributes, such
533 * as A_REVERSE. All attribute flags which don't affect appearance of a space
534 * or can be output by clearing (A_COLOR in case of bce-terminal) are excluded.
536 #define can_clear_with(ch) \
537 ((ch & ~(NONBLANK_ATTR|(back_color_erase ? A_COLOR:0))) == BLANK)
539 #ifdef NCURSES_EXPANDED
541 #undef toggle_attr_on
542 #define toggle_attr_on(S,at) _nc_toggle_attr_on(&(S), at)
543 extern void _nc_toggle_attr_on(attr_t *, attr_t);
545 #undef toggle_attr_off
546 #define toggle_attr_off(S,at) _nc_toggle_attr_off(&(S), at)
547 extern void _nc_toggle_attr_off(attr_t *, attr_t);
549 #undef can_clear_with
550 #define can_clear_with(ch) _nc_can_clear_with(ch)
551 extern int _nc_can_clear_with(chtype);
554 #define DelCharCost(count) _nc_DelCharCost(count)
555 extern int _nc_DelCharCost(int);
558 #define InsCharCost(count) _nc_InsCharCost(count)
559 extern int _nc_InsCharCost(int);
562 #define UpdateAttrs(c) _nc_UpdateAttrs(c)
563 extern void _nc_UpdateAttrs(chtype);
567 extern void _nc_expanded(void);
573 extern void _nc_do_xmc_glitch(attr_t);
577 #if defined(TRACE) || defined(SCROLLDEBUG)
578 extern void _nc_linedump(void);
582 #if defined(TRACE) || defined(SCROLLDEBUG)
583 extern void _nc_linedump(void);
587 extern void init_acs(void); /* no prefix, this name is traditional */
588 extern int _nc_msec_cost(const char *const, int); /* used by 'tack' program */
591 #define INFINITY 1000000 /* cost: too high to use */
593 extern void _nc_mvcur_init(void);
594 extern void _nc_mvcur_resume(void);
595 extern void _nc_mvcur_wrap(void);
597 extern int _nc_scrolln(int, int, int, int);
599 extern void _nc_screen_init(void);
600 extern void _nc_screen_resume(void);
601 extern void _nc_screen_wrap(void);
604 extern int _nc_has_mouse(void);
607 extern char * _nc_printf_string(const char *fmt, va_list ap);
610 extern void _nc_setup_scroll(void);
611 extern void _nc_perform_scroll(void);
614 extern void _nc_add_to_try(struct tries **tree, char *str, unsigned short code);
615 extern char *_nc_expand_try(struct tries *tree, unsigned short code, size_t len);
616 extern int _nc_remove_key(struct tries **tree, unsigned short code);
619 extern WINDOW *_nc_makenew(int, int, int, int, int);
620 extern char *_nc_trace_buf(int, size_t);
621 extern chtype _nc_background(WINDOW *);
622 extern chtype _nc_render(WINDOW *, chtype);
623 extern int _nc_keypad(bool);
624 extern int _nc_outch(int);
625 extern int _nc_setupscreen(short, short const, FILE *);
626 extern int _nc_timed_wait(int, int, int *);
627 extern int _nc_waddch_nosync(WINDOW *, const chtype);
628 extern void _nc_do_color(int, bool, int (*)(int));
629 extern void _nc_free_and_exit(int);
630 extern void _nc_freeall(void);
631 extern void _nc_freewin(WINDOW *win);
632 extern void _nc_hash_map(void);
633 extern void _nc_outstr(const char *str);
634 extern void _nc_scroll_optimize(void);
635 extern void _nc_scroll_window(WINDOW *, int const, short const, short const, chtype);
636 extern void _nc_set_buffer(FILE *ofp, bool buffered);
637 extern void _nc_signal_handler(bool);
638 extern void _nc_synchook(WINDOW *win);
641 extern void _nc_update_screensize(void);
645 * On systems with a broken linker, define 'SP' as a function to force the
646 * linker to pull in the data-only module with 'SP'.
648 #ifndef BROKEN_LINKER
649 #define BROKEN_LINKER 0
653 #define SP _nc_screen()
654 extern SCREEN *_nc_screen(void);
655 extern int _nc_alloc_screen(void);
656 extern void _nc_set_screen(SCREEN *);
658 /* current screen is private data; avoid possible linking conflicts too */
660 #define _nc_alloc_screen() ((SP = typeCalloc(SCREEN, 1)) != 0)
661 #define _nc_set_screen(sp) SP = sp
665 * We don't want to use the lines or columns capabilities internally,
666 * because if the application is running multiple screens under
667 * X windows, it's quite possible they could all have type xterm
668 * but have different sizes! So...
670 #define screen_lines SP->_lines
671 #define screen_columns SP->_columns
673 extern int _nc_slk_format; /* != 0 if slk_init() called */
674 extern int _nc_slk_initialize(WINDOW *, int);
677 * Some constants related to SLK's
679 #define MAX_SKEY_OLD 8 /* count of soft keys */
680 #define MAX_SKEY_LEN_OLD 8 /* max length of soft key text */
681 #define MAX_SKEY_PC 12 /* This is what most PC's have */
682 #define MAX_SKEY_LEN_PC 5
684 #define MAX_SKEY (SLK_STDFMT ? MAX_SKEY_OLD : MAX_SKEY_PC)
685 #define MAX_SKEY_LEN (SLK_STDFMT ? MAX_SKEY_LEN_OLD : MAX_SKEY_LEN_PC)
687 /* Macro to check whether or not we use a standard format */
688 #define SLK_STDFMT (_nc_slk_format < 3)
689 /* Macro to determine height of label window */
690 #define SLK_LINES (SLK_STDFMT ? 1 : (_nc_slk_format - 2))
692 extern int _nc_ripoffline(int line, int (*init)(WINDOW *,int));
698 #endif /* CURSES_PRIV_H */