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