11acd27e7Smillert /* keymaps.c -- Functions and keymaps for the GNU Readline library. */
21acd27e7Smillert
31acd27e7Smillert /* Copyright (C) 1988,1989 Free Software Foundation, Inc.
41acd27e7Smillert
51acd27e7Smillert This file is part of GNU Readline, a library for reading lines
61acd27e7Smillert of text with interactive input and history editing.
71acd27e7Smillert
81acd27e7Smillert Readline is free software; you can redistribute it and/or modify it
91acd27e7Smillert under the terms of the GNU General Public License as published by the
101acd27e7Smillert Free Software Foundation; either version 2, or (at your option) any
111acd27e7Smillert later version.
121acd27e7Smillert
131acd27e7Smillert Readline is distributed in the hope that it will be useful, but
141acd27e7Smillert WITHOUT ANY WARRANTY; without even the implied warranty of
151acd27e7Smillert MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
161acd27e7Smillert General Public License for more details.
171acd27e7Smillert
181acd27e7Smillert You should have received a copy of the GNU General Public License
191acd27e7Smillert along with Readline; see the file COPYING. If not, write to the Free
201acd27e7Smillert Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA. */
211acd27e7Smillert #define READLINE_LIBRARY
221acd27e7Smillert
231acd27e7Smillert #if defined (HAVE_CONFIG_H)
241acd27e7Smillert # include <config.h>
251acd27e7Smillert #endif
261acd27e7Smillert
271acd27e7Smillert #if defined (HAVE_STDLIB_H)
281acd27e7Smillert # include <stdlib.h>
291acd27e7Smillert #else
301acd27e7Smillert # include "ansi_stdlib.h"
311acd27e7Smillert #endif /* HAVE_STDLIB_H */
321acd27e7Smillert
331acd27e7Smillert #include <stdio.h> /* for FILE * definition for readline.h */
341acd27e7Smillert
351acd27e7Smillert #include "readline.h"
361acd27e7Smillert #include "rlconf.h"
371acd27e7Smillert
381acd27e7Smillert #include "emacs_keymap.c"
391acd27e7Smillert
401acd27e7Smillert #if defined (VI_MODE)
411acd27e7Smillert #include "vi_keymap.c"
421acd27e7Smillert #endif
431acd27e7Smillert
441acd27e7Smillert #include "xmalloc.h"
451acd27e7Smillert
461acd27e7Smillert /* **************************************************************** */
471acd27e7Smillert /* */
481acd27e7Smillert /* Functions for manipulating Keymaps. */
491acd27e7Smillert /* */
501acd27e7Smillert /* **************************************************************** */
511acd27e7Smillert
521acd27e7Smillert
531acd27e7Smillert /* Return a new, empty keymap.
541acd27e7Smillert Free it with free() when you are done. */
551acd27e7Smillert Keymap
rl_make_bare_keymap()561acd27e7Smillert rl_make_bare_keymap ()
571acd27e7Smillert {
581acd27e7Smillert register int i;
591acd27e7Smillert Keymap keymap = (Keymap)xmalloc (KEYMAP_SIZE * sizeof (KEYMAP_ENTRY));
601acd27e7Smillert
611acd27e7Smillert for (i = 0; i < KEYMAP_SIZE; i++)
621acd27e7Smillert {
631acd27e7Smillert keymap[i].type = ISFUNC;
64*15b117eaSkettenis keymap[i].function = (rl_command_func_t *)NULL;
651acd27e7Smillert }
661acd27e7Smillert
671acd27e7Smillert for (i = 'A'; i < ('Z' + 1); i++)
681acd27e7Smillert {
691acd27e7Smillert keymap[i].type = ISFUNC;
701acd27e7Smillert keymap[i].function = rl_do_lowercase_version;
711acd27e7Smillert }
721acd27e7Smillert
731acd27e7Smillert return (keymap);
741acd27e7Smillert }
751acd27e7Smillert
761acd27e7Smillert /* Return a new keymap which is a copy of MAP. */
771acd27e7Smillert Keymap
rl_copy_keymap(map)781acd27e7Smillert rl_copy_keymap (map)
791acd27e7Smillert Keymap map;
801acd27e7Smillert {
811acd27e7Smillert register int i;
821acd27e7Smillert Keymap temp = rl_make_bare_keymap ();
831acd27e7Smillert
841acd27e7Smillert for (i = 0; i < KEYMAP_SIZE; i++)
851acd27e7Smillert {
861acd27e7Smillert temp[i].type = map[i].type;
871acd27e7Smillert temp[i].function = map[i].function;
881acd27e7Smillert }
891acd27e7Smillert return (temp);
901acd27e7Smillert }
911acd27e7Smillert
921acd27e7Smillert /* Return a new keymap with the printing characters bound to rl_insert,
931acd27e7Smillert the uppercase Meta characters bound to run their lowercase equivalents,
941acd27e7Smillert and the Meta digits bound to produce numeric arguments. */
951acd27e7Smillert Keymap
rl_make_keymap()961acd27e7Smillert rl_make_keymap ()
971acd27e7Smillert {
981acd27e7Smillert register int i;
991acd27e7Smillert Keymap newmap;
1001acd27e7Smillert
1011acd27e7Smillert newmap = rl_make_bare_keymap ();
1021acd27e7Smillert
1031acd27e7Smillert /* All ASCII printing characters are self-inserting. */
1041acd27e7Smillert for (i = ' '; i < 127; i++)
1051acd27e7Smillert newmap[i].function = rl_insert;
1061acd27e7Smillert
1071acd27e7Smillert newmap[TAB].function = rl_insert;
1081acd27e7Smillert newmap[RUBOUT].function = rl_rubout; /* RUBOUT == 127 */
1091acd27e7Smillert newmap[CTRL('H')].function = rl_rubout;
1101acd27e7Smillert
1111acd27e7Smillert #if KEYMAP_SIZE > 128
1121acd27e7Smillert /* Printing characters in some 8-bit character sets. */
1131acd27e7Smillert for (i = 128; i < 160; i++)
1141acd27e7Smillert newmap[i].function = rl_insert;
1151acd27e7Smillert
1161acd27e7Smillert /* ISO Latin-1 printing characters should self-insert. */
1171acd27e7Smillert for (i = 160; i < 256; i++)
1181acd27e7Smillert newmap[i].function = rl_insert;
1191acd27e7Smillert #endif /* KEYMAP_SIZE > 128 */
1201acd27e7Smillert
1211acd27e7Smillert return (newmap);
1221acd27e7Smillert }
1231acd27e7Smillert
1241acd27e7Smillert /* Free the storage associated with MAP. */
1251acd27e7Smillert void
rl_discard_keymap(map)1261acd27e7Smillert rl_discard_keymap (map)
1271acd27e7Smillert Keymap map;
1281acd27e7Smillert {
1291acd27e7Smillert int i;
1301acd27e7Smillert
1311acd27e7Smillert if (!map)
1321acd27e7Smillert return;
1331acd27e7Smillert
1341acd27e7Smillert for (i = 0; i < KEYMAP_SIZE; i++)
1351acd27e7Smillert {
1361acd27e7Smillert switch (map[i].type)
1371acd27e7Smillert {
1381acd27e7Smillert case ISFUNC:
1391acd27e7Smillert break;
1401acd27e7Smillert
1411acd27e7Smillert case ISKMAP:
1421acd27e7Smillert rl_discard_keymap ((Keymap)map[i].function);
1431acd27e7Smillert break;
1441acd27e7Smillert
1451acd27e7Smillert case ISMACR:
1461acd27e7Smillert free ((char *)map[i].function);
1471acd27e7Smillert break;
1481acd27e7Smillert }
1491acd27e7Smillert }
1501acd27e7Smillert }
151