"Fossies" - the Fresh Open Source Software Archive

Member "tnftp-20200705/libedit/map.c" (4 Jul 2020, 42970 Bytes) of package /linux/privat/tnftp-20200705.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "map.c" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 20151004_vs_20200705.

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