align CHAR_T string in log
[nvi.git] / common / key.h
blob02af00ccb7059dc741a26e3ec5f3b0d6936292c8
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.41 2001/05/11 20:09:38 skimo Exp $ (Berkeley) $Date: 2001/05/11 20:09:38 $
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 FILE2INT(sp,n,nlen,w,wlen) \
30 sp->conv.file2int(sp, n, nlen, &sp->wp->cw, &wlen, &w)
31 #define INT2FILE(sp,w,wlen,n,nlen) \
32 sp->conv.int2file(sp, w, wlen, &sp->wp->cw, &nlen, &n)
33 #define CHAR2INTB(sp,n,nlen,w,wlen,buf) \
34 sp->conv.char2int(sp, n, nlen, &buf, &wlen, &w)
35 #define INT2CHAR(sp,w,wlen,n,nlen) \
36 sp->conv.int2char(sp, w, wlen, &sp->wp->cw, &nlen, &n)
37 #define INT2DISP(sp,w,wlen,n,nlen) \
38 sp->conv.int2disp(sp, w, wlen, &sp->wp->cw, &nlen, &n)
39 #define CONST
40 #define ISCNTRL(ch) \
41 iswcntrl((ch))
42 #define ISDIGIT(ch) \
43 iswdigit((ch))
44 #define ISPRINT(ch) \
45 iswprint((ch))
46 #define CHAR_WIDTH(sp, ch) wcwidth(ch)
47 #define INTISWIDE(c) (!!(c >> 8)) /* XXX wrong name */
48 #define L(ch) L ## ch
49 #else
50 #define FILE2INT(sp,n,nlen,w,wlen) \
51 w = n, wlen = nlen, 0
52 #define INT2FILE(sp,w,wlen,n,nlen) \
53 n = w, nlen = wlen, 0
54 #define CHAR2INTB(sp,n,nlen,w,wlen,buf) \
55 w = n, wlen = nlen, 0
56 #define INT2CHAR(sp,w,wlen,n,nlen) \
57 n = w, nlen = wlen, 0
58 #define INT2DISP(sp,w,wlen,n,nlen) \
59 n = w, nlen = wlen, 0
60 #define CONST const
61 #define ISCNTRL(ch) \
62 iscntrl((ch))
63 #define ISDIGIT(ch) \
64 isdigit((ch))
65 #define ISPRINT(ch) \
66 isprint((ch))
67 #define INTISWIDE(c) 0
68 #define CHAR_WIDTH(sp, ch) 1
69 #define L(ch) ch
70 #endif
71 #define CHAR2INT(sp,n,nlen,w,wlen) \
72 CHAR2INTB(sp,n,nlen,w,wlen,sp->wp->cw)
74 #define MEMCPYW(to, from, n) \
75 memcpy(to, from, (n) * sizeof(CHAR_T))
76 #define MEMMOVEW(to, from, n) \
77 memmove(to, from, (n) * sizeof(CHAR_T))
79 /* The maximum number of columns any character can take up on a screen. */
80 #define MAX_CHARACTER_COLUMNS 4
83 * Event types.
85 * The program structure depends on the event loop being able to return
86 * E_EOF/E_ERR multiple times -- eventually enough things will end due
87 * to the events that vi will reach the command level for the screen, at
88 * which point the exit flags will be set and vi will exit.
90 typedef enum {
91 E_NOTUSED = 0, /* Not set. */
92 E_CHARACTER, /* Input character: e_c set. */
93 E_EOF, /* End of input (NOT ^D). */
94 E_ERR, /* Input error. */
95 E_INTERRUPT, /* Interrupt. */
96 E_IPCOMMAND, /* IP command: e_ipcom set. */
97 E_REPAINT, /* Repaint: e_flno, e_tlno set. */
98 E_SIGHUP, /* SIGHUP. */
99 E_SIGTERM, /* SIGTERM. */
100 E_STRING, /* Input string: e_csp, e_len set. */
101 E_TIMEOUT, /* Timeout. */
102 E_WRESIZE, /* Window resize. */
103 E_FLAGS /* Flags */
104 } e_event_t;
107 * Character values.
109 typedef enum {
110 K_NOTUSED = 0, /* Not set. */
111 K_BACKSLASH, /* \ */
112 K_CARAT, /* ^ */
113 K_CNTRLD, /* ^D */
114 K_CNTRLR, /* ^R */
115 K_CNTRLT, /* ^T */
116 K_CNTRLZ, /* ^Z */
117 K_COLON, /* : */
118 K_CR, /* \r */
119 K_ESCAPE, /* ^[ */
120 K_FORMFEED, /* \f */
121 K_HEXCHAR, /* ^X */
122 K_NL, /* \n */
123 K_RIGHTBRACE, /* } */
124 K_RIGHTPAREN, /* ) */
125 K_TAB, /* \t */
126 K_VERASE, /* set from tty: default ^H */
127 K_VKILL, /* set from tty: default ^U */
128 K_VLNEXT, /* set from tty: default ^V */
129 K_VWERASE, /* set from tty: default ^W */
130 K_ZERO /* 0 */
131 } e_key_t;
133 struct _event {
134 TAILQ_ENTRY(_event) q; /* Linked list of events. */
135 e_event_t e_event; /* Event type. */
136 int e_ipcom; /* IP command. */
138 #define CH_ABBREVIATED 0x01 /* Character is from an abbreviation. */
139 #define CH_MAPPED 0x02 /* Character is from a map. */
140 #define CH_NOMAP 0x04 /* Do not map the character. */
141 #define CH_QUOTED 0x08 /* Character is already quoted. */
142 CHAR_T e_c; /* Character. */
143 e_key_t e_value; /* Key type. */
145 #define e_flags e_val1 /* Flags. */
146 #define e_lno e_val1 /* Single location. */
147 #define e_cno e_val2
148 #define e_flno e_val1 /* Text region. */
149 #define e_fcno e_val2
150 #define e_tlno e_val3
151 #define e_tcno e_val4
152 size_t e_val1; /* Value #1. */
153 size_t e_val2; /* Value #2. */
154 size_t e_val3; /* Value #3. */
155 size_t e_val4; /* Value #4. */
157 #define e_csp e_str1
158 #define e_len e_len1
159 CHAR_T *e_str1; /* String #1. */
160 size_t e_len1; /* String #1 length. */
161 CHAR_T *e_str2; /* String #2. */
162 size_t e_len2; /* String #2 length. */
165 typedef struct _keylist {
166 e_key_t value; /* Special value. */
167 CHAR_T ch; /* Key. */
168 } KEYLIST;
169 extern KEYLIST keylist[];
171 /* Return if more keys in queue. */
172 #define KEYS_WAITING(sp) ((sp)->wp->i_cnt != 0)
173 #define MAPPED_KEYS_WAITING(sp) \
174 (KEYS_WAITING(sp) && \
175 FL_ISSET((sp)->wp->i_event[(sp)->wp->i_next].e_flags, CH_MAPPED))
178 * Ex/vi commands are generally separated by whitespace characters. We
179 * can't use the standard isspace(3) macro because it returns true for
180 * characters like ^K in the ASCII character set. The 4.4BSD isblank(3)
181 * macro does exactly what we want, but it's not portable yet.
183 * XXX
184 * Note side effect, ch is evaluated multiple times.
186 #ifndef isblank
187 #define isblank(ch) ((ch) == ' ' || (ch) == '\t')
188 #endif
190 /* The "standard" tab width, for displaying things to users. */
191 #define STANDARD_TAB 6
193 /* Various special characters, messages. */
194 #define CH_BSEARCH '?' /* Backward search prompt. */
195 #define CH_CURSOR ' ' /* Cursor character. */
196 #define CH_ENDMARK '$' /* End of a range. */
197 #define CH_EXPROMPT ':' /* Ex prompt. */
198 #define CH_FSEARCH '/' /* Forward search prompt. */
199 #define CH_HEX '\030' /* Leading hex character. */
200 #define CH_LITERAL '\026' /* ASCII ^V. */
201 #define CH_NO 'n' /* No. */
202 #define CH_NOT_DIGIT 'a' /* A non-isdigit() character. */
203 #define CH_QUIT 'q' /* Quit. */
204 #define CH_YES 'y' /* Yes. */
207 * Checking for interrupts means that we look at the bit that gets set if the
208 * screen code supports asynchronous events, and call back into the event code
209 * so that non-asynchronous screens get a chance to post the interrupt.
211 * INTERRUPT_CHECK is the number of lines "operated" on before checking for
212 * interrupts.
214 #define INTERRUPT_CHECK 100
215 #define INTERRUPTED(sp) \
216 (F_ISSET((sp)->gp, G_INTERRUPTED) || \
217 (!v_event_get(sp, NULL, 0, EC_INTERRUPT) && \
218 F_ISSET((sp)->gp, G_INTERRUPTED)))
219 #define CLR_INTERRUPT(sp) \
220 F_CLR((sp)->gp, G_INTERRUPTED)
222 /* Flags describing types of characters being requested. */
223 #define EC_INTERRUPT 0x001 /* Checking for interrupts. */
224 #define EC_MAPCOMMAND 0x002 /* Apply the command map. */
225 #define EC_MAPINPUT 0x004 /* Apply the input map. */
226 #define EC_MAPNODIGIT 0x008 /* Return to a digit. */
227 #define EC_QUOTED 0x010 /* Try to quote next character */
228 #define EC_RAW 0x020 /* Any next character. XXX: not used. */
229 #define EC_TIMEOUT 0x040 /* Timeout to next character. */
231 /* Flags describing text input special cases. */
232 #define TXT_ADDNEWLINE 0x00000001 /* Replay starts on a new line. */
233 #define TXT_AICHARS 0x00000002 /* Leading autoindent chars. */
234 #define TXT_ALTWERASE 0x00000004 /* Option: altwerase. */
235 #define TXT_APPENDEOL 0x00000008 /* Appending after EOL. */
236 #define TXT_AUTOINDENT 0x00000010 /* Autoindent set this line. */
237 #define TXT_BACKSLASH 0x00000020 /* Backslashes escape characters. */
238 #define TXT_BEAUTIFY 0x00000040 /* Only printable characters. */
239 #define TXT_BS 0x00000080 /* Backspace returns the buffer. */
240 #define TXT_CEDIT 0x00000100 /* Can return TERM_CEDIT. */
241 #define TXT_CNTRLD 0x00000200 /* Control-D is a command. */
242 #define TXT_CNTRLT 0x00000400 /* Control-T is an indent special. */
243 #define TXT_CR 0x00000800 /* CR returns the buffer. */
244 #define TXT_DOTTERM 0x00001000 /* Leading '.' terminates the input. */
245 #define TXT_EMARK 0x00002000 /* End of replacement mark. */
246 #define TXT_EOFCHAR 0x00004000 /* ICANON set, return EOF character. */
247 #define TXT_ESCAPE 0x00008000 /* Escape returns the buffer. */
248 #define TXT_FILEC 0x00010000 /* Option: filec. */
249 #define TXT_INFOLINE 0x00020000 /* Editing the info line. */
250 #define TXT_MAPINPUT 0x00040000 /* Apply the input map. */
251 #define TXT_NLECHO 0x00080000 /* Echo the newline. */
252 #define TXT_NUMBER 0x00100000 /* Number the line. */
253 #define TXT_OVERWRITE 0x00200000 /* Overwrite characters. */
254 #define TXT_PROMPT 0x00400000 /* Display a prompt. */
255 #define TXT_RECORD 0x00800000 /* Record for replay. */
256 #define TXT_REPLACE 0x01000000 /* Replace; don't delete overwrite. */
257 #define TXT_REPLAY 0x02000000 /* Replay the last input. */
258 #define TXT_RESOLVE 0x04000000 /* Resolve the text into the file. */
259 #define TXT_SEARCHINCR 0x08000000 /* Incremental search. */
260 #define TXT_SHOWMATCH 0x10000000 /* Option: showmatch. */
261 #define TXT_TTYWERASE 0x20000000 /* Option: ttywerase. */
262 #define TXT_WRAPMARGIN 0x40000000 /* Option: wrapmargin. */