map.c 42 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418
  1. /* $NetBSD: map.c,v 1.15 2002/03/18 16:00:55 christos Exp $ */
  2. /*-
  3. * Copyright (c) 1992, 1993
  4. * The Regents of the University of California. All rights reserved.
  5. *
  6. * This code is derived from software contributed to Berkeley by
  7. * Christos Zoulas of Cornell University.
  8. *
  9. * Redistribution and use in source and binary forms, with or without
  10. * modification, are permitted provided that the following conditions
  11. * are met:
  12. * 1. Redistributions of source code must retain the above copyright
  13. * notice, this list of conditions and the following disclaimer.
  14. * 2. Redistributions in binary form must reproduce the above copyright
  15. * notice, this list of conditions and the following disclaimer in the
  16. * documentation and/or other materials provided with the distribution.
  17. * 3. All advertising materials mentioning features or use of this software
  18. * must display the following acknowledgement:
  19. * This product includes software developed by the University of
  20. * California, Berkeley and its contributors.
  21. * 4. Neither the name of the University nor the names of its contributors
  22. * may be used to endorse or promote products derived from this software
  23. * without specific prior written permission.
  24. *
  25. * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  26. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  27. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  28. * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  29. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  30. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  31. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  32. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  33. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  34. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  35. * SUCH DAMAGE.
  36. */
  37. #include "config.h"
  38. #if !defined(lint) && !defined(SCCSID)
  39. #if 0
  40. static char sccsid[] = "@(#)map.c 8.1 (Berkeley) 6/4/93";
  41. #else
  42. __RCSID("$NetBSD: map.c,v 1.15 2002/03/18 16:00:55 christos Exp $");
  43. #endif
  44. #endif /* not lint && not SCCSID */
  45. /*
  46. * map.c: Editor function definitions
  47. */
  48. #include <stdlib.h>
  49. #include "el.h"
  50. #define N_KEYS 256
  51. private void map_print_key(EditLine *, el_action_t *, const char *);
  52. private void map_print_some_keys(EditLine *, el_action_t *, int, int);
  53. private void map_print_all_keys(EditLine *);
  54. private void map_init_nls(EditLine *);
  55. private void map_init_meta(EditLine *);
  56. /* keymap tables ; should be N_KEYS*sizeof(KEYCMD) bytes long */
  57. private const el_action_t el_map_emacs[] = {
  58. /* 0 */ EM_SET_MARK, /* ^@ */
  59. /* 1 */ ED_MOVE_TO_BEG, /* ^A */
  60. /* 2 */ ED_PREV_CHAR, /* ^B */
  61. /* 3 */ ED_TTY_SIGINT, /* ^C */
  62. /* 4 */ EM_DELETE_OR_LIST, /* ^D */
  63. /* 5 */ ED_MOVE_TO_END, /* ^E */
  64. /* 6 */ ED_NEXT_CHAR, /* ^F */
  65. /* 7 */ ED_UNASSIGNED, /* ^G */
  66. /* 8 */ ED_DELETE_PREV_CHAR, /* ^H */
  67. /* 9 */ ED_UNASSIGNED, /* ^I */
  68. /* 10 */ ED_NEWLINE, /* ^J */
  69. /* 11 */ ED_KILL_LINE, /* ^K */
  70. /* 12 */ ED_CLEAR_SCREEN, /* ^L */
  71. /* 13 */ ED_NEWLINE, /* ^M */
  72. /* 14 */ ED_NEXT_HISTORY, /* ^N */
  73. /* 15 */ ED_TTY_FLUSH_OUTPUT, /* ^O */
  74. /* 16 */ ED_PREV_HISTORY, /* ^P */
  75. /* 17 */ ED_TTY_START_OUTPUT, /* ^Q */
  76. /* 18 */ ED_REDISPLAY, /* ^R */
  77. /* 19 */ ED_TTY_STOP_OUTPUT, /* ^S */
  78. /* 20 */ ED_TRANSPOSE_CHARS, /* ^T */
  79. /* 21 */ EM_KILL_LINE, /* ^U */
  80. /* 22 */ ED_QUOTED_INSERT, /* ^V */
  81. /* 23 */ EM_KILL_REGION, /* ^W */
  82. /* 24 */ ED_SEQUENCE_LEAD_IN, /* ^X */
  83. /* 25 */ EM_YANK, /* ^Y */
  84. /* 26 */ ED_TTY_SIGTSTP, /* ^Z */
  85. /* 27 */ EM_META_NEXT, /* ^[ */
  86. /* 28 */ ED_TTY_SIGQUIT, /* ^\ */
  87. /* 29 */ ED_TTY_DSUSP, /* ^] */
  88. /* 30 */ ED_UNASSIGNED, /* ^^ */
  89. /* 31 */ ED_UNASSIGNED, /* ^_ */
  90. /* 32 */ ED_INSERT, /* SPACE */
  91. /* 33 */ ED_INSERT, /* ! */
  92. /* 34 */ ED_INSERT, /* " */
  93. /* 35 */ ED_INSERT, /* # */
  94. /* 36 */ ED_INSERT, /* $ */
  95. /* 37 */ ED_INSERT, /* % */
  96. /* 38 */ ED_INSERT, /* & */
  97. /* 39 */ ED_INSERT, /* ' */
  98. /* 40 */ ED_INSERT, /* ( */
  99. /* 41 */ ED_INSERT, /* ) */
  100. /* 42 */ ED_INSERT, /* * */
  101. /* 43 */ ED_INSERT, /* + */
  102. /* 44 */ ED_INSERT, /* , */
  103. /* 45 */ ED_INSERT, /* - */
  104. /* 46 */ ED_INSERT, /* . */
  105. /* 47 */ ED_INSERT, /* / */
  106. /* 48 */ ED_DIGIT, /* 0 */
  107. /* 49 */ ED_DIGIT, /* 1 */
  108. /* 50 */ ED_DIGIT, /* 2 */
  109. /* 51 */ ED_DIGIT, /* 3 */
  110. /* 52 */ ED_DIGIT, /* 4 */
  111. /* 53 */ ED_DIGIT, /* 5 */
  112. /* 54 */ ED_DIGIT, /* 6 */
  113. /* 55 */ ED_DIGIT, /* 7 */
  114. /* 56 */ ED_DIGIT, /* 8 */
  115. /* 57 */ ED_DIGIT, /* 9 */
  116. /* 58 */ ED_INSERT, /* : */
  117. /* 59 */ ED_INSERT, /* ; */
  118. /* 60 */ ED_INSERT, /* < */
  119. /* 61 */ ED_INSERT, /* = */
  120. /* 62 */ ED_INSERT, /* > */
  121. /* 63 */ ED_INSERT, /* ? */
  122. /* 64 */ ED_INSERT, /* @ */
  123. /* 65 */ ED_INSERT, /* A */
  124. /* 66 */ ED_INSERT, /* B */
  125. /* 67 */ ED_INSERT, /* C */
  126. /* 68 */ ED_INSERT, /* D */
  127. /* 69 */ ED_INSERT, /* E */
  128. /* 70 */ ED_INSERT, /* F */
  129. /* 71 */ ED_INSERT, /* G */
  130. /* 72 */ ED_INSERT, /* H */
  131. /* 73 */ ED_INSERT, /* I */
  132. /* 74 */ ED_INSERT, /* J */
  133. /* 75 */ ED_INSERT, /* K */
  134. /* 76 */ ED_INSERT, /* L */
  135. /* 77 */ ED_INSERT, /* M */
  136. /* 78 */ ED_INSERT, /* N */
  137. /* 79 */ ED_INSERT, /* O */
  138. /* 80 */ ED_INSERT, /* P */
  139. /* 81 */ ED_INSERT, /* Q */
  140. /* 82 */ ED_INSERT, /* R */
  141. /* 83 */ ED_INSERT, /* S */
  142. /* 84 */ ED_INSERT, /* T */
  143. /* 85 */ ED_INSERT, /* U */
  144. /* 86 */ ED_INSERT, /* V */
  145. /* 87 */ ED_INSERT, /* W */
  146. /* 88 */ ED_INSERT, /* X */
  147. /* 89 */ ED_INSERT, /* Y */
  148. /* 90 */ ED_INSERT, /* Z */
  149. /* 91 */ ED_INSERT, /* [ */
  150. /* 92 */ ED_INSERT, /* \ */
  151. /* 93 */ ED_INSERT, /* ] */
  152. /* 94 */ ED_INSERT, /* ^ */
  153. /* 95 */ ED_INSERT, /* _ */
  154. /* 96 */ ED_INSERT, /* ` */
  155. /* 97 */ ED_INSERT, /* a */
  156. /* 98 */ ED_INSERT, /* b */
  157. /* 99 */ ED_INSERT, /* c */
  158. /* 100 */ ED_INSERT, /* d */
  159. /* 101 */ ED_INSERT, /* e */
  160. /* 102 */ ED_INSERT, /* f */
  161. /* 103 */ ED_INSERT, /* g */
  162. /* 104 */ ED_INSERT, /* h */
  163. /* 105 */ ED_INSERT, /* i */
  164. /* 106 */ ED_INSERT, /* j */
  165. /* 107 */ ED_INSERT, /* k */
  166. /* 108 */ ED_INSERT, /* l */
  167. /* 109 */ ED_INSERT, /* m */
  168. /* 110 */ ED_INSERT, /* n */
  169. /* 111 */ ED_INSERT, /* o */
  170. /* 112 */ ED_INSERT, /* p */
  171. /* 113 */ ED_INSERT, /* q */
  172. /* 114 */ ED_INSERT, /* r */
  173. /* 115 */ ED_INSERT, /* s */
  174. /* 116 */ ED_INSERT, /* t */
  175. /* 117 */ ED_INSERT, /* u */
  176. /* 118 */ ED_INSERT, /* v */
  177. /* 119 */ ED_INSERT, /* w */
  178. /* 120 */ ED_INSERT, /* x */
  179. /* 121 */ ED_INSERT, /* y */
  180. /* 122 */ ED_INSERT, /* z */
  181. /* 123 */ ED_INSERT, /* { */
  182. /* 124 */ ED_INSERT, /* | */
  183. /* 125 */ ED_INSERT, /* } */
  184. /* 126 */ ED_INSERT, /* ~ */
  185. /* 127 */ ED_DELETE_PREV_CHAR, /* ^? */
  186. /* 128 */ ED_UNASSIGNED, /* M-^@ */
  187. /* 129 */ ED_UNASSIGNED, /* M-^A */
  188. /* 130 */ ED_UNASSIGNED, /* M-^B */
  189. /* 131 */ ED_UNASSIGNED, /* M-^C */
  190. /* 132 */ ED_UNASSIGNED, /* M-^D */
  191. /* 133 */ ED_UNASSIGNED, /* M-^E */
  192. /* 134 */ ED_UNASSIGNED, /* M-^F */
  193. /* 135 */ ED_UNASSIGNED, /* M-^G */
  194. /* 136 */ ED_DELETE_PREV_WORD, /* M-^H */
  195. /* 137 */ ED_UNASSIGNED, /* M-^I */
  196. /* 138 */ ED_UNASSIGNED, /* M-^J */
  197. /* 139 */ ED_UNASSIGNED, /* M-^K */
  198. /* 140 */ ED_CLEAR_SCREEN, /* M-^L */
  199. /* 141 */ ED_UNASSIGNED, /* M-^M */
  200. /* 142 */ ED_UNASSIGNED, /* M-^N */
  201. /* 143 */ ED_UNASSIGNED, /* M-^O */
  202. /* 144 */ ED_UNASSIGNED, /* M-^P */
  203. /* 145 */ ED_UNASSIGNED, /* M-^Q */
  204. /* 146 */ ED_UNASSIGNED, /* M-^R */
  205. /* 147 */ ED_UNASSIGNED, /* M-^S */
  206. /* 148 */ ED_UNASSIGNED, /* M-^T */
  207. /* 149 */ ED_UNASSIGNED, /* M-^U */
  208. /* 150 */ ED_UNASSIGNED, /* M-^V */
  209. /* 151 */ ED_UNASSIGNED, /* M-^W */
  210. /* 152 */ ED_UNASSIGNED, /* M-^X */
  211. /* 153 */ ED_UNASSIGNED, /* M-^Y */
  212. /* 154 */ ED_UNASSIGNED, /* M-^Z */
  213. /* 155 */ ED_UNASSIGNED, /* M-^[ */
  214. /* 156 */ ED_UNASSIGNED, /* M-^\ */
  215. /* 157 */ ED_UNASSIGNED, /* M-^] */
  216. /* 158 */ ED_UNASSIGNED, /* M-^^ */
  217. /* 159 */ EM_COPY_PREV_WORD, /* M-^_ */
  218. /* 160 */ ED_UNASSIGNED, /* M-SPACE */
  219. /* 161 */ ED_UNASSIGNED, /* M-! */
  220. /* 162 */ ED_UNASSIGNED, /* M-" */
  221. /* 163 */ ED_UNASSIGNED, /* M-# */
  222. /* 164 */ ED_UNASSIGNED, /* M-$ */
  223. /* 165 */ ED_UNASSIGNED, /* M-% */
  224. /* 166 */ ED_UNASSIGNED, /* M-& */
  225. /* 167 */ ED_UNASSIGNED, /* M-' */
  226. /* 168 */ ED_UNASSIGNED, /* M-( */
  227. /* 169 */ ED_UNASSIGNED, /* M-) */
  228. /* 170 */ ED_UNASSIGNED, /* M-* */
  229. /* 171 */ ED_UNASSIGNED, /* M-+ */
  230. /* 172 */ ED_UNASSIGNED, /* M-, */
  231. /* 173 */ ED_UNASSIGNED, /* M-- */
  232. /* 174 */ ED_UNASSIGNED, /* M-. */
  233. /* 175 */ ED_UNASSIGNED, /* M-/ */
  234. /* 176 */ ED_ARGUMENT_DIGIT, /* M-0 */
  235. /* 177 */ ED_ARGUMENT_DIGIT, /* M-1 */
  236. /* 178 */ ED_ARGUMENT_DIGIT, /* M-2 */
  237. /* 179 */ ED_ARGUMENT_DIGIT, /* M-3 */
  238. /* 180 */ ED_ARGUMENT_DIGIT, /* M-4 */
  239. /* 181 */ ED_ARGUMENT_DIGIT, /* M-5 */
  240. /* 182 */ ED_ARGUMENT_DIGIT, /* M-6 */
  241. /* 183 */ ED_ARGUMENT_DIGIT, /* M-7 */
  242. /* 184 */ ED_ARGUMENT_DIGIT, /* M-8 */
  243. /* 185 */ ED_ARGUMENT_DIGIT, /* M-9 */
  244. /* 186 */ ED_UNASSIGNED, /* M-: */
  245. /* 187 */ ED_UNASSIGNED, /* M-; */
  246. /* 188 */ ED_UNASSIGNED, /* M-< */
  247. /* 189 */ ED_UNASSIGNED, /* M-= */
  248. /* 190 */ ED_UNASSIGNED, /* M-> */
  249. /* 191 */ ED_UNASSIGNED, /* M-? */
  250. /* 192 */ ED_UNASSIGNED, /* M-@ */
  251. /* 193 */ ED_UNASSIGNED, /* M-A */
  252. /* 194 */ ED_PREV_WORD, /* M-B */
  253. /* 195 */ EM_CAPITOL_CASE, /* M-C */
  254. /* 196 */ EM_DELETE_NEXT_WORD, /* M-D */
  255. /* 197 */ ED_UNASSIGNED, /* M-E */
  256. /* 198 */ EM_NEXT_WORD, /* M-F */
  257. /* 199 */ ED_UNASSIGNED, /* M-G */
  258. /* 200 */ ED_UNASSIGNED, /* M-H */
  259. /* 201 */ ED_UNASSIGNED, /* M-I */
  260. /* 202 */ ED_UNASSIGNED, /* M-J */
  261. /* 203 */ ED_UNASSIGNED, /* M-K */
  262. /* 204 */ EM_LOWER_CASE, /* M-L */
  263. /* 205 */ ED_UNASSIGNED, /* M-M */
  264. /* 206 */ ED_SEARCH_NEXT_HISTORY, /* M-N */
  265. /* 207 */ ED_SEQUENCE_LEAD_IN, /* M-O */
  266. /* 208 */ ED_SEARCH_PREV_HISTORY, /* M-P */
  267. /* 209 */ ED_UNASSIGNED, /* M-Q */
  268. /* 210 */ ED_UNASSIGNED, /* M-R */
  269. /* 211 */ ED_UNASSIGNED, /* M-S */
  270. /* 212 */ ED_UNASSIGNED, /* M-T */
  271. /* 213 */ EM_UPPER_CASE, /* M-U */
  272. /* 214 */ ED_UNASSIGNED, /* M-V */
  273. /* 215 */ EM_COPY_REGION, /* M-W */
  274. /* 216 */ ED_COMMAND, /* M-X */
  275. /* 217 */ ED_UNASSIGNED, /* M-Y */
  276. /* 218 */ ED_UNASSIGNED, /* M-Z */
  277. /* 219 */ ED_SEQUENCE_LEAD_IN, /* M-[ */
  278. /* 220 */ ED_UNASSIGNED, /* M-\ */
  279. /* 221 */ ED_UNASSIGNED, /* M-] */
  280. /* 222 */ ED_UNASSIGNED, /* M-^ */
  281. /* 223 */ ED_UNASSIGNED, /* M-_ */
  282. /* 223 */ ED_UNASSIGNED, /* M-` */
  283. /* 224 */ ED_UNASSIGNED, /* M-a */
  284. /* 225 */ ED_PREV_WORD, /* M-b */
  285. /* 226 */ EM_CAPITOL_CASE, /* M-c */
  286. /* 227 */ EM_DELETE_NEXT_WORD, /* M-d */
  287. /* 228 */ ED_UNASSIGNED, /* M-e */
  288. /* 229 */ EM_NEXT_WORD, /* M-f */
  289. /* 230 */ ED_UNASSIGNED, /* M-g */
  290. /* 231 */ ED_UNASSIGNED, /* M-h */
  291. /* 232 */ ED_UNASSIGNED, /* M-i */
  292. /* 233 */ ED_UNASSIGNED, /* M-j */
  293. /* 234 */ ED_UNASSIGNED, /* M-k */
  294. /* 235 */ EM_LOWER_CASE, /* M-l */
  295. /* 236 */ ED_UNASSIGNED, /* M-m */
  296. /* 237 */ ED_SEARCH_NEXT_HISTORY, /* M-n */
  297. /* 238 */ ED_UNASSIGNED, /* M-o */
  298. /* 239 */ ED_SEARCH_PREV_HISTORY, /* M-p */
  299. /* 240 */ ED_UNASSIGNED, /* M-q */
  300. /* 241 */ ED_UNASSIGNED, /* M-r */
  301. /* 242 */ ED_UNASSIGNED, /* M-s */
  302. /* 243 */ ED_UNASSIGNED, /* M-t */
  303. /* 244 */ EM_UPPER_CASE, /* M-u */
  304. /* 245 */ ED_UNASSIGNED, /* M-v */
  305. /* 246 */ EM_COPY_REGION, /* M-w */
  306. /* 247 */ ED_COMMAND, /* M-x */
  307. /* 248 */ ED_UNASSIGNED, /* M-y */
  308. /* 249 */ ED_UNASSIGNED, /* M-z */
  309. /* 250 */ ED_UNASSIGNED, /* M-{ */
  310. /* 251 */ ED_UNASSIGNED, /* M-| */
  311. /* 252 */ ED_UNASSIGNED, /* M-} */
  312. /* 253 */ ED_UNASSIGNED, /* M-~ */
  313. /* 254 */ ED_DELETE_PREV_WORD /* M-^? */
  314. /* 255 */
  315. };
  316. /*
  317. * keymap table for vi. Each index into above tbl; should be
  318. * N_KEYS entries long. Vi mode uses a sticky-extend to do command mode:
  319. * insert mode characters are in the normal keymap, and command mode
  320. * in the extended keymap.
  321. */
  322. private const el_action_t el_map_vi_insert[] = {
  323. #ifdef KSHVI
  324. /* 0 */ ED_UNASSIGNED, /* ^@ */
  325. /* 1 */ ED_INSERT, /* ^A */
  326. /* 2 */ ED_INSERT, /* ^B */
  327. /* 3 */ ED_INSERT, /* ^C */
  328. /* 4 */ VI_LIST_OR_EOF, /* ^D */
  329. /* 5 */ ED_INSERT, /* ^E */
  330. /* 6 */ ED_INSERT, /* ^F */
  331. /* 7 */ ED_INSERT, /* ^G */
  332. /* 8 */ VI_DELETE_PREV_CHAR, /* ^H */ /* BackSpace key */
  333. /* 9 */ ED_INSERT, /* ^I */ /* Tab Key */
  334. /* 10 */ ED_NEWLINE, /* ^J */
  335. /* 11 */ ED_INSERT, /* ^K */
  336. /* 12 */ ED_INSERT, /* ^L */
  337. /* 13 */ ED_NEWLINE, /* ^M */
  338. /* 14 */ ED_INSERT, /* ^N */
  339. /* 15 */ ED_INSERT, /* ^O */
  340. /* 16 */ ED_INSERT, /* ^P */
  341. /* 17 */ ED_TTY_START_OUTPUT, /* ^Q */
  342. /* 18 */ ED_INSERT, /* ^R */
  343. /* 19 */ ED_TTY_STOP_OUTPUT, /* ^S */
  344. /* 20 */ ED_INSERT, /* ^T */
  345. /* 21 */ VI_KILL_LINE_PREV, /* ^U */
  346. /* 22 */ ED_QUOTED_INSERT, /* ^V */
  347. /* 23 */ ED_DELETE_PREV_WORD, /* ^W */
  348. /* ED_DELETE_PREV_WORD: Only until strt edit pos */
  349. /* 24 */ ED_INSERT, /* ^X */
  350. /* 25 */ ED_INSERT, /* ^Y */
  351. /* 26 */ ED_INSERT, /* ^Z */
  352. /* 27 */ VI_COMMAND_MODE, /* ^[ */ /* [ Esc ] key */
  353. /* 28 */ ED_TTY_SIGQUIT, /* ^\ */
  354. /* 29 */ ED_INSERT, /* ^] */
  355. /* 30 */ ED_INSERT, /* ^^ */
  356. /* 31 */ ED_INSERT, /* ^_ */
  357. #else /* !KSHVI */
  358. /*
  359. * NOTE: These mappings do NOT Correspond well
  360. * to the KSH VI editing assignments.
  361. * On the other and they are convenient and
  362. * many people have gotten used to them.
  363. */
  364. /* 0 */ ED_UNASSIGNED, /* ^@ */
  365. /* 1 */ ED_MOVE_TO_BEG, /* ^A */
  366. /* 2 */ ED_PREV_CHAR, /* ^B */
  367. /* 3 */ ED_TTY_SIGINT, /* ^C */
  368. /* 4 */ VI_LIST_OR_EOF, /* ^D */
  369. /* 5 */ ED_MOVE_TO_END, /* ^E */
  370. /* 6 */ ED_NEXT_CHAR, /* ^F */
  371. /* 7 */ ED_UNASSIGNED, /* ^G */
  372. /* 8 */ ED_DELETE_PREV_CHAR, /* ^H */ /* BackSpace key */
  373. /* 9 */ ED_UNASSIGNED, /* ^I */ /* Tab Key */
  374. /* 10 */ ED_NEWLINE, /* ^J */
  375. /* 11 */ ED_KILL_LINE, /* ^K */
  376. /* 12 */ ED_CLEAR_SCREEN, /* ^L */
  377. /* 13 */ ED_NEWLINE, /* ^M */
  378. /* 14 */ ED_NEXT_HISTORY, /* ^N */
  379. /* 15 */ ED_TTY_FLUSH_OUTPUT, /* ^O */
  380. /* 16 */ ED_PREV_HISTORY, /* ^P */
  381. /* 17 */ ED_TTY_START_OUTPUT, /* ^Q */
  382. /* 18 */ ED_REDISPLAY, /* ^R */
  383. /* 19 */ ED_TTY_STOP_OUTPUT, /* ^S */
  384. /* 20 */ ED_TRANSPOSE_CHARS, /* ^T */
  385. /* 21 */ VI_KILL_LINE_PREV, /* ^U */
  386. /* 22 */ ED_QUOTED_INSERT, /* ^V */
  387. /* 23 */ ED_DELETE_PREV_WORD, /* ^W */
  388. /* 24 */ ED_UNASSIGNED, /* ^X */
  389. /* 25 */ ED_TTY_DSUSP, /* ^Y */
  390. /* 26 */ ED_TTY_SIGTSTP, /* ^Z */
  391. /* 27 */ VI_COMMAND_MODE, /* ^[ */
  392. /* 28 */ ED_TTY_SIGQUIT, /* ^\ */
  393. /* 29 */ ED_UNASSIGNED, /* ^] */
  394. /* 30 */ ED_UNASSIGNED, /* ^^ */
  395. /* 31 */ ED_UNASSIGNED, /* ^_ */
  396. #endif /* KSHVI */
  397. /* 32 */ ED_INSERT, /* SPACE */
  398. /* 33 */ ED_INSERT, /* ! */
  399. /* 34 */ ED_INSERT, /* " */
  400. /* 35 */ ED_INSERT, /* # */
  401. /* 36 */ ED_INSERT, /* $ */
  402. /* 37 */ ED_INSERT, /* % */
  403. /* 38 */ ED_INSERT, /* & */
  404. /* 39 */ ED_INSERT, /* ' */
  405. /* 40 */ ED_INSERT, /* ( */
  406. /* 41 */ ED_INSERT, /* ) */
  407. /* 42 */ ED_INSERT, /* * */
  408. /* 43 */ ED_INSERT, /* + */
  409. /* 44 */ ED_INSERT, /* , */
  410. /* 45 */ ED_INSERT, /* - */
  411. /* 46 */ ED_INSERT, /* . */
  412. /* 47 */ ED_INSERT, /* / */
  413. /* 48 */ ED_INSERT, /* 0 */
  414. /* 49 */ ED_INSERT, /* 1 */
  415. /* 50 */ ED_INSERT, /* 2 */
  416. /* 51 */ ED_INSERT, /* 3 */
  417. /* 52 */ ED_INSERT, /* 4 */
  418. /* 53 */ ED_INSERT, /* 5 */
  419. /* 54 */ ED_INSERT, /* 6 */
  420. /* 55 */ ED_INSERT, /* 7 */
  421. /* 56 */ ED_INSERT, /* 8 */
  422. /* 57 */ ED_INSERT, /* 9 */
  423. /* 58 */ ED_INSERT, /* : */
  424. /* 59 */ ED_INSERT, /* ; */
  425. /* 60 */ ED_INSERT, /* < */
  426. /* 61 */ ED_INSERT, /* = */
  427. /* 62 */ ED_INSERT, /* > */
  428. /* 63 */ ED_INSERT, /* ? */
  429. /* 64 */ ED_INSERT, /* @ */
  430. /* 65 */ ED_INSERT, /* A */
  431. /* 66 */ ED_INSERT, /* B */
  432. /* 67 */ ED_INSERT, /* C */
  433. /* 68 */ ED_INSERT, /* D */
  434. /* 69 */ ED_INSERT, /* E */
  435. /* 70 */ ED_INSERT, /* F */
  436. /* 71 */ ED_INSERT, /* G */
  437. /* 72 */ ED_INSERT, /* H */
  438. /* 73 */ ED_INSERT, /* I */
  439. /* 74 */ ED_INSERT, /* J */
  440. /* 75 */ ED_INSERT, /* K */
  441. /* 76 */ ED_INSERT, /* L */
  442. /* 77 */ ED_INSERT, /* M */
  443. /* 78 */ ED_INSERT, /* N */
  444. /* 79 */ ED_INSERT, /* O */
  445. /* 80 */ ED_INSERT, /* P */
  446. /* 81 */ ED_INSERT, /* Q */
  447. /* 82 */ ED_INSERT, /* R */
  448. /* 83 */ ED_INSERT, /* S */
  449. /* 84 */ ED_INSERT, /* T */
  450. /* 85 */ ED_INSERT, /* U */
  451. /* 86 */ ED_INSERT, /* V */
  452. /* 87 */ ED_INSERT, /* W */
  453. /* 88 */ ED_INSERT, /* X */
  454. /* 89 */ ED_INSERT, /* Y */
  455. /* 90 */ ED_INSERT, /* Z */
  456. /* 91 */ ED_INSERT, /* [ */
  457. /* 92 */ ED_INSERT, /* \ */
  458. /* 93 */ ED_INSERT, /* ] */
  459. /* 94 */ ED_INSERT, /* ^ */
  460. /* 95 */ ED_INSERT, /* _ */
  461. /* 96 */ ED_INSERT, /* ` */
  462. /* 97 */ ED_INSERT, /* a */
  463. /* 98 */ ED_INSERT, /* b */
  464. /* 99 */ ED_INSERT, /* c */
  465. /* 100 */ ED_INSERT, /* d */
  466. /* 101 */ ED_INSERT, /* e */
  467. /* 102 */ ED_INSERT, /* f */
  468. /* 103 */ ED_INSERT, /* g */
  469. /* 104 */ ED_INSERT, /* h */
  470. /* 105 */ ED_INSERT, /* i */
  471. /* 106 */ ED_INSERT, /* j */
  472. /* 107 */ ED_INSERT, /* k */
  473. /* 108 */ ED_INSERT, /* l */
  474. /* 109 */ ED_INSERT, /* m */
  475. /* 110 */ ED_INSERT, /* n */
  476. /* 111 */ ED_INSERT, /* o */
  477. /* 112 */ ED_INSERT, /* p */
  478. /* 113 */ ED_INSERT, /* q */
  479. /* 114 */ ED_INSERT, /* r */
  480. /* 115 */ ED_INSERT, /* s */
  481. /* 116 */ ED_INSERT, /* t */
  482. /* 117 */ ED_INSERT, /* u */
  483. /* 118 */ ED_INSERT, /* v */
  484. /* 119 */ ED_INSERT, /* w */
  485. /* 120 */ ED_INSERT, /* x */
  486. /* 121 */ ED_INSERT, /* y */
  487. /* 122 */ ED_INSERT, /* z */
  488. /* 123 */ ED_INSERT, /* { */
  489. /* 124 */ ED_INSERT, /* | */
  490. /* 125 */ ED_INSERT, /* } */
  491. /* 126 */ ED_INSERT, /* ~ */
  492. /* 127 */ ED_DELETE_PREV_CHAR, /* ^? */
  493. /* 128 */ ED_UNASSIGNED, /* M-^@ */
  494. /* 129 */ ED_UNASSIGNED, /* M-^A */
  495. /* 130 */ ED_UNASSIGNED, /* M-^B */
  496. /* 131 */ ED_UNASSIGNED, /* M-^C */
  497. /* 132 */ ED_UNASSIGNED, /* M-^D */
  498. /* 133 */ ED_UNASSIGNED, /* M-^E */
  499. /* 134 */ ED_UNASSIGNED, /* M-^F */
  500. /* 135 */ ED_UNASSIGNED, /* M-^G */
  501. /* 136 */ ED_UNASSIGNED, /* M-^H */
  502. /* 137 */ ED_UNASSIGNED, /* M-^I */
  503. /* 138 */ ED_UNASSIGNED, /* M-^J */
  504. /* 139 */ ED_UNASSIGNED, /* M-^K */
  505. /* 140 */ ED_UNASSIGNED, /* M-^L */
  506. /* 141 */ ED_UNASSIGNED, /* M-^M */
  507. /* 142 */ ED_UNASSIGNED, /* M-^N */
  508. /* 143 */ ED_UNASSIGNED, /* M-^O */
  509. /* 144 */ ED_UNASSIGNED, /* M-^P */
  510. /* 145 */ ED_UNASSIGNED, /* M-^Q */
  511. /* 146 */ ED_UNASSIGNED, /* M-^R */
  512. /* 147 */ ED_UNASSIGNED, /* M-^S */
  513. /* 148 */ ED_UNASSIGNED, /* M-^T */
  514. /* 149 */ ED_UNASSIGNED, /* M-^U */
  515. /* 150 */ ED_UNASSIGNED, /* M-^V */
  516. /* 151 */ ED_UNASSIGNED, /* M-^W */
  517. /* 152 */ ED_UNASSIGNED, /* M-^X */
  518. /* 153 */ ED_UNASSIGNED, /* M-^Y */
  519. /* 154 */ ED_UNASSIGNED, /* M-^Z */
  520. /* 155 */ ED_UNASSIGNED, /* M-^[ */
  521. /* 156 */ ED_UNASSIGNED, /* M-^\ */
  522. /* 157 */ ED_UNASSIGNED, /* M-^] */
  523. /* 158 */ ED_UNASSIGNED, /* M-^^ */
  524. /* 159 */ ED_UNASSIGNED, /* M-^_ */
  525. /* 160 */ ED_UNASSIGNED, /* M-SPACE */
  526. /* 161 */ ED_UNASSIGNED, /* M-! */
  527. /* 162 */ ED_UNASSIGNED, /* M-" */
  528. /* 163 */ ED_UNASSIGNED, /* M-# */
  529. /* 164 */ ED_UNASSIGNED, /* M-$ */
  530. /* 165 */ ED_UNASSIGNED, /* M-% */
  531. /* 166 */ ED_UNASSIGNED, /* M-& */
  532. /* 167 */ ED_UNASSIGNED, /* M-' */
  533. /* 168 */ ED_UNASSIGNED, /* M-( */
  534. /* 169 */ ED_UNASSIGNED, /* M-) */
  535. /* 170 */ ED_UNASSIGNED, /* M-* */
  536. /* 171 */ ED_UNASSIGNED, /* M-+ */
  537. /* 172 */ ED_UNASSIGNED, /* M-, */
  538. /* 173 */ ED_UNASSIGNED, /* M-- */
  539. /* 174 */ ED_UNASSIGNED, /* M-. */
  540. /* 175 */ ED_UNASSIGNED, /* M-/ */
  541. /* 176 */ ED_UNASSIGNED, /* M-0 */
  542. /* 177 */ ED_UNASSIGNED, /* M-1 */
  543. /* 178 */ ED_UNASSIGNED, /* M-2 */
  544. /* 179 */ ED_UNASSIGNED, /* M-3 */
  545. /* 180 */ ED_UNASSIGNED, /* M-4 */
  546. /* 181 */ ED_UNASSIGNED, /* M-5 */
  547. /* 182 */ ED_UNASSIGNED, /* M-6 */
  548. /* 183 */ ED_UNASSIGNED, /* M-7 */
  549. /* 184 */ ED_UNASSIGNED, /* M-8 */
  550. /* 185 */ ED_UNASSIGNED, /* M-9 */
  551. /* 186 */ ED_UNASSIGNED, /* M-: */
  552. /* 187 */ ED_UNASSIGNED, /* M-; */
  553. /* 188 */ ED_UNASSIGNED, /* M-< */
  554. /* 189 */ ED_UNASSIGNED, /* M-= */
  555. /* 190 */ ED_UNASSIGNED, /* M-> */
  556. /* 191 */ ED_UNASSIGNED, /* M-? */
  557. /* 192 */ ED_UNASSIGNED, /* M-@ */
  558. /* 193 */ ED_UNASSIGNED, /* M-A */
  559. /* 194 */ ED_UNASSIGNED, /* M-B */
  560. /* 195 */ ED_UNASSIGNED, /* M-C */
  561. /* 196 */ ED_UNASSIGNED, /* M-D */
  562. /* 197 */ ED_UNASSIGNED, /* M-E */
  563. /* 198 */ ED_UNASSIGNED, /* M-F */
  564. /* 199 */ ED_UNASSIGNED, /* M-G */
  565. /* 200 */ ED_UNASSIGNED, /* M-H */
  566. /* 201 */ ED_UNASSIGNED, /* M-I */
  567. /* 202 */ ED_UNASSIGNED, /* M-J */
  568. /* 203 */ ED_UNASSIGNED, /* M-K */
  569. /* 204 */ ED_UNASSIGNED, /* M-L */
  570. /* 205 */ ED_UNASSIGNED, /* M-M */
  571. /* 206 */ ED_UNASSIGNED, /* M-N */
  572. /* 207 */ ED_UNASSIGNED, /* M-O */
  573. /* 208 */ ED_UNASSIGNED, /* M-P */
  574. /* 209 */ ED_UNASSIGNED, /* M-Q */
  575. /* 210 */ ED_UNASSIGNED, /* M-R */
  576. /* 211 */ ED_UNASSIGNED, /* M-S */
  577. /* 212 */ ED_UNASSIGNED, /* M-T */
  578. /* 213 */ ED_UNASSIGNED, /* M-U */
  579. /* 214 */ ED_UNASSIGNED, /* M-V */
  580. /* 215 */ ED_UNASSIGNED, /* M-W */
  581. /* 216 */ ED_UNASSIGNED, /* M-X */
  582. /* 217 */ ED_UNASSIGNED, /* M-Y */
  583. /* 218 */ ED_UNASSIGNED, /* M-Z */
  584. /* 219 */ ED_UNASSIGNED, /* M-[ */
  585. /* 220 */ ED_UNASSIGNED, /* M-\ */
  586. /* 221 */ ED_UNASSIGNED, /* M-] */
  587. /* 222 */ ED_UNASSIGNED, /* M-^ */
  588. /* 223 */ ED_UNASSIGNED, /* M-_ */
  589. /* 224 */ ED_UNASSIGNED, /* M-` */
  590. /* 225 */ ED_UNASSIGNED, /* M-a */
  591. /* 226 */ ED_UNASSIGNED, /* M-b */
  592. /* 227 */ ED_UNASSIGNED, /* M-c */
  593. /* 228 */ ED_UNASSIGNED, /* M-d */
  594. /* 229 */ ED_UNASSIGNED, /* M-e */
  595. /* 230 */ ED_UNASSIGNED, /* M-f */
  596. /* 231 */ ED_UNASSIGNED, /* M-g */
  597. /* 232 */ ED_UNASSIGNED, /* M-h */
  598. /* 233 */ ED_UNASSIGNED, /* M-i */
  599. /* 234 */ ED_UNASSIGNED, /* M-j */
  600. /* 235 */ ED_UNASSIGNED, /* M-k */
  601. /* 236 */ ED_UNASSIGNED, /* M-l */
  602. /* 237 */ ED_UNASSIGNED, /* M-m */
  603. /* 238 */ ED_UNASSIGNED, /* M-n */
  604. /* 239 */ ED_UNASSIGNED, /* M-o */
  605. /* 240 */ ED_UNASSIGNED, /* M-p */
  606. /* 241 */ ED_UNASSIGNED, /* M-q */
  607. /* 242 */ ED_UNASSIGNED, /* M-r */
  608. /* 243 */ ED_UNASSIGNED, /* M-s */
  609. /* 244 */ ED_UNASSIGNED, /* M-t */
  610. /* 245 */ ED_UNASSIGNED, /* M-u */
  611. /* 246 */ ED_UNASSIGNED, /* M-v */
  612. /* 247 */ ED_UNASSIGNED, /* M-w */
  613. /* 248 */ ED_UNASSIGNED, /* M-x */
  614. /* 249 */ ED_UNASSIGNED, /* M-y */
  615. /* 250 */ ED_UNASSIGNED, /* M-z */
  616. /* 251 */ ED_UNASSIGNED, /* M-{ */
  617. /* 252 */ ED_UNASSIGNED, /* M-| */
  618. /* 253 */ ED_UNASSIGNED, /* M-} */
  619. /* 254 */ ED_UNASSIGNED, /* M-~ */
  620. /* 255 */ ED_UNASSIGNED /* M-^? */
  621. };
  622. private const el_action_t el_map_vi_command[] = {
  623. /* 0 */ ED_UNASSIGNED, /* ^@ */
  624. /* 1 */ ED_MOVE_TO_BEG, /* ^A */
  625. /* 2 */ ED_UNASSIGNED, /* ^B */
  626. /* 3 */ ED_TTY_SIGINT, /* ^C */
  627. /* 4 */ ED_UNASSIGNED, /* ^D */
  628. /* 5 */ ED_MOVE_TO_END, /* ^E */
  629. /* 6 */ ED_UNASSIGNED, /* ^F */
  630. /* 7 */ ED_UNASSIGNED, /* ^G */
  631. /* 8 */ ED_PREV_CHAR, /* ^H */
  632. /* 9 */ ED_UNASSIGNED, /* ^I */
  633. /* 10 */ ED_NEWLINE, /* ^J */
  634. /* 11 */ ED_KILL_LINE, /* ^K */
  635. /* 12 */ ED_CLEAR_SCREEN, /* ^L */
  636. /* 13 */ ED_NEWLINE, /* ^M */
  637. /* 14 */ ED_NEXT_HISTORY, /* ^N */
  638. /* 15 */ ED_TTY_FLUSH_OUTPUT, /* ^O */
  639. /* 16 */ ED_PREV_HISTORY, /* ^P */
  640. /* 17 */ ED_TTY_START_OUTPUT, /* ^Q */
  641. /* 18 */ ED_REDISPLAY, /* ^R */
  642. /* 19 */ ED_TTY_STOP_OUTPUT, /* ^S */
  643. /* 20 */ ED_UNASSIGNED, /* ^T */
  644. /* 21 */ VI_KILL_LINE_PREV, /* ^U */
  645. /* 22 */ ED_UNASSIGNED, /* ^V */
  646. /* 23 */ ED_DELETE_PREV_WORD, /* ^W */
  647. /* 24 */ ED_UNASSIGNED, /* ^X */
  648. /* 25 */ ED_UNASSIGNED, /* ^Y */
  649. /* 26 */ ED_UNASSIGNED, /* ^Z */
  650. /* 27 */ EM_META_NEXT, /* ^[ */
  651. /* 28 */ ED_TTY_SIGQUIT, /* ^\ */
  652. /* 29 */ ED_UNASSIGNED, /* ^] */
  653. /* 30 */ ED_UNASSIGNED, /* ^^ */
  654. /* 31 */ ED_UNASSIGNED, /* ^_ */
  655. /* 32 */ ED_NEXT_CHAR, /* SPACE */
  656. /* 33 */ ED_UNASSIGNED, /* ! */
  657. /* 34 */ ED_UNASSIGNED, /* " */
  658. /* 35 */ ED_UNASSIGNED, /* # */
  659. /* 36 */ ED_MOVE_TO_END, /* $ */
  660. /* 37 */ ED_UNASSIGNED, /* % */
  661. /* 38 */ ED_UNASSIGNED, /* & */
  662. /* 39 */ ED_UNASSIGNED, /* ' */
  663. /* 40 */ ED_UNASSIGNED, /* ( */
  664. /* 41 */ ED_UNASSIGNED, /* ) */
  665. /* 42 */ ED_UNASSIGNED, /* * */
  666. /* 43 */ ED_NEXT_HISTORY, /* + */
  667. /* 44 */ VI_REPEAT_PREV_CHAR, /* , */
  668. /* 45 */ ED_PREV_HISTORY, /* - */
  669. /* 46 */ ED_UNASSIGNED, /* . */
  670. /* 47 */ VI_SEARCH_PREV, /* / */
  671. /* 48 */ VI_ZERO, /* 0 */
  672. /* 49 */ ED_ARGUMENT_DIGIT, /* 1 */
  673. /* 50 */ ED_ARGUMENT_DIGIT, /* 2 */
  674. /* 51 */ ED_ARGUMENT_DIGIT, /* 3 */
  675. /* 52 */ ED_ARGUMENT_DIGIT, /* 4 */
  676. /* 53 */ ED_ARGUMENT_DIGIT, /* 5 */
  677. /* 54 */ ED_ARGUMENT_DIGIT, /* 6 */
  678. /* 55 */ ED_ARGUMENT_DIGIT, /* 7 */
  679. /* 56 */ ED_ARGUMENT_DIGIT, /* 8 */
  680. /* 57 */ ED_ARGUMENT_DIGIT, /* 9 */
  681. /* 58 */ ED_COMMAND, /* : */
  682. /* 59 */ VI_REPEAT_NEXT_CHAR, /* ; */
  683. /* 60 */ ED_UNASSIGNED, /* < */
  684. /* 61 */ ED_UNASSIGNED, /* = */
  685. /* 62 */ ED_UNASSIGNED, /* > */
  686. /* 63 */ VI_SEARCH_NEXT, /* ? */
  687. /* 64 */ ED_UNASSIGNED, /* @ */
  688. /* 65 */ VI_ADD_AT_EOL, /* A */
  689. /* 66 */ VI_PREV_SPACE_WORD, /* B */
  690. /* 67 */ VI_CHANGE_TO_EOL, /* C */
  691. /* 68 */ ED_KILL_LINE, /* D */
  692. /* 69 */ VI_TO_END_WORD, /* E */
  693. /* 70 */ VI_PREV_CHAR, /* F */
  694. /* 71 */ ED_UNASSIGNED, /* G */
  695. /* 72 */ ED_UNASSIGNED, /* H */
  696. /* 73 */ VI_INSERT_AT_BOL, /* I */
  697. /* 74 */ ED_SEARCH_NEXT_HISTORY, /* J */
  698. /* 75 */ ED_SEARCH_PREV_HISTORY, /* K */
  699. /* 76 */ ED_UNASSIGNED, /* L */
  700. /* 77 */ ED_UNASSIGNED, /* M */
  701. /* 78 */ VI_REPEAT_SEARCH_PREV, /* N */
  702. /* 79 */ ED_SEQUENCE_LEAD_IN, /* O */
  703. /* 80 */ VI_PASTE_PREV, /* P */
  704. /* 81 */ ED_UNASSIGNED, /* Q */
  705. /* 82 */ VI_REPLACE_MODE, /* R */
  706. /* 83 */ VI_SUBSTITUTE_LINE, /* S */
  707. /* 84 */ VI_TO_PREV_CHAR, /* T */
  708. /* 85 */ ED_UNASSIGNED, /* U */
  709. /* 86 */ ED_UNASSIGNED, /* V */
  710. /* 87 */ VI_NEXT_SPACE_WORD, /* W */
  711. /* 88 */ ED_DELETE_PREV_CHAR, /* X */
  712. /* 89 */ ED_UNASSIGNED, /* Y */
  713. /* 90 */ ED_UNASSIGNED, /* Z */
  714. /* 91 */ ED_SEQUENCE_LEAD_IN, /* [ */
  715. /* 92 */ ED_UNASSIGNED, /* \ */
  716. /* 93 */ ED_UNASSIGNED, /* ] */
  717. /* 94 */ ED_MOVE_TO_BEG, /* ^ */
  718. /* 95 */ ED_UNASSIGNED, /* _ */
  719. /* 96 */ ED_UNASSIGNED, /* ` */
  720. /* 97 */ VI_ADD, /* a */
  721. /* 98 */ VI_PREV_WORD, /* b */
  722. /* 99 */ VI_CHANGE_META, /* c */
  723. /* 100 */ VI_DELETE_META, /* d */
  724. /* 101 */ VI_END_WORD, /* e */
  725. /* 102 */ VI_NEXT_CHAR, /* f */
  726. /* 103 */ ED_UNASSIGNED, /* g */
  727. /* 104 */ ED_PREV_CHAR, /* h */
  728. /* 105 */ VI_INSERT, /* i */
  729. /* 106 */ ED_NEXT_HISTORY, /* j */
  730. /* 107 */ ED_PREV_HISTORY, /* k */
  731. /* 108 */ ED_NEXT_CHAR, /* l */
  732. /* 109 */ ED_UNASSIGNED, /* m */
  733. /* 110 */ VI_REPEAT_SEARCH_NEXT, /* n */
  734. /* 111 */ ED_UNASSIGNED, /* o */
  735. /* 112 */ VI_PASTE_NEXT, /* p */
  736. /* 113 */ ED_UNASSIGNED, /* q */
  737. /* 114 */ VI_REPLACE_CHAR, /* r */
  738. /* 115 */ VI_SUBSTITUTE_CHAR, /* s */
  739. /* 116 */ VI_TO_NEXT_CHAR, /* t */
  740. /* 117 */ VI_UNDO, /* u */
  741. /* 118 */ ED_UNASSIGNED, /* v */
  742. /* 119 */ VI_NEXT_WORD, /* w */
  743. /* 120 */ ED_DELETE_NEXT_CHAR, /* x */
  744. /* 121 */ ED_UNASSIGNED, /* y */
  745. /* 122 */ ED_UNASSIGNED, /* z */
  746. /* 123 */ ED_UNASSIGNED, /* { */
  747. /* 124 */ ED_UNASSIGNED, /* | */
  748. /* 125 */ ED_UNASSIGNED, /* } */
  749. /* 126 */ VI_CHANGE_CASE, /* ~ */
  750. /* 127 */ ED_DELETE_PREV_CHAR, /* ^? */
  751. /* 128 */ ED_UNASSIGNED, /* M-^@ */
  752. /* 129 */ ED_UNASSIGNED, /* M-^A */
  753. /* 130 */ ED_UNASSIGNED, /* M-^B */
  754. /* 131 */ ED_UNASSIGNED, /* M-^C */
  755. /* 132 */ ED_UNASSIGNED, /* M-^D */
  756. /* 133 */ ED_UNASSIGNED, /* M-^E */
  757. /* 134 */ ED_UNASSIGNED, /* M-^F */
  758. /* 135 */ ED_UNASSIGNED, /* M-^G */
  759. /* 136 */ ED_UNASSIGNED, /* M-^H */
  760. /* 137 */ ED_UNASSIGNED, /* M-^I */
  761. /* 138 */ ED_UNASSIGNED, /* M-^J */
  762. /* 139 */ ED_UNASSIGNED, /* M-^K */
  763. /* 140 */ ED_UNASSIGNED, /* M-^L */
  764. /* 141 */ ED_UNASSIGNED, /* M-^M */
  765. /* 142 */ ED_UNASSIGNED, /* M-^N */
  766. /* 143 */ ED_UNASSIGNED, /* M-^O */
  767. /* 144 */ ED_UNASSIGNED, /* M-^P */
  768. /* 145 */ ED_UNASSIGNED, /* M-^Q */
  769. /* 146 */ ED_UNASSIGNED, /* M-^R */
  770. /* 147 */ ED_UNASSIGNED, /* M-^S */
  771. /* 148 */ ED_UNASSIGNED, /* M-^T */
  772. /* 149 */ ED_UNASSIGNED, /* M-^U */
  773. /* 150 */ ED_UNASSIGNED, /* M-^V */
  774. /* 151 */ ED_UNASSIGNED, /* M-^W */
  775. /* 152 */ ED_UNASSIGNED, /* M-^X */
  776. /* 153 */ ED_UNASSIGNED, /* M-^Y */
  777. /* 154 */ ED_UNASSIGNED, /* M-^Z */
  778. /* 155 */ ED_UNASSIGNED, /* M-^[ */
  779. /* 156 */ ED_UNASSIGNED, /* M-^\ */
  780. /* 157 */ ED_UNASSIGNED, /* M-^] */
  781. /* 158 */ ED_UNASSIGNED, /* M-^^ */
  782. /* 159 */ ED_UNASSIGNED, /* M-^_ */
  783. /* 160 */ ED_UNASSIGNED, /* M-SPACE */
  784. /* 161 */ ED_UNASSIGNED, /* M-! */
  785. /* 162 */ ED_UNASSIGNED, /* M-" */
  786. /* 163 */ ED_UNASSIGNED, /* M-# */
  787. /* 164 */ ED_UNASSIGNED, /* M-$ */
  788. /* 165 */ ED_UNASSIGNED, /* M-% */
  789. /* 166 */ ED_UNASSIGNED, /* M-& */
  790. /* 167 */ ED_UNASSIGNED, /* M-' */
  791. /* 168 */ ED_UNASSIGNED, /* M-( */
  792. /* 169 */ ED_UNASSIGNED, /* M-) */
  793. /* 170 */ ED_UNASSIGNED, /* M-* */
  794. /* 171 */ ED_UNASSIGNED, /* M-+ */
  795. /* 172 */ ED_UNASSIGNED, /* M-, */
  796. /* 173 */ ED_UNASSIGNED, /* M-- */
  797. /* 174 */ ED_UNASSIGNED, /* M-. */
  798. /* 175 */ ED_UNASSIGNED, /* M-/ */
  799. /* 176 */ ED_UNASSIGNED, /* M-0 */
  800. /* 177 */ ED_UNASSIGNED, /* M-1 */
  801. /* 178 */ ED_UNASSIGNED, /* M-2 */
  802. /* 179 */ ED_UNASSIGNED, /* M-3 */
  803. /* 180 */ ED_UNASSIGNED, /* M-4 */
  804. /* 181 */ ED_UNASSIGNED, /* M-5 */
  805. /* 182 */ ED_UNASSIGNED, /* M-6 */
  806. /* 183 */ ED_UNASSIGNED, /* M-7 */
  807. /* 184 */ ED_UNASSIGNED, /* M-8 */
  808. /* 185 */ ED_UNASSIGNED, /* M-9 */
  809. /* 186 */ ED_UNASSIGNED, /* M-: */
  810. /* 187 */ ED_UNASSIGNED, /* M-; */
  811. /* 188 */ ED_UNASSIGNED, /* M-< */
  812. /* 189 */ ED_UNASSIGNED, /* M-= */
  813. /* 190 */ ED_UNASSIGNED, /* M-> */
  814. /* 191 */ ED_UNASSIGNED, /* M-? */
  815. /* 192 */ ED_UNASSIGNED, /* M-@ */
  816. /* 193 */ ED_UNASSIGNED, /* M-A */
  817. /* 194 */ ED_UNASSIGNED, /* M-B */
  818. /* 195 */ ED_UNASSIGNED, /* M-C */
  819. /* 196 */ ED_UNASSIGNED, /* M-D */
  820. /* 197 */ ED_UNASSIGNED, /* M-E */
  821. /* 198 */ ED_UNASSIGNED, /* M-F */
  822. /* 199 */ ED_UNASSIGNED, /* M-G */
  823. /* 200 */ ED_UNASSIGNED, /* M-H */
  824. /* 201 */ ED_UNASSIGNED, /* M-I */
  825. /* 202 */ ED_UNASSIGNED, /* M-J */
  826. /* 203 */ ED_UNASSIGNED, /* M-K */
  827. /* 204 */ ED_UNASSIGNED, /* M-L */
  828. /* 205 */ ED_UNASSIGNED, /* M-M */
  829. /* 206 */ ED_UNASSIGNED, /* M-N */
  830. /* 207 */ ED_SEQUENCE_LEAD_IN, /* M-O */
  831. /* 208 */ ED_UNASSIGNED, /* M-P */
  832. /* 209 */ ED_UNASSIGNED, /* M-Q */
  833. /* 210 */ ED_UNASSIGNED, /* M-R */
  834. /* 211 */ ED_UNASSIGNED, /* M-S */
  835. /* 212 */ ED_UNASSIGNED, /* M-T */
  836. /* 213 */ ED_UNASSIGNED, /* M-U */
  837. /* 214 */ ED_UNASSIGNED, /* M-V */
  838. /* 215 */ ED_UNASSIGNED, /* M-W */
  839. /* 216 */ ED_UNASSIGNED, /* M-X */
  840. /* 217 */ ED_UNASSIGNED, /* M-Y */
  841. /* 218 */ ED_UNASSIGNED, /* M-Z */
  842. /* 219 */ ED_SEQUENCE_LEAD_IN, /* M-[ */
  843. /* 220 */ ED_UNASSIGNED, /* M-\ */
  844. /* 221 */ ED_UNASSIGNED, /* M-] */
  845. /* 222 */ ED_UNASSIGNED, /* M-^ */
  846. /* 223 */ ED_UNASSIGNED, /* M-_ */
  847. /* 224 */ ED_UNASSIGNED, /* M-` */
  848. /* 225 */ ED_UNASSIGNED, /* M-a */
  849. /* 226 */ ED_UNASSIGNED, /* M-b */
  850. /* 227 */ ED_UNASSIGNED, /* M-c */
  851. /* 228 */ ED_UNASSIGNED, /* M-d */
  852. /* 229 */ ED_UNASSIGNED, /* M-e */
  853. /* 230 */ ED_UNASSIGNED, /* M-f */
  854. /* 231 */ ED_UNASSIGNED, /* M-g */
  855. /* 232 */ ED_UNASSIGNED, /* M-h */
  856. /* 233 */ ED_UNASSIGNED, /* M-i */
  857. /* 234 */ ED_UNASSIGNED, /* M-j */
  858. /* 235 */ ED_UNASSIGNED, /* M-k */
  859. /* 236 */ ED_UNASSIGNED, /* M-l */
  860. /* 237 */ ED_UNASSIGNED, /* M-m */
  861. /* 238 */ ED_UNASSIGNED, /* M-n */
  862. /* 239 */ ED_UNASSIGNED, /* M-o */
  863. /* 240 */ ED_UNASSIGNED, /* M-p */
  864. /* 241 */ ED_UNASSIGNED, /* M-q */
  865. /* 242 */ ED_UNASSIGNED, /* M-r */
  866. /* 243 */ ED_UNASSIGNED, /* M-s */
  867. /* 244 */ ED_UNASSIGNED, /* M-t */
  868. /* 245 */ ED_UNASSIGNED, /* M-u */
  869. /* 246 */ ED_UNASSIGNED, /* M-v */
  870. /* 247 */ ED_UNASSIGNED, /* M-w */
  871. /* 248 */ ED_UNASSIGNED, /* M-x */
  872. /* 249 */ ED_UNASSIGNED, /* M-y */
  873. /* 250 */ ED_UNASSIGNED, /* M-z */
  874. /* 251 */ ED_UNASSIGNED, /* M-{ */
  875. /* 252 */ ED_UNASSIGNED, /* M-| */
  876. /* 253 */ ED_UNASSIGNED, /* M-} */
  877. /* 254 */ ED_UNASSIGNED, /* M-~ */
  878. /* 255 */ ED_UNASSIGNED /* M-^? */
  879. };
  880. /* map_init():
  881. * Initialize and allocate the maps
  882. */
  883. protected int
  884. map_init(EditLine *el)
  885. {
  886. /*
  887. * Make sure those are correct before starting.
  888. */
  889. #ifdef MAP_DEBUG
  890. if (sizeof(el_map_emacs) != N_KEYS * sizeof(el_action_t))
  891. EL_ABORT((el->errfile, "Emacs map incorrect\n"));
  892. if (sizeof(el_map_vi_command) != N_KEYS * sizeof(el_action_t))
  893. EL_ABORT((el->errfile, "Vi command map incorrect\n"));
  894. if (sizeof(el_map_vi_insert) != N_KEYS * sizeof(el_action_t))
  895. EL_ABORT((el->errfile, "Vi insert map incorrect\n"));
  896. #endif
  897. el->el_map.alt = (el_action_t *)el_malloc(sizeof(el_action_t) * N_KEYS);
  898. if (el->el_map.alt == NULL)
  899. return (-1);
  900. el->el_map.key = (el_action_t *)el_malloc(sizeof(el_action_t) * N_KEYS);
  901. if (el->el_map.key == NULL)
  902. return (-1);
  903. el->el_map.emacs = el_map_emacs;
  904. el->el_map.vic = el_map_vi_command;
  905. el->el_map.vii = el_map_vi_insert;
  906. el->el_map.help = (el_bindings_t *) el_malloc(sizeof(el_bindings_t) *
  907. EL_NUM_FCNS);
  908. if (el->el_map.help == NULL)
  909. return (-1);
  910. (void) memcpy(el->el_map.help, help__get(),
  911. sizeof(el_bindings_t) * EL_NUM_FCNS);
  912. el->el_map.func = (el_func_t *)el_malloc(sizeof(el_func_t) *
  913. EL_NUM_FCNS);
  914. if (el->el_map.func == NULL)
  915. return (-1);
  916. memcpy(el->el_map.func, func__get(), sizeof(el_func_t) * EL_NUM_FCNS);
  917. el->el_map.nfunc = EL_NUM_FCNS;
  918. #ifdef VIDEFAULT
  919. map_init_vi(el);
  920. #else
  921. map_init_emacs(el);
  922. #endif /* VIDEFAULT */
  923. return (0);
  924. }
  925. /* map_end():
  926. * Free the space taken by the editor maps
  927. */
  928. protected void
  929. map_end(EditLine *el)
  930. {
  931. el_free((ptr_t) el->el_map.alt);
  932. el->el_map.alt = NULL;
  933. el_free((ptr_t) el->el_map.key);
  934. el->el_map.key = NULL;
  935. el->el_map.emacs = NULL;
  936. el->el_map.vic = NULL;
  937. el->el_map.vii = NULL;
  938. el_free((ptr_t) el->el_map.help);
  939. el->el_map.help = NULL;
  940. el_free((ptr_t) el->el_map.func);
  941. el->el_map.func = NULL;
  942. }
  943. /* map_init_nls():
  944. * Find all the printable keys and bind them to self insert
  945. */
  946. private void
  947. map_init_nls(EditLine *el)
  948. {
  949. int i;
  950. el_action_t *map = el->el_map.key;
  951. for (i = 0200; i <= 0377; i++)
  952. if (isprint(i))
  953. map[i] = ED_INSERT;
  954. }
  955. /* map_init_meta():
  956. * Bind all the meta keys to the appropriate ESC-<key> sequence
  957. */
  958. private void
  959. map_init_meta(EditLine *el)
  960. {
  961. char buf[3];
  962. int i;
  963. el_action_t *map = el->el_map.key;
  964. el_action_t *alt = el->el_map.alt;
  965. for (i = 0; i <= 0377 && map[i] != EM_META_NEXT; i++)
  966. continue;
  967. if (i > 0377) {
  968. for (i = 0; i <= 0377 && alt[i] != EM_META_NEXT; i++)
  969. continue;
  970. if (i > 0377) {
  971. i = 033;
  972. if (el->el_map.type == MAP_VI)
  973. map = alt;
  974. } else
  975. map = alt;
  976. }
  977. buf[0] = (char) i;
  978. buf[2] = 0;
  979. for (i = 0200; i <= 0377; i++)
  980. switch (map[i]) {
  981. case ED_INSERT:
  982. case ED_UNASSIGNED:
  983. case ED_SEQUENCE_LEAD_IN:
  984. break;
  985. default:
  986. buf[1] = i & 0177;
  987. key_add(el, buf, key_map_cmd(el, (int) map[i]), XK_CMD);
  988. break;
  989. }
  990. map[(int) buf[0]] = ED_SEQUENCE_LEAD_IN;
  991. }
  992. /* map_init_vi():
  993. * Initialize the vi bindings
  994. */
  995. protected void
  996. map_init_vi(EditLine *el)
  997. {
  998. int i;
  999. el_action_t *key = el->el_map.key;
  1000. el_action_t *alt = el->el_map.alt;
  1001. const el_action_t *vii = el->el_map.vii;
  1002. const el_action_t *vic = el->el_map.vic;
  1003. el->el_map.type = MAP_VI;
  1004. el->el_map.current = el->el_map.key;
  1005. key_reset(el);
  1006. for (i = 0; i < N_KEYS; i++) {
  1007. key[i] = vii[i];
  1008. alt[i] = vic[i];
  1009. }
  1010. map_init_meta(el);
  1011. map_init_nls(el);
  1012. tty_bind_char(el, 1);
  1013. term_bind_arrow(el);
  1014. }
  1015. /* map_init_emacs():
  1016. * Initialize the emacs bindings
  1017. */
  1018. protected void
  1019. map_init_emacs(EditLine *el)
  1020. {
  1021. int i;
  1022. char buf[3];
  1023. el_action_t *key = el->el_map.key;
  1024. el_action_t *alt = el->el_map.alt;
  1025. const el_action_t *emacs = el->el_map.emacs;
  1026. el->el_map.type = MAP_EMACS;
  1027. el->el_map.current = el->el_map.key;
  1028. key_reset(el);
  1029. for (i = 0; i < N_KEYS; i++) {
  1030. key[i] = emacs[i];
  1031. alt[i] = ED_UNASSIGNED;
  1032. }
  1033. map_init_meta(el);
  1034. map_init_nls(el);
  1035. buf[0] = CONTROL('X');
  1036. buf[1] = CONTROL('X');
  1037. buf[2] = 0;
  1038. key_add(el, buf, key_map_cmd(el, EM_EXCHANGE_MARK), XK_CMD);
  1039. tty_bind_char(el, 1);
  1040. term_bind_arrow(el);
  1041. }
  1042. /* map_set_editor():
  1043. * Set the editor
  1044. */
  1045. protected int
  1046. map_set_editor(EditLine *el, char *editor)
  1047. {
  1048. if (strcmp(editor, "emacs") == 0) {
  1049. map_init_emacs(el);
  1050. return (0);
  1051. }
  1052. if (strcmp(editor, "vi") == 0) {
  1053. map_init_vi(el);
  1054. return (0);
  1055. }
  1056. return (-1);
  1057. }
  1058. /* map_get_editor():
  1059. * Retrieve the editor
  1060. */
  1061. protected int
  1062. map_get_editor(EditLine *el, const char **editor)
  1063. {
  1064. if (editor == NULL)
  1065. return (-1);
  1066. switch (el->el_map.type) {
  1067. case MAP_EMACS:
  1068. *editor = "emacs";
  1069. return (0);
  1070. case MAP_VI:
  1071. *editor = "vi";
  1072. return (0);
  1073. }
  1074. return (-1);
  1075. }
  1076. /* map_print_key():
  1077. * Print the function description for 1 key
  1078. */
  1079. private void
  1080. map_print_key(EditLine *el, el_action_t *map, const char *in)
  1081. {
  1082. char outbuf[EL_BUFSIZ];
  1083. el_bindings_t *bp;
  1084. if (in[0] == '\0' || in[1] == '\0') {
  1085. (void) key__decode_str(in, outbuf, "");
  1086. for (bp = el->el_map.help; bp->name != NULL; bp++)
  1087. if (bp->func == map[(unsigned char) *in]) {
  1088. (void) fprintf(el->el_outfile,
  1089. "%s\t->\t%s\n", outbuf, bp->name);
  1090. return;
  1091. }
  1092. } else
  1093. key_print(el, in);
  1094. }
  1095. /* map_print_some_keys():
  1096. * Print keys from first to last
  1097. */
  1098. private void
  1099. map_print_some_keys(EditLine *el, el_action_t *map, int first, int last)
  1100. {
  1101. el_bindings_t *bp;
  1102. char firstbuf[2], lastbuf[2];
  1103. char unparsbuf[EL_BUFSIZ], extrabuf[EL_BUFSIZ];
  1104. firstbuf[0] = first;
  1105. firstbuf[1] = 0;
  1106. lastbuf[0] = last;
  1107. lastbuf[1] = 0;
  1108. if (map[first] == ED_UNASSIGNED) {
  1109. if (first == last)
  1110. (void) fprintf(el->el_outfile,
  1111. "%-15s-> is undefined\n",
  1112. key__decode_str(firstbuf, unparsbuf, STRQQ));
  1113. return;
  1114. }
  1115. for (bp = el->el_map.help; bp->name != NULL; bp++) {
  1116. if (bp->func == map[first]) {
  1117. if (first == last) {
  1118. (void) fprintf(el->el_outfile, "%-15s-> %s\n",
  1119. key__decode_str(firstbuf, unparsbuf, STRQQ),
  1120. bp->name);
  1121. } else {
  1122. (void) fprintf(el->el_outfile,
  1123. "%-4s to %-7s-> %s\n",
  1124. key__decode_str(firstbuf, unparsbuf, STRQQ),
  1125. key__decode_str(lastbuf, extrabuf, STRQQ),
  1126. bp->name);
  1127. }
  1128. return;
  1129. }
  1130. }
  1131. #ifdef MAP_DEBUG
  1132. if (map == el->el_map.key) {
  1133. (void) fprintf(el->el_outfile,
  1134. "BUG!!! %s isn't bound to anything.\n",
  1135. key__decode_str(firstbuf, unparsbuf, STRQQ));
  1136. (void) fprintf(el->el_outfile, "el->el_map.key[%d] == %d\n",
  1137. first, el->el_map.key[first]);
  1138. } else {
  1139. (void) fprintf(el->el_outfile,
  1140. "BUG!!! %s isn't bound to anything.\n",
  1141. key__decode_str(firstbuf, unparsbuf, STRQQ));
  1142. (void) fprintf(el->el_outfile, "el->el_map.alt[%d] == %d\n",
  1143. first, el->el_map.alt[first]);
  1144. }
  1145. #endif
  1146. EL_ABORT((el->el_errfile, "Error printing keys\n"));
  1147. }
  1148. /* map_print_all_keys():
  1149. * Print the function description for all keys.
  1150. */
  1151. private void
  1152. map_print_all_keys(EditLine *el)
  1153. {
  1154. int prev, i;
  1155. (void) fprintf(el->el_outfile, "Standard key bindings\n");
  1156. prev = 0;
  1157. for (i = 0; i < N_KEYS; i++) {
  1158. if (el->el_map.key[prev] == el->el_map.key[i])
  1159. continue;
  1160. map_print_some_keys(el, el->el_map.key, prev, i - 1);
  1161. prev = i;
  1162. }
  1163. map_print_some_keys(el, el->el_map.key, prev, i - 1);
  1164. (void) fprintf(el->el_outfile, "Alternative key bindings\n");
  1165. prev = 0;
  1166. for (i = 0; i < N_KEYS; i++) {
  1167. if (el->el_map.alt[prev] == el->el_map.alt[i])
  1168. continue;
  1169. map_print_some_keys(el, el->el_map.alt, prev, i - 1);
  1170. prev = i;
  1171. }
  1172. map_print_some_keys(el, el->el_map.alt, prev, i - 1);
  1173. (void) fprintf(el->el_outfile, "Multi-character bindings\n");
  1174. key_print(el, "");
  1175. (void) fprintf(el->el_outfile, "Arrow key bindings\n");
  1176. term_print_arrow(el, "");
  1177. }
  1178. /* map_bind():
  1179. * Add/remove/change bindings
  1180. */
  1181. protected int
  1182. map_bind(EditLine *el, int argc, const char **argv)
  1183. {
  1184. el_action_t *map;
  1185. int ntype, rem;
  1186. const char *p;
  1187. char inbuf[EL_BUFSIZ];
  1188. char outbuf[EL_BUFSIZ];
  1189. const char *in = NULL;
  1190. char *out = NULL;
  1191. el_bindings_t *bp;
  1192. int cmd;
  1193. int key;
  1194. if (argv == NULL)
  1195. return (-1);
  1196. map = el->el_map.key;
  1197. ntype = XK_CMD;
  1198. key = rem = 0;
  1199. for (argc = 1; (p = argv[argc]) != NULL; argc++)
  1200. if (p[0] == '-')
  1201. switch (p[1]) {
  1202. case 'a':
  1203. map = el->el_map.alt;
  1204. break;
  1205. case 's':
  1206. ntype = XK_STR;
  1207. break;
  1208. #ifdef notyet
  1209. case 'c':
  1210. ntype = XK_EXE;
  1211. break;
  1212. #endif
  1213. case 'k':
  1214. key = 1;
  1215. break;
  1216. case 'r':
  1217. rem = 1;
  1218. break;
  1219. case 'v':
  1220. map_init_vi(el);
  1221. return (0);
  1222. case 'e':
  1223. map_init_emacs(el);
  1224. return (0);
  1225. case 'l':
  1226. for (bp = el->el_map.help; bp->name != NULL;
  1227. bp++)
  1228. (void) fprintf(el->el_outfile,
  1229. "%s\n\t%s\n",
  1230. bp->name, bp->description);
  1231. return (0);
  1232. default:
  1233. (void) fprintf(el->el_errfile,
  1234. "%s: Invalid switch `%c'.\n",
  1235. argv[0], p[1]);
  1236. }
  1237. else
  1238. break;
  1239. if (argv[argc] == NULL) {
  1240. map_print_all_keys(el);
  1241. return (0);
  1242. }
  1243. if (key)
  1244. in = argv[argc++];
  1245. else if ((in = parse__string(inbuf, argv[argc++])) == NULL) {
  1246. (void) fprintf(el->el_errfile,
  1247. "%s: Invalid \\ or ^ in instring.\n",
  1248. argv[0]);
  1249. return (-1);
  1250. }
  1251. if (rem) {
  1252. if (key) {
  1253. (void) term_clear_arrow(el, in);
  1254. return (-1);
  1255. }
  1256. if (in[1])
  1257. (void) key_delete(el, in);
  1258. else if (map[(unsigned char) *in] == ED_SEQUENCE_LEAD_IN)
  1259. (void) key_delete(el, in);
  1260. else
  1261. map[(unsigned char) *in] = ED_UNASSIGNED;
  1262. return (0);
  1263. }
  1264. if (argv[argc] == NULL) {
  1265. if (key)
  1266. term_print_arrow(el, in);
  1267. else
  1268. map_print_key(el, map, in);
  1269. return (0);
  1270. }
  1271. #ifdef notyet
  1272. if (argv[argc + 1] != NULL) {
  1273. bindkey_usage();
  1274. return (-1);
  1275. }
  1276. #endif
  1277. switch (ntype) {
  1278. case XK_STR:
  1279. case XK_EXE:
  1280. if ((out = parse__string(outbuf, argv[argc])) == NULL) {
  1281. (void) fprintf(el->el_errfile,
  1282. "%s: Invalid \\ or ^ in outstring.\n", argv[0]);
  1283. return (-1);
  1284. }
  1285. if (key)
  1286. term_set_arrow(el, in, key_map_str(el, out), ntype);
  1287. else
  1288. key_add(el, in, key_map_str(el, out), ntype);
  1289. map[(unsigned char) *in] = ED_SEQUENCE_LEAD_IN;
  1290. break;
  1291. case XK_CMD:
  1292. if ((cmd = parse_cmd(el, argv[argc])) == -1) {
  1293. (void) fprintf(el->el_errfile,
  1294. "%s: Invalid command `%s'.\n", argv[0], argv[argc]);
  1295. return (-1);
  1296. }
  1297. if (key)
  1298. term_set_arrow(el, in, key_map_str(el, out), ntype);
  1299. else {
  1300. if (in[1]) {
  1301. key_add(el, in, key_map_cmd(el, cmd), ntype);
  1302. map[(unsigned char) *in] = ED_SEQUENCE_LEAD_IN;
  1303. } else {
  1304. key_clear(el, map, in);
  1305. map[(unsigned char) *in] = cmd;
  1306. }
  1307. }
  1308. break;
  1309. default:
  1310. EL_ABORT((el->el_errfile, "Bad XK_ type\n", ntype));
  1311. break;
  1312. }
  1313. return (0);
  1314. }
  1315. /* map_addfunc():
  1316. * add a user defined function
  1317. */
  1318. protected int
  1319. map_addfunc(EditLine *el, const char *name, const char *help, el_func_t func)
  1320. {
  1321. void *p;
  1322. int nf = el->el_map.nfunc + 2;
  1323. if (name == NULL || help == NULL || func == NULL)
  1324. return (-1);
  1325. if ((p = el_realloc(el->el_map.func, nf * sizeof(el_func_t))) == NULL)
  1326. return (-1);
  1327. el->el_map.func = (el_func_t *) p;
  1328. if ((p = el_realloc(el->el_map.help, nf * sizeof(el_bindings_t)))
  1329. == NULL)
  1330. return (-1);
  1331. el->el_map.help = (el_bindings_t *) p;
  1332. nf = el->el_map.nfunc;
  1333. el->el_map.func[nf] = func;
  1334. el->el_map.help[nf].name = name;
  1335. el->el_map.help[nf].func = nf;
  1336. el->el_map.help[nf].description = help;
  1337. el->el_map.help[++nf].name = NULL;
  1338. el->el_map.nfunc++;
  1339. return (0);
  1340. }