Home | History | Annotate | Line # | Download | only in libcurses
curses_private.h revision 1.17
      1 /*	$NetBSD: curses_private.h,v 1.17 2001/12/02 09:14:21 blymn Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 1998-2000 Brett Lymn
      5  *                         (blymn (at) baea.com.au, brett_lymn (at) yahoo.com.au)
      6  * All rights reserved.
      7  *
      8  * This code has been donated to The NetBSD Foundation by the Author.
      9  *
     10  * Redistribution and use in source and binary forms, with or without
     11  * modification, are permitted provided that the following conditions
     12  * are met:
     13  * 1. Redistributions of source code must retain the above copyright
     14  *    notice, this list of conditions and the following disclaimer.
     15  * 2. The name of the author may not be used to endorse or promote products
     16  *    derived from this software without specific prior written permission
     17  *
     18  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     19  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     20  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     21  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     22  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     23  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     24  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     25  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     26  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     27  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     28  *
     29  *
     30  */
     31 
     32 #include <termios.h>
     33 
     34 /* Private structure definitions for curses. */
     35 /*
     36  * A window an array of __LINE structures pointed to by the 'lines' pointer.
     37  * A line is an array of __LDATA structures pointed to by the 'line' pointer.
     38  *
     39  * IMPORTANT: the __LDATA structure must NOT induce any padding, so if new
     40  * fields are added -- padding fields with *constant values* should ensure
     41  * that the compiler will not generate any padding when storing an array of
     42  *  __LDATA structures.  This is to enable consistent use of memcmp, and memcpy
     43  * for comparing and copying arrays.
     44  */
     45 
     46 struct __ldata {
     47 	wchar_t	ch;			/* Character */
     48 	attr_t	attr;			/* Attributes */
     49 	wchar_t	bch;			/* Background character */
     50 	attr_t	battr;			/* Background attributes */
     51 };
     52 
     53 #define __LDATASIZE	(sizeof(__LDATA))
     54 
     55 struct __line {
     56 #define	__ISDIRTY	0x01		/* Line is dirty. */
     57 #define __ISPASTEOL	0x02		/* Cursor is past end of line */
     58 	unsigned int flags;
     59 	unsigned int hash;		/* Hash value for the line. */
     60 	int *firstchp, *lastchp;	/* First and last chngd columns ptrs */
     61 	int firstch, lastch;		/* First and last changed columns. */
     62 	__LDATA *line;			/* Pointer to the line text. */
     63 };
     64 
     65 struct __window {		/* Window structure. */
     66 	struct __window	*nextp, *orig;	/* Subwindows list and parent. */
     67 	int begy, begx;			/* Window home. */
     68 	int cury, curx;			/* Current x, y coordinates. */
     69 	int maxy, maxx;			/* Maximum values for curx, cury. */
     70 	short ch_off;			/* x offset for firstch/lastch. */
     71 	__LINE **lines;			/* Array of pointers to the lines */
     72 	__LINE  *lspace;		/* line space (for cleanup) */
     73 	__LDATA *wspace;		/* window space (for cleanup) */
     74 
     75 #define	__ENDLINE	0x00000001	/* End of screen. */
     76 #define	__FLUSH		0x00000002	/* Fflush(stdout) after refresh. */
     77 #define	__FULLWIN	0x00000004	/* Window is a screen. */
     78 #define	__IDLINE	0x00000008	/* Insert/delete sequences. */
     79 #define	__SCROLLWIN	0x00000010	/* Last char will scroll window. */
     80 #define	__SCROLLOK	0x00000020	/* Scrolling ok. */
     81 #define	__CLEAROK	0x00000040	/* Clear on next refresh. */
     82 #define	__LEAVEOK	0x00000100	/* If cursor left */
     83 #define	__KEYPAD	0x00010000	/* If interpreting keypad codes */
     84 #define	__NOTIMEOUT	0x00020000	/* Wait indefinitely for func keys */
     85 	unsigned int flags;
     86 	int	delay;			/* delay for getch() */
     87 	attr_t	wattr;			/* Character attributes */
     88 	wchar_t	bch;			/* Background character */
     89 	attr_t	battr;			/* Background attributes */
     90 	int	scr_t, scr_b;		/* Scrolling region top, bottom */
     91 };
     92 
     93 /* Set of attributes unset by 'me' - 'mb', 'md', 'mh', 'mk', 'mp' and 'mr'. */
     94 #define	__TERMATTR \
     95 	(__REVERSE | __BLINK | __DIM | __BOLD | __BLANK | __PROTECT)
     96 
     97 struct __winlist {
     98 	struct __window		*winp;	/* The window. */
     99 	struct __winlist	*nextp;	/* Next window. */
    100 };
    101 
    102 struct __color {
    103 	short	num;
    104 	short	red;
    105 	short	green;
    106 	short	blue;
    107 	int	flags;
    108 };
    109 
    110 /* List of colour pairs */
    111 struct __pair {
    112 	short	fore;
    113 	short	back;
    114 	int	flags;
    115 };
    116 
    117 /* Maximum colours */
    118 #define	MAX_COLORS	64
    119 /* Maximum colour pairs - determined by number of colour bits in attr_t */
    120 #define	MAX_PAIRS	64	/* PAIR_NUMBER(__COLOR) + 1 */
    121 
    122 typedef struct keymap keymap_t;
    123 
    124 /* this is the encapsulation of the terminal definition, one for
    125  * each terminal that curses talks to.
    126  */
    127 struct __screen {
    128 	FILE    *infd, *outfd;  /* input and output file descriptors */
    129 	WINDOW	*curscr;	/* Current screen. */
    130 	WINDOW	*stdscr;	/* Standard screen. */
    131 	WINDOW	*__virtscr;	/* Virtual screen (for doupdate()). */
    132 	int      curwin;        /* current window for refresh */
    133 	short    lx, ly;        /* loop parameters for refresh */
    134 	int	 COLS;		/* Columns on the screen. */
    135 	int	 LINES;		/* Lines on the screen. */
    136 	int	 COLORS;	/* Maximum colors on the screen */
    137 	int	 COLOR_PAIRS;	/* Maximum color pairs on the screen */
    138 	int	 My_term;	/* Use Def_term regardless. */
    139 	char	 GT;		/* Gtty indicates tabs. */
    140 	char	 NONL;		/* Term can't hack LF doing a CR. */
    141 	char	 UPPERCASE;	/* Terminal is uppercase only. */
    142 
    143         /* BEWARE!!! The order of the following terminal capabilities */
    144         /* (tc_foo) is important - do not update without fixing the zap */
    145         /* function in setterm.c */
    146 	char	tc_am, tc_bs, tc_cc, tc_da, tc_eo, tc_hc, tc_hl, tc_in, tc_mi,
    147 		tc_ms, tc_nc, tc_ns, tc_os, tc_ul, tc_ut, tc_xb, tc_xn, tc_xt,
    148 		tc_xs, tc_xx;
    149 	int     flag_count;
    150 	int	tc_pa, tc_Co, tc_NC;
    151 	int     int_count;
    152 	char	*tc_AB, *tc_ac, *tc_ae, *tc_AF, *tc_AL,
    153 		*tc_al, *tc_as, *tc_bc, *tc_bl, *tc_bt,
    154 		*tc_cd, *tc_ce, *tc_cl, *tc_cm, *tc_cr,
    155 		*tc_cs, *tc_dc, *tc_DL, *tc_dl, *tc_dm,
    156 		*tc_DO, *tc_do, *tc_eA, *tc_ed, *tc_ei,
    157 		*tc_ho, *tc_Ic, *tc_ic, *tc_im, *tc_Ip,
    158 		*tc_ip, *tc_k0, *tc_k1, *tc_k2, *tc_k3,
    159 		*tc_k4, *tc_k5, *tc_k6, *tc_k7, *tc_k8,
    160 		*tc_k9, *tc_kd, *tc_ke, *tc_kh, *tc_kl,
    161 		*tc_kr, *tc_ks, *tc_ku, *tc_LE, *tc_ll,
    162 		*tc_ma, *tc_mb, *tc_md, *tc_me, *tc_mh,
    163 		*tc_mk, *tc_mm, *tc_mo, *tc_mp, *tc_mr,
    164 		*tc_nd, *tc_nl, *tc_oc, *tc_op, *tc_pc,
    165 		*tc_rc, *tc_RI, *tc_Sb, *tc_sc, *tc_se,
    166 		*tc_SF, *tc_Sf, *tc_sf, *tc_so, *tc_sp,
    167 		*tc_SR, *tc_sr, *tc_ta, *tc_te, *tc_ti,
    168 		*tc_uc, *tc_ue, *tc_UP, *tc_up, *tc_us,
    169 		*tc_vb, *tc_ve, *tc_vi, *tc_vs;
    170 	char CA;
    171 	int str_count;
    172 	chtype acs_char[NUM_ACS];
    173 	struct __color colours[MAX_COLORS];
    174 	struct __pair  colour_pairs[MAX_PAIRS];
    175 	attr_t	nca;
    176 
    177 /* Style of colour manipulation */
    178 #define COLOR_NONE	0
    179 #define COLOR_ANSI	1	/* ANSI/DEC-style colour manipulation */
    180 #define COLOR_HP	2	/* HP-style colour manipulation */
    181 #define COLOR_TEK	3	/* Tektronix-style colour manipulation */
    182 #define COLOR_OTHER	4	/* None of the others but can set fore/back */
    183 	int color_type;
    184 
    185 	attr_t mask_op;
    186 	attr_t mask_me;
    187 	attr_t mask_ue;
    188 	attr_t mask_se;
    189 	struct tinfo *cursesi_genbuf;
    190 	int old_mode; /* old cursor visibility state for terminal */
    191 	keymap_t *base_keymap;
    192 	int echoit;
    193 	int pfast;
    194 	int rawmode;
    195 	int noqch;
    196 	int clearok;
    197 	int useraw;
    198 	struct __winlist *winlistp;
    199 	struct   termios cbreakt, rawt, *curt, save_termios;
    200 	struct termios orig_termios, baset, savedtty;
    201 	int ovmin;
    202 	int ovtime;
    203 	char *stdbuf;
    204 	unsigned int len;
    205 	int meta_state;
    206 	char pad_char;
    207 	char ttytype[1024];
    208 	int endwin;
    209 };
    210 
    211 
    212 extern char	 __GT;			/* Gtty indicates tabs. */
    213 extern char	 __NONL;		/* Term can't hack LF doing a CR. */
    214 extern char	 __UPPERCASE;		/* Terminal is uppercase only. */
    215 extern int	 My_term;		/* Use Def_term regardless. */
    216 extern const char	*Def_term;	/* Default terminal type. */
    217 extern SCREEN   *_cursesi_screen;       /* The current screen in use */
    218 
    219 /* Private functions. */
    220 #ifdef DEBUG
    221 void	 __CTRACE(const char *fmt, ...);
    222 #endif
    223 void     _cursesi_free_keymap(keymap_t *map);
    224 int      _cursesi_gettmode(SCREEN *screen);
    225 void     _cursesi_reset_acs(SCREEN *screen);
    226 void     _cursesi_resetterm(SCREEN *screen);
    227 int      _cursesi_setterm(char *type, SCREEN *screen);
    228 int	 __delay(void);
    229 unsigned int __hash(char *s, int len);
    230 void	 __id_subwins(WINDOW *orig);
    231 void	 __init_getch(SCREEN *screen);
    232 void	 __init_acs(SCREEN *screen);
    233 char	*__longname(char *bp, char *def);	/* Original BSD version */
    234 int	 __mvcur(int ly, int lx, int y, int x, int in_refresh);
    235 WINDOW  *__newwin(SCREEN *screen, int lines, int cols, int y, int x);
    236 int	 __nodelay(void);
    237 int	 __notimeout(void);
    238 char	*__parse_cap(const char *, ...);
    239 void	 __restartwin(void);
    240 void	 __restore_colors(void);
    241 void     __restore_cursor_vis(void);
    242 void     __restore_meta_state(void);
    243 void	 __restore_termios(void);
    244 void	 __restore_stophandler(void);
    245 void	 __save_termios(void);
    246 void	 __set_color(attr_t attr);
    247 void	 __set_stophandler(void);
    248 void	 __set_subwin(WINDOW *orig, WINDOW *win);
    249 void	 __startwin(SCREEN *screen);
    250 void	 __stop_signal_handler(int signo);
    251 int	 __stopwin(void);
    252 void	 __swflags(WINDOW *win);
    253 int	 __timeout(int delay);
    254 int	 __touchline(WINDOW *win, int y, int sx, int ex);
    255 int	 __touchwin(WINDOW *win);
    256 char	*__tscroll(const char *cap, int n1, int n2);
    257 void	 __unsetattr(int);
    258 int	 __waddch(WINDOW *win, __LDATA *dp);
    259 int	 __wgetnstr(WINDOW *, char *, int);
    260 
    261 /* Private #defines. */
    262 #define	min(a,b)	(a < b ? a : b)
    263 #define	max(a,b)	(a > b ? a : b)
    264 
    265 /* Private externs. */
    266 extern int		 __echoit;
    267 extern int		 __endwin;
    268 extern int		 __pfast;
    269 extern int		 __rawmode;
    270 extern int		 __noqch;
    271 extern attr_t		 __nca;
    272 extern attr_t		 __mask_op, __mask_me, __mask_ue, __mask_se;
    273 extern struct __winlist	*__winlistp;
    274 extern WINDOW		*__virtscr;
    275