Home | History | Annotate | Line # | Download | only in common
      1  1.4       rin /*	$NetBSD: gs.h,v 1.4 2018/08/07 08:05:47 rin Exp $ */
      2  1.1  christos /*-
      3  1.1  christos  * Copyright (c) 1993, 1994
      4  1.1  christos  *	The Regents of the University of California.  All rights reserved.
      5  1.1  christos  * Copyright (c) 1993, 1994, 1995, 1996
      6  1.1  christos  *	Keith Bostic.  All rights reserved.
      7  1.1  christos  *
      8  1.1  christos  * See the LICENSE file for redistribution information.
      9  1.1  christos  *
     10  1.1  christos  *	Id: gs.h,v 10.55 2001/11/01 10:28:25 skimo Exp  (Berkeley) Date: 2001/11/01 10:28:25
     11  1.1  christos  */
     12  1.1  christos 
     13  1.1  christos #define	TEMPORARY_FILE_STRING	"/tmp"	/* Default temporary file name. */
     14  1.1  christos 
     15  1.1  christos /*
     16  1.1  christos  * File reference structure (FREF).  The structure contains the name of the
     17  1.1  christos  * file, along with the information that follows the name.
     18  1.1  christos  *
     19  1.1  christos  * !!!
     20  1.1  christos  * The read-only bit follows the file name, not the file itself.
     21  1.1  christos  */
     22  1.1  christos struct _fref {
     23  1.3  christos 	TAILQ_ENTRY(_fref) q;		/* Linked list of file references. */
     24  1.1  christos 	char	*name;			/* File name. */
     25  1.1  christos 	char	*tname;			/* Backing temporary file name. */
     26  1.1  christos 
     27  1.1  christos 	db_recno_t	 lno;			/* 1-N: file cursor line. */
     28  1.1  christos 	size_t	 cno;			/* 0-N: file cursor column. */
     29  1.1  christos 
     30  1.1  christos #define	FR_CURSORSET	0x0001		/* If lno/cno values valid. */
     31  1.1  christos #define	FR_DONTDELETE	0x0002		/* Don't delete the temporary file. */
     32  1.1  christos #define	FR_EXNAMED	0x0004		/* Read/write renamed the file. */
     33  1.1  christos #define	FR_NAMECHANGE	0x0008		/* If the name changed. */
     34  1.1  christos #define	FR_NEWFILE	0x0010		/* File doesn't really exist yet. */
     35  1.1  christos #define	FR_RECOVER	0x0020		/* File is being recovered. */
     36  1.1  christos #define	FR_TMPEXIT	0x0040		/* Modified temporary file, no exit. */
     37  1.1  christos #define	FR_TMPFILE	0x0080		/* If file has no name. */
     38  1.1  christos #define	FR_UNLOCKED	0x0100		/* File couldn't be locked. */
     39  1.1  christos 	u_int16_t flags;
     40  1.1  christos };
     41  1.1  christos 
     42  1.1  christos /* Action arguments to scr_exadjust(). */
     43  1.1  christos typedef enum { EX_TERM_CE, EX_TERM_SCROLL } exadj_t;
     44  1.1  christos 
     45  1.1  christos /* Screen attribute arguments to scr_attr(). */
     46  1.1  christos typedef enum { SA_ALTERNATE, SA_INVERSE } scr_attr_t;
     47  1.1  christos 
     48  1.4       rin #ifdef IMCTRL
     49  1.4       rin /* Input method control arguments to scr_imctrl(). */
     50  1.4       rin typedef enum { IMCTRL_INIT, IMCTRL_OFF, IMCTRL_ON } imctrl_t;
     51  1.4       rin #endif
     52  1.4       rin 
     53  1.1  christos /* Key type arguments to scr_keyval(). */
     54  1.1  christos typedef enum { KEY_VEOF, KEY_VERASE, KEY_VKILL, KEY_VWERASE } scr_keyval_t;
     55  1.1  christos 
     56  1.1  christos /*
     57  1.1  christos  * GS:
     58  1.1  christos  *
     59  1.1  christos  * Structure that describes global state of the running program.
     60  1.1  christos  */
     61  1.1  christos struct _gs {
     62  1.1  christos 	char	*progname;		/* Programe name. */
     63  1.1  christos 
     64  1.1  christos 	int	 id;			/* Last allocated screen id. */
     65  1.3  christos 	TAILQ_HEAD(_dqh, _win) dq;	/* Displayed windows. */
     66  1.3  christos 	TAILQ_HEAD(_hqh, _scr) hq;	/* Hidden screens. */
     67  1.1  christos 
     68  1.1  christos 	void	*perl_interp;		/* Perl interpreter. */
     69  1.1  christos 	void	*tcl_interp;		/* Tcl_Interp *: Tcl interpreter. */
     70  1.1  christos 
     71  1.1  christos 	void	*cl_private;		/* Curses support private area. */
     72  1.1  christos 	void	*tk_private;		/* Tk/Tcl support private area. */
     73  1.1  christos 
     74  1.1  christos 					/* File references. */
     75  1.3  christos 	TAILQ_HEAD(_frefh, _fref) frefq;
     76  1.1  christos  					/* File structures. */
     77  1.3  christos  	TAILQ_HEAD(_exfh, _exf) exfq;
     78  1.1  christos 
     79  1.1  christos #define	GO_COLUMNS	0		/* Global options: columns. */
     80  1.1  christos #define	GO_LINES	1		/* Global options: lines. */
     81  1.1  christos #define	GO_SECURE	2		/* Global options: secure. */
     82  1.1  christos #define	GO_TERM		3		/* Global options: terminal type. */
     83  1.1  christos 	OPTION	 opts[GO_TERM + 1];
     84  1.1  christos 
     85  1.1  christos 	DB	*msg;			/* Message catalog DB. */
     86  1.1  christos 	MSGH	 msgq;			/* User message list. */
     87  1.1  christos #define	DEFAULT_NOPRINT	'\1'		/* Emergency non-printable character. */
     88  1.2  christos 	int	 noprint;		/* Cached, unprintable character. */
     89  1.1  christos 
     90  1.1  christos 	char	*c_option;		/* Ex initial, command-line command. */
     91  1.1  christos 
     92  1.1  christos #ifdef DEBUG
     93  1.1  christos 	FILE	*tracefp;		/* Trace file pointer. */
     94  1.1  christos #endif
     95  1.1  christos 
     96  1.2  christos #define	MAX_BIT_SEQ	0x7f		/* Max + 1 fast check character. */
     97  1.1  christos 	LIST_HEAD(_seqh, _seq) seqq;	/* Linked list of maps, abbrevs. */
     98  1.2  christos 	bitstr_t bit_decl(seqb, MAX_BIT_SEQ + 1);
     99  1.1  christos 
    100  1.2  christos #define	MAX_FAST_KEY	0xff		/* Max fast check character.*/
    101  1.1  christos #define	KEY_LEN(sp, ch)							\
    102  1.2  christos 	(((ch) & ~MAX_FAST_KEY) == 0 ?					\
    103  1.1  christos 	    sp->gp->cname[(unsigned char)ch].len : v_key_len(sp, ch))
    104  1.1  christos #define	KEY_NAME(sp, ch)						\
    105  1.2  christos 	(((ch) & ~MAX_FAST_KEY) == 0 ?					\
    106  1.1  christos 	    sp->gp->cname[(unsigned char)ch].name : v_key_name(sp, ch))
    107  1.1  christos 	struct {
    108  1.1  christos 		u_char	 name[MAX_CHARACTER_COLUMNS + 1];
    109  1.1  christos 		u_int8_t len;
    110  1.1  christos 	} cname[MAX_FAST_KEY + 1];	/* Fast lookup table. */
    111  1.1  christos 
    112  1.1  christos #define	KEY_VAL(sp, ch)							\
    113  1.2  christos 	(((ch) & ~MAX_FAST_KEY) == 0 ? 					\
    114  1.2  christos 	    sp->gp->special_key[(unsigned char)ch] : v_key_val(sp,ch))
    115  1.2  christos 	e_key_t				/* Fast lookup table. */
    116  1.1  christos 	    special_key[MAX_FAST_KEY + 1];
    117  1.1  christos 
    118  1.1  christos /* Flags. */
    119  1.1  christos #define	G_ABBREV	0x0001		/* If have abbreviations. */
    120  1.1  christos #define	G_BELLSCHED	0x0002		/* Bell scheduled. */
    121  1.1  christos #define	G_INTERRUPTED	0x0004		/* Interrupted. */
    122  1.1  christos #define	G_RECOVER_SET	0x0008		/* Recover system initialized. */
    123  1.1  christos #define	G_SCRIPTED	0x0010		/* Ex script session. */
    124  1.1  christos #define	G_SCRWIN	0x0020		/* Scripting windows running. */
    125  1.1  christos #define	G_SNAPSHOT	0x0040		/* Always snapshot files. */
    126  1.1  christos #define	G_SRESTART	0x0080		/* Screen restarted. */
    127  1.1  christos 	u_int32_t flags;
    128  1.1  christos 
    129  1.1  christos 	/* Screen interface functions. */
    130  1.1  christos 					/* Add a string to the screen. */
    131  1.1  christos 	int	(*scr_addstr) __P((SCR *, const char *, size_t));
    132  1.1  christos 					/* Add a string to the screen. */
    133  1.1  christos 	int	(*scr_waddstr) __P((SCR *, const CHAR_T *, size_t));
    134  1.1  christos 					/* Toggle a screen attribute. */
    135  1.1  christos 	int	(*scr_attr) __P((SCR *, scr_attr_t, int));
    136  1.1  christos 					/* Terminal baud rate. */
    137  1.1  christos 	int	(*scr_baud) __P((SCR *, u_long *));
    138  1.1  christos 					/* Beep/bell/flash the terminal. */
    139  1.1  christos 	int	(*scr_bell) __P((SCR *));
    140  1.1  christos 					/* Display a busy message. */
    141  1.1  christos 	void	(*scr_busy) __P((SCR *, const char *, busy_t));
    142  1.1  christos 					/* Prepare child. */
    143  1.1  christos 	int	(*scr_child) __P((SCR *));
    144  1.1  christos 					/* Clear to the end of the line. */
    145  1.1  christos 	int	(*scr_clrtoeol) __P((SCR *));
    146  1.1  christos 					/* Return the cursor location. */
    147  1.1  christos 	int	(*scr_cursor) __P((SCR *, size_t *, size_t *));
    148  1.1  christos 					/* Delete a line. */
    149  1.1  christos 	int	(*scr_deleteln) __P((SCR *));
    150  1.1  christos 					/* Discard a screen. */
    151  1.1  christos 	int	(*scr_discard) __P((SCR *, SCR **));
    152  1.1  christos 					/* Get a keyboard event. */
    153  1.1  christos 	int	(*scr_event) __P((SCR *, EVENT *, u_int32_t, int));
    154  1.1  christos 					/* Ex: screen adjustment routine. */
    155  1.1  christos 	int	(*scr_ex_adjust) __P((SCR *, exadj_t));
    156  1.1  christos 	int	(*scr_fmap)		/* Set a function key. */
    157  1.1  christos 	    __P((SCR *, seq_t, CHAR_T *, size_t, CHAR_T *, size_t));
    158  1.1  christos 					/* Get terminal key value. */
    159  1.1  christos 	int	(*scr_keyval) __P((SCR *, scr_keyval_t, CHAR_T *, int *));
    160  1.4       rin #ifdef IMCTRL
    161  1.4       rin 					/* Control the state of input method. */
    162  1.4       rin 	void	(*scr_imctrl) __P((SCR *, imctrl_t));
    163  1.4       rin #endif
    164  1.1  christos 					/* Insert a line. */
    165  1.1  christos 	int	(*scr_insertln) __P((SCR *));
    166  1.1  christos 					/* Handle an option change. */
    167  1.2  christos 	int	(*scr_optchange) __P((SCR *, int, const char *, u_long *));
    168  1.1  christos 					/* Move the cursor. */
    169  1.1  christos 	int	(*scr_move) __P((SCR *, size_t, size_t));
    170  1.1  christos 					/* Refresh the screen. */
    171  1.1  christos 	int	(*scr_refresh) __P((SCR *, int));
    172  1.1  christos 					/* Rename the file. */
    173  1.1  christos 	int	(*scr_rename) __P((SCR *, char *, int));
    174  1.1  christos 					/* Reply to an event. */
    175  1.1  christos 	int	(*scr_reply) __P((SCR *, int, char *));
    176  1.1  christos 					/* Set the screen type. */
    177  1.1  christos 	int	(*scr_screen) __P((SCR *, u_int32_t));
    178  1.1  christos 					/* Split the screen. */
    179  1.1  christos 	int	(*scr_split) __P((SCR *, SCR *));
    180  1.1  christos 					/* Suspend the editor. */
    181  1.1  christos 	int	(*scr_suspend) __P((SCR *, int *));
    182  1.1  christos 					/* Print usage message. */
    183  1.1  christos 	void	(*scr_usage) __P((void));
    184  1.1  christos 
    185  1.1  christos 	/* Threading stuff */
    186  1.1  christos 	void	*th_private;
    187  1.1  christos 
    188  1.1  christos 	int	(*run) __P((WIN *, void *(*)(void*), void *));
    189  1.1  christos 
    190  1.1  christos 	int	(*lock_init) __P((WIN *, void **));
    191  1.1  christos #define LOCK_INIT(wp,s)							    \
    192  1.1  christos 	wp->gp->lock_init(wp, &s->lock)
    193  1.1  christos 	int	(*lock_try) __P((WIN *, void **));
    194  1.1  christos #define LOCK_TRY(wp,s)							    \
    195  1.1  christos 	wp->gp->lock_try(wp, &s->lock)
    196  1.1  christos 	int	(*lock_unlock) __P((WIN *, void **));
    197  1.1  christos #define LOCK_UNLOCK(wp,s)						    \
    198  1.1  christos 	wp->gp->lock_unlock(wp, &s->lock)
    199  1.1  christos 	int	(*lock_end) __P((WIN *, void **));
    200  1.1  christos #define LOCK_END(wp,s)							    \
    201  1.1  christos 	wp->gp->lock_end(wp, &s->lock)
    202  1.1  christos };
    203  1.1  christos 
    204  1.1  christos /*
    205  1.1  christos  * XXX
    206  1.1  christos  * Block signals if there are asynchronous events.  Used to keep DB system calls
    207  1.1  christos  * from being interrupted and not restarted, as that will result in consistency
    208  1.1  christos  * problems.  This should be handled by DB.
    209  1.1  christos  */
    210  1.1  christos #ifdef BLOCK_SIGNALS
    211  1.1  christos #include <signal.h>
    212  1.1  christos extern sigset_t	__sigblockset;
    213  1.1  christos #define	SIGBLOCK \
    214  1.1  christos 	(void)sigprocmask(SIG_BLOCK, &__sigblockset, NULL)
    215  1.1  christos #define	SIGUNBLOCK \
    216  1.1  christos 	(void)sigprocmask(SIG_UNBLOCK, &__sigblockset, NULL);
    217  1.1  christos #else
    218  1.1  christos #define	SIGBLOCK
    219  1.1  christos #define	SIGUNBLOCK
    220  1.1  christos #endif
    221