funmap.c 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. /* funmap.c -- attach names to functions. */
  2. /* Copyright (C) 1987-2010 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 (BUFSIZ)
  21. #include <stdio.h>
  22. #endif /* BUFSIZ */
  23. #if defined (HAVE_STDLIB_H)
  24. # include <stdlib.h>
  25. #else
  26. # include "ansi_stdlib.h"
  27. #endif /* HAVE_STDLIB_H */
  28. #include "rlconf.h"
  29. #include "readline.h"
  30. #include "xmalloc.h"
  31. #ifdef __STDC__
  32. typedef int QSFUNC (const void *, const void *);
  33. #else
  34. typedef int QSFUNC ();
  35. #endif
  36. extern int _rl_qsort_string_compare PARAMS((char **, char **));
  37. FUNMAP **funmap;
  38. static int funmap_size;
  39. static int funmap_entry;
  40. /* After initializing the function map, this is the index of the first
  41. program specific function. */
  42. int funmap_program_specific_entry_start;
  43. static const FUNMAP default_funmap[] = {
  44. { "abort", rl_abort },
  45. { "accept-line", rl_newline },
  46. { "arrow-key-prefix", rl_arrow_keys },
  47. { "backward-byte", rl_backward_byte },
  48. { "backward-char", rl_backward_char },
  49. { "backward-delete-char", rl_rubout },
  50. { "backward-kill-line", rl_backward_kill_line },
  51. { "backward-kill-word", rl_backward_kill_word },
  52. { "backward-word", rl_backward_word },
  53. { "beginning-of-history", rl_beginning_of_history },
  54. { "beginning-of-line", rl_beg_of_line },
  55. { "call-last-kbd-macro", rl_call_last_kbd_macro },
  56. { "capitalize-word", rl_capitalize_word },
  57. { "character-search", rl_char_search },
  58. { "character-search-backward", rl_backward_char_search },
  59. { "clear-screen", rl_clear_screen },
  60. { "complete", rl_complete },
  61. { "copy-backward-word", rl_copy_backward_word },
  62. { "copy-forward-word", rl_copy_forward_word },
  63. { "copy-region-as-kill", rl_copy_region_to_kill },
  64. { "delete-char", rl_delete },
  65. { "delete-char-or-list", rl_delete_or_show_completions },
  66. { "delete-horizontal-space", rl_delete_horizontal_space },
  67. { "digit-argument", rl_digit_argument },
  68. { "do-lowercase-version", rl_do_lowercase_version },
  69. { "downcase-word", rl_downcase_word },
  70. { "dump-functions", rl_dump_functions },
  71. { "dump-macros", rl_dump_macros },
  72. { "dump-variables", rl_dump_variables },
  73. { "emacs-editing-mode", rl_emacs_editing_mode },
  74. { "end-kbd-macro", rl_end_kbd_macro },
  75. { "end-of-history", rl_end_of_history },
  76. { "end-of-line", rl_end_of_line },
  77. { "exchange-point-and-mark", rl_exchange_point_and_mark },
  78. { "forward-backward-delete-char", rl_rubout_or_delete },
  79. { "forward-byte", rl_forward_byte },
  80. { "forward-char", rl_forward_char },
  81. { "forward-search-history", rl_forward_search_history },
  82. { "forward-word", rl_forward_word },
  83. { "history-search-backward", rl_history_search_backward },
  84. { "history-search-forward", rl_history_search_forward },
  85. { "insert-comment", rl_insert_comment },
  86. { "insert-completions", rl_insert_completions },
  87. { "kill-whole-line", rl_kill_full_line },
  88. { "kill-line", rl_kill_line },
  89. { "kill-region", rl_kill_region },
  90. { "kill-word", rl_kill_word },
  91. { "menu-complete", rl_menu_complete },
  92. { "menu-complete-backward", rl_backward_menu_complete },
  93. { "next-history", rl_get_next_history },
  94. { "non-incremental-forward-search-history", rl_noninc_forward_search },
  95. { "non-incremental-reverse-search-history", rl_noninc_reverse_search },
  96. { "non-incremental-forward-search-history-again", rl_noninc_forward_search_again },
  97. { "non-incremental-reverse-search-history-again", rl_noninc_reverse_search_again },
  98. { "old-menu-complete", rl_old_menu_complete },
  99. { "overwrite-mode", rl_overwrite_mode },
  100. #ifdef __CYGWIN__
  101. { "paste-from-clipboard", rl_paste_from_clipboard },
  102. #endif
  103. { "possible-completions", rl_possible_completions },
  104. { "previous-history", rl_get_previous_history },
  105. { "quoted-insert", rl_quoted_insert },
  106. { "re-read-init-file", rl_re_read_init_file },
  107. { "redraw-current-line", rl_refresh_line},
  108. { "reverse-search-history", rl_reverse_search_history },
  109. { "revert-line", rl_revert_line },
  110. { "self-insert", rl_insert },
  111. { "set-mark", rl_set_mark },
  112. { "skip-csi-sequence", rl_skip_csi_sequence },
  113. { "start-kbd-macro", rl_start_kbd_macro },
  114. { "tab-insert", rl_tab_insert },
  115. { "tilde-expand", rl_tilde_expand },
  116. { "transpose-chars", rl_transpose_chars },
  117. { "transpose-words", rl_transpose_words },
  118. { "tty-status", rl_tty_status },
  119. { "undo", rl_undo_command },
  120. { "universal-argument", rl_universal_argument },
  121. { "unix-filename-rubout", rl_unix_filename_rubout },
  122. { "unix-line-discard", rl_unix_line_discard },
  123. { "unix-word-rubout", rl_unix_word_rubout },
  124. { "upcase-word", rl_upcase_word },
  125. { "yank", rl_yank },
  126. { "yank-last-arg", rl_yank_last_arg },
  127. { "yank-nth-arg", rl_yank_nth_arg },
  128. { "yank-pop", rl_yank_pop },
  129. #if defined (VI_MODE)
  130. { "vi-append-eol", rl_vi_append_eol },
  131. { "vi-append-mode", rl_vi_append_mode },
  132. { "vi-arg-digit", rl_vi_arg_digit },
  133. { "vi-back-to-indent", rl_vi_back_to_indent },
  134. { "vi-backward-bigword", rl_vi_bWord },
  135. { "vi-backward-word", rl_vi_bword },
  136. { "vi-bWord", rl_vi_bWord },
  137. { "vi-bword", rl_vi_bword },
  138. { "vi-change-case", rl_vi_change_case },
  139. { "vi-change-char", rl_vi_change_char },
  140. { "vi-change-to", rl_vi_change_to },
  141. { "vi-char-search", rl_vi_char_search },
  142. { "vi-column", rl_vi_column },
  143. { "vi-complete", rl_vi_complete },
  144. { "vi-delete", rl_vi_delete },
  145. { "vi-delete-to", rl_vi_delete_to },
  146. { "vi-eWord", rl_vi_eWord },
  147. { "vi-editing-mode", rl_vi_editing_mode },
  148. { "vi-end-bigword", rl_vi_eWord },
  149. { "vi-end-word", rl_vi_end_word },
  150. { "vi-eof-maybe", rl_vi_eof_maybe },
  151. { "vi-eword", rl_vi_eword },
  152. { "vi-fWord", rl_vi_fWord },
  153. { "vi-fetch-history", rl_vi_fetch_history },
  154. { "vi-first-print", rl_vi_first_print },
  155. { "vi-forward-bigword", rl_vi_fWord },
  156. { "vi-forward-word", rl_vi_fword },
  157. { "vi-fword", rl_vi_fword },
  158. { "vi-goto-mark", rl_vi_goto_mark },
  159. { "vi-insert-beg", rl_vi_insert_beg },
  160. { "vi-insertion-mode", rl_vi_insertion_mode },
  161. { "vi-match", rl_vi_match },
  162. { "vi-movement-mode", rl_vi_movement_mode },
  163. { "vi-next-word", rl_vi_next_word },
  164. { "vi-overstrike", rl_vi_overstrike },
  165. { "vi-overstrike-delete", rl_vi_overstrike_delete },
  166. { "vi-prev-word", rl_vi_prev_word },
  167. { "vi-put", rl_vi_put },
  168. { "vi-redo", rl_vi_redo },
  169. { "vi-replace", rl_vi_replace },
  170. { "vi-rubout", rl_vi_rubout },
  171. { "vi-search", rl_vi_search },
  172. { "vi-search-again", rl_vi_search_again },
  173. { "vi-set-mark", rl_vi_set_mark },
  174. { "vi-subst", rl_vi_subst },
  175. { "vi-tilde-expand", rl_vi_tilde_expand },
  176. { "vi-yank-arg", rl_vi_yank_arg },
  177. { "vi-yank-to", rl_vi_yank_to },
  178. #endif /* VI_MODE */
  179. {(char *)NULL, (rl_command_func_t *)NULL }
  180. };
  181. int
  182. rl_add_funmap_entry (name, function)
  183. const char *name;
  184. rl_command_func_t *function;
  185. {
  186. if (funmap_entry + 2 >= funmap_size)
  187. {
  188. funmap_size += 64;
  189. funmap = (FUNMAP **)xrealloc (funmap, funmap_size * sizeof (FUNMAP *));
  190. }
  191. funmap[funmap_entry] = (FUNMAP *)xmalloc (sizeof (FUNMAP));
  192. funmap[funmap_entry]->name = name;
  193. funmap[funmap_entry]->function = function;
  194. funmap[++funmap_entry] = (FUNMAP *)NULL;
  195. return funmap_entry;
  196. }
  197. static int funmap_initialized;
  198. /* Make the funmap contain all of the default entries. */
  199. void
  200. rl_initialize_funmap ()
  201. {
  202. register int i;
  203. if (funmap_initialized)
  204. return;
  205. for (i = 0; default_funmap[i].name; i++)
  206. rl_add_funmap_entry (default_funmap[i].name, default_funmap[i].function);
  207. funmap_initialized = 1;
  208. funmap_program_specific_entry_start = i;
  209. }
  210. /* Produce a NULL terminated array of known function names. The array
  211. is sorted. The array itself is allocated, but not the strings inside.
  212. You should free () the array when you done, but not the pointrs. */
  213. const char **
  214. rl_funmap_names ()
  215. {
  216. const char **result;
  217. int result_size, result_index;
  218. /* Make sure that the function map has been initialized. */
  219. rl_initialize_funmap ();
  220. for (result_index = result_size = 0, result = (const char **)NULL; funmap[result_index]; result_index++)
  221. {
  222. if (result_index + 2 > result_size)
  223. {
  224. result_size += 20;
  225. result = (const char **)xrealloc (result, result_size * sizeof (char *));
  226. }
  227. result[result_index] = funmap[result_index]->name;
  228. result[result_index + 1] = (char *)NULL;
  229. }
  230. qsort (result, result_index, sizeof (char *), (QSFUNC *)_rl_qsort_string_compare);
  231. return (result);
  232. }