]> ncurses.scripts.mit.edu Git - ncurses.git/blob - ncurses/curses.priv.h
ncurses 5.5
[ncurses.git] / ncurses / curses.priv.h
1 /****************************************************************************
2  * Copyright (c) 1998-2004,2005 Free Software Foundation, Inc.              *
3  *                                                                          *
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:                 *
11  *                                                                          *
12  * The above copyright notice and this permission notice shall be included  *
13  * in all copies or substantial portions of the Software.                   *
14  *                                                                          *
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.                               *
22  *                                                                          *
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       *
26  * authorization.                                                           *
27  ****************************************************************************/
28
29 /****************************************************************************
30  *  Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995               *
31  *     and: Eric S. Raymond <esr@snark.thyrsus.com>                         *
32  *     and: Thomas E. Dickey                        1996-on                 *
33  ****************************************************************************/
34
35
36 /*
37  * $Id: curses.priv.h,v 1.286 2005/09/10 22:34:50 tom Exp $
38  *
39  *      curses.priv.h
40  *
41  *      Header file for curses library objects which are private to
42  *      the library.
43  *
44  */
45
46 #ifndef CURSES_PRIV_H
47 #define CURSES_PRIV_H 1
48
49 #include <ncurses_dll.h>
50
51 #ifdef __cplusplus
52 extern "C" {
53 #endif
54
55 #include <ncurses_cfg.h>
56
57 #if USE_RCS_IDS
58 #define MODULE_ID(id) static const char Ident[] = id;
59 #else
60 #define MODULE_ID(id) /*nothing*/
61 #endif
62
63 #include <stdlib.h>
64 #include <string.h>
65 #include <sys/types.h>
66
67 #if HAVE_UNISTD_H
68 #include <unistd.h>
69 #endif
70
71 #if HAVE_SYS_BSDTYPES_H
72 #include <sys/bsdtypes.h>       /* needed for ISC */
73 #endif
74
75 #if HAVE_LIMITS_H
76 # include <limits.h>
77 #elif HAVE_SYS_PARAM_H
78 # include <sys/param.h>
79 #endif
80
81 #include <assert.h>
82 #include <stdio.h>
83
84 #include <errno.h>
85
86 #ifndef PATH_MAX
87 # if defined(_POSIX_PATH_MAX)
88 #  define PATH_MAX _POSIX_PATH_MAX
89 # elif defined(MAXPATHLEN)
90 #  define PATH_MAX MAXPATHLEN
91 # else
92 #  define PATH_MAX 255  /* the Posix minimum path-size */
93 # endif
94 #endif
95
96 #if DECL_ERRNO
97 extern int errno;
98 #endif
99
100 #include <nc_panel.h>
101
102 /* Some systems have a broken 'select()', but workable 'poll()'.  Use that */
103 #if HAVE_WORKING_POLL
104 #define USE_FUNC_POLL 1
105 #if HAVE_POLL_H
106 #include <poll.h>
107 #else
108 #include <sys/poll.h>
109 #endif
110 #else
111 #define USE_FUNC_POLL 0
112 #endif
113
114 /* include signal.h before curses.h to work-around defect in glibc 2.1.3 */
115 #include <signal.h>
116
117 /* Alessandro Rubini's GPM (general-purpose mouse) */
118 #if HAVE_LIBGPM && HAVE_GPM_H
119 #define USE_GPM_SUPPORT 1
120 #else
121 #define USE_GPM_SUPPORT 0
122 #endif
123
124 /* QNX mouse support */
125 #if defined(__QNX__) && !defined(__QNXNTO__)
126 #define USE_QNX_MOUSE 1
127 #else
128 #define USE_QNX_MOUSE 0
129 #endif
130
131 /* EMX mouse support */
132 #ifdef __EMX__
133 #define USE_EMX_MOUSE 1
134 #else
135 #define USE_EMX_MOUSE 0
136 #endif
137
138 #define DEFAULT_MAXCLICK 166
139 #define EV_MAX          8       /* size of mouse circular event queue */
140
141 /*
142  * If we don't have signals to support it, don't add a sigwinch handler.
143  * In any case, resizing is an extended feature.  Use it if we've got it.
144  */
145 #if !NCURSES_EXT_FUNCS
146 #undef HAVE_SIZECHANGE
147 #define HAVE_SIZECHANGE 0
148 #endif
149
150 #if HAVE_SIZECHANGE && defined(SIGWINCH)
151 #define USE_SIZECHANGE 1
152 #else
153 #define USE_SIZECHANGE 0
154 #undef USE_SIGWINCH
155 #define USE_SIGWINCH 0
156 #endif
157
158 /*
159  * If desired, one can configure this, disabling environment variables that
160  * point to custom terminfo/termcap locations.
161  */
162 #ifdef USE_ROOT_ENVIRON
163 #define use_terminfo_vars() 1
164 #else
165 #define use_terminfo_vars() _nc_env_access()
166 extern NCURSES_EXPORT(int) _nc_env_access (void);
167 #endif
168
169 /*
170  * Not all platforms have memmove; some have an equivalent bcopy.  (Some may
171  * have neither).
172  */
173 #if USE_OK_BCOPY
174 #define memmove(d,s,n) bcopy(s,d,n)
175 #elif USE_MY_MEMMOVE
176 #define memmove(d,s,n) _nc_memmove(d,s,n)
177 extern NCURSES_EXPORT(void *) _nc_memmove (void *, const void *, size_t);
178 #endif
179
180 /*
181  * Scroll hints are useless when hashmap is used
182  */
183 #if !USE_SCROLL_HINTS
184 #if !USE_HASHMAP
185 #define USE_SCROLL_HINTS 1
186 #else
187 #define USE_SCROLL_HINTS 0
188 #endif
189 #endif
190
191 #if USE_SCROLL_HINTS
192 #define if_USE_SCROLL_HINTS(stmt) stmt
193 #else
194 #define if_USE_SCROLL_HINTS(stmt) /*nothing*/
195 #endif
196
197 /*
198  * Note:  ht/cbt expansion flakes out randomly under Linux 1.1.47, but only
199  * when we're throwing control codes at the screen at high volume.  To see
200  * this, re-enable USE_HARD_TABS and run worm for a while.  Other systems
201  * probably don't want to define this either due to uncertainties about tab
202  * delays and expansion in raw mode.
203  */
204
205 struct tries {
206         struct tries    *child;     /* ptr to child.  NULL if none          */
207         struct tries    *sibling;   /* ptr to sibling.  NULL if none        */
208         unsigned char    ch;        /* character at this node               */
209         unsigned short   value;     /* code of string so far.  0 if none.   */
210 };
211
212 /*
213  * Common/troublesome character definitions
214  */
215 #define L_BRACE '{'
216 #define R_BRACE '}'
217 #define S_QUOTE '\''
218 #define D_QUOTE '"'
219
220 #define VT_ACSC "``aaffggiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~"
221
222 /*
223  * Structure for palette tables
224  */
225
226 typedef struct
227 {
228     short red, green, blue;     /* what color_content() returns */
229     short r, g, b;              /* params to init_color() */
230     int init;                   /* true if we called init_color() */
231 }
232 color_t;
233
234 #define MAXCOLUMNS    135
235 #define MAXLINES      66
236 #define FIFO_SIZE     MAXCOLUMNS+2  /* for nocbreak mode input */
237
238 #define ACS_LEN       128
239
240 #define WINDOWLIST struct _win_list
241
242 #if USE_WIDEC_SUPPORT
243 #define _nc_bkgd    _bkgrnd
244 #else
245 #undef _XOPEN_SOURCE_EXTENDED
246 #define _nc_bkgd    _bkgd
247 #define wgetbkgrnd(win, wch)    *wch = win->_bkgd
248 #define wbkgrnd     wbkgd
249 #endif
250
251 #include <curses.h>     /* we'll use -Ipath directive to get the right one! */
252 #include <term.h>
253 #include <term_entry.h>
254
255 #if NCURSES_EXT_COLORS && USE_WIDEC_SUPPORT
256 #define if_EXT_COLORS(stmt)     stmt
257 #define NetPair(value,p)        (value).ext_color = (p), \
258                                 AttrOf(value) &= ALL_BUT_COLOR, \
259                                 AttrOf(value) |= (A_COLOR & COLOR_PAIR((p > 255) ? 255 : p))
260 #define SetPair(value,p)        (value).ext_color = (p)
261 #define GetPair(value)          (value).ext_color
262 #define unColor(n)              (AttrOf(n) & ALL_BUT_COLOR)
263 #define GET_WINDOW_PAIR(w)      (w)->_color
264 #define SET_WINDOW_PAIR(w,p)    (w)->_color = (p)
265 #define SameAttrOf(a,b)         (AttrOf(a) == AttrOf(b) && GetPair(a) == GetPair(b))
266 #define VIDATTR(attr, pair)     vid_attr(attr, pair, 0)
267 #else
268 #define if_EXT_COLORS(stmt)     /* nothing */
269 #define SetPair(value,p)        RemAttr(value, A_COLOR), \
270                                 SetAttr(value, AttrOf(value) | (A_COLOR & COLOR_PAIR(p)))
271 #define GetPair(value)          PAIR_NUMBER(AttrOf(value))
272 #define unColor(n)              (AttrOf(n) & ALL_BUT_COLOR)
273 #define GET_WINDOW_PAIR(w)      PAIR_NUMBER((w)->_attrs)
274 #define SET_WINDOW_PAIR(w,p)    (w)->_attrs &= ALL_BUT_COLOR, \
275                                 (w)->_attrs |= (A_COLOR & COLOR_PAIR(p))
276 #define SameAttrOf(a,b)         (AttrOf(a) == AttrOf(b))
277 #define VIDATTR(attr, pair)     vidattr(attr)
278 #endif
279
280 #define SCREEN_ATTRS(s)         (*((s)->_current_attr))
281 #define GET_SCREEN_PAIR(s)      GetPair(SCREEN_ATTRS(s))
282 #define SET_SCREEN_PAIR(s,p)    SetPair(SCREEN_ATTRS(s), p)
283
284 /*
285  * Definitions for color pairs
286  */
287 typedef unsigned colorpair_t;   /* type big enough to store PAIR_OF() */
288 #define C_SHIFT 9               /* we need more bits than there are colors */
289 #define C_MASK                  ((1 << C_SHIFT) - 1)
290 #define PAIR_OF(fg, bg)         ((((fg) & C_MASK) << C_SHIFT) | ((bg) & C_MASK))
291 #define isDefaultColor(c)       ((c) >= COLOR_DEFAULT || (c) < 0)
292
293 #define COLOR_DEFAULT           C_MASK
294
295 #ifdef USE_TERMLIB
296
297 #undef NCURSES_CH_T             /* this is not a termlib feature */
298 #define NCURSES_CH_T void       /* ...but we need a pointer in SCREEN */
299
300 #endif  /* USE_TERMLIB */
301
302 #ifndef USE_TERMLIB
303 struct ldat
304 {
305         NCURSES_CH_T    *text;          /* text of the line */
306         NCURSES_SIZE_T  firstchar;      /* first changed character in the line */
307         NCURSES_SIZE_T  lastchar;       /* last changed character in the line */
308         NCURSES_SIZE_T  oldindex;       /* index of the line at last update */
309 };
310 #endif  /* USE_TERMLIB */
311
312 typedef enum {
313         M_XTERM = -1            /* use xterm's mouse tracking? */
314         ,M_NONE = 0             /* no mouse device */
315 #if USE_GPM_SUPPORT
316         ,M_GPM                  /* use GPM */
317 #endif
318 #if USE_SYSMOUSE
319         ,M_SYSMOUSE             /* FreeBSD sysmouse on console */
320 #endif
321 } MouseType;
322
323 /*
324  * Structures for scrolling.
325  */
326
327 typedef struct {
328         unsigned long hashval;
329         int oldcount, newcount;
330         int oldindex, newindex;
331 } HASHMAP;
332
333 /*
334  * Structures for soft labels.
335  */
336
337 struct _SLK;
338
339 #ifndef USE_TERMLIB
340
341 typedef struct
342 {
343         char *ent_text;         /* text for the label */
344         char *form_text;        /* formatted text (left/center/...) */
345         int ent_x;              /* x coordinate of this field */
346         char dirty;             /* this label has changed */
347         char visible;           /* field is visible */
348 } slk_ent;
349
350 typedef struct _SLK {
351         char dirty;             /* all labels have changed */
352         char hidden;            /* soft labels are hidden */
353         WINDOW *win;
354         slk_ent *ent;
355         short  maxlab;          /* number of available labels */
356         short  labcnt;          /* number of allocated labels */
357         short  maxlen;          /* length of labels */
358         NCURSES_CH_T attr;      /* soft label attribute */
359 } SLK;
360
361 #endif  /* USE_TERMLIB */
362
363 typedef struct {
364         int     line;           /* lines to take, < 0 => from bottom*/
365         int     (*hook)(WINDOW *, int); /* callback for user        */
366         WINDOW *w;              /* maybe we need this for cleanup   */
367 } ripoff_t;
368
369 /*
370  * The SCREEN structure.
371  */
372
373 struct screen {
374         int             _ifd;           /* input file ptr for screen        */
375         FILE            *_ofp;          /* output file ptr for screen       */
376         char            *_setbuf;       /* buffered I/O for output          */
377         int             _buffered;      /* setvbuf uses _setbuf data        */
378         int             _checkfd;       /* filedesc for typeahead check     */
379         TERMINAL        *_term;         /* terminal type information        */
380         short           _lines;         /* screen lines                     */
381         short           _columns;       /* screen columns                   */
382
383         short           _lines_avail;   /* lines available for stdscr       */
384         short           _topstolen;     /* lines stolen from top            */
385         ripoff_t        _rippedoff[5];  /* list of lines stolen             */
386         int             _rip_count;     /* ...and total lines stolen        */
387
388         WINDOW          *_curscr;       /* current screen                   */
389         WINDOW          *_newscr;       /* virtual screen to be updated to  */
390         WINDOW          *_stdscr;       /* screen's full-window context     */
391
392         struct tries    *_keytry;       /* "Try" for use with keypad mode   */
393         struct tries    *_key_ok;       /* Disabled keys via keyok(,FALSE)  */
394         bool            _tried;         /* keypad mode was initialized      */
395         bool            _keypad_on;     /* keypad mode is currently on      */
396
397         bool            _called_wgetch; /* check for recursion in wgetch()  */
398         int             _fifo[FIFO_SIZE];       /* input push-back buffer   */
399         short           _fifohead,      /* head of fifo queue               */
400                         _fifotail,      /* tail of fifo queue               */
401                         _fifopeek,      /* where to peek for next char      */
402                         _fifohold;      /* set if breakout marked           */
403
404         int             _endwin;        /* are we out of window mode?       */
405         NCURSES_CH_T    *_current_attr; /* holds current attributes set     */
406         int             _coloron;       /* is color enabled?                */
407         int             _color_defs;    /* are colors modified              */
408         int             _cursor;        /* visibility of the cursor         */
409         int             _cursrow;       /* physical cursor row              */
410         int             _curscol;       /* physical cursor column           */
411         bool            _notty;         /* true if we cannot switch non-tty */
412         int             _nl;            /* True if NL -> CR/NL is on        */
413         int             _raw;           /* True if in raw mode              */
414         int             _cbreak;        /* 1 if in cbreak mode              */
415                                         /* > 1 if in halfdelay mode         */
416         int             _echo;          /* True if echo on                  */
417         int             _use_meta;      /* use the meta key?                */
418         struct _SLK     *_slk;          /* ptr to soft key struct / NULL    */
419         int             slk_format;     /* selected format for this screen  */
420         /* cursor movement costs; units are 10ths of milliseconds */
421 #if NCURSES_NO_PADDING
422         int             _no_padding;    /* flag to set if padding disabled  */
423 #endif
424         int             _char_padding;  /* cost of character put            */
425         int             _cr_cost;       /* cost of (carriage_return)        */
426         int             _cup_cost;      /* cost of (cursor_address)         */
427         int             _home_cost;     /* cost of (cursor_home)            */
428         int             _ll_cost;       /* cost of (cursor_to_ll)           */
429 #if USE_HARD_TABS
430         int             _ht_cost;       /* cost of (tab)                    */
431         int             _cbt_cost;      /* cost of (backtab)                */
432 #endif /* USE_HARD_TABS */
433         int             _cub1_cost;     /* cost of (cursor_left)            */
434         int             _cuf1_cost;     /* cost of (cursor_right)           */
435         int             _cud1_cost;     /* cost of (cursor_down)            */
436         int             _cuu1_cost;     /* cost of (cursor_up)              */
437         int             _cub_cost;      /* cost of (parm_cursor_left)       */
438         int             _cuf_cost;      /* cost of (parm_cursor_right)      */
439         int             _cud_cost;      /* cost of (parm_cursor_down)       */
440         int             _cuu_cost;      /* cost of (parm_cursor_up)         */
441         int             _hpa_cost;      /* cost of (column_address)         */
442         int             _vpa_cost;      /* cost of (row_address)            */
443         /* used in tty_update.c, must be chars */
444         int             _ed_cost;       /* cost of (clr_eos)                */
445         int             _el_cost;       /* cost of (clr_eol)                */
446         int             _el1_cost;      /* cost of (clr_bol)                */
447         int             _dch1_cost;     /* cost of (delete_character)       */
448         int             _ich1_cost;     /* cost of (insert_character)       */
449         int             _dch_cost;      /* cost of (parm_dch)               */
450         int             _ich_cost;      /* cost of (parm_ich)               */
451         int             _ech_cost;      /* cost of (erase_chars)            */
452         int             _rep_cost;      /* cost of (repeat_char)            */
453         int             _hpa_ch_cost;   /* cost of (column_address)         */
454         int             _cup_ch_cost;   /* cost of (cursor_address)         */
455         int             _cuf_ch_cost;   /* cost of (parm_cursor_right)      */
456         int             _inline_cost;   /* cost of inline-move              */
457         int             _smir_cost;     /* cost of (enter_insert_mode)      */
458         int             _rmir_cost;     /* cost of (exit_insert_mode)       */
459         int             _ip_cost;       /* cost of (insert_padding)         */
460         /* used in lib_mvcur.c */
461         char *          _address_cursor;
462         /* used in tty_update.c */
463         int             _scrolling;     /* 1 if terminal's smart enough to  */
464
465         /* used in lib_color.c */
466         color_t         *_color_table;  /* screen's color palette            */
467         int             _color_count;   /* count of colors in palette        */
468         colorpair_t     *_color_pairs;  /* screen's color pair list          */
469         int             _pair_count;    /* count of color pairs              */
470 #if NCURSES_EXT_FUNCS
471         bool            _default_color; /* use default colors                */
472         bool            _has_sgr_39_49; /* has ECMA default color support    */
473         int             _default_fg;    /* assumed default foreground        */
474         int             _default_bg;    /* assumed default background        */
475 #endif
476         chtype          _xmc_suppress;  /* attributes to suppress if xmc     */
477         chtype          _xmc_triggers;  /* attributes to process if xmc      */
478         chtype          _acs_map[ACS_LEN]; /* the real alternate-charset map */
479
480         /* used in lib_vidattr.c */
481         bool            _use_rmso;      /* true if we may use 'rmso'         */
482         bool            _use_rmul;      /* true if we may use 'rmul'         */
483
484         /*
485          * These data correspond to the state of the idcok() and idlok()
486          * functions.  A caveat is in order here:  the XSI and SVr4
487          * documentation specify that these functions apply to the window which
488          * is given as an argument.  However, ncurses implements this logic
489          * only for the newscr/curscr update process, _not_ per-window.
490          */
491         bool            _nc_sp_idlok;
492         bool            _nc_sp_idcok;
493 #define _nc_idlok SP->_nc_sp_idlok
494 #define _nc_idcok SP->_nc_sp_idcok
495
496         /*
497          * These are the data that support the mouse interface.
498          */
499         MouseType       _mouse_type;
500         int             _maxclick;
501         bool            (*_mouse_event) (SCREEN *);
502         bool            (*_mouse_inline)(SCREEN *);
503         bool            (*_mouse_parse) (int);
504         void            (*_mouse_resume)(SCREEN *);
505         void            (*_mouse_wrap)  (SCREEN *);
506         int             _mouse_fd;      /* file-descriptor, if any */
507         bool            _mouse_active;  /* true if initialized */
508         NCURSES_CONST char *_mouse_xtermcap; /* string to enable/disable mouse */
509 #if USE_SYSMOUSE
510         MEVENT          _sysmouse_fifo[FIFO_SIZE];
511         int             _sysmouse_head;
512         int             _sysmouse_tail;
513         int             _sysmouse_char_width;   /* character width */
514         int             _sysmouse_char_height;  /* character height */
515         int             _sysmouse_old_buttons;
516         int             _sysmouse_new_buttons;
517 #endif
518
519         /*
520          * This supports automatic resizing
521          */
522 #if USE_SIZECHANGE
523         int             (*_resize)(int,int);
524 #endif
525
526         /*
527          * These are data that support the proper handling of the panel stack on an
528          * per screen basis.
529          */
530         struct panelhook _panelHook;
531         /*
532          * Linked-list of all windows, to support '_nc_resizeall()' and
533          * '_nc_freeall()'
534          */
535         WINDOWLIST      *_nc_sp_windows;
536 #define _nc_windows SP->_nc_sp_windows
537
538         bool            _sig_winch;
539         SCREEN          *_next_screen;
540
541         /* hashes for old and new lines */
542         unsigned long   *oldhash, *newhash;
543         HASHMAP         *hashtab;
544         int             hashtab_len;
545
546         bool            _cleanup;       /* cleanup after int/quit signal */
547         int             (*_outch)(int); /* output handler if not putc */
548
549         /* recent versions of 'screen' have partially-working support for
550          * UTF-8, but do not permit ACS at the same time (see tty_update.c).
551          */
552 #if USE_WIDEC_SUPPORT
553         bool            _legacy_coding;
554         bool            _screen_acs_fix;
555 #endif
556         bool            _screen_acs_map[ACS_LEN];
557 };
558
559 extern NCURSES_EXPORT_VAR(SCREEN *) _nc_screen_chain;
560
561 #if NCURSES_NOMACROS
562 #include <nomacros.h>
563 #endif
564
565         WINDOWLIST {
566         WINDOW  win;    /* first, so WINDOW_EXT() works */
567         WINDOWLIST *next;
568 #ifdef _XOPEN_SOURCE_EXTENDED
569         char addch_work[(MB_LEN_MAX * 9) + 1];
570         unsigned addch_used;    /* number of bytes in addch_work[] */
571         int addch_x;            /* x-position for addch_work[] */
572         int addch_y;            /* y-position for addch_work[] */
573 #endif
574 };
575
576 #define WINDOW_EXT(win,field) (((WINDOWLIST *)(win))->field)
577
578 /* usually in <limits.h> */
579 #ifndef UCHAR_MAX
580 #define UCHAR_MAX 255
581 #endif
582
583 /* The terminfo source is assumed to be 7-bit ASCII */
584 #define is7bits(c)      ((unsigned)(c) < 128)
585
586 /* Checks for isprint() should be done on 8-bit characters (non-wide) */
587 #define is8bits(c)      ((unsigned)(c) <= UCHAR_MAX)
588
589 #ifndef min
590 #define min(a,b)        ((a) > (b)  ?  (b)  :  (a))
591 #endif
592
593 #ifndef max
594 #define max(a,b)        ((a) < (b)  ?  (b)  :  (a))
595 #endif
596
597 /* usually in <unistd.h> */
598 #ifndef STDIN_FILENO
599 #define STDIN_FILENO 0
600 #endif
601
602 #ifndef STDOUT_FILENO
603 #define STDOUT_FILENO 1
604 #endif
605
606 #ifndef STDERR_FILENO
607 #define STDERR_FILENO 2
608 #endif
609
610 #ifndef EXIT_SUCCESS
611 #define EXIT_SUCCESS 0
612 #endif
613
614 #ifndef EXIT_FAILURE
615 #define EXIT_FAILURE 1
616 #endif
617
618 #ifndef R_OK
619 #define R_OK    4               /* Test for read permission.  */
620 #endif
621 #ifndef W_OK
622 #define W_OK    2               /* Test for write permission.  */
623 #endif
624 #ifndef X_OK
625 #define X_OK    1               /* Test for execute permission.  */
626 #endif
627 #ifndef F_OK
628 #define F_OK    0               /* Test for existence.  */
629 #endif
630
631 #if HAVE_FCNTL_H
632 #include <fcntl.h>              /* may define O_BINARY  */
633 #endif
634
635 #ifndef O_BINARY
636 #define O_BINARY 0
637 #endif
638
639 #ifdef TRACE
640 #define TRACE_OUTCHARS(n) _nc_outchars += (n);
641 #else
642 #define TRACE_OUTCHARS(n) /* nothing */
643 #endif
644
645 #define UChar(c)        ((unsigned char)(c))
646 #define ChCharOf(c)     ((c) & (chtype)A_CHARTEXT)
647 #define ChAttrOf(c)     ((c) & (chtype)A_ATTRIBUTES)
648
649 #ifndef MB_LEN_MAX
650 #define MB_LEN_MAX 8 /* should be >= MB_CUR_MAX, but that may be a function */
651 #endif
652
653 #if USE_WIDEC_SUPPORT /* { */
654 #define isEILSEQ(status) ((status == (size_t)-1) && (errno == EILSEQ))
655
656 #define init_mb(state)  memset(&state, 0, sizeof(state))
657
658 #if NCURSES_EXT_COLORS
659 #define NulColor        , 0
660 #else
661 #define NulColor        /* nothing */
662 #endif
663
664 #define NulChar         0,0,0,0 /* FIXME: see CCHARW_MAX */
665 #define CharOf(c)       ((c).chars[0])
666 #define AttrOf(c)       ((c).attr)
667 #define AddAttr(c,a)    AttrOf(c) |= a
668 #define RemAttr(c,a)    AttrOf(c) &= ~(a)
669 #define SetAttr(c,a)    AttrOf(c) = a
670 #define NewChar(ch)     { ChAttrOf(ch), { ChCharOf(ch), NulChar } NulColor }
671 #define NewChar2(c,a)   { a, { c, NulChar } NulColor }
672 #define CharEq(a,b)     (!memcmp(&a, &b, sizeof(a)))
673 #define SetChar(ch,c,a) do {                                                        \
674                             NCURSES_CH_T *_cp = &ch;                                \
675                             memset(_cp, 0, sizeof(ch));                             \
676                             _cp->chars[0] = c;                                      \
677                             _cp->attr = a;                                          \
678                             if_EXT_COLORS(SetPair(ch, PAIR_NUMBER(a)));             \
679                         } while (0)
680 #define CHREF(wch)      (&wch)
681 #define CHDEREF(wch)    (*wch)
682 #define ARG_CH_T        NCURSES_CH_T *
683 #define CARG_CH_T       const NCURSES_CH_T *
684 #define PUTC_DATA       char PUTC_buf[MB_LEN_MAX]; int PUTC_i, PUTC_n; \
685                         mbstate_t PUT_st; wchar_t PUTC_ch
686 #define PUTC_INIT       init_mb (PUT_st);                                           \
687                         PUTC_i = 0
688 #define PUTC(ch,b)      do { if(!isWidecExt(ch)) {                                  \
689                         if (Charable(ch)) {                                         \
690                             fputc(CharOf(ch), b);                                   \
691                             TRACE_OUTCHARS(1);                                      \
692                         } else {                                                    \
693                             PUTC_INIT;                                              \
694                             do {                                                    \
695                                 PUTC_ch = PUTC_i < CCHARW_MAX ?                     \
696                                             (ch).chars[PUTC_i] : L'\0';             \
697                                 PUTC_n = wcrtomb(PUTC_buf,                          \
698                                                  (ch).chars[PUTC_i], &PUT_st);      \
699                                 if (PUTC_ch == L'\0')                               \
700                                     --PUTC_n;                                       \
701                                 if (PUTC_n <= 0)                                    \
702                                     break;                                          \
703                                 fwrite(PUTC_buf, (unsigned) PUTC_n, 1, b);          \
704                                 ++PUTC_i;                                           \
705                             } while (PUTC_ch != L'\0');                             \
706                             TRACE_OUTCHARS(PUTC_i);                                 \
707                         } } } while (0)
708
709 #define BLANK           { WA_NORMAL, {' '} NulColor }
710 #define ZEROS           { WA_NORMAL, {'\0'} NulColor }
711 #define ISBLANK(ch)     ((ch).chars[0] == L' ' && (ch).chars[1] == L'\0')
712
713         /*
714          * Wide characters cannot be represented in the A_CHARTEXT mask of
715          * attr_t's but an application might have set a narrow character there.
716          * But even in that case, it would only be a printable character, or
717          * zero.  Otherwise we can use those bits to tell if a cell is the
718          * first or extension part of a wide character.
719          */
720 #define WidecExt(ch)    (AttrOf(ch) & A_CHARTEXT)
721 #define isWidecBase(ch) (WidecExt(ch) == 1)
722 #define isWidecExt(ch)  (WidecExt(ch) > 1 && WidecExt(ch) < 32)
723 #define SetWidecExt(dst, ext)   AttrOf(dst) &= ~A_CHARTEXT,             \
724                                 AttrOf(dst) |= (ext + 1)
725
726 #define if_WIDEC(code)  code
727 #define Charable(ch)    ((SP != 0 && SP->_legacy_coding)                \
728                          || (AttrOf(ch) & A_ALTCHARSET)                 \
729                          || (!isWidecExt(ch) &&                         \
730                              (ch).chars[1] == L'\0' &&                  \
731                              _nc_is_charable(CharOf(ch))))
732
733 #define L(ch)           L ## ch
734 #else /* }{ */
735 #define CharOf(c)       ChCharOf(c)
736 #define AttrOf(c)       ChAttrOf(c)
737 #define AddAttr(c,a)    c |= a
738 #define RemAttr(c,a)    c &= ~(a & A_ATTRIBUTES)
739 #define SetAttr(c,a)    c = (c & ~A_ATTRIBUTES) | a
740 #define NewChar(ch)     (ch)
741 #define NewChar2(c,a)   (c | a)
742 #define CharEq(a,b)     (a == b)
743 #define SetChar(ch,c,a) ch = c | a
744 #define CHREF(wch)      wch
745 #define CHDEREF(wch)    wch
746 #define ARG_CH_T        NCURSES_CH_T
747 #define CARG_CH_T       NCURSES_CH_T
748 #define PUTC_DATA       int data = 0
749 #define PUTC(a,b)       do { data = CharOf(ch); putc(data,b); } while (0)
750
751 #define BLANK           (' '|A_NORMAL)
752 #define ZEROS           ('\0'|A_NORMAL)
753 #define ISBLANK(ch)     (CharOf(ch) == ' ')
754
755 #define isWidecExt(ch)  (0)
756 #define if_WIDEC(code) /* nothing */
757
758 #define L(ch)           ch
759 #endif /* } */
760
761 #define AttrOfD(ch)     AttrOf(CHDEREF(ch))
762 #define CharOfD(ch)     CharOf(CHDEREF(ch))
763 #define SetChar2(wch,ch)    SetChar(wch,ChCharOf(ch),ChAttrOf(ch))
764
765 #define BLANK_ATTR      A_NORMAL
766 #define BLANK_TEXT      L(' ')
767
768 #define CHANGED     -1
769
770 #define LEGALYX(w, y, x) \
771               ((w) != 0 && \
772                 ((x) >= 0 && (x) <= (w)->_maxx && \
773                  (y) >= 0 && (y) <= (w)->_maxy))
774
775 #define CHANGED_CELL(line,col) \
776         if (line->firstchar == _NOCHANGE) \
777                 line->firstchar = line->lastchar = col; \
778         else if ((col) < line->firstchar) \
779                 line->firstchar = col; \
780         else if ((col) > line->lastchar) \
781                 line->lastchar = col
782
783 #define CHANGED_RANGE(line,start,end) \
784         if (line->firstchar == _NOCHANGE \
785          || line->firstchar > (start)) \
786                 line->firstchar = start; \
787         if (line->lastchar == _NOCHANGE \
788          || line->lastchar < (end)) \
789                 line->lastchar = end
790
791 #define CHANGED_TO_EOL(line,start,end) \
792         if (line->firstchar == _NOCHANGE \
793          || line->firstchar > (start)) \
794                 line->firstchar = start; \
795         line->lastchar = end
796
797 #define SIZEOF(v) (sizeof(v)/sizeof(v[0]))
798
799 #define FreeIfNeeded(p)  if ((p) != 0) free(p)
800
801 /* FreeAndNull() is not a comma-separated expression because some compilers
802  * do not accept a mixture of void with values.
803  */
804 #define FreeAndNull(p)   free(p); p = 0
805
806 #include <nc_alloc.h>
807
808 /*
809  * Prefixes for call/return points of library function traces.  We use these to
810  * instrument the public functions so that the traces can be easily transformed
811  * into regression scripts.
812  */
813 #define T_CALLED(fmt) "called {" fmt
814 #define T_CREATE(fmt) "create :" fmt
815 #define T_RETURN(fmt) "return }" fmt
816
817 #ifdef TRACE
818
819 #define START_TRACE() \
820         if ((_nc_tracing & TRACE_MAXIMUM) == 0) { \
821             int t = _nc_getenv_num("NCURSES_TRACE"); \
822             if (t >= 0) \
823                 trace((unsigned) t); \
824         }
825
826 #define TR(n, a)        if (_nc_tracing & (n)) _tracef a
827 #define T(a)            TR(TRACE_CALLS, a)
828 #define TPUTS_TRACE(s)  _nc_tputs_trace = s;
829 #define TRACE_RETURN(value,type) return _nc_retrace_##type(value)
830
831 #define returnAttr(code)        TRACE_RETURN(code,attr_t)
832 #define returnBits(code)        TRACE_RETURN(code,unsigned)
833 #define returnBool(code)        TRACE_RETURN(code,bool)
834 #define returnCPtr(code)        TRACE_RETURN(code,cptr)
835 #define returnCVoidPtr(code)    TRACE_RETURN(code,cvoid_ptr)
836 #define returnChar(code)        TRACE_RETURN(code,chtype)
837 #define returnCode(code)        TRACE_RETURN(code,int)
838 #define returnPtr(code)         TRACE_RETURN(code,ptr)
839 #define returnSP(code)          TRACE_RETURN(code,sp)
840 #define returnVoid              T((T_RETURN(""))); return
841 #define returnVoidPtr(code)     TRACE_RETURN(code,void_ptr)
842 #define returnWin(code)         TRACE_RETURN(code,win)
843
844 extern NCURSES_EXPORT(NCURSES_BOOL)     _nc_retrace_bool (NCURSES_BOOL);
845 extern NCURSES_EXPORT(NCURSES_CONST void *) _nc_retrace_cvoid_ptr (NCURSES_CONST void *);
846 extern NCURSES_EXPORT(SCREEN *)         _nc_retrace_sp (SCREEN *);
847 extern NCURSES_EXPORT(WINDOW *)         _nc_retrace_win (WINDOW *);
848 extern NCURSES_EXPORT(attr_t)           _nc_retrace_attr_t (attr_t);
849 extern NCURSES_EXPORT(char *)           _nc_retrace_ptr (char *);
850 extern NCURSES_EXPORT(char *)           _nc_trace_ttymode(TTY *tty);
851 extern NCURSES_EXPORT(char *)           _nc_varargs (const char *, va_list);
852 extern NCURSES_EXPORT(chtype)           _nc_retrace_chtype (chtype);
853 extern NCURSES_EXPORT(const char *)     _nc_altcharset_name(attr_t, chtype);
854 extern NCURSES_EXPORT(const char *)     _nc_retrace_cptr (const char *);
855 extern NCURSES_EXPORT(int)              _nc_retrace_int (int);
856 extern NCURSES_EXPORT(unsigned)         _nc_retrace_unsigned (unsigned);
857 extern NCURSES_EXPORT(void *)           _nc_retrace_void_ptr (void *);
858 extern NCURSES_EXPORT(void)             _nc_fifo_dump (void);
859 extern NCURSES_EXPORT_VAR(const char *) _nc_tputs_trace;
860 extern NCURSES_EXPORT_VAR(long)         _nc_outchars;
861 extern NCURSES_EXPORT_VAR(unsigned)     _nc_tracing;
862
863 #if USE_WIDEC_SUPPORT
864 extern NCURSES_EXPORT(const char *) _nc_viswbuf2 (int, const wchar_t *);
865 extern NCURSES_EXPORT(const char *) _nc_viswbufn (const wchar_t *, int);
866 extern NCURSES_EXPORT(const char *) _nc_viscbuf2 (int, const cchar_t *, int);
867 extern NCURSES_EXPORT(const char *) _nc_viscbuf (const cchar_t *, int);
868 #endif
869
870 #else /* !TRACE */
871
872 #define START_TRACE() /* nothing */
873
874 #define T(a)
875 #define TR(n, a)
876 #define TPUTS_TRACE(s)
877
878 #define returnAttr(code)        return code
879 #define returnBits(code)        return code
880 #define returnBool(code)        return code
881 #define returnCPtr(code)        return code
882 #define returnCVoidPtr(code)    return code
883 #define returnChar(code)        return code
884 #define returnCode(code)        return code
885 #define returnPtr(code)         return code
886 #define returnSP(code)          return code
887 #define returnVoid              return
888 #define returnVoidPtr(code)     return code
889 #define returnWin(code)         return code
890
891 #endif /* TRACE/!TRACE */
892
893 extern NCURSES_EXPORT(const char *) _nc_visbuf2 (int, const char *);
894 extern NCURSES_EXPORT(const char *) _nc_visbufn (const char *, int);
895
896 #define empty_module(name) \
897 extern  NCURSES_EXPORT(void) name (void); \
898         NCURSES_EXPORT(void) name (void) { }
899
900 #define ALL_BUT_COLOR ((chtype)~(A_COLOR))
901 #define NONBLANK_ATTR (A_NORMAL|A_BOLD|A_DIM|A_BLINK)
902 #define XMC_CHANGES(c) ((c) & SP->_xmc_suppress)
903
904 #define toggle_attr_on(S,at) {\
905    if (PAIR_NUMBER(at) > 0) {\
906       (S) = ((S) & ALL_BUT_COLOR) | (at);\
907    } else {\
908       (S) |= (at);\
909    }\
910    TR(TRACE_ATTRS, ("new attribute is %s", _traceattr((S))));}
911
912
913 #define toggle_attr_off(S,at) {\
914    if (PAIR_NUMBER(at) > 0) {\
915       (S) &= ~(at|A_COLOR);\
916    } else {\
917       (S) &= ~(at);\
918    }\
919    TR(TRACE_ATTRS, ("new attribute is %s", _traceattr((S))));}
920
921 #define DelCharCost(count) \
922                 ((parm_dch != 0) \
923                 ? SP->_dch_cost \
924                 : ((delete_character != 0) \
925                         ? (SP->_dch1_cost * count) \
926                         : INFINITY))
927
928 #define InsCharCost(count) \
929                 ((parm_ich != 0) \
930                 ? SP->_ich_cost \
931                 : ((enter_insert_mode && exit_insert_mode) \
932                   ? SP->_smir_cost + SP->_rmir_cost + (SP->_ip_cost * count) \
933                   : ((insert_character != 0) \
934                     ? ((SP->_ich1_cost + SP->_ip_cost) * count) \
935                     : INFINITY)))
936
937 #if USE_XMC_SUPPORT
938 #define UpdateAttrs(c)  if (!SameAttrOf(SCREEN_ATTRS(SP), c)) { \
939                                 attr_t chg = AttrOf(SCREEN_ATTRS(SP)); \
940                                 VIDATTR(AttrOf(c), GetPair(c)); \
941                                 if (magic_cookie_glitch > 0 \
942                                  && XMC_CHANGES((chg ^ AttrOf(SCREEN_ATTRS(SP))))) { \
943                                         T(("%s @%d before glitch %d,%d", \
944                                                 __FILE__, __LINE__, \
945                                                 SP->_cursrow, \
946                                                 SP->_curscol)); \
947                                         _nc_do_xmc_glitch(chg); \
948                                 } \
949                         }
950 #else
951 #define UpdateAttrs(c)  if (!SameAttrOf(SCREEN_ATTRS(SP), c)) \
952                                 VIDATTR(AttrOf(c), GetPair(c));
953 #endif
954
955 /*
956  * Macros to make additional parameter to implement wgetch_events()
957  */
958 #ifdef NCURSES_WGETCH_EVENTS
959 #define EVENTLIST_0th(param) param
960 #define EVENTLIST_1st(param) param
961 #define EVENTLIST_2nd(param) , param
962 #else
963 #define EVENTLIST_0th(param) void
964 #define EVENTLIST_1st(param) /* nothing */
965 #define EVENTLIST_2nd(param) /* nothing */
966 #endif
967
968 #if NCURSES_EXPANDED && NCURSES_EXT_FUNCS
969
970 #undef  toggle_attr_on
971 #define toggle_attr_on(S,at) _nc_toggle_attr_on(&(S), at)
972 extern NCURSES_EXPORT(void) _nc_toggle_attr_on (attr_t *, attr_t);
973
974 #undef  toggle_attr_off
975 #define toggle_attr_off(S,at) _nc_toggle_attr_off(&(S), at)
976 extern NCURSES_EXPORT(void) _nc_toggle_attr_off (attr_t *, attr_t);
977
978 #undef  DelCharCost
979 #define DelCharCost(count) _nc_DelCharCost(count)
980 extern NCURSES_EXPORT(int) _nc_DelCharCost (int);
981
982 #undef  InsCharCost
983 #define InsCharCost(count) _nc_InsCharCost(count)
984 extern NCURSES_EXPORT(int) _nc_InsCharCost (int);
985
986 #undef  UpdateAttrs
987 #define UpdateAttrs(c) _nc_UpdateAttrs(c)
988 extern NCURSES_EXPORT(void) _nc_UpdateAttrs (NCURSES_CH_T);
989
990 #else
991
992 extern NCURSES_EXPORT(void) _nc_expanded (void);
993
994 #endif
995
996 #if !HAVE_GETCWD
997 #define getcwd(buf,len) getwd(buf)
998 #endif
999
1000 /* charable.c */
1001 #if USE_WIDEC_SUPPORT
1002 extern NCURSES_EXPORT(bool) _nc_is_charable(wchar_t);
1003 extern NCURSES_EXPORT(int) _nc_to_char(wint_t);
1004 extern NCURSES_EXPORT(wint_t) _nc_to_widechar(int);
1005 #endif
1006
1007 /* doupdate.c */
1008 #if USE_XMC_SUPPORT
1009 extern NCURSES_EXPORT(void) _nc_do_xmc_glitch (attr_t);
1010 #endif
1011
1012 /* hardscroll.c */
1013 #if defined(TRACE) || defined(SCROLLDEBUG) || defined(HASHDEBUG)
1014 extern NCURSES_EXPORT(void) _nc_linedump (void);
1015 #endif
1016
1017 /* lib_acs.c */
1018 extern NCURSES_EXPORT(void) _nc_init_acs (void);        /* corresponds to traditional 'init_acs()' */
1019 extern NCURSES_EXPORT(int) _nc_msec_cost (const char *const, int);  /* used by 'tack' program */
1020
1021 /* lib_addch.c */
1022 #if USE_WIDEC_SUPPORT
1023 NCURSES_EXPORT(int) _nc_build_wch(WINDOW *win, ARG_CH_T ch);
1024 #endif
1025
1026 /* lib_addstr.c */
1027 #if USE_WIDEC_SUPPORT && !defined(USE_TERMLIB)
1028 extern NCURSES_EXPORT(int) _nc_wchstrlen(const cchar_t *);
1029 #endif
1030
1031 /* lib_color.c */
1032 extern NCURSES_EXPORT(bool) _nc_reset_colors(void);
1033
1034 /* lib_getch.c */
1035 extern NCURSES_EXPORT(int) _nc_wgetch(WINDOW *, unsigned long *, int EVENTLIST_2nd(_nc_eventlist *));
1036
1037 /* lib_insch.c */
1038 extern NCURSES_EXPORT(int) _nc_insert_ch(WINDOW *, chtype);
1039
1040 /* lib_mvcur.c */
1041 #define INFINITY        1000000 /* cost: too high to use */
1042
1043 extern NCURSES_EXPORT(void) _nc_mvcur_init (void);
1044 extern NCURSES_EXPORT(void) _nc_mvcur_resume (void);
1045 extern NCURSES_EXPORT(void) _nc_mvcur_wrap (void);
1046
1047 extern NCURSES_EXPORT(int) _nc_scrolln (int, int, int, int);
1048
1049 extern NCURSES_EXPORT(void) _nc_screen_init (void);
1050 extern NCURSES_EXPORT(void) _nc_screen_resume (void);
1051 extern NCURSES_EXPORT(void) _nc_screen_wrap (void);
1052
1053 /* lib_mouse.c */
1054 extern NCURSES_EXPORT(int) _nc_has_mouse (void);
1055
1056 /* lib_mvcur.c */
1057 #define INFINITY        1000000 /* cost: too high to use */
1058 #define BAUDBYTE        9       /* 9 = 7 bits + 1 parity + 1 stop */
1059
1060 /* lib_setup.c */
1061 extern NCURSES_EXPORT(char *) _nc_get_locale(void);
1062 extern NCURSES_EXPORT(int) _nc_unicode_locale(void);
1063 extern NCURSES_EXPORT(int) _nc_locale_breaks_acs(void);
1064 extern NCURSES_EXPORT(int) _nc_setupterm(NCURSES_CONST char *, int , int *, bool);
1065
1066 /* lib_wacs.c */
1067 #if USE_WIDEC_SUPPORT
1068 extern NCURSES_EXPORT(void) _nc_init_wacs(void);
1069 #endif
1070
1071 typedef struct {
1072     char *s_head;       /* beginning of the string (may be null) */
1073     char *s_tail;       /* end of the string (may be null) */
1074     size_t s_size;      /* current remaining size available */
1075     size_t s_init;      /* total size available */
1076 } string_desc;
1077
1078 /* strings.c */
1079 extern NCURSES_EXPORT(string_desc *) _nc_str_init (string_desc *, char *, size_t);
1080 extern NCURSES_EXPORT(string_desc *) _nc_str_null (string_desc *, size_t);
1081 extern NCURSES_EXPORT(string_desc *) _nc_str_copy (string_desc *, string_desc *);
1082 extern NCURSES_EXPORT(bool) _nc_safe_strcat (string_desc *, const char *);
1083 extern NCURSES_EXPORT(bool) _nc_safe_strcpy (string_desc *, const char *);
1084
1085 #if !HAVE_STRSTR
1086 #define strstr _nc_strstr
1087 extern NCURSES_EXPORT(char *) _nc_strstr (const char *, const char *);
1088 #endif
1089
1090 /* safe_sprintf.c */
1091 extern NCURSES_EXPORT(char *) _nc_printf_string (const char *, va_list);
1092
1093 /* tries.c */
1094 extern NCURSES_EXPORT(void) _nc_add_to_try (struct tries **, const char *, unsigned short);
1095 extern NCURSES_EXPORT(char *) _nc_expand_try (struct tries *, unsigned short, int *, size_t);
1096 extern NCURSES_EXPORT(int) _nc_remove_key (struct tries **, unsigned short);
1097 extern NCURSES_EXPORT(int) _nc_remove_string (struct tries **, const char *);
1098
1099 /* elsewhere ... */
1100 extern NCURSES_EXPORT(ENTRY *) _nc_delink_entry(ENTRY *, TERMTYPE *);
1101 extern NCURSES_EXPORT(WINDOW *) _nc_makenew (int, int, int, int, int);
1102 extern NCURSES_EXPORT(char *) _nc_home_terminfo (void);
1103 extern NCURSES_EXPORT(char *) _nc_trace_buf (int, size_t);
1104 extern NCURSES_EXPORT(char *) _nc_trace_bufcat (int, const char *);
1105 extern NCURSES_EXPORT(int) _nc_access (const char *, int);
1106 extern NCURSES_EXPORT(int) _nc_baudrate (int);
1107 extern NCURSES_EXPORT(int) _nc_freewin (WINDOW *);
1108 extern NCURSES_EXPORT(int) _nc_getenv_num (const char *);
1109 extern NCURSES_EXPORT(int) _nc_keypad (bool);
1110 extern NCURSES_EXPORT(int) _nc_ospeed (int);
1111 extern NCURSES_EXPORT(int) _nc_outch (int);
1112 extern NCURSES_EXPORT(int) _nc_setupscreen (short, short const, FILE *);
1113 extern NCURSES_EXPORT(int) _nc_timed_wait(int, int, int * EVENTLIST_2nd(_nc_eventlist *));
1114 extern NCURSES_EXPORT(void) _nc_do_color (int, int, bool, int (*)(int));
1115 extern NCURSES_EXPORT(void) _nc_flush (void);
1116 extern NCURSES_EXPORT(void) _nc_free_entry(ENTRY *, TERMTYPE *);
1117 extern NCURSES_EXPORT(void) _nc_freeall (void);
1118 extern NCURSES_EXPORT(void) _nc_hash_map (void);
1119 extern NCURSES_EXPORT(void) _nc_init_keytry (void);
1120 extern NCURSES_EXPORT(void) _nc_keep_tic_dir (const char *);
1121 extern NCURSES_EXPORT(void) _nc_make_oldhash (int i);
1122 extern NCURSES_EXPORT(void) _nc_scroll_oldhash (int n, int top, int bot);
1123 extern NCURSES_EXPORT(void) _nc_scroll_optimize (void);
1124 extern NCURSES_EXPORT(void) _nc_set_buffer (FILE *, bool);
1125 extern NCURSES_EXPORT(void) _nc_signal_handler (bool);
1126 extern NCURSES_EXPORT(void) _nc_synchook (WINDOW *);
1127 extern NCURSES_EXPORT(void) _nc_trace_tries (struct tries *);
1128
1129 #if NO_LEAKS
1130 extern NCURSES_EXPORT(void) _nc_alloc_entry_leaks(void);
1131 extern NCURSES_EXPORT(void) _nc_captoinfo_leaks(void);
1132 extern NCURSES_EXPORT(void) _nc_comp_scan_leaks(void);
1133 #endif
1134
1135 #ifndef USE_TERMLIB
1136 extern NCURSES_EXPORT(NCURSES_CH_T) _nc_render (WINDOW *, NCURSES_CH_T);
1137 extern NCURSES_EXPORT(int) _nc_waddch_nosync (WINDOW *, const NCURSES_CH_T);
1138 extern NCURSES_EXPORT(void) _nc_scroll_window (WINDOW *, int const, short const, short const, NCURSES_CH_T);
1139 #endif
1140
1141 #if USE_WIDEC_SUPPORT && !defined(USE_TERMLIB)
1142 #ifdef linux
1143 extern NCURSES_EXPORT(size_t) _nc_wcrtomb (char *, wchar_t, mbstate_t *);
1144 #else
1145 #define _nc_wcrtomb(s,wc,ps) wcrtomb(s,wc,ps)
1146 #endif
1147 #endif
1148
1149 #if USE_SIZECHANGE
1150 extern NCURSES_EXPORT(void) _nc_update_screensize (void);
1151 #endif
1152
1153 #if HAVE_RESIZETERM
1154 extern NCURSES_EXPORT(void) _nc_resize_margins (WINDOW *);
1155 #else
1156 #define _nc_resize_margins(wp) /* nothing */
1157 #endif
1158
1159 #ifdef NCURSES_WGETCH_EVENTS
1160 extern NCURSES_EXPORT(int) _nc_eventlist_timeout(_nc_eventlist *);
1161 #else
1162 #define wgetch_events(win, evl) wgetch(win)
1163 #define wgetnstr_events(win, str, maxlen, evl) wgetnstr(win, str, maxlen)
1164 #endif
1165
1166 /*
1167  * Not everyone has vsscanf(), but we'd like to use it for scanw().
1168  */
1169 #if !HAVE_VSSCANF
1170 extern int vsscanf(const char *str, const char *format, va_list __arg);
1171 #endif
1172
1173 /* scroll indices */
1174 extern NCURSES_EXPORT_VAR(int *) _nc_oldnums;
1175
1176 #define USE_SETBUF_0 0
1177
1178 #define NC_BUFFERED(flag) _nc_set_buffer(SP->_ofp, flag)
1179
1180 #define NC_OUTPUT ((SP != 0) ? SP->_ofp : stdout)
1181
1182 /*
1183  * On systems with a broken linker, define 'SP' as a function to force the
1184  * linker to pull in the data-only module with 'SP'.
1185  */
1186 #if BROKEN_LINKER
1187 #define SP _nc_screen()
1188 extern NCURSES_EXPORT(SCREEN *) _nc_screen (void);
1189 extern NCURSES_EXPORT(int) _nc_alloc_screen (void);
1190 extern NCURSES_EXPORT(void) _nc_set_screen (SCREEN *);
1191 #else
1192 /* current screen is private data; avoid possible linking conflicts too */
1193 extern NCURSES_EXPORT_VAR(SCREEN *) SP;
1194 #define _nc_alloc_screen() ((SP = typeCalloc(SCREEN, 1)) != 0)
1195 #define _nc_set_screen(sp) SP = sp
1196 #endif
1197
1198 /*
1199  * We don't want to use the lines or columns capabilities internally, because
1200  * if the application is running multiple screens under X, it's quite possible
1201  * they could all have type xterm but have different sizes!  So...
1202  */
1203 #define screen_lines    SP->_lines
1204 #define screen_columns  SP->_columns
1205
1206 extern NCURSES_EXPORT_VAR(int) _nc_slk_format;  /* != 0 if slk_init() called */
1207 extern NCURSES_EXPORT(int) _nc_slk_initialize (WINDOW *, int);
1208
1209 /*
1210  * Some constants related to SLK's
1211  */
1212 #define MAX_SKEY_OLD       8    /* count of soft keys */
1213 #define MAX_SKEY_LEN_OLD   8    /* max length of soft key text */
1214 #define MAX_SKEY_PC       12    /* This is what most PC's have */
1215 #define MAX_SKEY_LEN_PC    5
1216
1217 /* Macro to check whether or not we use a standard format */
1218 #define SLK_STDFMT(fmt) (fmt < 3)
1219 /* Macro to determine height of label window */
1220 #define SLK_LINES(fmt)  (SLK_STDFMT(fmt) ? 1 : ((fmt) - 2))
1221
1222 #define MAX_SKEY(fmt)     (SLK_STDFMT(fmt)? MAX_SKEY_OLD : MAX_SKEY_PC)
1223 #define MAX_SKEY_LEN(fmt) (SLK_STDFMT(fmt)? MAX_SKEY_LEN_OLD : MAX_SKEY_LEN_PC)
1224
1225 extern NCURSES_EXPORT(int) _nc_ripoffline (int line, int (*init)(WINDOW *,int));
1226
1227 /*
1228  * Common error messages
1229  */
1230 #define MSG_NO_MEMORY "Out of memory"
1231 #define MSG_NO_INPUTS "Premature EOF"
1232
1233 #ifdef __cplusplus
1234 }
1235 #endif
1236
1237 #endif /* CURSES_PRIV_H */