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