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