funmap.c
上传用户:tsgydb
上传日期:2007-04-14
资源大小:10674k
文件大小:9k
源码类别:

MySQL数据库

开发平台:

Visual C++

  1. /* funmap.c -- attach names to functions. */
  2. /* Copyright (C) 1987, 1989, 1992 Free Software Foundation, Inc.
  3.    This file is part of the GNU Readline Library, a library for
  4.    reading lines of text with interactive input and history editing.
  5.    The GNU Readline Library is free software; you can redistribute it
  6.    and/or modify it under the terms of the GNU General Public License
  7.    as published by the Free Software Foundation; either version 1, or
  8.    (at your option) any later version.
  9.    The GNU Readline Library is distributed in the hope that it will be
  10.    useful, but WITHOUT ANY WARRANTY; without even the implied warranty
  11.    of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12.    GNU General Public License for more details.
  13.    The GNU General Public License is often shipped with GNU software, and
  14.    is generally kept in a file called COPYING or LICENSE.  If you do not
  15.    have a copy of the license, write to the Free Software Foundation,
  16.    675 Mass Ave, Cambridge, MA 02139, USA. */
  17. #define READLINE_LIBRARY
  18. #if defined (HAVE_CONFIG_H)
  19. #  include <config.h>
  20. #endif
  21. extern char *xmalloc (), *xrealloc ();
  22. #if !defined (BUFSIZ)
  23. #include <stdio.h>
  24. #endif /* BUFSIZ */
  25. #if defined (HAVE_STDLIB_H)
  26. #  include <stdlib.h>
  27. #else
  28. #  include "ansi_stdlib.h"
  29. #endif /* HAVE_STDLIB_H */
  30. #include "rlconf.h"
  31. #include "readline.h"
  32. extern int _rl_qsort_string_compare ();
  33. FUNMAP **funmap;
  34. static int funmap_size;
  35. static int funmap_entry;
  36. /* After initializing the function map, this is the index of the first
  37.    program specific function. */
  38. int funmap_program_specific_entry_start;
  39. static FUNMAP default_funmap[] = {
  40.   { "abort", rl_abort },
  41.   { "accept-line", rl_newline },
  42.   { "arrow-key-prefix", rl_arrow_keys },
  43.   { "backward-char", rl_backward },
  44.   { "backward-delete-char", rl_rubout },
  45.   { "backward-kill-line", rl_backward_kill_line },
  46.   { "backward-kill-word", rl_backward_kill_word },
  47.   { "backward-word", rl_backward_word },
  48.   { "beginning-of-history", rl_beginning_of_history },
  49.   { "beginning-of-line", rl_beg_of_line },
  50.   { "call-last-kbd-macro", rl_call_last_kbd_macro },
  51.   { "capitalize-word", rl_capitalize_word },
  52.   { "character-search", rl_char_search },
  53.   { "character-search-backward", rl_backward_char_search },
  54.   { "clear-screen", rl_clear_screen },
  55.   { "complete", rl_complete },
  56.   { "copy-backward-word", rl_copy_backward_word },
  57.   { "copy-forward-word", rl_copy_forward_word },
  58.   { "copy-region-as-kill", rl_copy_region_to_kill },
  59.   { "delete-char", rl_delete },
  60.   { "delete-char-or-list", rl_delete_or_show_completions },
  61.   { "delete-horizontal-space", rl_delete_horizontal_space },
  62.   { "digit-argument", rl_digit_argument },
  63.   { "do-lowercase-version", rl_do_lowercase_version },
  64.   { "downcase-word", rl_downcase_word },
  65.   { "dump-functions", rl_dump_functions },
  66.   { "dump-macros", rl_dump_macros },
  67.   { "dump-variables", rl_dump_variables },
  68.   { "emacs-editing-mode", rl_emacs_editing_mode },
  69.   { "end-kbd-macro", rl_end_kbd_macro },
  70.   { "end-of-history", rl_end_of_history },
  71.   { "end-of-line", rl_end_of_line },
  72.   { "exchange-point-and-mark", rl_exchange_point_and_mark },
  73.   { "forward-backward-delete-char", rl_rubout_or_delete },
  74.   { "forward-char", rl_forward },
  75.   { "forward-search-history", rl_forward_search_history },
  76.   { "forward-word", rl_forward_word },
  77.   { "history-search-backward", rl_history_search_backward },
  78.   { "history-search-forward", rl_history_search_forward },
  79.   { "insert-comment", rl_insert_comment },
  80.   { "insert-completions", rl_insert_completions },
  81.   { "kill-whole-line", rl_kill_full_line },
  82.   { "kill-line", rl_kill_line },
  83.   { "kill-region", rl_kill_region },
  84.   { "kill-word", rl_kill_word },
  85.   { "menu-complete", rl_menu_complete },
  86.   { "next-history", rl_get_next_history },
  87.   { "non-incremental-forward-search-history", rl_noninc_forward_search },
  88.   { "non-incremental-reverse-search-history", rl_noninc_reverse_search },
  89.   { "non-incremental-forward-search-history-again", rl_noninc_forward_search_again },
  90.   { "non-incremental-reverse-search-history-again", rl_noninc_reverse_search_again },
  91. #ifdef __CYGWIN32__
  92.   { "paste-from-clipboard", rl_paste_from_clipboard },
  93. #endif
  94.   { "possible-completions", rl_possible_completions },
  95.   { "previous-history", rl_get_previous_history },
  96.   { "quoted-insert", rl_quoted_insert },
  97.   { "re-read-init-file", rl_re_read_init_file },
  98.   { "redraw-current-line", rl_refresh_line},
  99.   { "reverse-search-history", rl_reverse_search_history },
  100.   { "revert-line", rl_revert_line },
  101.   { "self-insert", rl_insert },
  102.   { "set-mark", rl_set_mark },
  103.   { "start-kbd-macro", rl_start_kbd_macro },
  104.   { "tab-insert", rl_tab_insert },
  105.   { "tilde-expand", rl_tilde_expand },
  106.   { "transpose-chars", rl_transpose_chars },
  107.   { "transpose-words", rl_transpose_words },
  108.   { "tty-status", rl_tty_status },
  109.   { "undo", rl_undo_command },
  110.   { "universal-argument", rl_universal_argument },
  111.   { "unix-line-discard", rl_unix_line_discard },
  112.   { "unix-word-rubout", rl_unix_word_rubout },
  113.   { "upcase-word", rl_upcase_word },
  114.   { "yank", rl_yank },
  115.   { "yank-last-arg", rl_yank_last_arg },
  116.   { "yank-nth-arg", rl_yank_nth_arg },
  117.   { "yank-pop", rl_yank_pop },
  118. #if defined (VI_MODE)
  119.   { "vi-append-eol", rl_vi_append_eol },
  120.   { "vi-append-mode", rl_vi_append_mode },
  121.   { "vi-arg-digit", rl_vi_arg_digit },
  122.   { "vi-back-to-indent", rl_vi_back_to_indent },
  123.   { "vi-bWord", rl_vi_bWord },
  124.   { "vi-bracktype", rl_vi_bracktype },
  125.   { "vi-bword", rl_vi_bword },
  126.   { "vi-change-case", rl_vi_change_case },
  127.   { "vi-change-char", rl_vi_change_char },
  128.   { "vi-change-to", rl_vi_change_to },
  129.   { "vi-char-search", rl_vi_char_search },
  130.   { "vi-column", rl_vi_column },
  131.   { "vi-complete", rl_vi_complete },
  132.   { "vi-delete", rl_vi_delete },
  133.   { "vi-delete-to", rl_vi_delete_to },
  134.   { "vi-eWord", rl_vi_eWord },
  135.   { "vi-editing-mode", rl_vi_editing_mode },
  136.   { "vi-end-word", rl_vi_end_word },
  137.   { "vi-eof-maybe", rl_vi_eof_maybe },
  138.   { "vi-eword", rl_vi_eword },
  139.   { "vi-fWord", rl_vi_fWord },
  140.   { "vi-fetch-history", rl_vi_fetch_history },
  141.   { "vi-first-print", rl_vi_first_print },
  142.   { "vi-fword", rl_vi_fword },
  143.   { "vi-goto-mark", rl_vi_goto_mark },
  144.   { "vi-insert-beg", rl_vi_insert_beg },
  145.   { "vi-insertion-mode", rl_vi_insertion_mode },
  146.   { "vi-match", rl_vi_match },
  147.   { "vi-movement-mode", rl_vi_movement_mode },
  148.   { "vi-next-word", rl_vi_next_word },
  149.   { "vi-overstrike", rl_vi_overstrike },
  150.   { "vi-overstrike-delete", rl_vi_overstrike_delete },
  151.   { "vi-prev-word", rl_vi_prev_word },
  152.   { "vi-put", rl_vi_put },
  153.   { "vi-redo", rl_vi_redo },
  154.   { "vi-replace", rl_vi_replace },
  155.   { "vi-search", rl_vi_search },
  156.   { "vi-search-again", rl_vi_search_again },
  157.   { "vi-set-mark", rl_vi_set_mark },
  158.   { "vi-subst", rl_vi_subst },
  159.   { "vi-tilde-expand", rl_vi_tilde_expand },
  160.   { "vi-yank-arg", rl_vi_yank_arg },
  161.   { "vi-yank-to", rl_vi_yank_to },
  162. #endif /* VI_MODE */
  163.  {(char *)NULL, (Function *)NULL }
  164. };
  165. int
  166. rl_add_funmap_entry (name, function)
  167.      char *name;
  168.      Function *function;
  169. {
  170.   if (funmap_entry + 2 >= funmap_size)
  171.     {
  172.       funmap_size += 64;
  173.       funmap = (FUNMAP **)xrealloc (funmap, funmap_size * sizeof (FUNMAP *));
  174.     }
  175.   
  176.   funmap[funmap_entry] = (FUNMAP *)xmalloc (sizeof (FUNMAP));
  177.   funmap[funmap_entry]->name = name;
  178.   funmap[funmap_entry]->function = function;
  179.   funmap[++funmap_entry] = (FUNMAP *)NULL;
  180.   return funmap_entry;
  181. }
  182. static int funmap_initialized;
  183. /* Make the funmap contain all of the default entries. */
  184. void
  185. rl_initialize_funmap ()
  186. {
  187.   register int i;
  188.   if (funmap_initialized)
  189.     return;
  190.   for (i = 0; default_funmap[i].name; i++)
  191.     rl_add_funmap_entry (default_funmap[i].name, default_funmap[i].function);
  192.   funmap_initialized = 1;
  193.   funmap_program_specific_entry_start = i;
  194. }
  195. /* Produce a NULL terminated array of known function names.  The array
  196.    is sorted.  The array itself is allocated, but not the strings inside.
  197.    You should free () the array when you done, but not the pointrs. */
  198. char **
  199. rl_funmap_names ()
  200. {
  201.   char **result;
  202.   int result_size, result_index;
  203.   /* Make sure that the function map has been initialized. */
  204.   rl_initialize_funmap ();
  205.   for (result_index = result_size = 0, result = (char **)NULL; funmap[result_index]; result_index++)
  206.     {
  207.       if (result_index + 2 > result_size)
  208. {
  209.   result_size += 20;
  210.   result = (char **)xrealloc (result, result_size * sizeof (char *));
  211. }
  212.       result[result_index] = funmap[result_index]->name;
  213.       result[result_index + 1] = (char *)NULL;
  214.     }
  215.   qsort (result, result_index, sizeof (char *), _rl_qsort_string_compare);
  216.   return (result);
  217. }
  218. /* Things that mean `Control'. */
  219. char *possible_control_prefixes[] = {
  220.   "Control-", "C-", "CTRL-", (char *)NULL
  221. };
  222. char *possible_meta_prefixes[] = {
  223.   "Meta", "M-", (char *)NULL
  224. };