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