121308Sache/* funmap.c -- attach names to functions. */
221308Sache
321308Sache/* Copyright (C) 1987, 1989, 1992 Free Software Foundation, Inc.
421308Sache
521308Sache   This file is part of the GNU Readline Library, a library for
621308Sache   reading lines of text with interactive input and history editing.
721308Sache
821308Sache   The GNU Readline Library is free software; you can redistribute it
921308Sache   and/or modify it under the terms of the GNU General Public License
1058310Sache   as published by the Free Software Foundation; either version 2, or
1121308Sache   (at your option) any later version.
1221308Sache
1321308Sache   The GNU Readline Library is distributed in the hope that it will be
1421308Sache   useful, but WITHOUT ANY WARRANTY; without even the implied warranty
1521308Sache   of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1621308Sache   GNU General Public License for more details.
1721308Sache
1821308Sache   The GNU General Public License is often shipped with GNU software, and
1921308Sache   is generally kept in a file called COPYING or LICENSE.  If you do not
2021308Sache   have a copy of the license, write to the Free Software Foundation,
2158310Sache   59 Temple Place, Suite 330, Boston, MA 02111 USA. */
2221308Sache#define READLINE_LIBRARY
2321308Sache
2421308Sache#if defined (HAVE_CONFIG_H)
2521308Sache#  include <config.h>
2621308Sache#endif
2721308Sache
2821308Sache#if !defined (BUFSIZ)
2921308Sache#include <stdio.h>
3021308Sache#endif /* BUFSIZ */
3121308Sache
3221308Sache#if defined (HAVE_STDLIB_H)
3321308Sache#  include <stdlib.h>
3421308Sache#else
3521308Sache#  include "ansi_stdlib.h"
3621308Sache#endif /* HAVE_STDLIB_H */
3721308Sache
3821308Sache#include "rlconf.h"
3921308Sache#include "readline.h"
4021308Sache
4158310Sache#include "xmalloc.h"
4258310Sache
4358310Sache#ifdef __STDC__
4458310Sachetypedef int QSFUNC (const void *, const void *);
4558310Sache#else
4658310Sachetypedef int QSFUNC ();
4758310Sache#endif
4858310Sache
49119610Sacheextern int _rl_qsort_string_compare PARAMS((char **, char **));
5021308Sache
5121308SacheFUNMAP **funmap;
5221308Sachestatic int funmap_size;
5321308Sachestatic int funmap_entry;
5421308Sache
5521308Sache/* After initializing the function map, this is the index of the first
5621308Sache   program specific function. */
5721308Sacheint funmap_program_specific_entry_start;
5821308Sache
5921308Sachestatic FUNMAP default_funmap[] = {
6021308Sache  { "abort", rl_abort },
6121308Sache  { "accept-line", rl_newline },
6221308Sache  { "arrow-key-prefix", rl_arrow_keys },
63119610Sache  { "backward-byte", rl_backward_byte },
64119610Sache  { "backward-char", rl_backward_char },
6521308Sache  { "backward-delete-char", rl_rubout },
6621308Sache  { "backward-kill-line", rl_backward_kill_line },
6721308Sache  { "backward-kill-word", rl_backward_kill_word },
6821308Sache  { "backward-word", rl_backward_word },
6921308Sache  { "beginning-of-history", rl_beginning_of_history },
7021308Sache  { "beginning-of-line", rl_beg_of_line },
7121308Sache  { "call-last-kbd-macro", rl_call_last_kbd_macro },
7221308Sache  { "capitalize-word", rl_capitalize_word },
7321308Sache  { "character-search", rl_char_search },
7421308Sache  { "character-search-backward", rl_backward_char_search },
7521308Sache  { "clear-screen", rl_clear_screen },
7621308Sache  { "complete", rl_complete },
7721308Sache  { "copy-backward-word", rl_copy_backward_word },
7821308Sache  { "copy-forward-word", rl_copy_forward_word },
7921308Sache  { "copy-region-as-kill", rl_copy_region_to_kill },
8021308Sache  { "delete-char", rl_delete },
8147558Sache  { "delete-char-or-list", rl_delete_or_show_completions },
8221308Sache  { "delete-horizontal-space", rl_delete_horizontal_space },
8321308Sache  { "digit-argument", rl_digit_argument },
8421308Sache  { "do-lowercase-version", rl_do_lowercase_version },
8521308Sache  { "downcase-word", rl_downcase_word },
8621308Sache  { "dump-functions", rl_dump_functions },
8726497Sache  { "dump-macros", rl_dump_macros },
8821308Sache  { "dump-variables", rl_dump_variables },
8921308Sache  { "emacs-editing-mode", rl_emacs_editing_mode },
9021308Sache  { "end-kbd-macro", rl_end_kbd_macro },
9121308Sache  { "end-of-history", rl_end_of_history },
9221308Sache  { "end-of-line", rl_end_of_line },
9321308Sache  { "exchange-point-and-mark", rl_exchange_point_and_mark },
9447558Sache  { "forward-backward-delete-char", rl_rubout_or_delete },
95119610Sache  { "forward-byte", rl_forward_byte },
96119610Sache  { "forward-char", rl_forward_char },
9721308Sache  { "forward-search-history", rl_forward_search_history },
9821308Sache  { "forward-word", rl_forward_word },
9921308Sache  { "history-search-backward", rl_history_search_backward },
10021308Sache  { "history-search-forward", rl_history_search_forward },
10121308Sache  { "insert-comment", rl_insert_comment },
10221308Sache  { "insert-completions", rl_insert_completions },
10321308Sache  { "kill-whole-line", rl_kill_full_line },
10421308Sache  { "kill-line", rl_kill_line },
10521308Sache  { "kill-region", rl_kill_region },
10621308Sache  { "kill-word", rl_kill_word },
10735486Sache  { "menu-complete", rl_menu_complete },
10821308Sache  { "next-history", rl_get_next_history },
10921308Sache  { "non-incremental-forward-search-history", rl_noninc_forward_search },
11021308Sache  { "non-incremental-reverse-search-history", rl_noninc_reverse_search },
11121308Sache  { "non-incremental-forward-search-history-again", rl_noninc_forward_search_again },
11221308Sache  { "non-incremental-reverse-search-history-again", rl_noninc_reverse_search_again },
113119610Sache  { "overwrite-mode", rl_overwrite_mode },
11475406Sache#ifdef __CYGWIN__
11535486Sache  { "paste-from-clipboard", rl_paste_from_clipboard },
11635486Sache#endif
11721308Sache  { "possible-completions", rl_possible_completions },
11821308Sache  { "previous-history", rl_get_previous_history },
11921308Sache  { "quoted-insert", rl_quoted_insert },
12021308Sache  { "re-read-init-file", rl_re_read_init_file },
12121308Sache  { "redraw-current-line", rl_refresh_line},
12221308Sache  { "reverse-search-history", rl_reverse_search_history },
12321308Sache  { "revert-line", rl_revert_line },
12421308Sache  { "self-insert", rl_insert },
12521308Sache  { "set-mark", rl_set_mark },
12621308Sache  { "start-kbd-macro", rl_start_kbd_macro },
12721308Sache  { "tab-insert", rl_tab_insert },
12821308Sache  { "tilde-expand", rl_tilde_expand },
12921308Sache  { "transpose-chars", rl_transpose_chars },
13021308Sache  { "transpose-words", rl_transpose_words },
13121308Sache  { "tty-status", rl_tty_status },
13221308Sache  { "undo", rl_undo_command },
13321308Sache  { "universal-argument", rl_universal_argument },
134136644Sache  { "unix-filename-rubout", rl_unix_filename_rubout },
13521308Sache  { "unix-line-discard", rl_unix_line_discard },
13621308Sache  { "unix-word-rubout", rl_unix_word_rubout },
13721308Sache  { "upcase-word", rl_upcase_word },
13821308Sache  { "yank", rl_yank },
13921308Sache  { "yank-last-arg", rl_yank_last_arg },
14021308Sache  { "yank-nth-arg", rl_yank_nth_arg },
14121308Sache  { "yank-pop", rl_yank_pop },
14221308Sache
14321308Sache#if defined (VI_MODE)
14421308Sache  { "vi-append-eol", rl_vi_append_eol },
14521308Sache  { "vi-append-mode", rl_vi_append_mode },
14621308Sache  { "vi-arg-digit", rl_vi_arg_digit },
14721308Sache  { "vi-back-to-indent", rl_vi_back_to_indent },
14821308Sache  { "vi-bWord", rl_vi_bWord },
14921308Sache  { "vi-bword", rl_vi_bword },
15021308Sache  { "vi-change-case", rl_vi_change_case },
15121308Sache  { "vi-change-char", rl_vi_change_char },
15221308Sache  { "vi-change-to", rl_vi_change_to },
15321308Sache  { "vi-char-search", rl_vi_char_search },
15421308Sache  { "vi-column", rl_vi_column },
15521308Sache  { "vi-complete", rl_vi_complete },
15621308Sache  { "vi-delete", rl_vi_delete },
15721308Sache  { "vi-delete-to", rl_vi_delete_to },
15821308Sache  { "vi-eWord", rl_vi_eWord },
15921308Sache  { "vi-editing-mode", rl_vi_editing_mode },
16021308Sache  { "vi-end-word", rl_vi_end_word },
16121308Sache  { "vi-eof-maybe", rl_vi_eof_maybe },
16221308Sache  { "vi-eword", rl_vi_eword },
16321308Sache  { "vi-fWord", rl_vi_fWord },
16421308Sache  { "vi-fetch-history", rl_vi_fetch_history },
16521308Sache  { "vi-first-print", rl_vi_first_print },
16621308Sache  { "vi-fword", rl_vi_fword },
16721308Sache  { "vi-goto-mark", rl_vi_goto_mark },
16821308Sache  { "vi-insert-beg", rl_vi_insert_beg },
16921308Sache  { "vi-insertion-mode", rl_vi_insertion_mode },
17021308Sache  { "vi-match", rl_vi_match },
17121308Sache  { "vi-movement-mode", rl_vi_movement_mode },
17221308Sache  { "vi-next-word", rl_vi_next_word },
17321308Sache  { "vi-overstrike", rl_vi_overstrike },
17421308Sache  { "vi-overstrike-delete", rl_vi_overstrike_delete },
17521308Sache  { "vi-prev-word", rl_vi_prev_word },
17621308Sache  { "vi-put", rl_vi_put },
17721308Sache  { "vi-redo", rl_vi_redo },
17821308Sache  { "vi-replace", rl_vi_replace },
179157184Sache  { "vi-rubout", rl_vi_rubout },
18021308Sache  { "vi-search", rl_vi_search },
18121308Sache  { "vi-search-again", rl_vi_search_again },
18221308Sache  { "vi-set-mark", rl_vi_set_mark },
18321308Sache  { "vi-subst", rl_vi_subst },
18421308Sache  { "vi-tilde-expand", rl_vi_tilde_expand },
18521308Sache  { "vi-yank-arg", rl_vi_yank_arg },
18621308Sache  { "vi-yank-to", rl_vi_yank_to },
18721308Sache#endif /* VI_MODE */
18821308Sache
18975406Sache {(char *)NULL, (rl_command_func_t *)NULL }
19021308Sache};
19121308Sache
19221308Sacheint
19321308Sacherl_add_funmap_entry (name, function)
19475406Sache     const char *name;
19575406Sache     rl_command_func_t *function;
19621308Sache{
19721308Sache  if (funmap_entry + 2 >= funmap_size)
19821308Sache    {
19921308Sache      funmap_size += 64;
20021308Sache      funmap = (FUNMAP **)xrealloc (funmap, funmap_size * sizeof (FUNMAP *));
20121308Sache    }
20221308Sache
20321308Sache  funmap[funmap_entry] = (FUNMAP *)xmalloc (sizeof (FUNMAP));
20421308Sache  funmap[funmap_entry]->name = name;
20521308Sache  funmap[funmap_entry]->function = function;
20621308Sache
20721308Sache  funmap[++funmap_entry] = (FUNMAP *)NULL;
20821308Sache  return funmap_entry;
20921308Sache}
21021308Sache
21121308Sachestatic int funmap_initialized;
21221308Sache
21321308Sache/* Make the funmap contain all of the default entries. */
21421308Sachevoid
21521308Sacherl_initialize_funmap ()
21621308Sache{
21721308Sache  register int i;
21821308Sache
21921308Sache  if (funmap_initialized)
22021308Sache    return;
22121308Sache
22221308Sache  for (i = 0; default_funmap[i].name; i++)
22321308Sache    rl_add_funmap_entry (default_funmap[i].name, default_funmap[i].function);
22421308Sache
22521308Sache  funmap_initialized = 1;
22621308Sache  funmap_program_specific_entry_start = i;
22721308Sache}
22821308Sache
22921308Sache/* Produce a NULL terminated array of known function names.  The array
23021308Sache   is sorted.  The array itself is allocated, but not the strings inside.
23121308Sache   You should free () the array when you done, but not the pointrs. */
23275406Sacheconst char **
23321308Sacherl_funmap_names ()
23421308Sache{
23575406Sache  const char **result;
23621308Sache  int result_size, result_index;
23721308Sache
23821308Sache  /* Make sure that the function map has been initialized. */
23921308Sache  rl_initialize_funmap ();
24021308Sache
24175406Sache  for (result_index = result_size = 0, result = (const char **)NULL; funmap[result_index]; result_index++)
24221308Sache    {
24321308Sache      if (result_index + 2 > result_size)
24421308Sache	{
24521308Sache	  result_size += 20;
24675406Sache	  result = (const char **)xrealloc (result, result_size * sizeof (char *));
24721308Sache	}
24821308Sache
24921308Sache      result[result_index] = funmap[result_index]->name;
25021308Sache      result[result_index + 1] = (char *)NULL;
25121308Sache    }
25221308Sache
25358310Sache  qsort (result, result_index, sizeof (char *), (QSFUNC *)_rl_qsort_string_compare);
25421308Sache  return (result);
25521308Sache}
256