funmap.c revision 136644
12490Sjkh/* funmap.c -- attach names to functions. */
22490Sjkh
32490Sjkh/* Copyright (C) 1987, 1989, 1992 Free Software Foundation, Inc.
42490Sjkh
52490Sjkh   This file is part of the GNU Readline Library, a library for
62490Sjkh   reading lines of text with interactive input and history editing.
72490Sjkh
82490Sjkh   The GNU Readline Library is free software; you can redistribute it
92490Sjkh   and/or modify it under the terms of the GNU General Public License
102490Sjkh   as published by the Free Software Foundation; either version 2, or
112490Sjkh   (at your option) any later version.
122490Sjkh
13203932Simp   The GNU Readline Library is distributed in the hope that it will be
142490Sjkh   useful, but WITHOUT ANY WARRANTY; without even the implied warranty
152490Sjkh   of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
162490Sjkh   GNU General Public License for more details.
172490Sjkh
182490Sjkh   The GNU General Public License is often shipped with GNU software, and
192490Sjkh   is generally kept in a file called COPYING or LICENSE.  If you do not
202490Sjkh   have a copy of the license, write to the Free Software Foundation,
212490Sjkh   59 Temple Place, Suite 330, Boston, MA 02111 USA. */
222490Sjkh#define READLINE_LIBRARY
232490Sjkh
242490Sjkh#if defined (HAVE_CONFIG_H)
252490Sjkh#  include <config.h>
262490Sjkh#endif
272490Sjkh
282490Sjkh#if !defined (BUFSIZ)
292490Sjkh#include <stdio.h>
3010352Sjoerg#endif /* BUFSIZ */
31179654Sscf
32179654Sscf#if defined (HAVE_STDLIB_H)
3310352Sjoerg#  include <stdlib.h>
3410352Sjoerg#else
352490Sjkh#  include "ansi_stdlib.h"
3653920Sbillf#endif /* HAVE_STDLIB_H */
372490Sjkh
382490Sjkh#include "rlconf.h"
392490Sjkh#include "readline.h"
402490Sjkh
412490Sjkh#include "xmalloc.h"
4253920Sbillf
432490Sjkh#ifdef __STDC__
4453920Sbillftypedef int QSFUNC (const void *, const void *);
4553920Sbillf#else
4653920Sbillftypedef int QSFUNC ();
472490Sjkh#endif
482490Sjkh
4957527Sjoergextern int _rl_qsort_string_compare PARAMS((char **, char **));
5057527Sjoerg
512490SjkhFUNMAP **funmap;
5257527Sjoergstatic int funmap_size;
5378793Sachestatic int funmap_entry;
5410352Sjoerg
5557527Sjoerg/* After initializing the function map, this is the index of the first
5657527Sjoerg   program specific function. */
5710352Sjoergint funmap_program_specific_entry_start;
5835857Sjb
5957527Sjoergstatic FUNMAP default_funmap[] = {
6054622Sbillf  { "abort", rl_abort },
612490Sjkh  { "accept-line", rl_newline },
62203479Simp  { "arrow-key-prefix", rl_arrow_keys },
63203479Simp  { "backward-byte", rl_backward_byte },
64203479Simp  { "backward-char", rl_backward_char },
6510352Sjoerg  { "backward-delete-char", rl_rubout },
66152306Sru  { "backward-kill-line", rl_backward_kill_line },
6710352Sjoerg  { "backward-kill-word", rl_backward_kill_word },
6810352Sjoerg  { "backward-word", rl_backward_word },
6910352Sjoerg  { "beginning-of-history", rl_beginning_of_history },
70203921Suqs  { "beginning-of-line", rl_beg_of_line },
71203921Suqs  { "call-last-kbd-macro", rl_call_last_kbd_macro },
722490Sjkh  { "capitalize-word", rl_capitalize_word },
732490Sjkh  { "character-search", rl_char_search },
7454622Sbillf  { "character-search-backward", rl_backward_char_search },
752490Sjkh  { "clear-screen", rl_clear_screen },
7610352Sjoerg  { "complete", rl_complete },
7710352Sjoerg  { "copy-backward-word", rl_copy_backward_word },
7854622Sbillf  { "copy-forward-word", rl_copy_forward_word },
7954622Sbillf  { "copy-region-as-kill", rl_copy_region_to_kill },
8054622Sbillf  { "delete-char", rl_delete },
8154622Sbillf  { "delete-char-or-list", rl_delete_or_show_completions },
8254622Sbillf  { "delete-horizontal-space", rl_delete_horizontal_space },
8354622Sbillf  { "digit-argument", rl_digit_argument },
8454622Sbillf  { "do-lowercase-version", rl_do_lowercase_version },
8554622Sbillf  { "downcase-word", rl_downcase_word },
8654622Sbillf  { "dump-functions", rl_dump_functions },
8754622Sbillf  { "dump-macros", rl_dump_macros },
8854622Sbillf  { "dump-variables", rl_dump_variables },
8954622Sbillf  { "emacs-editing-mode", rl_emacs_editing_mode },
9054622Sbillf  { "end-kbd-macro", rl_end_kbd_macro },
9154622Sbillf  { "end-of-history", rl_end_of_history },
9254622Sbillf  { "end-of-line", rl_end_of_line },
9354622Sbillf  { "exchange-point-and-mark", rl_exchange_point_and_mark },
9454622Sbillf  { "forward-backward-delete-char", rl_rubout_or_delete },
9554622Sbillf  { "forward-byte", rl_forward_byte },
9654622Sbillf  { "forward-char", rl_forward_char },
9754622Sbillf  { "forward-search-history", rl_forward_search_history },
9854622Sbillf  { "forward-word", rl_forward_word },
9954622Sbillf  { "history-search-backward", rl_history_search_backward },
10054622Sbillf  { "history-search-forward", rl_history_search_forward },
10154622Sbillf  { "insert-comment", rl_insert_comment },
10254622Sbillf  { "insert-completions", rl_insert_completions },
10354622Sbillf  { "kill-whole-line", rl_kill_full_line },
10410352Sjoerg  { "kill-line", rl_kill_line },
10510352Sjoerg  { "kill-region", rl_kill_region },
10610352Sjoerg  { "kill-word", rl_kill_word },
10754622Sbillf  { "menu-complete", rl_menu_complete },
10854622Sbillf  { "next-history", rl_get_next_history },
10954622Sbillf  { "non-incremental-forward-search-history", rl_noninc_forward_search },
11054622Sbillf  { "non-incremental-reverse-search-history", rl_noninc_reverse_search },
11154622Sbillf  { "non-incremental-forward-search-history-again", rl_noninc_forward_search_again },
11254622Sbillf  { "non-incremental-reverse-search-history-again", rl_noninc_reverse_search_again },
11354622Sbillf  { "overwrite-mode", rl_overwrite_mode },
11454622Sbillf#ifdef __CYGWIN__
11554622Sbillf  { "paste-from-clipboard", rl_paste_from_clipboard },
11654622Sbillf#endif
11710352Sjoerg  { "possible-completions", rl_possible_completions },
11810352Sjoerg  { "previous-history", rl_get_previous_history },
11910352Sjoerg  { "quoted-insert", rl_quoted_insert },
12054622Sbillf  { "re-read-init-file", rl_re_read_init_file },
12154622Sbillf  { "redraw-current-line", rl_refresh_line},
122126040Sfanf  { "reverse-search-history", rl_reverse_search_history },
123126040Sfanf  { "revert-line", rl_revert_line },
12454622Sbillf  { "self-insert", rl_insert },
12554622Sbillf  { "set-mark", rl_set_mark },
12654622Sbillf  { "start-kbd-macro", rl_start_kbd_macro },
12754622Sbillf  { "tab-insert", rl_tab_insert },
12854622Sbillf  { "tilde-expand", rl_tilde_expand },
12954622Sbillf  { "transpose-chars", rl_transpose_chars },
13054622Sbillf  { "transpose-words", rl_transpose_words },
13154622Sbillf  { "tty-status", rl_tty_status },
13254622Sbillf  { "undo", rl_undo_command },
13354622Sbillf  { "universal-argument", rl_universal_argument },
134126044Sfanf  { "unix-filename-rubout", rl_unix_filename_rubout },
13510352Sjoerg  { "unix-line-discard", rl_unix_line_discard },
13610352Sjoerg  { "unix-word-rubout", rl_unix_word_rubout },
13710352Sjoerg  { "upcase-word", rl_upcase_word },
13854622Sbillf  { "yank", rl_yank },
139126040Sfanf  { "yank-last-arg", rl_yank_last_arg },
14054622Sbillf  { "yank-nth-arg", rl_yank_nth_arg },
14154622Sbillf  { "yank-pop", rl_yank_pop },
14210352Sjoerg
14354622Sbillf#if defined (VI_MODE)
14410352Sjoerg  { "vi-append-eol", rl_vi_append_eol },
14510352Sjoerg  { "vi-append-mode", rl_vi_append_mode },
146230131Suqs  { "vi-arg-digit", rl_vi_arg_digit },
147230131Suqs  { "vi-back-to-indent", rl_vi_back_to_indent },
148230131Suqs  { "vi-bWord", rl_vi_bWord },
149230131Suqs  { "vi-bword", rl_vi_bword },
150129114Sdds  { "vi-change-case", rl_vi_change_case },
151230131Suqs  { "vi-change-char", rl_vi_change_char },
152230131Suqs  { "vi-change-to", rl_vi_change_to },
153230131Suqs  { "vi-char-search", rl_vi_char_search },
154230131Suqs  { "vi-column", rl_vi_column },
155230131Suqs  { "vi-complete", rl_vi_complete },
156230131Suqs  { "vi-delete", rl_vi_delete },
157230131Suqs  { "vi-delete-to", rl_vi_delete_to },
158230131Suqs  { "vi-eWord", rl_vi_eWord },
159230131Suqs  { "vi-editing-mode", rl_vi_editing_mode },
160230131Suqs  { "vi-end-word", rl_vi_end_word },
16110352Sjoerg  { "vi-eof-maybe", rl_vi_eof_maybe },
16254622Sbillf  { "vi-eword", rl_vi_eword },
16310352Sjoerg  { "vi-fWord", rl_vi_fWord },
16410352Sjoerg  { "vi-fetch-history", rl_vi_fetch_history },
165230131Suqs  { "vi-first-print", rl_vi_first_print },
166230131Suqs  { "vi-fword", rl_vi_fword },
167230131Suqs  { "vi-goto-mark", rl_vi_goto_mark },
168230131Suqs  { "vi-insert-beg", rl_vi_insert_beg },
169129114Sdds  { "vi-insertion-mode", rl_vi_insertion_mode },
170129114Sdds  { "vi-match", rl_vi_match },
171129114Sdds  { "vi-movement-mode", rl_vi_movement_mode },
172129114Sdds  { "vi-next-word", rl_vi_next_word },
173129114Sdds  { "vi-overstrike", rl_vi_overstrike },
174129114Sdds  { "vi-overstrike-delete", rl_vi_overstrike_delete },
175129114Sdds  { "vi-prev-word", rl_vi_prev_word },
176221907Suqs  { "vi-put", rl_vi_put },
177129114Sdds  { "vi-redo", rl_vi_redo },
178129114Sdds  { "vi-replace", rl_vi_replace },
179129114Sdds  { "vi-search", rl_vi_search },
180129114Sdds  { "vi-search-again", rl_vi_search_again },
181221907Suqs  { "vi-set-mark", rl_vi_set_mark },
182221907Suqs  { "vi-subst", rl_vi_subst },
183129114Sdds  { "vi-tilde-expand", rl_vi_tilde_expand },
184129114Sdds  { "vi-yank-arg", rl_vi_yank_arg },
185129114Sdds  { "vi-yank-to", rl_vi_yank_to },
186129114Sdds#endif /* VI_MODE */
187129114Sdds
188230131Suqs {(char *)NULL, (rl_command_func_t *)NULL }
189230131Suqs};
190230131Suqs
191230131Suqsint
192230131Suqsrl_add_funmap_entry (name, function)
193230131Suqs     const char *name;
194230131Suqs     rl_command_func_t *function;
195230131Suqs{
196230131Suqs  if (funmap_entry + 2 >= funmap_size)
197230131Suqs    {
198230131Suqs      funmap_size += 64;
199230131Suqs      funmap = (FUNMAP **)xrealloc (funmap, funmap_size * sizeof (FUNMAP *));
200230131Suqs    }
201230131Suqs
202230131Suqs  funmap[funmap_entry] = (FUNMAP *)xmalloc (sizeof (FUNMAP));
203230131Suqs  funmap[funmap_entry]->name = name;
204230131Suqs  funmap[funmap_entry]->function = function;
205230131Suqs
206230131Suqs  funmap[++funmap_entry] = (FUNMAP *)NULL;
207230131Suqs  return funmap_entry;
208230131Suqs}
209230131Suqs
210230131Suqsstatic int funmap_initialized;
211230131Suqs
212230131Suqs/* Make the funmap contain all of the default entries. */
213230131Suqsvoid
214230131Suqsrl_initialize_funmap ()
215230131Suqs{
216230131Suqs  register int i;
217230131Suqs
218230131Suqs  if (funmap_initialized)
219230131Suqs    return;
220230131Suqs
221230131Suqs  for (i = 0; default_funmap[i].name; i++)
222230131Suqs    rl_add_funmap_entry (default_funmap[i].name, default_funmap[i].function);
223230131Suqs
224129114Sdds  funmap_initialized = 1;
225129114Sdds  funmap_program_specific_entry_start = i;
226129114Sdds}
227129114Sdds
228230131Suqs/* Produce a NULL terminated array of known function names.  The array
229230131Suqs   is sorted.  The array itself is allocated, but not the strings inside.
230230131Suqs   You should free () the array when you done, but not the pointrs. */
231230131Suqsconst char **
23254622Sbillfrl_funmap_names ()
233230131Suqs{
234230131Suqs  const char **result;
235230131Suqs  int result_size, result_index;
236230131Suqs
237230131Suqs  /* Make sure that the function map has been initialized. */
238230131Suqs  rl_initialize_funmap ();
239230131Suqs
240230131Suqs  for (result_index = result_size = 0, result = (const char **)NULL; funmap[result_index]; result_index++)
241230131Suqs    {
242230131Suqs      if (result_index + 2 > result_size)
243230131Suqs	{
244230131Suqs	  result_size += 20;
245230131Suqs	  result = (const char **)xrealloc (result, result_size * sizeof (char *));
246230131Suqs	}
247230131Suqs
248230131Suqs      result[result_index] = funmap[result_index]->name;
249230131Suqs      result[result_index + 1] = (char *)NULL;
250230131Suqs    }
251230131Suqs
252230131Suqs  qsort (result, result_index, sizeof (char *), (QSFUNC *)_rl_qsort_string_compare);
253230131Suqs  return (result);
254230131Suqs}
255230131Suqs