home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / gnu / gdb-4.12.tar.gz / gdb-4.12.tar / gdb-4.12 / readline / keymaps.c < prev    next >
C/C++ Source or Header  |  1994-02-03  |  4KB  |  181 lines

  1. /* keymaps.c -- Functions and keymaps for the GNU Readline library. */
  2.  
  3. /* Copyright (C) 1988, 1989, 1991 Free Software Foundation, Inc.
  4.  
  5.    This file is part of GNU Readline, a library for reading lines
  6.    of text with interactive input and history editing.
  7.  
  8.    Readline is free software; you can redistribute it and/or modify
  9.    it under the terms of the GNU General Public License as published by
  10.    the Free Software Foundation; either version 2 of the License, or
  11.    (at your option) any later version.
  12.  
  13.    Readline is distributed in the hope that it will be useful,
  14.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16.    GNU General Public License for more details.
  17.  
  18.    You should have received a copy of the GNU General Public License
  19.    along with this program; if not, write to the Free Software
  20.    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  21.  
  22. #include "sysdep.h"
  23. #include <stdio.h>
  24. #include "readline.h"
  25. #include "keymaps.h"
  26. #include "emacs_keymap.c"
  27.  
  28. #ifdef VI_MODE
  29. #include "vi_keymap.c"
  30. #endif
  31.  
  32. /* Remove these declarations when we have a complete libgnu.a. */
  33. /* #define STATIC_MALLOC */
  34. #if !defined (STATIC_MALLOC)
  35. extern char *xmalloc (), *xrealloc ();
  36. #else
  37. static char *xmalloc (), *xrealloc ();
  38. #endif /* STATIC_MALLOC */
  39.  
  40. /* **************************************************************** */
  41. /*                                    */
  42. /*              Functions for manipulating Keymaps.        */
  43. /*                                    */
  44. /* **************************************************************** */
  45.  
  46.  
  47. /* Return a new, empty keymap.
  48.    Free it with free() when you are done. */
  49. Keymap
  50. rl_make_bare_keymap ()
  51. {
  52.   register int i;
  53.   Keymap keymap = (Keymap)xmalloc (128 * sizeof (KEYMAP_ENTRY));
  54.  
  55.   for (i = 0; i < 128; i++)
  56.     {
  57.       keymap[i].type = ISFUNC;
  58.       keymap[i].function = (Function *)NULL;
  59.     }
  60.  
  61.   for (i = 'A'; i < ('Z' + 1); i++)
  62.     {
  63.       keymap[i].type = ISFUNC;
  64.       keymap[i].function = rl_do_lowercase_version;
  65.     }
  66.  
  67.   return (keymap);
  68. }
  69.  
  70. /* Return a new keymap which is a copy of MAP. */
  71. Keymap
  72. rl_copy_keymap (map)
  73.      Keymap map;
  74. {
  75.   register int i;
  76.   Keymap temp = rl_make_bare_keymap ();
  77.  
  78.   for (i = 0; i < 128; i++)
  79.     {
  80.       temp[i].type = map[i].type;
  81.       temp[i].function = map[i].function;
  82.     }
  83.   return (temp);
  84. }
  85.  
  86. /* Return a new keymap with the printing characters bound to rl_insert,
  87.    the uppercase Meta characters bound to run their lowercase equivalents,
  88.    and the Meta digits bound to produce numeric arguments. */
  89. Keymap
  90. rl_make_keymap ()
  91. {
  92.   extern rl_insert (), rl_rubout ();
  93.   register int i;
  94.   Keymap newmap;
  95.  
  96.   newmap = rl_make_bare_keymap ();
  97.  
  98.   /* All printing characters are self-inserting. */
  99.   for (i = ' '; i < 126; i++)
  100.     newmap[i].function = rl_insert;
  101.  
  102.   newmap[TAB].function = rl_insert;
  103.   newmap[RUBOUT].function = rl_rubout;
  104.   newmap[CTRL('H')].function = rl_rubout;
  105.  
  106.   return (newmap);
  107. }
  108.  
  109. /* Free the storage associated with MAP. */
  110. rl_discard_keymap (map)
  111.      Keymap (map);
  112. {
  113.   int i;
  114.  
  115.   if (!map)
  116.     return;
  117.  
  118.   for (i = 0; i < 128; i++)
  119.     {
  120.       switch (map[i].type)
  121.     {
  122.     case ISFUNC:
  123.       break;
  124.  
  125.     case ISKMAP:
  126.       rl_discard_keymap ((Keymap)map[i].function);
  127.       break;
  128.  
  129.     case ISMACR:
  130.       free ((char *)map[i].function);
  131.       break;
  132.     }
  133.     }
  134. }
  135.  
  136. #ifdef STATIC_MALLOC
  137.  
  138. /* **************************************************************** */
  139. /*                                    */
  140. /*            xmalloc and xrealloc ()                     */
  141. /*                                    */
  142. /* **************************************************************** */
  143.  
  144. static void memory_error_and_abort ();
  145.  
  146. static char *
  147. xmalloc (bytes)
  148.      int bytes;
  149. {
  150.   char *temp = (char *)malloc (bytes);
  151.  
  152.   if (!temp)
  153.     memory_error_and_abort ();
  154.   return (temp);
  155. }
  156.  
  157. static char *
  158. xrealloc (pointer, bytes)
  159.      char *pointer;
  160.      int bytes;
  161. {
  162.   char *temp;
  163.  
  164.   if (!pointer)
  165.     temp = (char *)malloc (bytes);
  166.   else
  167.     temp = (char *)realloc (pointer, bytes);
  168.  
  169.   if (!temp)
  170.     memory_error_and_abort ();
  171.   return (temp);
  172. }
  173.  
  174. static void
  175. memory_error_and_abort ()
  176. {
  177.   fprintf (stderr, "readline: Out of virtual memory!\n");
  178.   abort ();
  179. }
  180. #endif /* STATIC_MALLOC */
  181.