]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/ncurses/ncurses/curses.priv.h
This commit was generated by cvs2svn to compensate for changes in r159985,
[FreeBSD/FreeBSD.git] / contrib / ncurses / ncurses / curses.priv.h
1 /****************************************************************************
2  * Copyright (c) 1998-2001,2002 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-2002                                      *
33  ****************************************************************************/
34
35
36 /*
37  * $Id: curses.priv.h,v 1.219 2002/05/25 12:22:43 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 #ifndef PATH_MAX
82 # if defined(_POSIX_PATH_MAX)
83 #  define PATH_MAX _POSIX_PATH_MAX
84 # elif defined(MAXPATHLEN)
85 #  define PATH_MAX MAXPATHLEN
86 # else
87 #  define PATH_MAX 255  /* the Posix minimum path-size */
88 # endif
89 #endif
90
91 #include <assert.h>
92 #include <stdio.h>
93
94 #include <errno.h>
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
134 #endif
135
136 #define DEFAULT_MAXCLICK 166
137 #define EV_MAX          8       /* size of mouse circular event queue */
138
139 /*
140  * If we don't have signals to support it, don't add a sigwinch handler.
141  * In any case, resizing is an extended feature.  Use it if we've got it.
142  */
143 #if !NCURSES_EXT_FUNCS
144 #undef HAVE_SIZECHANGE
145 #endif
146
147 #if HAVE_SIZECHANGE && defined(SIGWINCH)
148 #define USE_SIZECHANGE 1
149 #else
150 #undef USE_SIGWINCH
151 #endif
152
153 /*
154  * If desired, one can configure this, disabling environment variables that
155  * point to custom terminfo/termcap locations.
156  */
157 #ifdef USE_ROOT_ENVIRON
158 #define use_terminfo_vars() 1
159 #else
160 #define use_terminfo_vars() _nc_env_access()
161 extern NCURSES_EXPORT(int) _nc_env_access (void);
162 #endif
163
164 /*
165  * Not all platforms have memmove; some have an equivalent bcopy.  (Some may
166  * have neither).
167  */
168 #if USE_OK_BCOPY
169 #define memmove(d,s,n) bcopy(s,d,n)
170 #elif USE_MY_MEMMOVE
171 #define memmove(d,s,n) _nc_memmove(d,s,n)
172 extern NCURSES_EXPORT(void *) _nc_memmove (void *, const void *, size_t);
173 #endif
174
175 /*
176  * Scroll hints are useless when hashmap is used
177  */
178 #if !USE_SCROLL_HINTS
179 #if !USE_HASHMAP
180 #define USE_SCROLL_HINTS 1
181 #else
182 #define USE_SCROLL_HINTS 0
183 #endif
184 #endif
185
186 #if USE_SCROLL_HINTS
187 #define if_USE_SCROLL_HINTS(stmt) stmt
188 #else
189 #define if_USE_SCROLL_HINTS(stmt) /*nothing*/
190 #endif
191
192 /*
193  * Note:  ht/cbt expansion flakes out randomly under Linux 1.1.47, but only
194  * when we're throwing control codes at the screen at high volume.  To see
195  * this, re-enable USE_HARD_TABS and run worm for a while.  Other systems
196  * probably don't want to define this either due to uncertainties about tab
197  * delays and expansion in raw mode.
198  */
199
200 struct tries {
201         struct tries    *child;     /* ptr to child.  NULL if none          */
202         struct tries    *sibling;   /* ptr to sibling.  NULL if none        */
203         unsigned char    ch;        /* character at this node               */
204         unsigned short   value;     /* code of string so far.  0 if none.   */
205 };
206
207 /*
208  * Definitions for color pairs
209  */
210 #define C_SHIFT 8               /* we need more bits than there are colors */
211 #define C_MASK  ((1 << C_SHIFT) - 1)
212
213 #define PAIR_OF(fg, bg) ((((fg) & C_MASK) << C_SHIFT) | ((bg) & C_MASK))
214
215 /*
216  * Common/troublesome character definitions
217  */
218 #define L_BRACE '{'
219 #define R_BRACE '}'
220 #define S_QUOTE '\''
221 #define D_QUOTE '"'
222
223 #define VT_ACSC "``aaffggiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~"
224
225 /*
226  * Structure for palette tables
227  */
228
229 typedef struct
230 {
231     short red, green, blue;
232 }
233 color_t;
234
235 #define MAXCOLUMNS    135
236 #define MAXLINES      66
237 #define FIFO_SIZE     MAXCOLUMNS+2  /* for nocbreak mode input */
238
239 #define ACS_LEN       128
240
241 #define WINDOWLIST struct _win_list
242
243 #if USE_WIDEC_SUPPORT
244 #define _nc_bkgd    _bkgrnd
245 #else
246 #undef _XOPEN_SOURCE_EXTENDED
247 #define _nc_bkgd    _bkgd
248 #define wgetbkgrnd(win, wch)    *wch = win->_bkgd
249 #define wbkgrnd     wbkgd
250 #endif
251
252 #include <curses.h>     /* we'll use -Ipath directive to get the right one! */
253 #include <term.h>
254
255 struct ldat
256 {
257         NCURSES_CH_T    *text;          /* text of the line */
258         NCURSES_SIZE_T  firstchar;      /* first changed character in the line */
259         NCURSES_SIZE_T  lastchar;       /* last changed character in the line */
260         NCURSES_SIZE_T  oldindex;       /* index of the line at last update */
261 };
262
263 /*
264  * Structure for soft labels.
265  */
266
267 typedef struct
268 {
269         char *text;             /* text for the label */
270         char *form_text;        /* formatted text (left/center/...) */
271         int x;                  /* x coordinate of this field */
272         char dirty;             /* this label has changed */
273         char visible;           /* field is visible */
274 } slk_ent;
275
276 typedef struct {
277         char dirty;             /* all labels have changed */
278         char hidden;            /* soft labels are hidden */
279         struct _win_st *win;
280         slk_ent *ent;
281         char*  buffer;           /* buffer for labels */
282         short  maxlab;           /* number of available labels */
283         short  labcnt;           /* number of allocated labels */
284         short  maxlen;           /* length of labels */
285         chtype attr;             /* soft label attribute */
286 } SLK;
287
288 typedef struct {
289         unsigned long hashval;
290         int oldcount, newcount;
291         int oldindex, newindex;
292 } HASHMAP;
293
294 struct screen {
295         int             _ifd;           /* input file ptr for screen        */
296         FILE            *_ofp;          /* output file ptr for screen       */
297         char            *_setbuf;       /* buffered I/O for output          */
298         int             _buffered;      /* setvbuf uses _setbuf data        */
299         int             _checkfd;       /* filedesc for typeahead check     */
300         struct term     *_term;         /* terminal type information        */
301         short           _lines;         /* screen lines                     */
302         short           _columns;       /* screen columns                   */
303         short           _lines_avail;   /* lines available for stdscr       */
304         short           _topstolen;     /* lines stolen from top            */
305
306         WINDOW          *_curscr;       /* current screen                   */
307         WINDOW          *_newscr;       /* virtual screen to be updated to  */
308         WINDOW          *_stdscr;       /* screen's full-window context     */
309
310         struct tries    *_keytry;       /* "Try" for use with keypad mode   */
311         struct tries    *_key_ok;       /* Disabled keys via keyok(,FALSE)  */
312         bool            _tried;         /* keypad mode was initialized      */
313         bool            _keypad_on;     /* keypad mode is currently on      */
314
315         unsigned int    _fifo[FIFO_SIZE];       /* input push-back buffer   */
316         short           _fifohead,      /* head of fifo queue               */
317                         _fifotail,      /* tail of fifo queue               */
318                         _fifopeek,      /* where to peek for next char      */
319                         _fifohold;      /* set if breakout marked           */
320
321         int             _endwin;        /* are we out of window mode?       */
322         attr_t          _current_attr;  /* terminal attribute current set   */
323         int             _coloron;       /* is color enabled?                */
324         int             _cursor;        /* visibility of the cursor         */
325         int             _cursrow;       /* physical cursor row              */
326         int             _curscol;       /* physical cursor column           */
327         int             _nl;            /* True if NL -> CR/NL is on        */
328         int             _raw;           /* True if in raw mode              */
329         int             _cbreak;        /* 1 if in cbreak mode              */
330                                         /* > 1 if in halfdelay mode         */
331         int             _echo;          /* True if echo on                  */
332         int             _use_meta;      /* use the meta key?                */
333         SLK             *_slk;          /* ptr to soft key struct / NULL    */
334         int             slk_format;     /* selected format for this screen  */
335         /* cursor movement costs; units are 10ths of milliseconds */
336 #if NCURSES_NO_PADDING
337         int             _no_padding;    /* flag to set if padding disabled  */
338 #endif
339         int             _char_padding;  /* cost of character put            */
340         int             _cr_cost;       /* cost of (carriage_return)        */
341         int             _cup_cost;      /* cost of (cursor_address)         */
342         int             _home_cost;     /* cost of (cursor_home)            */
343         int             _ll_cost;       /* cost of (cursor_to_ll)           */
344 #if USE_HARD_TABS
345         int             _ht_cost;       /* cost of (tab)                    */
346         int             _cbt_cost;      /* cost of (backtab)                */
347 #endif /* USE_HARD_TABS */
348         int             _cub1_cost;     /* cost of (cursor_left)            */
349         int             _cuf1_cost;     /* cost of (cursor_right)           */
350         int             _cud1_cost;     /* cost of (cursor_down)            */
351         int             _cuu1_cost;     /* cost of (cursor_up)              */
352         int             _cub_cost;      /* cost of (parm_cursor_left)       */
353         int             _cuf_cost;      /* cost of (parm_cursor_right)      */
354         int             _cud_cost;      /* cost of (parm_cursor_down)       */
355         int             _cuu_cost;      /* cost of (parm_cursor_up)         */
356         int             _hpa_cost;      /* cost of (column_address)         */
357         int             _vpa_cost;      /* cost of (row_address)            */
358         /* used in tty_update.c, must be chars */
359         int             _ed_cost;       /* cost of (clr_eos)                */
360         int             _el_cost;       /* cost of (clr_eol)                */
361         int             _el1_cost;      /* cost of (clr_bol)                */
362         int             _dch1_cost;     /* cost of (delete_character)       */
363         int             _ich1_cost;     /* cost of (insert_character)       */
364         int             _dch_cost;      /* cost of (parm_dch)               */
365         int             _ich_cost;      /* cost of (parm_ich)               */
366         int             _ech_cost;      /* cost of (erase_chars)            */
367         int             _rep_cost;      /* cost of (repeat_char)            */
368         int             _hpa_ch_cost;   /* cost of (column_address)         */
369         int             _cup_ch_cost;   /* cost of (cursor_address)         */
370         int             _cuf_ch_cost;   /* cost of (parm_cursor_right)      */
371         int             _inline_cost;   /* cost of inline-move              */
372         int             _smir_cost;     /* cost of (enter_insert_mode)      */
373         int             _rmir_cost;     /* cost of (exit_insert_mode)       */
374         int             _ip_cost;       /* cost of (insert_padding)         */
375         /* used in lib_mvcur.c */
376         char *          _address_cursor;
377         /* used in tty_update.c */
378         int             _scrolling;     /* 1 if terminal's smart enough to  */
379
380         /* used in lib_color.c */
381         color_t         *_color_table;  /* screen's color palette            */
382         int             _color_count;   /* count of colors in palette        */
383         unsigned short  *_color_pairs;  /* screen's color pair list          */
384         int             _pair_count;    /* count of color pairs              */
385 #if NCURSES_EXT_FUNCS
386         bool            _default_color; /* use default colors                */
387         bool            _has_sgr_39_49; /* has ECMA default color support    */
388         int             _default_fg;    /* assumed default foreground        */
389         int             _default_bg;    /* assumed default background        */
390 #endif
391         chtype          _xmc_suppress;  /* attributes to suppress if xmc     */
392         chtype          _xmc_triggers;  /* attributes to process if xmc      */
393         chtype          _acs_map[ACS_LEN];
394
395         /* used in lib_vidattr.c */
396         bool            _use_rmso;      /* true if we may use 'rmso'         */
397         bool            _use_rmul;      /* true if we may use 'rmul'         */
398
399         /*
400          * These data correspond to the state of the idcok() and idlok()
401          * functions.  A caveat is in order here:  the XSI and SVr4
402          * documentation specify that these functions apply to the window which
403          * is given as an argument.  However, ncurses implements this logic
404          * only for the newscr/curscr update process, _not_ per-window.
405          */
406         bool            _nc_sp_idlok;
407         bool            _nc_sp_idcok;
408 #define _nc_idlok SP->_nc_sp_idlok
409 #define _nc_idcok SP->_nc_sp_idcok
410
411         /*
412          * These are the data that support the mouse interface.
413          */
414         int             _maxclick;
415         bool            (*_mouse_event) (SCREEN *);
416         bool            (*_mouse_inline)(SCREEN *);
417         bool            (*_mouse_parse) (int);
418         void            (*_mouse_resume)(SCREEN *);
419         void            (*_mouse_wrap)  (SCREEN *);
420         int             _mouse_fd;      /* file-descriptor, if any */
421
422         /*
423          * This supports automatic resizing
424          */
425 #if USE_SIZECHANGE
426         int             (*_resize)(int,int);
427 #endif
428
429         /*
430          * These are data that support the proper handling of the panel stack on an
431          * per screen basis.
432          */
433         struct panelhook _panelHook;
434         /*
435          * Linked-list of all windows, to support '_nc_resizeall()' and
436          * '_nc_freeall()'
437          */
438         WINDOWLIST      *_nc_sp_windows;
439 #define _nc_windows SP->_nc_sp_windows
440
441         bool            _sig_winch;
442         SCREEN          *_next_screen;
443
444         /* hashes for old and new lines */
445         unsigned long   *oldhash, *newhash;
446         HASHMAP         *hashtab;
447         int             hashtab_len;
448
449         bool            _cleanup;       /* cleanup after int/quit signal */
450         int             (*_outch)(int); /* output handler if not putc */
451 };
452
453 extern NCURSES_EXPORT_VAR(SCREEN *) _nc_screen_chain;
454
455 #if NCURSES_NOMACROS
456 #include <nomacros.h>
457 #endif
458
459 /*
460  * The margins are used in resizeterm() to retain the original layout after
461  * resizing.
462  */
463         WINDOWLIST {
464         WINDOWLIST *next;
465 #if HAVE_RESIZETERM
466         int     l_margin;
467         int     r_margin;
468         int     t_margin;
469         int     b_margin;
470 #endif
471         WINDOW  win;
472 };
473
474 typedef struct {
475         int     line;                   /* lines to take, < 0 => from bottom*/
476         int     (*hook)(struct _win_st *, int); /* callback for user        */
477         struct _win_st *w;              /* maybe we need this for cleanup   */
478 } ripoff_t;
479
480 /* The terminfo source is assumed to be 7-bit ASCII */
481 #define is7bits(c)      ((unsigned)(c) < 128)
482
483 #ifndef min
484 #define min(a,b)        ((a) > (b)  ?  (b)  :  (a))
485 #endif
486
487 #ifndef max
488 #define max(a,b)        ((a) < (b)  ?  (b)  :  (a))
489 #endif
490
491 /* usually in <unistd.h> */
492 #ifndef STDIN_FILENO
493 #define STDIN_FILENO 0
494 #endif
495
496 #ifndef STDOUT_FILENO
497 #define STDOUT_FILENO 1
498 #endif
499
500 #ifndef STDERR_FILENO
501 #define STDERR_FILENO 2
502 #endif
503
504 #ifndef EXIT_SUCCESS
505 #define EXIT_SUCCESS 0
506 #endif
507
508 #ifndef EXIT_FAILURE
509 #define EXIT_FAILURE 1
510 #endif
511
512 #ifndef R_OK
513 #define R_OK    4               /* Test for read permission.  */
514 #endif
515 #ifndef W_OK
516 #define W_OK    2               /* Test for write permission.  */
517 #endif
518 #ifndef X_OK
519 #define X_OK    1               /* Test for execute permission.  */
520 #endif
521 #ifndef F_OK
522 #define F_OK    0               /* Test for existence.  */
523 #endif
524
525 #if HAVE_FCNTL_H
526 #include <fcntl.h>              /* may define O_BINARY  */
527 #endif
528
529 #ifndef O_BINARY
530 #define O_BINARY 0
531 #endif
532
533 #define UChar(c)        ((unsigned char)(c))
534 #define ChCharOf(c)     ((c) & (chtype)A_CHARTEXT)
535 #define ChAttrOf(c)     ((c) & (chtype)A_ATTRIBUTES)
536
537 #if USE_WIDEC_SUPPORT /* { */
538 #define CharOf(c)       ((c).chars[0])
539 #define AttrOf(c)       ((c).attr)
540 #define AddAttr(c,a)    (c).attr |= a
541 #define RemAttr(c,a)    (c).attr &= ~(a)
542 #define SetAttr(c,a)    (c).attr = a
543 #define NewChar(ch)     { ChAttrOf(ch), { ChCharOf(ch) } }
544 #define NewChar2(c,a)   { a, { c } }
545 #define CharEq(a,b)     (!memcmp(&a, &b, sizeof(a)))
546 #define SetChar(ch,c,a) do {                                                        \
547                             NCURSES_CH_T *_cp = &ch;                                \
548                             memset(_cp,0,sizeof(ch)); _cp->chars[0] = c; _cp->attr = a; \
549                         } while (0)
550 #define CHREF(wch)      (&wch)
551 #define CHDEREF(wch)    (*wch)
552 #define ARG_CH_T        NCURSES_CH_T *
553 #define CARG_CH_T       const NCURSES_CH_T *
554 #define PUTC_DATA       char PUTC_buf[MB_LEN_MAX]; int PUTC_i, PUTC_n; \
555                         mbstate_t PUT_st; wchar_t PUTC_ch
556 #define PUTC(ch,b)      do { if(!isnac(ch)) {                                       \
557                             memset (&PUT_st, '\0', sizeof (PUT_st));                \
558                             PUTC_i = 0;                                             \
559                             do {                                                    \
560                                 PUTC_ch = PUTC_i < CCHARW_MAX ?                     \
561                                             (ch).chars[PUTC_i] : L'\0';             \
562                                 PUTC_n = wcrtomb(PUTC_buf,                          \
563                                                  (ch).chars[PUTC_i], &PUT_st);      \
564                                 if (PUTC_ch == L'\0')                               \
565                                     --PUTC_n;                                       \
566                                 if (PUTC_n <= 0)                                    \
567                                     break;                                          \
568                                 fwrite(PUTC_buf, (unsigned) PUTC_n, 1, b);          \
569                                 ++PUTC_i;                                           \
570                             } while (PUTC_ch != L'\0');                             \
571                         } } while (0)
572
573 #define BLANK           { WA_NORMAL, ' ' }
574 #define ISBLANK(ch)     ((ch).chars[0] == L' ' && (ch).chars[1] == L'\0')
575
576 #define WA_NAC          1
577 #define isnac(ch)       (AttrOf(ch) & WA_NAC)
578 #define if_WIDEC(code)  code
579 #define Charable(ch)    (!isnac(ch) &&                                  \
580                          (ch).chars[1] == L'\0' &&                      \
581                          (wctob(CharOf(ch)) == (char)CharOf(ch)))
582
583 #define L(ch)           L ## ch
584 #else /* }{ */
585 #define CharOf(c)       ChCharOf(c)
586 #define AttrOf(c)       ChAttrOf(c)
587 #define AddAttr(c,a)    c |= a
588 #define RemAttr(c,a)    c &= ~(a & A_ATTRIBUTES)
589 #define SetAttr(c,a)    c = (c & ~A_ATTRIBUTES) | a
590 #define NewChar(ch)     (ch)
591 #define NewChar2(c,a)   (c | a)
592 #define CharEq(a,b)     (a == b)
593 #define SetChar(ch,c,a) ch = c | a
594 #define CHREF(wch)      wch
595 #define CHDEREF(wch)    wch
596 #define ARG_CH_T        NCURSES_CH_T
597 #define CARG_CH_T       NCURSES_CH_T
598 #define PUTC_DATA       int data = 0
599 #define PUTC(a,b)       do { data = CharOf(ch); putc(data,b); } while (0)
600
601 #define BLANK           (' '|A_NORMAL)
602 #define ISBLANK(ch)     (CharOf(ch) == ' ')
603
604 #define isnac(ch)       (0)
605 #define if_WIDEC(code) /* nothing */
606
607 #define L(ch)           ch
608 #endif /* } */
609
610 #define AttrOfD(ch)     AttrOf(CHDEREF(ch))
611 #define CharOfD(ch)     CharOf(CHDEREF(ch))
612 #define SetChar2(wch,ch)    SetChar(wch,ChCharOf(ch),ChAttrOf(ch))
613
614 #define BLANK_ATTR      A_NORMAL
615 #define BLANK_TEXT      L(' ')
616
617 #define CHANGED     -1
618
619 #define CHANGED_CELL(line,col) \
620         if (line->firstchar == _NOCHANGE) \
621                 line->firstchar = line->lastchar = col; \
622         else if ((col) < line->firstchar) \
623                 line->firstchar = col; \
624         else if ((col) > line->lastchar) \
625                 line->lastchar = col
626
627 #define CHANGED_RANGE(line,start,end) \
628         if (line->firstchar == _NOCHANGE \
629          || line->firstchar > (start)) \
630                 line->firstchar = start; \
631         if (line->lastchar == _NOCHANGE \
632          || line->lastchar < (end)) \
633                 line->lastchar = end
634
635 #define CHANGED_TO_EOL(line,start,end) \
636         if (line->firstchar == _NOCHANGE \
637          || line->firstchar > (start)) \
638                 line->firstchar = start; \
639         line->lastchar = end
640
641 #define SIZEOF(v) (sizeof(v)/sizeof(v[0]))
642
643 #define FreeIfNeeded(p)  if ((p) != 0) free(p)
644
645 /* FreeAndNull() is not a comma-separated expression because some compilers
646  * do not accept a mixture of void with values.
647  */
648 #define FreeAndNull(p)   free(p); p = 0
649
650 #include <nc_alloc.h>
651
652 /*
653  * Prefixes for call/return points of library function traces.  We use these to
654  * instrument the public functions so that the traces can be easily transformed
655  * into regression scripts.
656  */
657 #define T_CALLED(fmt) "called {" fmt
658 #define T_CREATE(fmt) "create :" fmt
659 #define T_RETURN(fmt) "return }" fmt
660
661 #ifdef TRACE
662 #define TR(n, a)        if (_nc_tracing & (n)) _tracef a
663 #define T(a)            TR(TRACE_CALLS, a)
664 #define TPUTS_TRACE(s)  _nc_tputs_trace = s;
665 #define TRACE_RETURN(value,type) return _nc_retrace_##type(value)
666 #define returnAttr(code) TRACE_RETURN(code,attr_t)
667 #define returnChar(code) TRACE_RETURN(code,chtype)
668 #define returnCode(code) TRACE_RETURN(code,int)
669 #define returnPtr(code)  TRACE_RETURN(code,ptr)
670 #define returnSP(code)   TRACE_RETURN(code,sp)
671 #define returnVoid       T((T_RETURN(""))); return
672 #define returnWin(code)  TRACE_RETURN(code,win)
673 extern NCURSES_EXPORT(SCREEN *) _nc_retrace_sp (SCREEN *);
674 extern NCURSES_EXPORT(WINDOW *) _nc_retrace_win (WINDOW *);
675 extern NCURSES_EXPORT(attr_t) _nc_retrace_attr_t (attr_t);
676 extern NCURSES_EXPORT(attr_t) _nc_retrace_chtype (chtype);
677 extern NCURSES_EXPORT(char *) _nc_retrace_ptr (char *);
678 extern NCURSES_EXPORT(char *) _nc_trace_ttymode(TTY *tty);
679 extern NCURSES_EXPORT(char *) _nc_varargs (const char *, va_list);
680 extern NCURSES_EXPORT(const char *) _nc_altcharset_name(attr_t, chtype);
681 extern NCURSES_EXPORT(int) _nc_retrace_int (int);
682 extern NCURSES_EXPORT(void) _nc_fifo_dump (void);
683 extern NCURSES_EXPORT_VAR(const char *) _nc_tputs_trace;
684 extern NCURSES_EXPORT_VAR(long) _nc_outchars;
685 extern NCURSES_EXPORT_VAR(unsigned) _nc_tracing;
686 #if USE_WIDEC_SUPPORT
687 extern NCURSES_EXPORT(const char *) _nc_viswbuf2 (int, const wchar_t *);
688 extern NCURSES_EXPORT(const char *) _nc_viscbuf2 (int, const cchar_t *, int);
689 extern NCURSES_EXPORT(const char *) _nc_viscbuf (const cchar_t *, int);
690 #endif
691 #else
692 #define T(a)
693 #define TR(n, a)
694 #define TPUTS_TRACE(s)
695 #define returnAttr(code) return code
696 #define returnChar(code) return code
697 #define returnCode(code) return code
698 #define returnPtr(code)  return code
699 #define returnSP(code)   return code
700 #define returnVoid       return
701 #define returnWin(code)  return code
702 #endif
703
704 #define empty_module(name) \
705 extern  NCURSES_EXPORT(void) name (void); \
706         NCURSES_EXPORT(void) name (void) { }
707
708 /* used in _nc_visbuf() whether or not we're tracing */
709 extern NCURSES_EXPORT(const char *) _nc_visbuf2 (int, const char *);
710
711 #define ALL_BUT_COLOR ((chtype)~(A_COLOR))
712 #define IGNORE_COLOR_OFF FALSE
713 #define NONBLANK_ATTR (A_BOLD|A_DIM|A_BLINK)
714 #define XMC_CHANGES(c) ((c) & SP->_xmc_suppress)
715
716
717 #define toggle_attr_on(S,at) {\
718    if (PAIR_NUMBER(at) > 0)\
719       (S) = ((S) & ALL_BUT_COLOR) | (at);\
720    else\
721       (S) |= (at);\
722    TR(TRACE_ATTRS, ("new attribute is %s", _traceattr((S))));}
723
724
725 #define toggle_attr_off(S,at) {\
726    if (IGNORE_COLOR_OFF == TRUE) {\
727       if (PAIR_NUMBER(at) == 0xff) /* turn off color */\
728          (S) &= ~(at);\
729       else /* leave color alone */\
730          (S) &= ~((at)&ALL_BUT_COLOR);\
731    } else {\
732       if (PAIR_NUMBER(at) > 0x00) /* turn off color */\
733          (S) &= ~(at|A_COLOR);\
734       else /* leave color alone */\
735          (S) &= ~(at);\
736    }\
737    TR(TRACE_ATTRS, ("new attribute is %s", _traceattr((S))));}
738
739 #define DelCharCost(count) \
740                 ((parm_dch != 0) \
741                 ? SP->_dch_cost \
742                 : ((delete_character != 0) \
743                         ? (SP->_dch1_cost * count) \
744                         : INFINITY))
745
746 #define InsCharCost(count) \
747                 ((parm_ich != 0) \
748                 ? SP->_ich_cost \
749                 : ((enter_insert_mode && exit_insert_mode) \
750                   ? SP->_smir_cost + SP->_rmir_cost + (SP->_ip_cost * count) \
751                   : ((insert_character != 0) \
752                     ? (SP->_ich1_cost * count) \
753                     : INFINITY)))
754
755 #if USE_XMC_SUPPORT
756 #define UpdateAttrs(a)  if (SP->_current_attr != (a)) { \
757                                 attr_t chg = SP->_current_attr; \
758                                 vidattr((a)); \
759                                 if (magic_cookie_glitch > 0 \
760                                  && XMC_CHANGES((chg ^ SP->_current_attr))) { \
761                                         T(("%s @%d before glitch %d,%d", \
762                                                 __FILE__, __LINE__, \
763                                                 SP->_cursrow, \
764                                                 SP->_curscol)); \
765                                         _nc_do_xmc_glitch(chg); \
766                                 } \
767                         }
768 #else
769 #define UpdateAttrs(a)  if (SP->_current_attr != (a)) \
770                                 vidattr((a));
771 #endif
772
773 #if NCURSES_EXPANDED && NCURSES_EXT_FUNCS
774
775 #undef  toggle_attr_on
776 #define toggle_attr_on(S,at) _nc_toggle_attr_on(&(S), at)
777 extern NCURSES_EXPORT(void) _nc_toggle_attr_on (attr_t *, attr_t);
778
779 #undef  toggle_attr_off
780 #define toggle_attr_off(S,at) _nc_toggle_attr_off(&(S), at)
781 extern NCURSES_EXPORT(void) _nc_toggle_attr_off (attr_t *, attr_t);
782
783 #undef  DelCharCost
784 #define DelCharCost(count) _nc_DelCharCost(count)
785 extern NCURSES_EXPORT(int) _nc_DelCharCost (int);
786
787 #undef  InsCharCost
788 #define InsCharCost(count) _nc_InsCharCost(count)
789 extern NCURSES_EXPORT(int) _nc_InsCharCost (int);
790
791 #undef  UpdateAttrs
792 #define UpdateAttrs(c) _nc_UpdateAttrs(c)
793 extern NCURSES_EXPORT(void) _nc_UpdateAttrs (chtype);
794
795 #else
796
797 extern NCURSES_EXPORT(void) _nc_expanded (void);
798
799 #endif
800
801 #if !HAVE_GETCWD
802 #define getcwd(buf,len) getwd(buf)
803 #endif
804
805 /* doupdate.c */
806 #if USE_XMC_SUPPORT
807 extern NCURSES_EXPORT(void) _nc_do_xmc_glitch (attr_t);
808 #endif
809
810 /* hardscroll.c */
811 #if defined(TRACE) || defined(SCROLLDEBUG) || defined(HASHDEBUG)
812 extern NCURSES_EXPORT(void) _nc_linedump (void);
813 #endif
814
815 /* lib_acs.c */
816 extern NCURSES_EXPORT(void) _nc_init_acs (void);        /* corresponds to traditional 'init_acs()' */
817 extern NCURSES_EXPORT(int) _nc_msec_cost (const char *const, int);  /* used by 'tack' program */
818
819 /* lib_addstr.c */
820 #if USE_WIDEC_SUPPORT
821 extern NCURSES_EXPORT(int) _nc_wchstrlen(const cchar_t *);
822 #endif
823
824 /* lib_getch.c */
825 extern NCURSES_EXPORT(int) _nc_wgetch(WINDOW *, unsigned long *, int);
826
827 /* lib_mvcur.c */
828 #define INFINITY        1000000 /* cost: too high to use */
829
830 extern NCURSES_EXPORT(void) _nc_mvcur_init (void);
831 extern NCURSES_EXPORT(void) _nc_mvcur_resume (void);
832 extern NCURSES_EXPORT(void) _nc_mvcur_wrap (void);
833
834 extern NCURSES_EXPORT(int) _nc_scrolln (int, int, int, int);
835
836 extern NCURSES_EXPORT(void) _nc_screen_init (void);
837 extern NCURSES_EXPORT(void) _nc_screen_resume (void);
838 extern NCURSES_EXPORT(void) _nc_screen_wrap (void);
839
840 /* lib_mouse.c */
841 extern NCURSES_EXPORT(int) _nc_has_mouse (void);
842
843 /* lib_mvcur.c */
844 #define INFINITY        1000000 /* cost: too high to use */
845
846 /* lib_wacs.c */
847 #if USE_WIDEC_SUPPORT
848 extern NCURSES_EXPORT(void) _nc_init_wacs(void);
849 #endif
850
851 typedef struct {
852     char *s_head;
853     char *s_tail;
854     size_t s_size;
855 } string_desc;
856
857 /* strings.c */
858 extern NCURSES_EXPORT(string_desc *) _nc_str_init (string_desc *, char *, size_t);
859 extern NCURSES_EXPORT(string_desc *) _nc_str_null (string_desc *, size_t);
860 extern NCURSES_EXPORT(string_desc *) _nc_str_copy (string_desc *, string_desc *);
861 extern NCURSES_EXPORT(bool) _nc_safe_strcat (string_desc *, const char *);
862 extern NCURSES_EXPORT(bool) _nc_safe_strcpy (string_desc *, const char *);
863
864 extern NCURSES_EXPORT(void) _nc_mvcur_init (void);
865 extern NCURSES_EXPORT(void) _nc_mvcur_resume (void);
866 extern NCURSES_EXPORT(void) _nc_mvcur_wrap (void);
867
868 extern NCURSES_EXPORT(int) _nc_scrolln (int, int, int, int);
869
870 extern NCURSES_EXPORT(void) _nc_screen_init (void);
871 extern NCURSES_EXPORT(void) _nc_screen_resume (void);
872 extern NCURSES_EXPORT(void) _nc_screen_wrap (void);
873
874 #if !HAVE_STRSTR
875 #define strstr _nc_strstr
876 extern NCURSES_EXPORT(char *) _nc_strstr (const char *, const char *);
877 #endif
878
879 /* safe_sprintf.c */
880 extern NCURSES_EXPORT(char *) _nc_printf_string (const char *, va_list);
881
882 /* tries.c */
883 extern NCURSES_EXPORT(void) _nc_add_to_try (struct tries **, const char *, unsigned short);
884 extern NCURSES_EXPORT(char *) _nc_expand_try (struct tries *, unsigned short, int *, size_t);
885 extern NCURSES_EXPORT(int) _nc_remove_key (struct tries **, unsigned short);
886 extern NCURSES_EXPORT(int) _nc_remove_string (struct tries **, char *);
887
888 /* elsewhere ... */
889 extern NCURSES_EXPORT(WINDOW *) _nc_makenew (int, int, int, int, int);
890 extern NCURSES_EXPORT(char *) _nc_home_terminfo (void);
891 extern NCURSES_EXPORT(char *) _nc_trace_buf (int, size_t);
892 extern NCURSES_EXPORT(NCURSES_CH_T) _nc_render (WINDOW *, NCURSES_CH_T);
893 extern NCURSES_EXPORT(int)  _nc_access (const char *, int);
894 extern NCURSES_EXPORT(int) _nc_baudrate (int);
895 extern NCURSES_EXPORT(int) _nc_freewin (WINDOW *);
896 extern NCURSES_EXPORT(int) _nc_getenv_num (const char *);
897 extern NCURSES_EXPORT(int) _nc_keypad (bool);
898 extern NCURSES_EXPORT(int) _nc_ospeed (int);
899 extern NCURSES_EXPORT(int) _nc_outch (int);
900 extern NCURSES_EXPORT(int) _nc_setupscreen (short, short const, FILE *);
901 extern NCURSES_EXPORT(int) _nc_timed_wait (int, int, int *);
902 extern NCURSES_EXPORT(int) _nc_waddch_nosync (WINDOW *, const NCURSES_CH_T);
903 extern NCURSES_EXPORT(void) _nc_do_color (int, int, bool, int (*)(int));
904 extern NCURSES_EXPORT(void) _nc_flush (void);
905 extern NCURSES_EXPORT(void) _nc_freeall (void);
906 extern NCURSES_EXPORT(void) _nc_hash_map (void);
907 extern NCURSES_EXPORT(void) _nc_init_keytry (void);
908 extern NCURSES_EXPORT(void) _nc_keep_tic_dir (const char *);
909 extern NCURSES_EXPORT(void) _nc_make_oldhash (int i);
910 extern NCURSES_EXPORT(void) _nc_outstr (const char *str);
911 extern NCURSES_EXPORT(void) _nc_scroll_oldhash (int n, int top, int bot);
912 extern NCURSES_EXPORT(void) _nc_scroll_optimize (void);
913 extern NCURSES_EXPORT(void) _nc_scroll_window (WINDOW *, int const, short const, short const, NCURSES_CH_T);
914 extern NCURSES_EXPORT(void) _nc_set_buffer (FILE *, bool);
915 extern NCURSES_EXPORT(void) _nc_signal_handler (bool);
916 extern NCURSES_EXPORT(void) _nc_synchook (WINDOW *);
917 extern NCURSES_EXPORT(void) _nc_trace_tries (struct tries *);
918
919 #if USE_SIZECHANGE
920 extern NCURSES_EXPORT(void) _nc_update_screensize (void);
921 #endif
922
923 #if HAVE_RESIZETERM
924 extern NCURSES_EXPORT(void) _nc_resize_margins (WINDOW *);
925 #else
926 #define _nc_resize_margins(wp) /* nothing */
927 #endif
928
929 /*
930  * Not everyone has vsscanf(), but we'd like to use it for scanw().
931  */
932 #if !HAVE_VSSCANF
933 extern int vsscanf(const char *str, const char *format, va_list __arg);
934 #endif
935
936 /* scroll indices */
937 extern NCURSES_EXPORT_VAR(int *) _nc_oldnums;
938
939 #define USE_SETBUF_0 0
940
941 #define NC_BUFFERED(flag) \
942         if ((SP->_buffered != 0) != flag) \
943                 _nc_set_buffer(SP->_ofp, flag)
944
945 #define NC_OUTPUT ((SP != 0) ? SP->_ofp : stdout)
946
947 /*
948  * On systems with a broken linker, define 'SP' as a function to force the
949  * linker to pull in the data-only module with 'SP'.
950  */
951 #if BROKEN_LINKER
952 #define SP _nc_screen()
953 extern NCURSES_EXPORT(SCREEN *) _nc_screen (void);
954 extern NCURSES_EXPORT(int) _nc_alloc_screen (void);
955 extern NCURSES_EXPORT(void) _nc_set_screen (SCREEN *);
956 #else
957 /* current screen is private data; avoid possible linking conflicts too */
958 extern NCURSES_EXPORT_VAR(SCREEN *) SP;
959 #define _nc_alloc_screen() ((SP = typeCalloc(SCREEN, 1)) != 0)
960 #define _nc_set_screen(sp) SP = sp
961 #endif
962
963 /*
964  * We don't want to use the lines or columns capabilities internally, because
965  * if the application is running multiple screens under X, it's quite possible
966  * they could all have type xterm but have different sizes!  So...
967  */
968 #define screen_lines    SP->_lines
969 #define screen_columns  SP->_columns
970
971 extern NCURSES_EXPORT_VAR(int) _nc_slk_format;  /* != 0 if slk_init() called */
972 extern NCURSES_EXPORT(int) _nc_slk_initialize (WINDOW *, int);
973
974 /*
975  * Some constants related to SLK's
976  */
977 #define MAX_SKEY_OLD       8    /* count of soft keys */
978 #define MAX_SKEY_LEN_OLD   8    /* max length of soft key text */
979 #define MAX_SKEY_PC       12    /* This is what most PC's have */
980 #define MAX_SKEY_LEN_PC    5
981
982 /* Macro to check whether or not we use a standard format */
983 #define SLK_STDFMT(fmt) (fmt < 3)
984 /* Macro to determine height of label window */
985 #define SLK_LINES(fmt)  (SLK_STDFMT(fmt) ? 1 : ((fmt) - 2))
986
987 #define MAX_SKEY(fmt)     (SLK_STDFMT(fmt)? MAX_SKEY_OLD : MAX_SKEY_PC)
988 #define MAX_SKEY_LEN(fmt) (SLK_STDFMT(fmt)? MAX_SKEY_LEN_OLD : MAX_SKEY_LEN_PC)
989
990 extern NCURSES_EXPORT(int) _nc_ripoffline (int line, int (*init)(WINDOW *,int));
991
992 #ifdef __cplusplus
993 }
994 #endif
995
996 #endif /* CURSES_PRIV_H */