121308Sache/* keymaps.c -- Functions and keymaps for the GNU Readline library. */
221308Sache
321308Sache/* Copyright (C) 1988,1989 Free Software Foundation, Inc.
421308Sache
521308Sache   This file is part of GNU Readline, a library for reading lines
621308Sache   of text with interactive input and history editing.
721308Sache
821308Sache   Readline is free software; you can redistribute it and/or modify it
921308Sache   under the terms of the GNU General Public License as published by the
1058310Sache   Free Software Foundation; either version 2, or (at your option) any
1121308Sache   later version.
1221308Sache
1321308Sache   Readline is distributed in the hope that it will be useful, but
1421308Sache   WITHOUT ANY WARRANTY; without even the implied warranty of
1521308Sache   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
1621308Sache   General Public License for more details.
1721308Sache
1821308Sache   You should have received a copy of the GNU General Public License
1921308Sache   along with Readline; see the file COPYING.  If not, write to the Free
2058310Sache   Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA. */
2121308Sache#define READLINE_LIBRARY
2221308Sache
2321308Sache#if defined (HAVE_CONFIG_H)
2421308Sache#  include <config.h>
2521308Sache#endif
2621308Sache
2721308Sache#if defined (HAVE_STDLIB_H)
2821308Sache#  include <stdlib.h>
2921308Sache#else
3021308Sache#  include "ansi_stdlib.h"
3121308Sache#endif /* HAVE_STDLIB_H */
3221308Sache
3358310Sache#include <stdio.h>	/* for FILE * definition for readline.h */
3458310Sache
3558310Sache#include "readline.h"
3621308Sache#include "rlconf.h"
3758310Sache
3821308Sache#include "emacs_keymap.c"
3921308Sache
4021308Sache#if defined (VI_MODE)
4121308Sache#include "vi_keymap.c"
4221308Sache#endif
4321308Sache
4458310Sache#include "xmalloc.h"
4521308Sache
4621308Sache/* **************************************************************** */
4721308Sache/*								    */
4821308Sache/*		      Functions for manipulating Keymaps.	    */
4921308Sache/*								    */
5021308Sache/* **************************************************************** */
5121308Sache
5221308Sache
5321308Sache/* Return a new, empty keymap.
5421308Sache   Free it with free() when you are done. */
5521308SacheKeymap
5621308Sacherl_make_bare_keymap ()
5721308Sache{
5821308Sache  register int i;
5921308Sache  Keymap keymap = (Keymap)xmalloc (KEYMAP_SIZE * sizeof (KEYMAP_ENTRY));
6021308Sache
6121308Sache  for (i = 0; i < KEYMAP_SIZE; i++)
6221308Sache    {
6321308Sache      keymap[i].type = ISFUNC;
6475406Sache      keymap[i].function = (rl_command_func_t *)NULL;
6521308Sache    }
6621308Sache
67136644Sache#if 0
6821308Sache  for (i = 'A'; i < ('Z' + 1); i++)
6921308Sache    {
7021308Sache      keymap[i].type = ISFUNC;
7121308Sache      keymap[i].function = rl_do_lowercase_version;
7221308Sache    }
73136644Sache#endif
7421308Sache
7521308Sache  return (keymap);
7621308Sache}
7721308Sache
7821308Sache/* Return a new keymap which is a copy of MAP. */
7921308SacheKeymap
8021308Sacherl_copy_keymap (map)
8121308Sache     Keymap map;
8221308Sache{
8321308Sache  register int i;
84136644Sache  Keymap temp;
8521308Sache
86136644Sache  temp = rl_make_bare_keymap ();
8721308Sache  for (i = 0; i < KEYMAP_SIZE; i++)
8821308Sache    {
8921308Sache      temp[i].type = map[i].type;
9021308Sache      temp[i].function = map[i].function;
9121308Sache    }
9221308Sache  return (temp);
9321308Sache}
9421308Sache
9521308Sache/* Return a new keymap with the printing characters bound to rl_insert,
9621308Sache   the uppercase Meta characters bound to run their lowercase equivalents,
9721308Sache   and the Meta digits bound to produce numeric arguments. */
9821308SacheKeymap
9921308Sacherl_make_keymap ()
10021308Sache{
10121308Sache  register int i;
10221308Sache  Keymap newmap;
10321308Sache
10421308Sache  newmap = rl_make_bare_keymap ();
10521308Sache
10621308Sache  /* All ASCII printing characters are self-inserting. */
10721308Sache  for (i = ' '; i < 127; i++)
10821308Sache    newmap[i].function = rl_insert;
10921308Sache
11021308Sache  newmap[TAB].function = rl_insert;
11121308Sache  newmap[RUBOUT].function = rl_rubout;	/* RUBOUT == 127 */
11221308Sache  newmap[CTRL('H')].function = rl_rubout;
11321308Sache
11421308Sache#if KEYMAP_SIZE > 128
115136644Sache  /* Printing characters in ISO Latin-1 and some 8-bit character sets. */
116136644Sache  for (i = 128; i < 256; i++)
11721308Sache    newmap[i].function = rl_insert;
11821308Sache#endif /* KEYMAP_SIZE > 128 */
11921308Sache
12021308Sache  return (newmap);
12121308Sache}
12221308Sache
12321308Sache/* Free the storage associated with MAP. */
12421308Sachevoid
12521308Sacherl_discard_keymap (map)
12647558Sache     Keymap map;
12721308Sache{
12821308Sache  int i;
12921308Sache
13021308Sache  if (!map)
13121308Sache    return;
13221308Sache
13321308Sache  for (i = 0; i < KEYMAP_SIZE; i++)
13421308Sache    {
13521308Sache      switch (map[i].type)
13621308Sache	{
13721308Sache	case ISFUNC:
13821308Sache	  break;
13921308Sache
14021308Sache	case ISKMAP:
14121308Sache	  rl_discard_keymap ((Keymap)map[i].function);
14221308Sache	  break;
14321308Sache
14421308Sache	case ISMACR:
14521308Sache	  free ((char *)map[i].function);
14621308Sache	  break;
14721308Sache	}
14821308Sache    }
14921308Sache}
150