Imported from ../bash-4.0-rc1.tar.gz.
[platform/upstream/bash.git] / builtins / enable.def
index 61ea109..40cbb44 100644 (file)
@@ -1,42 +1,51 @@
 This file is enable.def, from which is created enable.c.
 It implements the builtin "enable" in Bash.
 
-Copyright (C) 1987, 1989, 1991 Free Software Foundation, Inc.
+Copyright (C) 1987-2009 Free Software Foundation, Inc.
 
 This file is part of GNU Bash, the Bourne Again SHell.
 
-Bash is free software; you can redistribute it and/or modify it under
-the terms of the GNU General Public License as published by the Free
-Software Foundation; either version 1, or (at your option) any later
-version.
+Bash is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
 
-Bash is distributed in the hope that it will be useful, but WITHOUT ANY
-WARRANTY; without even the implied warranty of MERCHANTABILITY or
-FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
-for more details.
+Bash is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
 
-You should have received a copy of the GNU General Public License along
-with Bash; see the file COPYING.  If not, write to the Free Software
-Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
+You should have received a copy of the GNU General Public License
+along with Bash.  If not, see <http://www.gnu.org/licenses/>.
 
 $PRODUCES enable.c
 
 $BUILTIN enable
 $FUNCTION enable_builtin
-$SHORT_DOC enable [-pnds] [-a] [-f filename] [name ...]
-Enable and disable builtin shell commands.  This allows
-you to use a disk command which has the same name as a shell
-builtin.  If -n is used, the NAMEs become disabled; otherwise
-NAMEs are enabled.  For example, to use the `test' found on your
-path instead of the shell builtin version, type `enable -n test'.
-On systems supporting dynamic loading, the -f option may be used
-to load new builtins from the shared object FILENAME.  The -d
-option will delete a builtin previously loaded with -f.  If no
-non-option names are given, or the -p option is supplied, a list
-of builtins is printed.  The -a option means to print every builtin
-with an indication of whether or not it is enabled.  The -s option
-restricts the output to the Posix.2 `special' builtins.  The -n
-option displays a list of all disabled builtins.
+$SHORT_DOC enable [-a] [-dnps] [-f filename] [name ...]
+Enable and disable shell builtins.
+
+Enables and disables builtin shell commands.  Disabling allows you to
+execute a disk command which has the same name as a shell builtin
+without using a full pathname.
+
+Options:
+  -a   print a list of builtins showing whether or not each is enabled
+  -n   disable each NAME or display a list of disabled builtins
+  -p   print the list of builtins in a reusable format
+  -s   print only the names of Posix `special' builtins
+
+Options controlling dynamic loading:
+  -f   Load builtin NAME from shared object FILENAME
+  -d   Remove a builtin loaded with -f
+
+Without options, each NAME is enabled.
+
+To use the `test' found in $PATH instead of the shell builtin
+version, type `enable -n test'.
+
+Exit Status:
+Returns success unless NAME is not a shell builtin or an error occurs.
 $END
 
 #include <config.h>
@@ -50,18 +59,16 @@ $END
 
 #include <stdio.h>
 #include "../bashansi.h"
+#include "../bashintl.h"
+
 #include "../shell.h"
 #include "../builtins.h"
 #include "../flags.h"
 #include "common.h"
 #include "bashgetopt.h"
 
-#if defined (HAVE_DLOPEN) && defined (HAVE_DLSYM)
-static int dyn_load_builtin ();
-#endif
-
-#if defined (HAVE_DLCLOSE)
-static int dyn_unload_builtin ();
+#if defined (PROGRAMMABLE_COMPLETION)
+#  include "../pcomplete.h"
 #endif
 
 #define ENABLED  1
@@ -75,8 +82,18 @@ static int dyn_unload_builtin ();
 #define PFLAG  0x10
 #define SFLAG  0x20
 
-static int enable_shell_command ();
-static void list_some_builtins ();
+#if defined (HAVE_DLOPEN) && defined (HAVE_DLSYM)
+static int dyn_load_builtin __P((WORD_LIST *, int, char *));
+#endif
+
+#if defined (HAVE_DLCLOSE)
+static int dyn_unload_builtin __P((char *));
+static void delete_builtin __P((struct builtin *));
+static int local_dlclose __P((void *));
+#endif
+
+static void list_some_builtins __P((int));
+static int enable_shell_command __P((char *, int));
 
 /* Enable/disable shell commands present in LIST.  If list is not specified,
    then print out a list of shell commands showing which are enabled and
@@ -117,7 +134,7 @@ enable_builtin (list)
          filename = list_optarg;
          break;
 #else
-         builtin_error ("dynamic loading not available");
+         builtin_error (_("dynamic loading not available"));
          return (EX_USAGE);
 #endif
 #if defined (HAVE_DLCLOSE)
@@ -125,7 +142,7 @@ enable_builtin (list)
          flags |= DFLAG;
          break;
 #else
-         builtin_error ("dynamic loading not available");
+         builtin_error (_("dynamic loading not available"));
          return (EX_USAGE);
 #endif /* HAVE_DLCLOSE */
        default:
@@ -140,7 +157,7 @@ enable_builtin (list)
   /* Restricted shells cannot load new builtins. */
   if (restricted && (flags & (FFLAG|DFLAG)))
     {
-      builtin_error ("restricted");
+      sh_restricted ((char *)NULL);
       return (EXECUTION_FAILURE);
     }
 #endif
