put in RANGE structures for global command
[nvi.git] / common / key.h
blobbe1ec4c9c69d089bdb3aacc4efc7bf6f1f14c474
1 /*-
2 * Copyright (c) 1991, 1993
3 * The Regents of the University of California. All rights reserved.
5 * %sccs.include.redist.c%
7 * $Id: key.h,v 8.24 1993/12/22 13:44:43 bostic Exp $ (Berkeley) $Date: 1993/12/22 13:44:43 $
8 */
10 /* Structure to return a character and associated information. */
11 struct _ch {
12 CHAR_T ch; /* Character. */
14 #define K_CARAT 1
15 #define K_CNTRLR 2
16 #define K_CNTRLT 3
17 #define K_CNTRLZ 4
18 #define K_COLON 5
19 #define K_CR 6
20 #define K_ESCAPE 7
21 #define K_FORMFEED 8
22 #define K_NL 9
23 #define K_RIGHTBRACE 10
24 #define K_RIGHTPAREN 11
25 #define K_TAB 12
26 #define K_VEOF 13
27 #define K_VERASE 14
28 #define K_VKILL 15
29 #define K_VLNEXT 16
30 #define K_VWERASE 17
31 #define K_ZERO 18
32 u_char value; /* Special character flag values. */
34 #define CH_ABBREVIATED 0x01 /* Character from an abbreviation. */
35 #define CH_NOMAP 0x02 /* Do not attempt to map the character. */
36 #define CH_QUOTED 0x04 /* Character is already quoted. */
37 u_char flags;
41 * Structure for the key input buffer.
43 * MAX_MAP_COUNT was chosen based on the vi maze script, which remaps
44 * characters roughly 250 times.
46 struct _ibuf {
47 CHAR_T *ch; /* Array of characters. */
48 u_char *chf; /* Array of character flags (CH_*). */
49 #define MAX_MAP_COUNT 270 /* Maximum times a character can remap. */
50 u_char *cmap; /* Number of times character has been mapped. */
52 size_t cnt; /* Count of remaining characters. */
53 size_t len; /* Array length. */
54 size_t next; /* Offset of next array entry. */
56 /* Return if more keys in queue. */
57 #define KEYS_WAITING(sp) ((sp)->gp->tty->cnt)
58 #define MAPPED_KEYS_WAITING(sp) \
59 (KEYS_WAITING(sp) && sp->gp->tty->cmap[sp->gp->tty->next])
62 * Structure to name a character. Used both as an interface to the
63 * screen and to name objects named by characters in error messages.
65 struct _chname {
66 char *name; /* Character name. */
67 u_char len; /* Length of the character name. */
71 * Routines that return a key as a side-effect return:
73 * INP_OK Returning a character; must be 0.
74 * INP_EOF EOF.
75 * INP_ERR Error.
77 * The vi structure depends on the key routines being able to return INP_EOF
78 * multiple times without failing -- eventually enough things will end due to
79 * INP_EOF that vi will reach the command level for the screen, at which point
80 * the exit flags will be set and vi will exit.
82 enum input { INP_OK=0, INP_EOF, INP_ERR };
85 * Routines that return a confirmation return:
87 * CONF_NO User answered no.
88 * CONF_QUIT User answered quit, eof or an error.
89 * CONF_YES User answered yes.
91 enum confirm { CONF_NO, CONF_QUIT, CONF_YES };
94 * Ex/vi commands are generally separated by whitespace characters. We
95 * can't use the standard isspace(3) macro because it returns true for
96 * characters like ^K in the ASCII character set. The 4.4BSD isblank(3)
97 * macro does exactly what we want, but it's not portable yet.
99 * XXX
100 * Note side effect, ch is evaluated multiple times.
102 #ifndef isblank
103 #define isblank(ch) ((ch) == ' ' || (ch) == '\t')
104 #endif
106 /* Various special characters, messages. */
107 #define CURSOR_CH ' ' /* Cursor character. */
108 #define END_CH '$' /* End of a range. */
109 #define HEX_CH 'x' /* Leading hex number. */
110 #define NOT_DIGIT_CH 'a' /* A non-isdigit() character. */
111 #define NO_CH 'n' /* No. */
112 #define QUIT_CH 'q' /* Quit. */
113 #define YES_CH 'y' /* Yes. */
114 #define CONFSTRING "confirm? [ynq]"
115 #define CONTMSG "Enter return to continue: "
116 #define CONTMSG_I "Enter return to continue [q to quit]: "
118 /* Flags describing how input is handled. */
119 #define TXT_AICHARS 0x000001 /* Leading autoindent chars. */
120 #define TXT_ALTWERASE 0x000002 /* Option: altwerase. */
121 #define TXT_APPENDEOL 0x000004 /* Appending after EOL. */
122 #define TXT_AUTOINDENT 0x000008 /* Autoindent set this line. */
123 #define TXT_BEAUTIFY 0x000010 /* Only printable characters. */
124 #define TXT_BS 0x000020 /* Backspace returns the buffer. */
125 #define TXT_CNTRLT 0x000040 /* Control-T is an indent special. */
126 #define TXT_CR 0x000080 /* CR returns the buffer. */
127 #define TXT_EMARK 0x000100 /* End of replacement mark. */
128 #define TXT_ESCAPE 0x000200 /* Escape returns the buffer. */
129 #define TXT_INFOLINE 0x000400 /* Editing the info line. */
130 #define TXT_MAPCOMMAND 0x000800 /* Apply the command map. */
131 #define TXT_MAPINPUT 0x001000 /* Apply the input map. */
132 #define TXT_MAPNODIGIT 0x002000 /* Return to a digit. */
133 #define TXT_NLECHO 0x004000 /* Echo the newline. */
134 #define TXT_OVERWRITE 0x008000 /* Overwrite characters. */
135 #define TXT_PROMPT 0x010000 /* Display a prompt. */
136 #define TXT_RECORD 0x020000 /* Record for replay. */
137 #define TXT_REPLACE 0x040000 /* Replace; don't delete overwrite. */
138 #define TXT_REPLAY 0x080000 /* Replay the last input. */
139 #define TXT_RESOLVE 0x100000 /* Resolve the text into the file. */
140 #define TXT_SHOWMATCH 0x200000 /* Option: showmatch. */
141 #define TXT_TTYWERASE 0x400000 /* Option: ttywerase. */
142 #define TXT_WRAPMARGIN 0x800000 /* Option: wrapmargin. */
144 #define TXT_VALID_EX \
145 (TXT_BEAUTIFY | TXT_CR | TXT_NLECHO | TXT_PROMPT)
147 /* Support keyboard routines. */
148 int __term_key_val __P((SCR *, ARG_CHAR_T));
149 void term_ab_flush __P((SCR *, char *));
150 int term_init __P((SCR *));
151 enum input term_key __P((SCR *, CH *, u_int));
152 int term_key_ch __P((SCR *, int, CHAR_T *));
153 void term_map_flush __P((SCR *, char *));
154 int term_push __P((SCR *, CHAR_T *, size_t, u_int, u_int));
155 enum input term_user_key __P((SCR *, CH *));
156 int term_waiting __P((SCR *));