funmap.c revision 75406
1157114Sscottl/* funmap.c -- attach names to functions. */
2157114Sscottl
3157114Sscottl/* Copyright (C) 1987, 1989, 1992 Free Software Foundation, Inc.
4157114Sscottl
5157114Sscottl   This file is part of the GNU Readline Library, a library for
6157114Sscottl   reading lines of text with interactive input and history editing.
7157114Sscottl
8157114Sscottl   The GNU Readline Library is free software; you can redistribute it
9157114Sscottl   and/or modify it under the terms of the GNU General Public License
10157114Sscottl   as published by the Free Software Foundation; either version 2, or
11157114Sscottl   (at your option) any later version.
12157114Sscottl
13157114Sscottl   The GNU Readline Library is distributed in the hope that it will be
14157114Sscottl   useful, but WITHOUT ANY WARRANTY; without even the implied warranty
15157114Sscottl   of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16157114Sscottl   GNU General Public License for more details.
17157114Sscottl
18157114Sscottl   The GNU General Public License is often shipped with GNU software, and
19157114Sscottl   is generally kept in a file called COPYING or LICENSE.  If you do not
20157114Sscottl   have a copy of the license, write to the Free Software Foundation,
21157114Sscottl   59 Temple Place, Suite 330, Boston, MA 02111 USA. */
22157114Sscottl#define READLINE_LIBRARY
23157114Sscottl
24157114Sscottl#if defined (HAVE_CONFIG_H)
25157114Sscottl#  include <config.h>
26171980Sscottl#endif
27171980Sscottl
28171980Sscottl#if !defined (BUFSIZ)
29171980Sscottl#include <stdio.h>
30171980Sscottl#endif /* BUFSIZ */
31171980Sscottl
32171980Sscottl#if defined (HAVE_STDLIB_H)
33171980Sscottl#  include <stdlib.h>
34171980Sscottl#else
35171980Sscottl#  include "ansi_stdlib.h"
36171980Sscottl#endif /* HAVE_STDLIB_H */
37171980Sscottl
38171980Sscottl#include "rlconf.h"
39171980Sscottl#include "readline.h"
40171980Sscottl
41171980Sscottl#include "xmalloc.h"
42171980Sscottl
43171980Sscottl#ifdef __STDC__
44171980Sscottltypedef int QSFUNC (const void *, const void *);
45171980Sscottl#else
46171980Sscottltypedef int QSFUNC ();
47171980Sscottl#endif
48171980Sscottl
49171980Sscottlextern int _rl_qsort_string_compare __P((char **, char **));
50171980Sscottl
51171980SscottlFUNMAP **funmap;
52157114Sscottlstatic int funmap_size;
53157114Sscottlstatic int funmap_entry;
54157114Sscottl
55157114Sscottl/* After initializing the function map, this is the index of the first
56157114Sscottl   program specific function. */
57157114Sscottlint funmap_program_specific_entry_start;
58157114Sscottl
59157114Sscottlstatic FUNMAP default_funmap[] = {
60162118Sambrisko  { "abort", rl_abort },
61157114Sscottl  { "accept-line", rl_newline },
62157114Sscottl  { "arrow-key-prefix", rl_arrow_keys },
63158737Sambrisko  { "backward-char", rl_backward },
64158737Sambrisko  { "backward-delete-char", rl_rubout },
65157114Sscottl  { "backward-kill-line", rl_backward_kill_line },
66157114Sscottl  { "backward-kill-word", rl_backward_kill_word },
67157114Sscottl  { "backward-word", rl_backward_word },
68157114Sscottl  { "beginning-of-history", rl_beginning_of_history },
69157114Sscottl  { "beginning-of-line", rl_beg_of_line },
70157114Sscottl  { "call-last-kbd-macro", rl_call_last_kbd_macro },
71157114Sscottl  { "capitalize-word", rl_capitalize_word },
72158737Sambrisko  { "character-search", rl_char_search },
73158737Sambrisko  { "character-search-backward", rl_backward_char_search },
74163398Sscottl  { "clear-screen", rl_clear_screen },
75157114Sscottl  { "complete", rl_complete },
76157114Sscottl  { "copy-backward-word", rl_copy_backward_word },
77157114Sscottl  { "copy-forward-word", rl_copy_forward_word },
78157114Sscottl  { "copy-region-as-kill", rl_copy_region_to_kill },
79157114Sscottl  { "delete-char", rl_delete },
80157114Sscottl  { "delete-char-or-list", rl_delete_or_show_completions },
81157114Sscottl  { "delete-horizontal-space", rl_delete_horizontal_space },
82157114Sscottl  { "digit-argument", rl_digit_argument },
83157114Sscottl  { "do-lowercase-version", rl_do_lowercase_version },
84157114Sscottl  { "downcase-word", rl_downcase_word },
85159811Sps  { "dump-functions", rl_dump_functions },
86157114Sscottl  { "dump-macros", rl_dump_macros },
87158737Sambrisko  { "dump-variables", rl_dump_variables },
88159806Sps  { "emacs-editing-mode", rl_emacs_editing_mode },
89180037Sjhb  { "end-kbd-macro", rl_end_kbd_macro },
90159806Sps  { "end-of-history", rl_end_of_history },
91159806Sps  { "end-of-line", rl_end_of_line },
92157114Sscottl  { "exchange-point-and-mark", rl_exchange_point_and_mark },
93157114Sscottl  { "forward-backward-delete-char", rl_rubout_or_delete },
94157114Sscottl  { "forward-char", rl_forward },
95159811Sps  { "forward-search-history", rl_forward_search_history },
96158737Sambrisko  { "forward-word", rl_forward_word },
97158737Sambrisko  { "history-search-backward", rl_history_search_backward },
98158737Sambrisko  { "history-search-forward", rl_history_search_forward },
99159811Sps  { "insert-comment", rl_insert_comment },
100159811Sps  { "insert-completions", rl_insert_completions },
101157114Sscottl  { "kill-whole-line", rl_kill_full_line },
102157114Sscottl  { "kill-line", rl_kill_line },
103157114Sscottl  { "kill-region", rl_kill_region },
104157114Sscottl  { "kill-word", rl_kill_word },
105157114Sscottl  { "menu-complete", rl_menu_complete },
106158737Sambrisko  { "next-history", rl_get_next_history },
107192450Simp  { "non-incremental-forward-search-history", rl_noninc_forward_search },
108162619Sscottl  { "non-incremental-reverse-search-history", rl_noninc_reverse_search },
109178968Sscottl  { "non-incremental-forward-search-history-again", rl_noninc_forward_search_again },
110178968Sscottl  { "non-incremental-reverse-search-history-again", rl_noninc_reverse_search_again },
111171980Sscottl#ifdef __CYGWIN__
112171980Sscottl  { "paste-from-clipboard", rl_paste_from_clipboard },
113171980Sscottl#endif
114171980Sscottl  { "possible-completions", rl_possible_completions },
115171980Sscottl  { "previous-history", rl_get_previous_history },
116171980Sscottl  { "quoted-insert", rl_quoted_insert },
117171980Sscottl  { "re-read-init-file", rl_re_read_init_file },
118171980Sscottl  { "redraw-current-line", rl_refresh_line},
119157114Sscottl  { "reverse-search-history", rl_reverse_search_history },
120162118Sambrisko  { "revert-line", rl_revert_line },
121162118Sambrisko  { "self-insert", rl_insert },
122162473Sambrisko  { "set-mark", rl_set_mark },
123162118Sambrisko  { "start-kbd-macro", rl_start_kbd_macro },
124162118Sambrisko  { "tab-insert", rl_tab_insert },
125162473Sambrisko  { "tilde-expand", rl_tilde_expand },
126165852Sscottl  { "transpose-chars", rl_transpose_chars },
127162473Sambrisko  { "transpose-words", rl_transpose_words },
128162118Sambrisko  { "tty-status", rl_tty_status },
129162118Sambrisko  { "undo", rl_undo_command },
130162118Sambrisko  { "universal-argument", rl_universal_argument },
131178968Sscottl  { "unix-line-discard", rl_unix_line_discard },
132178968Sscottl  { "unix-word-rubout", rl_unix_word_rubout },
133178968Sscottl  { "upcase-word", rl_upcase_word },
134178968Sscottl  { "yank", rl_yank },
135178968Sscottl  { "yank-last-arg", rl_yank_last_arg },
136157114Sscottl  { "yank-nth-arg", rl_yank_nth_arg },
137157114Sscottl  { "yank-pop", rl_yank_pop },
138157114Sscottl
139157114Sscottl#if defined (VI_MODE)
140158737Sambrisko  { "vi-append-eol", rl_vi_append_eol },
141157114Sscottl  { "vi-append-mode", rl_vi_append_mode },
142157114Sscottl  { "vi-arg-digit", rl_vi_arg_digit },
143157114Sscottl  { "vi-back-to-indent", rl_vi_back_to_indent },
144157114Sscottl  { "vi-bWord", rl_vi_bWord },
145157114Sscottl  { "vi-bword", rl_vi_bword },
146157114Sscottl  { "vi-change-case", rl_vi_change_case },
147157114Sscottl  { "vi-change-char", rl_vi_change_char },
148158737Sambrisko  { "vi-change-to", rl_vi_change_to },
149157114Sscottl  { "vi-char-search", rl_vi_char_search },
150157114Sscottl  { "vi-column", rl_vi_column },
151157114Sscottl  { "vi-complete", rl_vi_complete },
152157114Sscottl  { "vi-delete", rl_vi_delete },
153157114Sscottl  { "vi-delete-to", rl_vi_delete_to },
154158737Sambrisko  { "vi-eWord", rl_vi_eWord },
155157114Sscottl  { "vi-editing-mode", rl_vi_editing_mode },
156171980Sscottl  { "vi-end-word", rl_vi_end_word },
157171980Sscottl  { "vi-eof-maybe", rl_vi_eof_maybe },
158171980Sscottl  { "vi-eword", rl_vi_eword },
159171980Sscottl  { "vi-fWord", rl_vi_fWord },
160171980Sscottl  { "vi-fetch-history", rl_vi_fetch_history },
161171980Sscottl  { "vi-first-print", rl_vi_first_print },
162171980Sscottl  { "vi-fword", rl_vi_fword },
163171980Sscottl  { "vi-goto-mark", rl_vi_goto_mark },
164171980Sscottl  { "vi-insert-beg", rl_vi_insert_beg },
165171980Sscottl  { "vi-insertion-mode", rl_vi_insertion_mode },
166184897Sambrisko  { "vi-match", rl_vi_match },
167184897Sambrisko  { "vi-movement-mode", rl_vi_movement_mode },
168184897Sambrisko  { "vi-next-word", rl_vi_next_word },
169184897Sambrisko  { "vi-overstrike", rl_vi_overstrike },
170184897Sambrisko  { "vi-overstrike-delete", rl_vi_overstrike_delete },
171171980Sscottl  { "vi-prev-word", rl_vi_prev_word },
172171980Sscottl  { "vi-put", rl_vi_put },
173171980Sscottl  { "vi-redo", rl_vi_redo },
174171980Sscottl  { "vi-replace", rl_vi_replace },
175171980Sscottl  { "vi-search", rl_vi_search },
176171980Sscottl  { "vi-search-again", rl_vi_search_again },
177171980Sscottl  { "vi-set-mark", rl_vi_set_mark },
178184897Sambrisko  { "vi-subst", rl_vi_subst },
179171980Sscottl  { "vi-tilde-expand", rl_vi_tilde_expand },
180171980Sscottl  { "vi-yank-arg", rl_vi_yank_arg },
181171980Sscottl  { "vi-yank-to", rl_vi_yank_to },
182171980Sscottl#endif /* VI_MODE */
183171980Sscottl
184171980Sscottl {(char *)NULL, (rl_command_func_t *)NULL }
185184897Sambrisko};
186171980Sscottl
187171980Sscottlint
188171980Sscottlrl_add_funmap_entry (name, function)
189171980Sscottl     const char *name;
190171980Sscottl     rl_command_func_t *function;
191171980Sscottl{
192171980Sscottl  if (funmap_entry + 2 >= funmap_size)
193171980Sscottl    {
194171980Sscottl      funmap_size += 64;
195171980Sscottl      funmap = (FUNMAP **)xrealloc (funmap, funmap_size * sizeof (FUNMAP *));
196182085Simp    }
197171980Sscottl
198184897Sambrisko  funmap[funmap_entry] = (FUNMAP *)xmalloc (sizeof (FUNMAP));
199171980Sscottl  funmap[funmap_entry]->name = name;
200171980Sscottl  funmap[funmap_entry]->function = function;
201171980Sscottl
202171980Sscottl  funmap[++funmap_entry] = (FUNMAP *)NULL;
203171980Sscottl  return funmap_entry;
204184897Sambrisko}
205184897Sambrisko
206184897Sambriskostatic int funmap_initialized;
207184897Sambrisko
208184897Sambrisko/* Make the funmap contain all of the default entries. */
209184897Sambriskovoid
210184897Sambriskorl_initialize_funmap ()
211184897Sambrisko{
212184897Sambrisko  register int i;
213171980Sscottl
214171980Sscottl  if (funmap_initialized)
215171980Sscottl    return;
216182085Simp
217171980Sscottl  for (i = 0; default_funmap[i].name; i++)
218184897Sambrisko    rl_add_funmap_entry (default_funmap[i].name, default_funmap[i].function);
219171980Sscottl
220171980Sscottl  funmap_initialized = 1;
221171980Sscottl  funmap_program_specific_entry_start = i;
222171980Sscottl}
223184897Sambrisko
224184897Sambrisko/* Produce a NULL terminated array of known function names.  The array
225171980Sscottl   is sorted.  The array itself is allocated, but not the strings inside.
226171980Sscottl   You should free () the array when you done, but not the pointrs. */
227171980Sscottlconst char **
228171980Sscottlrl_funmap_names ()
229171980Sscottl{
230157114Sscottl  const char **result;
231157114Sscottl  int result_size, result_index;
232157114Sscottl
233194851Sscottl  /* Make sure that the function map has been initialized. */
234157114Sscottl  rl_initialize_funmap ();
235157114Sscottl
236171980Sscottl  for (result_index = result_size = 0, result = (const char **)NULL; funmap[result_index]; result_index++)
237157114Sscottl    {
238157114Sscottl      if (result_index + 2 > result_size)
239157114Sscottl	{
240171980Sscottl	  result_size += 20;
241157114Sscottl	  result = (const char **)xrealloc (result, result_size * sizeof (char *));
242157114Sscottl	}
243157114Sscottl
244157114Sscottl      result[result_index] = funmap[result_index]->name;
245157114Sscottl      result[result_index + 1] = (char *)NULL;
246157114Sscottl    }
247157114Sscottl
248157114Sscottl  qsort (result, result_index, sizeof (char *), (QSFUNC *)_rl_qsort_string_compare);
249157114Sscottl  return (result);
250157114Sscottl}
251157114Sscottl