xref: /minix/external/bsd/nvi/dist/common/key.h (revision 84d9c625)
1 /*	$NetBSD: key.h,v 1.2 2013/11/22 15:52:05 christos Exp $ */
2 /*-
3  * Copyright (c) 1991, 1993, 1994
4  *	The Regents of the University of California.  All rights reserved.
5  * Copyright (c) 1991, 1993, 1994, 1995, 1996
6  *	Keith Bostic.  All rights reserved.
7  *
8  * See the LICENSE file for redistribution information.
9  *
10  *	Id: key.h,v 10.50 2001/06/28 17:53:58 skimo Exp  (Berkeley) Date: 2001/06/28 17:53:58
11  */
12 
13 #include "multibyte.h"
14 
15 #ifdef USE_WIDECHAR
16 #define FILE2INT5(sp,buf,n,nlen,w,wlen)					    \
17     sp->conv.file2int(sp, n, nlen, &buf, &wlen, &w)
18 #define INT2FILE(sp,w,wlen,n,nlen) 					    \
19     sp->conv.int2file(sp, w, wlen, &sp->wp->cw, &nlen, &n)
20 #define CHAR2INT5(sp,buf,n,nlen,w,wlen)					    \
21     sp->conv.sys2int(sp, n, nlen, &buf, &wlen, &w)
22 #define INT2CHAR(sp,w,wlen,n,nlen) 					    \
23     sp->conv.int2sys(sp, w, wlen, &sp->wp->cw, &nlen, &n)
24 #define INT2SYS(sp,w,wlen,n,nlen) 					    \
25     sp->conv.int2sys(sp, w, wlen, &sp->wp->cw, &nlen, &n)
26 #define INPUT2INT5(sp,cw,n,nlen,w,wlen)					    \
27     sp->conv.input2int(sp, n, nlen, &(cw), &wlen, &w)
28 #define CONST
29 #define INTISWIDE(c)	(wctob(c) == EOF)	    /* XXX wrong name */
30 #define CHAR_WIDTH(sp, ch)  wcwidth(ch)
31 #else
32 #define FILE2INT5(sp,buf,n,nlen,w,wlen) \
33     (w = n, wlen = nlen, 0)
34 #define INT2FILE(sp,w,wlen,n,nlen) \
35     (n = w, nlen = wlen, 0)
36 #define CHAR2INT5(sp,buf,n,nlen,w,wlen) \
37     (w = n, wlen = nlen, 0)
38 #define INT2CHAR(sp,w,wlen,n,nlen) \
39     (n = w, nlen = wlen, 0)
40 #define INT2SYS(sp,w,wlen,n,nlen) \
41     (n = w, nlen = wlen, 0)
42 #define INPUT2INT5(sp,buf,n,nlen,w,wlen) \
43     (w = n, wlen = nlen, 0)
44 #define CONST const
45 #define INTISWIDE(c)	    0
46 #define CHAR_WIDTH(sp, ch)  1
47 #endif
48 #define FILE2INT(sp,n,nlen,w,wlen)					    \
49     FILE2INT5(sp,sp->wp->cw,n,nlen,w,wlen)
50 #define CHAR2INT(sp,n,nlen,w,wlen)					    \
51     CHAR2INT5(sp,sp->wp->cw,n,nlen,w,wlen)
52 
53 #define MEMCPYW(to, from, n) \
54     memcpy(to, from, (n) * sizeof(CHAR_T))
55 #define MEMMOVEW(to, from, n) \
56     memmove(to, from, (n) * sizeof(CHAR_T))
57 
58 /* The maximum number of columns any character can take up on a screen. */
59 #define	MAX_CHARACTER_COLUMNS	4
60 
61 /*
62  * Event types.
63  *
64  * The program structure depends on the event loop being able to return
65  * E_EOF/E_ERR multiple times -- eventually enough things will end due
66  * to the events that vi will reach the command level for the screen, at
67  * which point the exit flags will be set and vi will exit.
68  */
69 typedef enum {
70 	E_NOTUSED = 0,			/* Not set. */
71 	E_CHARACTER,			/* Input character: e_c set. */
72 	E_EOF,				/* End of input (NOT ^D). */
73 	E_ERR,				/* Input error. */
74 	E_INTERRUPT,			/* Interrupt. */
75 	E_IPCOMMAND,			/* IP command: e_ipcom set. */
76 	E_REPAINT,			/* Repaint: e_flno, e_tlno set. */
77 	E_SIGHUP,			/* SIGHUP. */
78 	E_SIGTERM,			/* SIGTERM. */
79 	E_STRING,			/* Input string: e_csp, e_len set. */
80 	E_TIMEOUT,			/* Timeout. */
81 	E_WRESIZE,			/* Window resize. */
82 	E_FLAGS				/* Flags */
83 } e_event_t;
84 
85 /*
86  * Character values.
87  */
88 typedef enum {
89 	K_NOTUSED = 0,			/* Not set. */
90 	K_BACKSLASH,			/*  \ */
91 	K_CARAT,			/*  ^ */
92 	K_CNTRLD,			/* ^D */
93 	K_CNTRLR,			/* ^R */
94 	K_CNTRLT,			/* ^T */
95 	K_CNTRLZ,			/* ^Z */
96 	K_COLON,			/*  : */
97 	K_CR,				/* \r */
98 	K_ESCAPE,			/* ^[ */
99 	K_FORMFEED,			/* \f */
100 	K_HEXCHAR,			/* ^X */
101 	K_NL,				/* \n */
102 	K_RIGHTBRACE,			/*  } */
103 	K_RIGHTPAREN,			/*  ) */
104 	K_TAB,				/* \t */
105 	K_VERASE,			/* set from tty: default ^H */
106 	K_VKILL,			/* set from tty: default ^U */
107 	K_VLNEXT,			/* set from tty: default ^V */
108 	K_VWERASE,			/* set from tty: default ^W */
109 	K_ZERO				/*  0 */
110 } e_key_t;
111 
112 struct _event {
113 	TAILQ_ENTRY(_event) q;		/* Linked list of events. */
114 	e_event_t e_event;		/* Event type. */
115 	int	  e_ipcom;		/* IP command. */
116 
117 #define	CH_ABBREVIATED	0x01		/* Character is from an abbreviation. */
118 #define	CH_MAPPED	0x02		/* Character is from a map. */
119 #define	CH_NOMAP	0x04		/* Do not map the character. */
120 #define	CH_QUOTED	0x08		/* Character is already quoted. */
121 	ARG_CHAR_T e_c;			/* Character. */
122 	e_key_t	  e_value;		/* Key type. */
123 
124 #define	e_flags	e_val1			/* Flags. */
125 #define	e_lno	e_val1			/* Single location. */
126 #define	e_cno	e_val2
127 #define	e_flno	e_val1			/* Text region. */
128 #define	e_fcno	e_val2
129 #define	e_tlno	e_val3
130 #define	e_tcno	e_val4
131 	size_t	  e_val1;		/* Value #1. */
132 	size_t	  e_val2;		/* Value #2. */
133 	size_t	  e_val3;		/* Value #3. */
134 	size_t	  e_val4;		/* Value #4. */
135 
136 #define	e_csp	e_str1
137 #define	e_len	e_len1
138 	CHAR_T	 *e_str1;		/* String #1. */
139 	size_t	  e_len1;		/* String #1 length. */
140 	CHAR_T	 *e_str2;		/* String #2. */
141 	size_t	  e_len2;		/* String #2 length. */
142 };
143 
144 typedef struct _keylist {
145 	e_key_t value;			/* Special value. */
146 	int	ch;			/* Key. */
147 } KEYLIST;
148 extern KEYLIST keylist[];
149 
150 					/* Return if more keys in queue. */
151 #define	KEYS_WAITING(sp)	((sp)->wp->i_cnt != 0)
152 #define	MAPPED_KEYS_WAITING(sp)						\
153 	(KEYS_WAITING(sp) &&						\
154 	    FL_ISSET((sp)->wp->i_event[(sp)->wp->i_next].e_flags, CH_MAPPED))
155 
156 /* The "standard" tab width, for displaying things to users. */
157 #define	STANDARD_TAB	6
158 
159 /* Various special characters, messages. */
160 #define	CH_BSEARCH	'?'		/* Backward search prompt. */
161 #define	CH_CURSOR	' '		/* Cursor character. */
162 #define	CH_ENDMARK	'$'		/* End of a range. */
163 #define	CH_EXPROMPT	':'		/* Ex prompt. */
164 #define	CH_FSEARCH	'/'		/* Forward search prompt. */
165 #define	CH_HEX		'\030'		/* Leading hex character. */
166 #define	CH_LITERAL	'\026'		/* ASCII ^V. */
167 #define	CH_NO		'n'		/* No. */
168 #define	CH_NOT_DIGIT	'a'		/* A non-isdigit() character. */
169 #define	CH_QUIT		'q'		/* Quit. */
170 #define	CH_YES		'y'		/* Yes. */
171 
172 /*
173  * Checking for interrupts means that we look at the bit that gets set if the
174  * screen code supports asynchronous events, and call back into the event code
175  * so that non-asynchronous screens get a chance to post the interrupt.
176  *
177  * INTERRUPT_CHECK is the number of lines "operated" on before checking for
178  * interrupts.
179  */
180 #define	INTERRUPT_CHECK	100
181 #define	INTERRUPTED(sp)							\
182 	(F_ISSET((sp)->gp, G_INTERRUPTED) ||				\
183 	(!v_event_get(sp, NULL, 0, EC_INTERRUPT) &&			\
184 	F_ISSET((sp)->gp, G_INTERRUPTED)))
185 #define	CLR_INTERRUPT(sp)						\
186 	F_CLR((sp)->gp, G_INTERRUPTED)
187 
188 /* Flags describing types of characters being requested. */
189 #define	EC_INTERRUPT	0x001		/* Checking for interrupts. */
190 #define	EC_MAPCOMMAND	0x002		/* Apply the command map. */
191 #define	EC_MAPINPUT	0x004		/* Apply the input map. */
192 #define	EC_MAPNODIGIT	0x008		/* Return to a digit. */
193 #define	EC_QUOTED	0x010		/* Try to quote next character */
194 #define	EC_RAW		0x020		/* Any next character. XXX: not used. */
195 #define	EC_TIMEOUT	0x040		/* Timeout to next character. */
196 
197 /* Flags describing text input special cases. */
198 #define	TXT_ADDNEWLINE	0x00000001	/* Replay starts on a new line. */
199 #define	TXT_AICHARS	0x00000002	/* Leading autoindent chars. */
200 #define	TXT_ALTWERASE	0x00000004	/* Option: altwerase. */
201 #define	TXT_APPENDEOL	0x00000008	/* Appending after EOL. */
202 #define	TXT_AUTOINDENT	0x00000010	/* Autoindent set this line. */
203 #define	TXT_BACKSLASH	0x00000020	/* Backslashes escape characters. */
204 #define	TXT_BEAUTIFY	0x00000040	/* Only printable characters. */
205 #define	TXT_BS		0x00000080	/* Backspace returns the buffer. */
206 #define	TXT_CEDIT	0x00000100	/* Can return TERM_CEDIT. */
207 #define	TXT_CNTRLD	0x00000200	/* Control-D is a command. */
208 #define	TXT_CNTRLT	0x00000400	/* Control-T is an indent special. */
209 #define	TXT_CR		0x00000800	/* CR returns the buffer. */
210 #define	TXT_DOTTERM	0x00001000	/* Leading '.' terminates the input. */
211 #define	TXT_EMARK	0x00002000	/* End of replacement mark. */
212 #define	TXT_EOFCHAR	0x00004000	/* ICANON set, return EOF character. */
213 #define	TXT_ESCAPE	0x00008000	/* Escape returns the buffer. */
214 #define	TXT_FILEC	0x00010000	/* Option: filec. */
215 #define	TXT_INFOLINE	0x00020000	/* Editing the info line. */
216 #define	TXT_MAPINPUT	0x00040000	/* Apply the input map. */
217 #define	TXT_NLECHO	0x00080000	/* Echo the newline. */
218 #define	TXT_NUMBER	0x00100000	/* Number the line. */
219 #define	TXT_OVERWRITE	0x00200000	/* Overwrite characters. */
220 #define	TXT_PROMPT	0x00400000	/* Display a prompt. */
221 #define	TXT_RECORD	0x00800000	/* Record for replay. */
222 #define	TXT_REPLACE	0x01000000	/* Replace; don't delete overwrite. */
223 #define	TXT_REPLAY	0x02000000	/* Replay the last input. */
224 #define	TXT_RESOLVE	0x04000000	/* Resolve the text into the file. */
225 #define	TXT_SEARCHINCR	0x08000000	/* Incremental search. */
226 #define	TXT_SHOWMATCH	0x10000000	/* Option: showmatch. */
227 #define	TXT_TTYWERASE	0x20000000	/* Option: ttywerase. */
228 #define	TXT_WRAPMARGIN	0x40000000	/* Option: wrapmargin. */
229