2 /***************************************************************************
4 ****************************************************************************
5 * ncurses is copyright (C) 1992-1995 *
7 * zmbenhal@netcom.com *
9 * esr@snark.thyrsus.com *
11 * Permission is hereby granted to reproduce and distribute ncurses *
12 * by any means and for any fee, whether alone or as part of a *
13 * larger distribution, in source or in binary form, PROVIDED *
14 * this notice is included with any such distribution, and is not *
15 * removed from any of its header files. Mention of ncurses in any *
16 * applications linked with it is highly appreciated. *
18 * ncurses comes AS IS with no warranty, implied or expressed. *
20 ***************************************************************************/
24 * $Id: curses.priv.h,v 1.61 1997/04/26 20:54:54 tom Exp $
28 * Header file for curses library objects which are private to
34 #define CURSES_PRIV_H 1
36 #include <ncurses_cfg.h>
39 #define MODULE_ID(id) static const char Ident[] = id;
41 #define MODULE_ID(id) /*nothing*/
46 #include <sys/types.h>
52 #if HAVE_SYS_BSDTYPES_H
53 #include <sys/bsdtypes.h> /* needed for ISC */
58 #elif HAVE_SYS_PARAM_H
59 # include <sys/param.h>
63 # if defined(_POSIX_PATH_MAX)
64 # define PATH_MAX _POSIX_PATH_MAX
65 # elif defined(MAXPATHLEN)
66 # define PATH_MAX MAXPATHLEN
68 # define PATH_MAX 255 /* the Posix minimum path-size */
77 #if !HAVE_EXTERN_ERRNO
81 /* Some systems have a broken 'select()', but workable 'poll()'. Use that */
82 #if HAVE_POLL && HAVE_SYS_STROPTS_H && HAVE_POLL_H
83 #define USE_FUNC_POLL 1
85 #define USE_FUNC_POLL 0
88 /* Alessandro Rubini's GPM (general-purpose mouse) */
89 #if HAVE_LIBGPM && HAVE_GPM_H
90 #define USE_GPM_SUPPORT 1
92 #define USE_GPM_SUPPORT 0
96 * ht/cbt expansion flakes out randomly under Linux 1.1.47, but only when
97 * we're throwing control codes at the screen at high volume. To see this,
98 * re-enable TABS_OK and run worm for a while. Other systems probably don't
99 * want to define this either due to uncertainties about tab delays and
100 * expansion in raw mode.
102 #undef TABS_OK /* OK to use tab/backtab for local motions? */
105 * The internal types (e.g., struct screen) must precede <curses.h>, otherwise
106 * we cannot construct lint-libraries (structures must be fully-defined).
110 struct tries *child; /* ptr to child. NULL if none */
111 struct tries *sibling; /* ptr to sibling. NULL if none */
112 unsigned char ch; /* character at this node */
113 unsigned short value; /* code of string so far. 0 if none. */
117 * Structure for soft labels.
122 char *text; /* text for the label */
123 char *form_text; /* formatted text (left/center/...) */
124 int x; /* x coordinate of this field */
125 char dirty; /* this label has changed */
126 char visible; /* field is visible */
130 char dirty; /* all labels have changed */
131 char hidden; /* soft labels are hidden */
134 char *buffer; /* buffer for labels */
135 short maxlab; /* number of available labels */
136 short labcnt; /* number of allocated labels */
137 short maxlen; /* length of labels */
141 * Definitions for color pairs
143 #define C_SHIFT 8 /* we need more bits than there are colors */
144 #define C_MASK ((1 << C_SHIFT) - 1)
146 #define PAIR_OF(fg, bg) ((((fg) & C_MASK) << C_SHIFT) | ((bg) & C_MASK))
149 * Structure for palette tables
154 short red, green, blue;
158 #define MAXCOLUMNS 135
160 #define FIFO_SIZE MAXLINES
163 int _ifd; /* input file ptr for screen */
164 FILE *_ofp; /* output file ptr for screen */
165 char *_setbuf; /* buffered I/O for output */
166 int _checkfd; /* filedesc for typeahead check */
167 struct term *_term; /* terminal type information */
168 short _lines; /* screen lines */
169 short _columns; /* screen columns */
170 short _lines_avail; /* lines available for stdscr */
171 short _topstolen; /* lines stolen from top */
172 struct _win_st *_curscr; /* current screen */
173 struct _win_st *_newscr; /* virtual screen to be updated to */
174 struct _win_st *_stdscr; /* screen's full-window context */
175 struct tries *_keytry; /* "Try" for use with keypad mode */
176 unsigned int _fifo[FIFO_SIZE]; /* input push-back buffer */
177 signed char _fifohead, /* head of fifo queue */
178 _fifotail, /* tail of fifo queue */
179 _fifopeek; /* where to peek for next char */
180 int _endwin; /* are we out of window mode? */
181 unsigned long _current_attr; /* terminal attribute current set */
182 int _coloron; /* is color enabled? */
183 int _cursor; /* visibility of the cursor */
184 int _cursrow; /* physical cursor row */
185 int _curscol; /* physical cursor column */
186 int _nl; /* True if NL -> CR/NL is on */
187 int _raw; /* True if in raw mode */
188 int _cbreak; /* 1 if in cbreak mode */
189 /* > 1 if in halfdelay mode */
190 int _echo; /* True if echo on */
191 int _use_meta; /* use the meta key? */
192 SLK *_slk; /* ptr to soft key struct / NULL */
193 int _baudrate; /* used to compute padding */
195 /* cursor movement costs; units are 10ths of milliseconds */
196 int _char_padding; /* cost of character put */
197 int _cr_cost; /* cost of (carriage_return) */
198 int _cup_cost; /* cost of (cursor_address) */
199 int _home_cost; /* cost of (cursor_home) */
200 int _ll_cost; /* cost of (cursor_to_ll) */
202 int _ht_cost; /* cost of (tab) */
203 int _cbt_cost; /* cost of (backtab) */
205 int _cub1_cost; /* cost of (cursor_left) */
206 int _cuf1_cost; /* cost of (cursor_right) */
207 int _cud1_cost; /* cost of (cursor_down) */
208 int _cuu1_cost; /* cost of (cursor_up) */
209 int _cub_cost; /* cost of (parm_cursor_left) */
210 int _cuf_cost; /* cost of (parm_cursor_right) */
211 int _cud_cost; /* cost of (parm_cursor_down) */
212 int _cuu_cost; /* cost of (parm_cursor_up) */
213 int _hpa_cost; /* cost of (column_address) */
214 int _vpa_cost; /* cost of (row_address) */
215 /* used in lib_doupdate.c, must be chars */
216 int _ed_cost; /* cost of (clr_eos) */
217 int _el_cost; /* cost of (clr_eol) */
218 int _el1_cost; /* cost of (clr_bol) */
219 int _dch1_cost; /* cost of (delete_character) */
220 int _ich1_cost; /* cost of (insert_character) */
221 int _dch_cost; /* cost of (parm_dch) */
222 int _ich_cost; /* cost of (parm_ich) */
223 int _ech_cost; /* cost of (erase_chars) */
224 int _rep_cost; /* cost of (repeat_char) */
225 int _hpa_ch_cost; /* cost of (column_address) */
226 int _cup_ch_cost; /* cost of (cursor_address) */
227 /* used in lib_mvcur.c */
228 char * _address_cursor;
229 int _carriage_return_length;
230 int _cursor_home_length;
231 int _cursor_to_ll_length;
232 /* used in lib_color.c */
233 color_t *_color_table; /* screen's color palette */
234 int _color_count; /* count of colors in palette */
235 unsigned short *_color_pairs; /* screen's color pair list */
236 int _pair_count; /* count of color pairs */
237 int _default_color; /* use default colors */
240 /* Ncurses' public interface follows the internal types */
241 #include <curses.h> /* we'll use -Ipath directive to get the right one! */
243 #ifdef NCURSES_NOMACROS
244 #include <nomacros.h>
247 #define WINDOWLIST struct _win_list
254 int line; /* lines to take, < 0 => from bottom*/
255 int (*hook)(struct _win_st *, int); /* callback for user */
256 struct _win_st *w; /* maybe we need this for cleanup */
259 /* The terminfo source is assumed to be 7-bit ASCII */
260 #define is7bits(c) ((unsigned)(c) < 128)
263 #define min(a,b) ((a) > (b) ? (b) : (a))
267 #define max(a,b) ((a) < (b) ? (b) : (a))
270 /* usually in <unistd.h> */
271 #ifndef STDOUT_FILENO
272 #define STDOUT_FILENO 1
275 #ifndef STDERR_FILENO
276 #define STDERR_FILENO 2
280 #define EXIT_SUCCESS 0
284 #define EXIT_FAILURE 1
288 #define R_OK 4 /* Test for read permission. */
291 #define W_OK 2 /* Test for write permission. */
294 #define X_OK 1 /* Test for execute permission. */
297 #define F_OK 0 /* Test for existence. */
300 #define TextOf(c) ((c) & (chtype)A_CHARTEXT)
301 #define AttrOf(c) ((c) & (chtype)A_ATTRIBUTES)
303 #define BLANK (' '|A_NORMAL)
307 #define typeCalloc(type,elts) (type *)calloc(elts,sizeof(type))
308 #define FreeIfNeeded(p) if(p != 0) free(p)
309 #define FreeAndNull(p) free(p); p = 0
311 #include <nc_alloc.h>
314 * Prefixes for call/return points of library function traces. We use these to
315 * instrument the public functions so that the traces can be easily transformed
316 * into regression scripts.
318 #define T_CALLED(fmt) "called " fmt
319 #define T_CREATE(fmt) "create " fmt
320 #define T_RETURN(fmt) "return " fmt
323 #define TR(n, a) if (_nc_tracing & (n)) _tracef a
324 #define T(a) TR(TRACE_CALLS, a)
325 #define TPUTS_TRACE(s) _nc_tputs_trace = s;
326 #define TRACE_RETURN(value,type) return _nc_retrace_##type(value)
327 #define returnWin(code) TRACE_RETURN(code,win)
328 #define returnPtr(code) TRACE_RETURN(code,ptr)
329 #define returnCode(code) TRACE_RETURN(code,int)
330 #define returnVoid T((T_RETURN(""))); return
331 extern unsigned _nc_tracing;
332 extern WINDOW * _nc_retrace_win(WINDOW *);
333 extern char *_nc_retrace_ptr(char *);
334 extern const char *_nc_tputs_trace;
335 extern const char *_nc_visbuf(const char *);
336 extern const char *_nc_visbuf2(int, const char *);
337 extern int _nc_retrace_int(int);
338 extern long _nc_outchars;
342 #define TPUTS_TRACE(s)
343 #define returnWin(code) return code
344 #define returnCode(code) return code
345 #define returnVoid return
348 #define _trace_key(ch) ((ch > KEY_MIN) ? keyname(ch) : _tracechar((unsigned char)ch))
350 #define ALL_BUT_COLOR ((chtype)~(A_COLOR))
351 #define IGNORE_COLOR_OFF FALSE
354 /* Macro to put together character and attribute info and return it.
355 If colors are in the attribute, they have precedence. */
356 #define ch_or_attr(ch,at) \
357 ((PAIR_NUMBER(at) > 0) ? \
358 ((((chtype)ch) & ALL_BUT_COLOR) | (at)) : ((((chtype)ch) | (at))))
361 #define toggle_attr_on(S,at) \
362 if (PAIR_NUMBER(at) > 0)\
363 (S) = ((S) & ALL_BUT_COLOR) | (at);\
366 T(("new attribute is %s", _traceattr((S))))
369 #define toggle_attr_off(S,at) \
370 if (IGNORE_COLOR_OFF == TRUE) {\
371 if (PAIR_NUMBER(at) == 0xff) /* turn off color */\
373 else /* leave color alone */\
374 (S) &= ~((at)&ALL_BUT_COLOR);\
376 if (PAIR_NUMBER(at) > 0x00) /* turn off color */\
377 (S) &= ~(at|A_COLOR);\
378 else /* leave color alone */\
381 T(("new attribute is %s", _traceattr((S))));
383 #define DelCharCost(count) \
386 : ((delete_character != 0) \
387 ? (SP->_dch1_cost * count) \
390 #define InsCharCost(count) \
393 : ((insert_character != 0) \
394 ? (SP->_ich1_cost * count) \
397 #define UpdateAttrs(c) if (SP->_current_attr != AttrOf(c)) \
401 * Check whether the given character can be output by clearing commands. This
402 * includes test for being a space and not including any 'bad' attributes, such
403 * as A_REVERSE. All attribute flags which don't affect appearance of a space
404 * or can be output by clearing (A_COLOR in case of bce-terminal) are excluded.
406 #define NONBLANK_ATTR (A_BOLD|A_DIM|A_BLINK)
407 #define can_clear_with(ch) \
408 ((ch & ~(NONBLANK_ATTR|(back_color_erase ? A_COLOR:0))) == BLANK)
410 #ifdef NCURSES_EXPANDED
413 #define ch_or_attr(ch,at) _nc_ch_or_attr(ch,at)
414 extern chtype _nc_ch_or_attr(chtype, attr_t);
416 #undef toggle_attr_on
417 #define toggle_attr_on(S,at) _nc_toggle_attr_on(&(S), at)
418 extern void _nc_toggle_attr_on(attr_t *, attr_t);
420 #undef toggle_attr_off
421 #define toggle_attr_off(S,at) _nc_toggle_attr_off(&(S), at)
422 extern void _nc_toggle_attr_off(attr_t *, attr_t);
424 #undef can_clear_with
425 #define can_clear_with(ch) _nc_can_clear_with(ch)
426 extern int _nc_can_clear_with(chtype);
429 #define DelCharCost(count) _nc_DelCharCost(count)
430 extern int _nc_DelCharCost(int);
433 #define InsCharCost(count) _nc_InsCharCost(count)
434 extern int _nc_InsCharCost(int);
437 #define UpdateAttrs(c) _nc_UpdateAttrs(c)
438 extern void _nc_UpdateAttrs(chtype);
442 extern void _nc_expanded(void);
447 extern void init_acs(void); /* no prefix, this name is traditional */
450 #define INFINITY 1000000 /* cost: too high to use */
452 extern void _nc_mvcur_init(void);
453 extern void _nc_mvcur_resume(void);
454 extern void _nc_mvcur_wrap(void);
455 extern int _nc_mvcur_scrolln(int, int, int, int);
458 extern void _nc_mouse_init(SCREEN *);
459 extern bool _nc_mouse_event(SCREEN *);
460 extern bool _nc_mouse_inline(SCREEN *);
461 extern bool _nc_mouse_parse(int);
462 extern void _nc_mouse_wrap(SCREEN *);
463 extern void _nc_mouse_resume(SCREEN *);
464 extern int _nc_max_click_interval;
465 extern int _nc_mouse_fd(void);
468 extern WINDOW *_nc_makenew(int, int, int, int, int);
469 extern chtype _nc_background(WINDOW *);
470 extern chtype _nc_render(WINDOW *, chtype);
471 extern char *_nc_trace_buf(int, size_t);
472 extern int _nc_initscr(void);
473 extern int _nc_keypad(bool);
474 extern int _nc_outch(int);
475 extern int _nc_setupscreen(short, short const, FILE *);
476 extern int _nc_timed_wait(int, int, int *);
477 extern int _nc_waddch_nosync(WINDOW *, const chtype);
478 extern void _nc_backspace(WINDOW *win);
479 extern void _nc_do_color(int, int (*)(int));
480 extern void _nc_freeall(void);
481 extern void _nc_free_and_exit(int);
482 extern void _nc_freewin(WINDOW *win);
483 extern void _nc_get_screensize(void);
484 extern void _nc_hash_map(void);
485 extern void _nc_outstr(const char *str);
486 extern void _nc_scroll_optimize(void);
487 extern void _nc_scroll_window(WINDOW *, int const, short const, short const);
488 extern void _nc_set_buffer(FILE *ofp, bool buffered);
489 extern void _nc_signal_handler(bool);
490 extern void _nc_synchook(WINDOW *win);
493 * On systems with a broken linker, define 'SP' as a function to force the
494 * linker to pull in the data-only module with 'SP'.
496 #ifndef BROKEN_LINKER
497 #define BROKEN_LINKER 0
501 #define SP _nc_screen()
502 extern SCREEN *_nc_screen(void);
503 extern int _nc_alloc_screen(void);
504 extern void _nc_set_screen(SCREEN *);
507 #define _nc_alloc_screen() ((SP = typeCalloc(SCREEN, 1)) != 0)
508 #define _nc_set_screen(sp) SP = sp
512 extern int _nc_usleep(unsigned int);
513 #define usleep(msecs) _nc_usleep(msecs)
517 * We don't want to use the lines or columns capabilities internally,
518 * because if the application is running multiple screens under
519 * X windows, it's quite possible they could all have type xterm
520 * but have different sizes! So...
522 #define screen_lines SP->_lines
523 #define screen_columns SP->_columns
525 extern int _nc_slk_format; /* != 0 if slk_init() called */
526 extern int _nc_slk_initialize(WINDOW *, int);
528 /* Macro to check whether or not we use a standard format */
529 #define SLK_STDFMT (_nc_slk_format < 3)
530 /* Macro to determine height of label window */
531 #define SLK_LINES (SLK_STDFMT ? 1 : (_nc_slk_format - 2))
533 extern int _nc_ripoffline(int line, int (*init)(WINDOW *,int));
535 #define UNINITIALISED ((struct tries * ) -1)
537 extern bool _nc_idlok, _nc_idcok;
539 extern WINDOWLIST *_nc_windows;
541 #endif /* CURSES_PRIV_H */