keymaps.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. /* keymaps.c -- Functions and keymaps for the GNU Readline library. */
  2. /* Copyright (C) 1988,1989-2009 Free Software Foundation, Inc.
  3. This file is part of the GNU Readline Library (Readline), a library
  4. for reading lines of text with interactive input and history editing.
  5. Readline is free software: you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation, either version 3 of the License, or
  8. (at your option) any later version.
  9. Readline is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with Readline. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #define READLINE_LIBRARY
  17. #if defined (HAVE_CONFIG_H)
  18. # include <config.h>
  19. #endif
  20. #if defined (HAVE_STDLIB_H)
  21. # include <stdlib.h>
  22. #else
  23. # include "ansi_stdlib.h"
  24. #endif /* HAVE_STDLIB_H */
  25. #include <stdio.h> /* for FILE * definition for readline.h */
  26. #include "readline.h"
  27. #include "rlconf.h"
  28. #include "emacs_keymap.c"
  29. #if defined (VI_MODE)
  30. #include "vi_keymap.c"
  31. #endif
  32. #include "xmalloc.h"
  33. /* **************************************************************** */
  34. /* */
  35. /* Functions for manipulating Keymaps. */
  36. /* */
  37. /* **************************************************************** */
  38. /* Return a new, empty keymap.
  39. Free it with free() when you are done. */
  40. Keymap
  41. rl_make_bare_keymap ()
  42. {
  43. register int i;
  44. Keymap keymap;
  45. keymap = (Keymap)xmalloc (KEYMAP_SIZE * sizeof (KEYMAP_ENTRY));
  46. for (i = 0; i < KEYMAP_SIZE; i++)
  47. {
  48. keymap[i].type = ISFUNC;
  49. keymap[i].function = (rl_command_func_t *)NULL;
  50. }
  51. #if 0
  52. for (i = 'A'; i < ('Z' + 1); i++)
  53. {
  54. keymap[i].type = ISFUNC;
  55. keymap[i].function = rl_do_lowercase_version;
  56. }
  57. #endif
  58. return (keymap);
  59. }
  60. /* Return a new keymap which is a copy of MAP. Just copies pointers, does
  61. not copy text of macros or descend into child keymaps. */
  62. Keymap
  63. rl_copy_keymap (map)
  64. Keymap map;
  65. {
  66. register int i;
  67. Keymap temp;
  68. temp = rl_make_bare_keymap ();
  69. for (i = 0; i < KEYMAP_SIZE; i++)
  70. {
  71. temp[i].type = map[i].type;
  72. temp[i].function = map[i].function;
  73. }
  74. return (temp);
  75. }
  76. /* Return a new keymap with the printing characters bound to rl_insert,
  77. the uppercase Meta characters bound to run their lowercase equivalents,
  78. and the Meta digits bound to produce numeric arguments. */
  79. Keymap
  80. rl_make_keymap ()
  81. {
  82. register int i;
  83. Keymap newmap;
  84. newmap = rl_make_bare_keymap ();
  85. /* All ASCII printing characters are self-inserting. */
  86. for (i = ' '; i < 127; i++)
  87. newmap[i].function = rl_insert;
  88. newmap[TAB].function = rl_insert;
  89. newmap[RUBOUT].function = rl_rubout; /* RUBOUT == 127 */
  90. newmap[CTRL('H')].function = rl_rubout;
  91. #if KEYMAP_SIZE > 128
  92. /* Printing characters in ISO Latin-1 and some 8-bit character sets. */
  93. for (i = 128; i < 256; i++)
  94. newmap[i].function = rl_insert;
  95. #endif /* KEYMAP_SIZE > 128 */
  96. return (newmap);
  97. }
  98. /* Free the storage associated with MAP. */
  99. void
  100. rl_discard_keymap (map)
  101. Keymap map;
  102. {
  103. int i;
  104. if (map == 0)
  105. return;
  106. for (i = 0; i < KEYMAP_SIZE; i++)
  107. {
  108. switch (map[i].type)
  109. {
  110. case ISFUNC:
  111. break;
  112. case ISKMAP:
  113. rl_discard_keymap ((Keymap)map[i].function);
  114. xfree ((char *)map[i].function);
  115. break;
  116. case ISMACR:
  117. xfree ((char *)map[i].function);
  118. break;
  119. }
  120. }
  121. }
  122. /* Convenience function that discards, then frees, MAP. */
  123. void
  124. rl_free_keymap (map)
  125. Keymap map;
  126. {
  127. rl_discard_keymap (map);
  128. xfree ((char *)map);
  129. }