gs.h revision 1.2 1 1.2 christos /* $NetBSD: gs.h,v 1.2 2013/11/22 15:52:05 christos 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.1 christos CIRCLEQ_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.1 christos /* Key type arguments to scr_keyval(). */
49 1.1 christos typedef enum { KEY_VEOF, KEY_VERASE, KEY_VKILL, KEY_VWERASE } scr_keyval_t;
50 1.1 christos
51 1.1 christos /*
52 1.1 christos * GS:
53 1.1 christos *
54 1.1 christos * Structure that describes global state of the running program.
55 1.1 christos */
56 1.1 christos struct _gs {
57 1.1 christos char *progname; /* Programe name. */
58 1.1 christos
59 1.1 christos int id; /* Last allocated screen id. */
60 1.1 christos CIRCLEQ_HEAD(_dqh, _win) dq; /* Displayed windows. */
61 1.1 christos CIRCLEQ_HEAD(_hqh, _scr) hq; /* Hidden screens. */
62 1.1 christos
63 1.1 christos void *perl_interp; /* Perl interpreter. */
64 1.1 christos void *tcl_interp; /* Tcl_Interp *: Tcl interpreter. */
65 1.1 christos
66 1.1 christos void *cl_private; /* Curses support private area. */
67 1.1 christos void *tk_private; /* Tk/Tcl support private area. */
68 1.1 christos
69 1.1 christos /* File references. */
70 1.1 christos CIRCLEQ_HEAD(_frefh, _fref) frefq;
71 1.1 christos /* File structures. */
72 1.1 christos CIRCLEQ_HEAD(_exfh, _exf) exfq;
73 1.1 christos
74 1.1 christos #define GO_COLUMNS 0 /* Global options: columns. */
75 1.1 christos #define GO_LINES 1 /* Global options: lines. */
76 1.1 christos #define GO_SECURE 2 /* Global options: secure. */
77 1.1 christos #define GO_TERM 3 /* Global options: terminal type. */
78 1.1 christos OPTION opts[GO_TERM + 1];
79 1.1 christos
80 1.1 christos DB *msg; /* Message catalog DB. */
81 1.1 christos MSGH msgq; /* User message list. */
82 1.1 christos #define DEFAULT_NOPRINT '\1' /* Emergency non-printable character. */
83 1.2 christos int noprint; /* Cached, unprintable character. */
84 1.1 christos
85 1.1 christos char *c_option; /* Ex initial, command-line command. */
86 1.1 christos
87 1.1 christos #ifdef DEBUG
88 1.1 christos FILE *tracefp; /* Trace file pointer. */
89 1.1 christos #endif
90 1.1 christos
91 1.2 christos #define MAX_BIT_SEQ 0x7f /* Max + 1 fast check character. */
92 1.1 christos LIST_HEAD(_seqh, _seq) seqq; /* Linked list of maps, abbrevs. */
93 1.2 christos bitstr_t bit_decl(seqb, MAX_BIT_SEQ + 1);
94 1.1 christos
95 1.2 christos #define MAX_FAST_KEY 0xff /* Max fast check character.*/
96 1.1 christos #define KEY_LEN(sp, ch) \
97 1.2 christos (((ch) & ~MAX_FAST_KEY) == 0 ? \
98 1.1 christos sp->gp->cname[(unsigned char)ch].len : v_key_len(sp, ch))
99 1.1 christos #define KEY_NAME(sp, ch) \
100 1.2 christos (((ch) & ~MAX_FAST_KEY) == 0 ? \
101 1.1 christos sp->gp->cname[(unsigned char)ch].name : v_key_name(sp, ch))
102 1.1 christos struct {
103 1.1 christos u_char name[MAX_CHARACTER_COLUMNS + 1];
104 1.1 christos u_int8_t len;
105 1.1 christos } cname[MAX_FAST_KEY + 1]; /* Fast lookup table. */
106 1.1 christos
107 1.1 christos #define KEY_VAL(sp, ch) \
108 1.2 christos (((ch) & ~MAX_FAST_KEY) == 0 ? \
109 1.2 christos sp->gp->special_key[(unsigned char)ch] : v_key_val(sp,ch))
110 1.2 christos e_key_t /* Fast lookup table. */
111 1.1 christos special_key[MAX_FAST_KEY + 1];
112 1.1 christos
113 1.1 christos /* Flags. */
114 1.1 christos #define G_ABBREV 0x0001 /* If have abbreviations. */
115 1.1 christos #define G_BELLSCHED 0x0002 /* Bell scheduled. */
116 1.1 christos #define G_INTERRUPTED 0x0004 /* Interrupted. */
117 1.1 christos #define G_RECOVER_SET 0x0008 /* Recover system initialized. */
118 1.1 christos #define G_SCRIPTED 0x0010 /* Ex script session. */
119 1.1 christos #define G_SCRWIN 0x0020 /* Scripting windows running. */
120 1.1 christos #define G_SNAPSHOT 0x0040 /* Always snapshot files. */
121 1.1 christos #define G_SRESTART 0x0080 /* Screen restarted. */
122 1.1 christos u_int32_t flags;
123 1.1 christos
124 1.1 christos /* Screen interface functions. */
125 1.1 christos /* Add a string to the screen. */
126 1.1 christos int (*scr_addstr) __P((SCR *, const char *, size_t));
127 1.1 christos /* Add a string to the screen. */
128 1.1 christos int (*scr_waddstr) __P((SCR *, const CHAR_T *, size_t));
129 1.1 christos /* Toggle a screen attribute. */
130 1.1 christos int (*scr_attr) __P((SCR *, scr_attr_t, int));
131 1.1 christos /* Terminal baud rate. */
132 1.1 christos int (*scr_baud) __P((SCR *, u_long *));
133 1.1 christos /* Beep/bell/flash the terminal. */
134 1.1 christos int (*scr_bell) __P((SCR *));
135 1.1 christos /* Display a busy message. */
136 1.1 christos void (*scr_busy) __P((SCR *, const char *, busy_t));
137 1.1 christos /* Prepare child. */
138 1.1 christos int (*scr_child) __P((SCR *));
139 1.1 christos /* Clear to the end of the line. */
140 1.1 christos int (*scr_clrtoeol) __P((SCR *));
141 1.1 christos /* Return the cursor location. */
142 1.1 christos int (*scr_cursor) __P((SCR *, size_t *, size_t *));
143 1.1 christos /* Delete a line. */
144 1.1 christos int (*scr_deleteln) __P((SCR *));
145 1.1 christos /* Discard a screen. */
146 1.1 christos int (*scr_discard) __P((SCR *, SCR **));
147 1.1 christos /* Get a keyboard event. */
148 1.1 christos int (*scr_event) __P((SCR *, EVENT *, u_int32_t, int));
149 1.1 christos /* Ex: screen adjustment routine. */
150 1.1 christos int (*scr_ex_adjust) __P((SCR *, exadj_t));
151 1.1 christos int (*scr_fmap) /* Set a function key. */
152 1.1 christos __P((SCR *, seq_t, CHAR_T *, size_t, CHAR_T *, size_t));
153 1.1 christos /* Get terminal key value. */
154 1.1 christos int (*scr_keyval) __P((SCR *, scr_keyval_t, CHAR_T *, int *));
155 1.1 christos /* Insert a line. */
156 1.1 christos int (*scr_insertln) __P((SCR *));
157 1.1 christos /* Handle an option change. */
158 1.2 christos int (*scr_optchange) __P((SCR *, int, const char *, u_long *));
159 1.1 christos /* Move the cursor. */
160 1.1 christos int (*scr_move) __P((SCR *, size_t, size_t));
161 1.1 christos /* Refresh the screen. */
162 1.1 christos int (*scr_refresh) __P((SCR *, int));
163 1.1 christos /* Rename the file. */
164 1.1 christos int (*scr_rename) __P((SCR *, char *, int));
165 1.1 christos /* Reply to an event. */
166 1.1 christos int (*scr_reply) __P((SCR *, int, char *));
167 1.1 christos /* Set the screen type. */
168 1.1 christos int (*scr_screen) __P((SCR *, u_int32_t));
169 1.1 christos /* Split the screen. */
170 1.1 christos int (*scr_split) __P((SCR *, SCR *));
171 1.1 christos /* Suspend the editor. */
172 1.1 christos int (*scr_suspend) __P((SCR *, int *));
173 1.1 christos /* Print usage message. */
174 1.1 christos void (*scr_usage) __P((void));
175 1.1 christos
176 1.1 christos /* Threading stuff */
177 1.1 christos void *th_private;
178 1.1 christos
179 1.1 christos int (*run) __P((WIN *, void *(*)(void*), void *));
180 1.1 christos
181 1.1 christos int (*lock_init) __P((WIN *, void **));
182 1.1 christos #define LOCK_INIT(wp,s) \
183 1.1 christos wp->gp->lock_init(wp, &s->lock)
184 1.1 christos int (*lock_try) __P((WIN *, void **));
185 1.1 christos #define LOCK_TRY(wp,s) \
186 1.1 christos wp->gp->lock_try(wp, &s->lock)
187 1.1 christos int (*lock_unlock) __P((WIN *, void **));
188 1.1 christos #define LOCK_UNLOCK(wp,s) \
189 1.1 christos wp->gp->lock_unlock(wp, &s->lock)
190 1.1 christos int (*lock_end) __P((WIN *, void **));
191 1.1 christos #define LOCK_END(wp,s) \
192 1.1 christos wp->gp->lock_end(wp, &s->lock)
193 1.1 christos };
194 1.1 christos
195 1.1 christos /*
196 1.1 christos * XXX
197 1.1 christos * Block signals if there are asynchronous events. Used to keep DB system calls
198 1.1 christos * from being interrupted and not restarted, as that will result in consistency
199 1.1 christos * problems. This should be handled by DB.
200 1.1 christos */
201 1.1 christos #ifdef BLOCK_SIGNALS
202 1.1 christos #include <signal.h>
203 1.1 christos extern sigset_t __sigblockset;
204 1.1 christos #define SIGBLOCK \
205 1.1 christos (void)sigprocmask(SIG_BLOCK, &__sigblockset, NULL)
206 1.1 christos #define SIGUNBLOCK \
207 1.1 christos (void)sigprocmask(SIG_UNBLOCK, &__sigblockset, NULL);
208 1.1 christos #else
209 1.1 christos #define SIGBLOCK
210 1.1 christos #define SIGUNBLOCK
211 1.1 christos #endif
212