Imported from ../bash-2.05b.tar.gz.
[platform/upstream/bash.git] / builtins / bind.def
index 5adfe38..ddf5619 100644 (file)
@@ -1,7 +1,7 @@
 This file is bind.def, from which is created bind.c.
 It implements the builtin "bind" in Bash.
 
-Copyright (C) 1987, 1989, 1991 Free Software Foundation, Inc.
+Copyright (C) 1987-2002 Free Software Foundation, Inc.
 
 This file is part of GNU Bash, the Bourne Again SHell.
 
@@ -26,11 +26,12 @@ $PRODUCES bind.c
 $BUILTIN bind
 $DEPENDS_ON READLINE
 $FUNCTION bind_builtin
-$SHORT_DOC bind [-lpvsPVS] [-m keymap] [-f filename] [-q name] [-u name] [-r keyseq] [-x keyseq:shell-command] [keyseq:readline-function]
-Bind a key sequence to a Readline function, or to a macro.  The
-syntax is equivalent to that found in ~/.inputrc, but must be
-passed as a single argument: bind '"\C-x\C-r": re-read-init-file'.
-Arguments we accept:
+$SHORT_DOC bind [-lpvsPVS] [-m keymap] [-f filename] [-q name] [-u name] [-r keyseq] [-x keyseq:shell-command] [keyseq:readline-function or readline-command]
+Bind a key sequence to a Readline function or a macro, or set
+a Readline variable.  The non-option argument syntax is equivalent
+to that found in ~/.inputrc, but must be passed as a single argument:
+bind '"\C-x\C-r": re-read-init-file'.
+bind accepts the following options:
   -m  keymap         Use `keymap' as the keymap for the duration of this
                      command.  Acceptable keymap names are emacs,
                      emacs-standard, emacs-meta, emacs-ctlx, vi, vi-move,
@@ -40,8 +41,8 @@ Arguments we accept:
   -p                 List functions and bindings in a form that can be
                      reused as input.
   -r  keyseq         Remove the binding for KEYSEQ.
-  -x  keyseq:shell-command     Cause SHELL-COMMAND to be executed when KEYSEQ
-                               is entered.
+  -x  keyseq:shell-command     Cause SHELL-COMMAND to be executed when
+                               KEYSEQ is entered.
   -f  filename       Read key bindings from FILENAME.
   -q  function-name  Query about which keys invoke the named function.
   -u  function-name  Unbind all keys which are bound to the named function.
@@ -49,8 +50,8 @@ Arguments we accept:
   -v                 List variable names and values in a form that can
                      be reused as input.
   -S                 List key sequences that invoke macros and their values
-  -s                 List key sequences that invoke macros and their values in
-                     a form that can be reused as input.
+  -s                 List key sequences that invoke macros and their values
+                     in a form that can be reused as input.
 $END
 
 #if defined (READLINE)
@@ -76,8 +77,8 @@ extern int errno;
 #include "bashgetopt.h"
 #include "common.h"
 
-static int query_bindings ();
-static int unbind_command ();
+static int query_bindings __P((char *));
+static int unbind_command __P((char *));
 
 extern int no_line_editing;
 
@@ -102,7 +103,6 @@ bind_builtin (list)
      WORD_LIST *list;
 {
   int return_code;
-  FILE *old_rl_outstream;
   Keymap kmap, saved_keymap;
   int flags, opt;
   char *initfile, *map_name, *fun_name, *unbind_name, *remove_seq, *cmd_seq;
@@ -118,10 +118,9 @@ bind_builtin (list)
   if (!bash_readline_initialized)
     initialize_readline ();
 
-  /* Cannot use unwind_protect_pointer () on "FILE *", it is only
-     guaranteed to work for strings. */
-  /* XXX -- see if we can use unwind_protect here */
-  old_rl_outstream = rl_outstream;
+  begin_unwind_frame ("bind_builtin");
+  unwind_protect_var (rl_outstream);
+
   rl_outstream = stdout;
 
   reset_internal_getopt ();  
@@ -189,10 +188,10 @@ bind_builtin (list)
     {
       kmap = rl_get_keymap_by_name (map_name);
       if (!kmap)
-        {
+       {
          builtin_error ("`%s': invalid keymap name", map_name);
          BIND_RETURN (EXECUTION_FAILURE);
-        }
+       }
     }
 
   if (kmap)
@@ -229,7 +228,7 @@ bind_builtin (list)
     {
       if (rl_read_init_file (initfile) != 0)
        {
-         builtin_error ("cannot read %s: %s", initfile, strerror (errno));
+         builtin_error ("%s: cannot read: %s", initfile, strerror (errno));
          BIND_RETURN (EXECUTION_FAILURE);
        }
     }
@@ -242,9 +241,9 @@ bind_builtin (list)
 
   if ((flags & RFLAG) && remove_seq)
     {
-      if (rl_set_key (remove_seq, (Function *)NULL, rl_get_keymap ()) != 0)
+      if (rl_set_key (remove_seq, (rl_command_func_t *)NULL, rl_get_keymap ()) != 0)
        {
-         builtin_error ("cannot unbind %s", remove_seq);
+         builtin_error ("`%s': cannot unbind", remove_seq);
          BIND_RETURN (EXECUTION_FAILURE);
        }
     }
@@ -263,7 +262,8 @@ bind_builtin (list)
   if (saved_keymap)
     rl_set_keymap (saved_keymap);
 
-  rl_outstream = old_rl_outstream;
+  run_unwind_frame ("bind_builtin");
+
   return (return_code);
 }
 
@@ -271,14 +271,14 @@ static int
 query_bindings (name)
      char *name;
 {
-  Function *function;
+  rl_command_func_t *function;
   char **keyseqs;
   int j;
 
   function = rl_named_function (name);
   if (function == 0)
     {
-      builtin_error ("unknown function name `%s'", name);
+      builtin_error ("`%s': unknown function name", name);
       return EXECUTION_FAILURE;
     }
 
@@ -295,7 +295,7 @@ query_bindings (name)
     printf ("\"%s\"%s", keyseqs[j], keyseqs[j + 1] ? ", " : ".\n");
   if (keyseqs[j])
     printf ("...\n");
-  free_array (keyseqs);
+  strvec_dispose (keyseqs);
   return EXECUTION_SUCCESS;
 }
 
@@ -303,12 +303,12 @@ static int
 unbind_command (name)
      char *name;
 {
-  Function *function;
+  rl_command_func_t *function;
 
   function = rl_named_function (name);
   if (function == 0)
     {
-      builtin_error ("unknown function name `%s'", name);
+      builtin_error ("`%s': unknown function name", name);
       return EXECUTION_FAILURE;
     }