home *** CD-ROM | disk | FTP | other *** search
/ Il CD di internet / CD.iso / SOURCE / D / CLISP / CLISPSRC.TAR / clisp-1995-01-01 / src / readline / keymaps.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-10-31  |  4.3 KB  |  186 lines

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