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