@@ -160,9 +177,12 @@ enable_builtin (list)
     {
       filter = (flags & NFLAG) ? DISABLED : ENABLED;
       if (flags & SFLAG)
-        filter |= SPECIAL;
+       filter |= SPECIAL;
 
       result = dyn_load_builtin (list, filter, filename);
+#if defined (PROGRAMMABLE_COMPLETION)
+      set_itemlist_dirty (&it_builtins);
+#endif
     }
 #endif
 #if defined (HAVE_DLCLOSE)
@@ -175,6 +195,9 @@ enable_builtin (list)
            result = EXECUTION_FAILURE;
          list = list->next;
        }
+#if defined (PROGRAMMABLE_COMPLETION)
+      set_itemlist_dirty (&it_builtins);
+#endif
     }
 #endif
   else
@@ -185,7 +208,7 @@ enable_builtin (list)
 
          if (opt == EXECUTION_FAILURE)
            {
-             builtin_error ("%s: not a shell builtin", list->word->word);
+             sh_notbuiltin (list->word->word);
              result = EXECUTION_FAILURE;
            }
          list = list->next;
@@ -234,9 +257,21 @@ enable_shell_command (name, disable_p)
 
   if (disable_p)
     b->flags &= ~BUILTIN_ENABLED;
+#if defined (RESTRICTED_SHELL)
+  else if (restricted && ((b->flags & BUILTIN_ENABLED) == 0))
+    {
+      sh_restricted ((char *)NULL);
+      return (EXECUTION_FAILURE);
+    }
+#endif
   else
     b->flags |= BUILTIN_ENABLED;
 
+#if defined (PROGRAMMABLE_COMPLETION)
+  set_itemlist_dirty (&it_enabled);
+  set_itemlist_dirty (&it_disabled);
+#endif
+
   return (EXECUTION_SUCCESS);
 }
 
@@ -274,7 +309,7 @@ dyn_load_builtin (list, flags, filename)
 
   if (handle == 0)
     {
-      builtin_error ("cannot open shared object %s: %s", filename, dlerror ());
+      builtin_error (_("cannot open shared object %s: %s"), filename, dlerror ());
       return (EXECUTION_FAILURE);
     }
 
@@ -290,15 +325,15 @@ dyn_load_builtin (list, flags, filename)
       name = list->word->word;
 
       size = strlen (name);
-      struct_name = xmalloc (size + 8);
+      struct_name = (char *)xmalloc (size + 8);
       strcpy (struct_name, name);
       strcpy (struct_name + size, "_struct");
 
       b = (struct builtin *)dlsym (handle, struct_name);
       if (b == 0)
        {
-         builtin_error ("cannot find %s in shared object %s: %s", struct_name,
-                         filename, dlerror ());
+         builtin_error (_("cannot find %s in shared object %s: %s"),
+                         struct_name, filename, dlerror ());
          free (struct_name);
          continue;
        }
@@ -311,10 +346,10 @@ dyn_load_builtin (list, flags, filename)
       b->handle = handle;
 
       if (old_builtin = builtin_address_internal (name, 1))
-        {
-          replaced++;
+       {
+         replaced++;
          FASTCOPY ((char *)b, (char *)old_builtin, sizeof (struct builtin));
-        }
+       }
       else
          new_builtins[new++] = b;
     }
@@ -340,7 +375,7 @@ dyn_load_builtin (list, flags, filename)
                  sizeof (struct builtin));
 
       new_shell_builtins[total].name = (char *)0;
-      new_shell_builtins[total].function = (Function *)0;
+      new_shell_builtins[total].function = (sh_builtin_func_t *)0;
       new_shell_builtins[total].flags = 0;
 
       if (shell_builtins != static_shell_builtins)
@@ -391,6 +426,20 @@ delete_builtin (b)
   shell_builtins = new_shell_builtins;
 }
 
+/* Tenon's MachTen has a dlclose that doesn't return a value, so we
+   finesse it with a local wrapper. */
+static int
+local_dlclose (handle)
+     void *handle;
+{
+#if !defined (__MACHTEN__)
+  return (dlclose (handle));
+#else /* __MACHTEN__ */
+  dlclose (handle);
+  return ((dlerror () != NULL) ? -1 : 0);    
+#endif /* __MACHTEN__ */
+}
+
 static int
 dyn_unload_builtin (name)
      char *name;
@@ -402,12 +451,12 @@ dyn_unload_builtin (name)
   b = builtin_address_internal (name, 1);
   if (b == 0)
     {
-      builtin_error ("%s: not a shell builtin", name);
+      sh_notbuiltin (name);
       return (EXECUTION_FAILURE);
     }
   if (b->flags & STATIC_BUILTIN)
     {
-      builtin_error ("%s: not dynamically loaded", name);
+      builtin_error (_("%s: not dynamically loaded"), name);
       return (EXECUTION_FAILURE);
     }
 
@@ -420,9 +469,9 @@ dyn_unload_builtin (name)
 
   /* Don't remove the shared object unless the reference count of builtins
      using it drops to zero. */
-  if (ref == 1 && dlclose (handle) != 0)
+  if (ref == 1 && local_dlclose (handle) != 0)
     {
-      builtin_error ("cannot delete %s: %s", name, dlerror ());
+      builtin_error (_("%s: cannot delete: %s"), name, dlerror ());
       return (EXECUTION_FAILURE);
     }