gs.h revision 1.8
1/*	$OpenBSD: gs.h,v 1.8 2005/10/17 19:12:16 otto Exp $	*/
2
3/*-
4 * Copyright (c) 1993, 1994
5 *	The Regents of the University of California.  All rights reserved.
6 * Copyright (c) 1993, 1994, 1995, 1996
7 *	Keith Bostic.  All rights reserved.
8 *
9 * See the LICENSE file for redistribution information.
10 *
11 *	@(#)gs.h	10.34 (Berkeley) 9/24/96
12 */
13
14#define	TEMPORARY_FILE_STRING	"/tmp"	/* Default temporary file name. */
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 */
23struct _fref {
24	CIRCLEQ_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(). */
44typedef enum { EX_TERM_CE, EX_TERM_SCROLL } exadj_t;
45
46/* Screen attribute arguments to scr_attr(). */
47typedef enum { SA_ALTERNATE, SA_INVERSE } scr_attr_t;
48
49/* Key type arguments to scr_keyval(). */
50typedef 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 */
57struct _gs {
58	char	*progname;		/* Programe name. */
59
60	int	 id;			/* Last allocated screen id. */
61	CIRCLEQ_HEAD(_dqh, _scr) dq;	/* Displayed screens. */
62	CIRCLEQ_HEAD(_hqh, _scr) hq;	/* Hidden screens. */
63
64	SCR	*ccl_sp;		/* Colon command-line screen. */
65
66	void	*perl_interp;		/* Perl interpreter. */
67	void	*tcl_interp;		/* Tcl_Interp *: Tcl interpreter. */
68
69	void	*cl_private;		/* Curses support private area. */
70	void	*ip_private;		/* IP support private area. */
71	void	*tk_private;		/* Tk/Tcl support private area. */
72
73					/* File references. */
74	CIRCLEQ_HEAD(_frefh, _fref) frefq;
75
76#define	GO_COLUMNS	0		/* Global options: columns. */
77#define	GO_LINES	1		/* Global options: lines. */
78#define	GO_SECURE	2		/* Global options: secure. */
79#define	GO_TERM		3		/* Global options: terminal type. */
80	OPTION	 opts[GO_TERM + 1];
81
82	DB	*msg;			/* Message catalog DB. */
83	MSGH	 msgq;			/* User message list. */
84#define	DEFAULT_NOPRINT	'\1'		/* Emergency non-printable character. */
85	CHAR_T	 noprint;		/* Cached, unprintable character. */
86
87	char	*tmp_bp;		/* Temporary buffer. */
88	size_t	 tmp_blen;		/* Temporary buffer size. */
89
90	/*
91	 * Ex command structures (EXCMD).  Defined here because ex commands
92	 * exist outside of any particular screen or file.
93	 */
94#define	EXCMD_RUNNING(gp)	(LIST_FIRST(&(gp)->ecq)->clen != 0)
95	LIST_HEAD(_excmdh, _excmd) ecq;	/* Ex command linked list. */
96	EXCMD	 excmd;			/* Default ex command structure. */
97	char	 *if_name;		/* Current associated file. */
98	recno_t	  if_lno;		/* Current associated line number. */
99
100	char	*c_option;		/* Ex initial, command-line command. */
101
102#ifdef DEBUG
103	FILE	*tracefp;		/* Trace file pointer. */
104#endif
105
106	EVENT	*i_event;		/* Array of input events. */
107	size_t	 i_nelem;		/* Number of array elements. */
108	size_t	 i_cnt;			/* Count of events. */
109	size_t	 i_next;		/* Offset of next event. */
110
111	CB	*dcbp;			/* Default cut buffer pointer. */
112	CB	 dcb_store;		/* Default cut buffer storage. */
113	LIST_HEAD(_cuth, _cb) cutq;	/* Linked list of cut buffers. */
114
115#define	MAX_BIT_SEQ	128		/* Max + 1 fast check character. */
116	LIST_HEAD(_seqh, _seq) seqq;	/* Linked list of maps, abbrevs. */
117	bitstr_t bit_decl(seqb, MAX_BIT_SEQ);
118
119#define	MAX_FAST_KEY	254		/* Max fast check character.*/
120#define	KEY_LEN(sp, ch)							\
121	((unsigned char)(ch) <= MAX_FAST_KEY ?				\
122	    sp->gp->cname[(unsigned char)ch].len : v_key_len(sp, ch))
123#define	KEY_NAME(sp, ch)						\
124	((unsigned char)(ch) <= MAX_FAST_KEY ?				\
125	    sp->gp->cname[(unsigned char)ch].name : v_key_name(sp, ch))
126	struct {
127		CHAR_T	 name[MAX_CHARACTER_COLUMNS + 1];
128		u_int8_t len;
129	} cname[MAX_FAST_KEY + 1];	/* Fast lookup table. */
130
131#define	KEY_VAL(sp, ch)							\
132	((unsigned char)(ch) <= MAX_FAST_KEY ? 				\
133	    sp->gp->special_key[(unsigned char)ch] :			\
134	    (unsigned char)(ch) > sp->gp->max_special ? 0 : v_key_val(sp,ch))
135	CHAR_T	 max_special;		/* Max special character. */
136	u_char				/* Fast lookup table. */
137	    special_key[MAX_FAST_KEY + 1];
138
139/* Flags. */
140#define	G_ABBREV	0x0001		/* If have abbreviations. */
141#define	G_BELLSCHED	0x0002		/* Bell scheduled. */
142#define	G_INTERRUPTED	0x0004		/* Interrupted. */
143#define	G_RECOVER_SET	0x0008		/* Recover system initialized. */
144#define	G_SCRIPTED	0x0010		/* Ex script session. */
145#define	G_SCRWIN	0x0020		/* Scripting windows running. */
146#define	G_SNAPSHOT	0x0040		/* Always snapshot files. */
147#define	G_SRESTART	0x0080		/* Screen restarted. */
148#define	G_TMP_INUSE	0x0100		/* Temporary buffer in use. */
149	u_int32_t flags;
150
151	/* Screen interface functions. */
152					/* Add a string to the screen. */
153	int	(*scr_addstr)(SCR *, const char *, size_t);
154					/* Toggle a screen attribute. */
155	int	(*scr_attr)(SCR *, scr_attr_t, int);
156					/* Terminal baud rate. */
157	int	(*scr_baud)(SCR *, u_long *);
158					/* Beep/bell/flash the terminal. */
159	int	(*scr_bell)(SCR *);
160					/* Display a busy message. */
161	void	(*scr_busy)(SCR *, const char *, busy_t);
162					/* Clear to the end of the line. */
163	int	(*scr_clrtoeol)(SCR *);
164					/* Return the cursor location. */
165	int	(*scr_cursor)(SCR *, size_t *, size_t *);
166					/* Delete a line. */
167	int	(*scr_deleteln)(SCR *);
168					/* Get a keyboard event. */
169	int	(*scr_event)(SCR *, EVENT *, u_int32_t, int);
170					/* Ex: screen adjustment routine. */
171	int	(*scr_ex_adjust)(SCR *, exadj_t);
172	int	(*scr_fmap)		/* Set a function key. */
173(SCR *, seq_t, CHAR_T *, size_t, CHAR_T *, size_t);
174					/* Get terminal key value. */
175	int	(*scr_keyval)(SCR *, scr_keyval_t, CHAR_T *, int *);
176					/* Insert a line. */
177	int	(*scr_insertln)(SCR *);
178					/* Handle an option change. */
179	int	(*scr_optchange)(SCR *, int, char *, u_long *);
180					/* Move the cursor. */
181	int	(*scr_move)(SCR *, size_t, size_t);
182					/* Message or ex output. */
183	void	(*scr_msg)(SCR *, mtype_t, char *, size_t);
184					/* Refresh the screen. */
185	int	(*scr_refresh)(SCR *, int);
186					/* Rename the file. */
187	int	(*scr_rename)(SCR *, char *, int);
188					/* Set the screen type. */
189	int	(*scr_screen)(SCR *, u_int32_t);
190					/* Suspend the editor. */
191	int	(*scr_suspend)(SCR *, int *);
192					/* Print usage message. */
193	void	(*scr_usage)(void);
194};
195
196/*
197 * XXX
198 * Block signals if there are asynchronous events.  Used to keep DB system calls
199 * from being interrupted and not restarted, as that will result in consistency
200 * problems.  This should be handled by DB.
201 */
202#ifdef BLOCK_SIGNALS
203#include <signal.h>
204extern sigset_t	__sigblockset;
205#define	SIGBLOCK \
206	(void)sigprocmask(SIG_BLOCK, &__sigblockset, NULL)
207#define	SIGUNBLOCK \
208	(void)sigprocmask(SIG_UNBLOCK, &__sigblockset, NULL);
209#else
210#define	SIGBLOCK
211#define	SIGUNBLOCK
212#endif
213