Imported from ../bash-2.0.tar.gz.
[platform/upstream/bash.git] / builtins / type.def
index aecc303..5e828c6 100644 (file)
@@ -23,26 +23,38 @@ $PRODUCES type.c
 
 $BUILTIN type
 $FUNCTION type_builtin
-$SHORT_DOC type [-all] [-type | -path] [name ...]
+$SHORT_DOC type [-apt] name [name ...]
 For each NAME, indicate how it would be interpreted if used as a
 command name.
 
-If the -type flag is used, returns a single word which is one of
+If the -t option is used, returns a single word which is one of
 `alias', `keyword', `function', `builtin', `file' or `', if NAME is an
 alias, shell reserved word, shell function, shell builtin, disk file,
 or unfound, respectively.
 
-If the -path flag is used, either returns the name of the disk file
-that would be exec'ed, or nothing if -type wouldn't return `file'.
+If the -p flag is used, either returns the name of the disk file
+that would be executed, or nothing if -t would not return `file'.
 
-If the -all flag is used, displays all of the places that contain an
+If the -a flag is used, displays all of the places that contain an
 executable named `file'.  This includes aliases and functions, if and
-only if the -path flag is not also used.
+only if the -p flag is not also used.
+
+Type accepts -all, -path, and -type in place of -a, -p, and -t,
+respectively.
 $END
 
-#include <stdio.h>
-#include <sys/types.h>
+#include <config.h>
+
+#include "../bashtypes.h"
 #include "../posixstat.h"
+
+#if defined (HAVE_UNISTD_H)
+#  include <unistd.h>
+#endif
+
+#include <stdio.h>
+#include "../bashansi.h"
+
 #include "../shell.h"
 #include "../execute_cmd.h"
 
@@ -52,7 +64,7 @@ $END
 
 #include "common.h"
 
-extern STRING_INT_ALIST word_token_alist[];
+extern int find_reserved_word ();
 
 /* For each word in LIST, find out what the shell is going to do with
    it as a simple command. i.e., which file would this shell use to
@@ -75,18 +87,19 @@ extern STRING_INT_ALIST word_token_alist[];
        builtin
        file
  */
+int
 type_builtin (list)
      WORD_LIST *list;
 {
   int path_only, type_only, all, verbose;
   int successful_finds;
 
+  if (list == 0)
+    return (EXECUTION_SUCCESS);
+
   path_only = type_only = all = 0;
   successful_finds = 0;
 
-  if (!list)
-    return (EXECUTION_SUCCESS);
-
   while (list && *(list->word->word) == '-')
     {
       char *flag = &(list->word->word[1]);
@@ -108,7 +121,7 @@ type_builtin (list)
       else
        {
          bad_option (flag);
-         builtin_error ("usage: type [-all | -path | -type ] name [name ...]");
+         builtin_usage ();
          return (EX_USAGE);
        }
       list = list->next;
@@ -116,7 +129,7 @@ type_builtin (list)
 
   if (type_only)
     verbose = 1;
-  else if (!path_only)
+  else if (path_only == 0)
     verbose = 2;
   else if (path_only)
     verbose = 3;
@@ -156,22 +169,29 @@ type_builtin (list)
  * ALL says whether or not to look for all occurrences of COMMAND, or
  * return after finding it once.
  */
+int
 describe_command (command, verbose, all)
      char *command;
      int verbose, all;
 {
-  int found = 0, i, found_file = 0;
-  char *full_path = (char *)NULL;
+  int found, i, found_file;
+  char *full_path;
   SHELL_VAR *func;
+#if defined (ALIAS)
+  alias_t *alias;
+#endif
+
+  found = found_file = 0;
+  full_path = (char *)NULL;
 
 #if defined (ALIAS)
   /* Command is an alias? */
-  ASSOC *alias = find_alias (command);
+  alias = find_alias (command);
 
   if (alias)
     {
       if (verbose == 1)
-       printf ("alias\n");
+       puts ("alias");
       else if (verbose == 2)
        printf ("%s is aliased to `%s'\n", command, alias->value);
       else if (verbose == 4)
@@ -193,7 +213,7 @@ describe_command (command, verbose, all)
   if (i >= 0)
     {
       if (verbose == 1)
-       printf ("keyword\n");
+       puts ("keyword");
       else if (verbose == 2)
        printf ("%s is a shell keyword\n", command);
       else if (verbose == 4)
@@ -211,7 +231,7 @@ describe_command (command, verbose, all)
   if (func)
     {
       if (verbose == 1)
-       printf ("function\n");
+       puts ("function");
       else if (verbose == 2)
        {
 #define PRETTY_PRINT_FUNC 1
@@ -240,7 +260,7 @@ describe_command (command, verbose, all)
   if (find_shell_builtin (command))
     {
       if (verbose == 1)
-       printf ("builtin\n");
+       puts ("builtin");
       else if (verbose == 2)
        printf ("%s is a shell builtin\n", command);
       else if (verbose == 4)
@@ -261,7 +281,7 @@ describe_command (command, verbose, all)
       if (f & FS_EXECABLE)
         {
          if (verbose == 1)
-           printf ("file\n");
+           puts ("file");
          else if (verbose == 2)
            printf ("%s is %s\n", command, command);
          else if (verbose == 3 || verbose == 4)
@@ -281,7 +301,7 @@ describe_command (command, verbose, all)
       if ((full_path = find_hashed_filename (command)) != (char *)NULL)
        {
          if (verbose == 1)
-           printf ("file\n");
+           puts ("file");
          else if (verbose == 2)
            printf ("%s is hashed (%s)\n", command, full_path);
          else if (verbose == 3 || verbose == 4)
@@ -308,7 +328,7 @@ describe_command (command, verbose, all)
       found = 1;
 
       if (verbose == 1)
-       printf ("file\n");
+       puts ("file");
       else if (verbose == 2)
        printf ("%s is %s\n", command, full_path);
       else if (verbose == 3 || verbose == 4)