reset screen offset of top line if it exceeds the number of screens
[nvi.git] / common / key.h
blob7ddf2e352508a726b53a2b9a211cc8e799321b74
1 /*-
2 * Copyright (c) 1991, 1993, 1994
3 * The Regents of the University of California. All rights reserved.
4 * Copyright (c) 1991, 1993, 1994, 1995, 1996
5 * Keith Bostic. All rights reserved.
7 * See the LICENSE file for redistribution information.
9 * $Id: key.h,v 10.50 2001/06/28 17:53:58 skimo Exp $ (Berkeley) $Date: 2001/06/28 17:53:58 $
12 #include "multibyte.h"
15 * Fundamental character types.
17 * CHAR_T An integral type that can hold any character.
18 * ARG_CHAR_T The type of a CHAR_T when passed as an argument using
19 * traditional promotion rules. It should also be able
20 * to be compared against any CHAR_T for equality without
21 * problems.
22 * MAX_CHAR_T The maximum value of any character.
24 * If no integral type can hold a character, don't even try the port.
26 typedef u_int ARG_CHAR_T;
28 #ifdef USE_WIDECHAR
29 #define FILE2INT5(sp,buf,n,nlen,w,wlen) \
30 sp->conv.file2int(sp, n, nlen, &buf, &wlen, &w)
31 #define INT2FILE(sp,w,wlen,n,nlen) \
32 sp->conv.int2file(sp, w, wlen, &sp->wp->cw, &nlen, &n)
33 #define CHAR2INT5(sp,buf,n,nlen,w,wlen) \
34 sp->conv.sys2int(sp, n, nlen, &buf, &wlen, &w)
35 #define INT2CHAR(sp,w,wlen,n,nlen) \
36 sp->conv.int2sys(sp, w, wlen, &sp->wp->cw, &nlen, &n)
37 #define INT2SYS(sp,w,wlen,n,nlen) \
38 sp->conv.int2sys(sp, w, wlen, &sp->wp->cw, &nlen, &n)
39 #define INPUT2INT5(sp,cw,n,nlen,w,wlen) \
40 sp->conv.input2int(sp, n, nlen, &(cw), &wlen, &w)
41 #define CONST
42 #define ISCNTRL(ch) \
43 iswcntrl((ch))
44 #define ISDIGIT(ch) \
45 iswdigit((ch))
46 #define ISPRINT(ch) \
47 iswprint((ch))
48 #define ISBLANK(ch) \
49 iswblank((ch))
50 #define ISALPHA(ch) \
51 iswalpha((ch))
52 #define ISALNUM(ch) \
53 iswalnum((ch))
54 #define ISSPACE(ch) \
55 iswspace((ch))
56 #define CHAR_WIDTH(sp, ch) wcwidth(ch)
57 #define INTISWIDE(c) (!!(c >> 8)) /* XXX wrong name */
58 #define WS "%ls"
59 #define WVS "%*ls"
60 #define WC "%lc"
61 #else
62 #define FILE2INT5(sp,buf,n,nlen,w,wlen) \
63 (w = n, wlen = nlen, 0)
64 #define INT2FILE(sp,w,wlen,n,nlen) \
65 (n = w, nlen = wlen, 0)
66 #define CHAR2INT5(sp,buf,n,nlen,w,wlen) \
67 (w = n, wlen = nlen, 0)
68 #define INT2CHAR(sp,w,wlen,n,nlen) \
69 (n = w, nlen = wlen, 0)
70 #define INT2SYS(sp,w,wlen,n,nlen) \
71 (n = w, nlen = wlen, 0)
72 #define INPUT2INT5(sp,buf,n,nlen,w,wlen) \
73 (w = n, wlen = nlen, 0)
74 #define CONST const
75 #define ISCNTRL(ch) \
76 iscntrl((ch))
77 #define ISDIGIT(ch) \
78 isdigit((ch))
79 #define ISPRINT(ch) \
80 isprint((ch))
81 #define ISBLANK(ch) \
82 isblank((ch))
83 #define ISALPHA(ch) \
84 isalpha((ch))
85 #define ISALNUM(ch) \
86 isalnum((ch))
87 #define ISSPACE(ch) \
88 isspace((ch))
89 #define INTISWIDE(c) 0
90 #define CHAR_WIDTH(sp, ch) 1
91 #define WS "%s"
92 #define WVS "%*s"
93 #define WC "%c"
94 #endif
95 #define FILE2INT(sp,n,nlen,w,wlen) \
96 FILE2INT5(sp,sp->wp->cw,n,nlen,w,wlen)
97 #define CHAR2INT(sp,n,nlen,w,wlen) \
98 CHAR2INT5(sp,sp->wp->cw,n,nlen,w,wlen)
100 #define MEMCPYW(to, from, n) \
101 memcpy(to, from, (n) * sizeof(CHAR_T))
102 #define MEMMOVEW(to, from, n) \
103 memmove(to, from, (n) * sizeof(CHAR_T))
105 /* The maximum number of columns any character can take up on a screen. */
106 #define MAX_CHARACTER_COLUMNS 4
109 * Event types.
111 * The program structure depends on the event loop being able to return
112 * E_EOF/E_ERR multiple times -- eventually enough things will end due
113 * to the events that vi will reach the command level for the screen, at
114 * which point the exit flags will be set and vi will exit.
116 typedef enum {
117 E_NOTUSED = 0, /* Not set. */
118 E_CHARACTER, /* Input character: e_c set. */
119 E_EOF, /* End of input (NOT ^D). */
120 E_ERR, /* Input error. */
121 E_INTERRUPT, /* Interrupt. */
122 E_IPCOMMAND, /* IP command: e_ipcom set. */
123 E_REPAINT, /* Repaint: e_flno, e_tlno set. */
124 E_SIGHUP, /* SIGHUP. */
125 E_SIGTERM, /* SIGTERM. */
126 E_STRING, /* Input string: e_csp, e_len set. */
127 E_TIMEOUT, /* Timeout. */
128 E_WRESIZE, /* Window resize. */
129 E_FLAGS /* Flags */
130 } e_event_t;
133 * Character values.
135 typedef enum {
136 K_NOTUSED = 0, /* Not set. */
137 K_BACKSLASH, /* \ */
138 K_CARAT, /* ^ */
139 K_CNTRLD, /* ^D */
140 K_CNTRLR, /* ^R */
141 K_CNTRLT, /* ^T */
142 K_CNTRLZ, /* ^Z */
143 K_COLON, /* : */
144 K_CR, /* \r */
145 K_ESCAPE, /* ^[ */
146 K_FORMFEED, /* \f */
147 K_HEXCHAR, /* ^X */
148 K_NL, /* \n */
149 K_RIGHTBRACE, /* } */
150 K_RIGHTPAREN, /* ) */
151 K_TAB, /* \t */
152 K_VERASE, /* set from tty: default ^H */
153 K_VKILL, /* set from tty: default ^U */
154 K_VLNEXT, /* set from tty: default ^V */
155 K_VWERASE, /* set from tty: default ^W */
156 K_ZERO /* 0 */
157 } e_key_t;
159 struct _event {
160 TAILQ_ENTRY(_event) q; /* Linked list of events. */
161 e_event_t e_event; /* Event type. */
162 int e_ipcom; /* IP command. */
164 #define CH_ABBREVIATED 0x01 /* Character is from an abbreviation. */
165 #define CH_MAPPED 0x02 /* Character is from a map. */
166 #define CH_NOMAP 0x04 /* Do not map the character. */
167 #define CH_QUOTED 0x08 /* Character is already quoted. */
168 CHAR_T e_c; /* Character. */
169 e_key_t e_value; /* Key type. */
171 #define e_flags e_val1 /* Flags. */
172 #define e_lno e_val1 /* Single location. */
173 #define e_cno e_val2
174 #define e_flno e_val1 /* Text region. */
175 #define e_fcno e_val2
176 #define e_tlno e_val3
177 #define e_tcno e_val4
178 size_t e_val1; /* Value #1. */
179 size_t e_val2; /* Value #2. */
180 size_t e_val3; /* Value #3. */
181 size_t e_val4; /* Value #4. */
183 #define e_csp e_str1
184 #define e_len e_len1
185 CHAR_T *e_str1; /* String #1. */
186 size_t e_len1; /* String #1 length. */
187 CHAR_T *e_str2; /* String #2. */
188 size_t e_len2; /* String #2 length. */
191 typedef struct _keylist {
192 e_key_t value; /* Special value. */
193 CHAR_T ch; /* Key. */
194 } KEYLIST;
195 extern KEYLIST keylist[];
197 /* Return if more keys in queue. */
198 #define KEYS_WAITING(sp) ((sp)->wp->i_cnt != 0)
199 #define MAPPED_KEYS_WAITING(sp) \
200 (KEYS_WAITING(sp) && \
201 FL_ISSET((sp)->wp->i_event[(sp)->wp->i_next].e_flags, CH_MAPPED))
204 * Ex/vi commands are generally separated by whitespace characters. We
205 * can't use the standard isspace(3) macro because it returns true for
206 * characters like ^K in the ASCII character set. The 4.4BSD isblank(3)
207 * macro does exactly what we want, but it's not portable yet.
209 * XXX
210 * Note side effect, ch is evaluated multiple times.
212 #ifndef isblank
213 #define isblank(ch) ((ch) == ' ' || (ch) == '\t')
214 #endif
216 /* The "standard" tab width, for displaying things to users. */
217 #define STANDARD_TAB 6
219 /* Various special characters, messages. */
220 #define CH_BSEARCH '?' /* Backward search prompt. */
221 #define CH_CURSOR ' ' /* Cursor character. */
222 #define CH_ENDMARK '$' /* End of a range. */
223 #define CH_EXPROMPT ':' /* Ex prompt. */
224 #define CH_FSEARCH '/' /* Forward search prompt. */
225 #define CH_HEX '\030' /* Leading hex character. */
226 #define CH_LITERAL '\026' /* ASCII ^V. */
227 #define CH_NO 'n' /* No. */
228 #define CH_NOT_DIGIT 'a' /* A non-isdigit() character. */
229 #define CH_QUIT 'q' /* Quit. */
230 #define CH_YES 'y' /* Yes. */
233 * Checking for interrupts means that we look at the bit that gets set if the
234 * screen code supports asynchronous events, and call back into the event code
235 * so that non-asynchronous screens get a chance to post the interrupt.
237 * INTERRUPT_CHECK is the number of lines "operated" on before checking for
238 * interrupts.
240 #define INTERRUPT_CHECK 100
241 #define INTERRUPTED(sp) \
242 (F_ISSET((sp)->gp, G_INTERRUPTED) || \
243 (!v_event_get(sp, NULL, 0, EC_INTERRUPT) && \
244 F_ISSET((sp)->gp, G_INTERRUPTED)))
245 #define CLR_INTERRUPT(sp) \
246 F_CLR((sp)->gp, G_INTERRUPTED)
248 /* Flags describing types of characters being requested. */
249 #define EC_INTERRUPT 0x001 /* Checking for interrupts. */
250 #define EC_MAPCOMMAND 0x002 /* Apply the command map. */
251 #define EC_MAPINPUT 0x004 /* Apply the input map. */
252 #define EC_MAPNODIGIT 0x008 /* Return to a digit. */
253 #define EC_QUOTED 0x010 /* Try to quote next character */
254 #define EC_RAW 0x020 /* Any next character. XXX: not used. */
255 #define EC_TIMEOUT 0x040 /* Timeout to next character. */
257 /* Flags describing text input special cases. */
258 #define TXT_ADDNEWLINE 0x00000001 /* Replay starts on a new line. */
259 #define TXT_AICHARS 0x00000002 /* Leading autoindent chars. */
260 #define TXT_ALTWERASE 0x00000004 /* Option: altwerase. */
261 #define TXT_APPENDEOL 0x00000008 /* Appending after EOL. */
262 #define TXT_AUTOINDENT 0x00000010 /* Autoindent set this line. */
263 #define TXT_BACKSLASH 0x00000020 /* Backslashes escape characters. */
264 #define TXT_BEAUTIFY 0x00000040 /* Only printable characters. */
265 #define TXT_BS 0x00000080 /* Backspace returns the buffer. */
266 #define TXT_CEDIT 0x00000100 /* Can return TERM_CEDIT. */
267 #define TXT_CNTRLD 0x00000200 /* Control-D is a command. */
268 #define TXT_CNTRLT 0x00000400 /* Control-T is an indent special. */
269 #define TXT_CR 0x00000800 /* CR returns the buffer. */
270 #define TXT_DOTTERM 0x00001000 /* Leading '.' terminates the input. */
271 #define TXT_EMARK 0x00002000 /* End of replacement mark. */
272 #define TXT_EOFCHAR 0x00004000 /* ICANON set, return EOF character. */
273 #define TXT_ESCAPE 0x00008000 /* Escape returns the buffer. */
274 #define TXT_FILEC 0x00010000 /* Option: filec. */
275 #define TXT_INFOLINE 0x00020000 /* Editing the info line. */
276 #define TXT_MAPINPUT 0x00040000 /* Apply the input map. */
277 #define TXT_NLECHO 0x00080000 /* Echo the newline. */
278 #define TXT_NUMBER 0x00100000 /* Number the line. */
279 #define TXT_OVERWRITE 0x00200000 /* Overwrite characters. */
280 #define TXT_PROMPT 0x00400000 /* Display a prompt. */
281 #define TXT_RECORD 0x00800000 /* Record for replay. */
282 #define TXT_REPLACE 0x01000000 /* Replace; don't delete overwrite. */
283 #define TXT_REPLAY 0x02000000 /* Replay the last input. */
284 #define TXT_RESOLVE 0x04000000 /* Resolve the text into the file. */
285 #define TXT_SEARCHINCR 0x08000000 /* Incremental search. */
286 #define TXT_SHOWMATCH 0x10000000 /* Option: showmatch. */
287 #define TXT_TTYWERASE 0x20000000 /* Option: ttywerase. */
288 #define TXT_WRAPMARGIN 0x40000000 /* Option: wrapmargin. */