diff options
author | Jari Aalto <jari.aalto@cante.net> | 1999-02-19 17:11:39 +0000 |
---|---|---|
committer | Jari Aalto <jari.aalto@cante.net> | 2009-09-12 16:46:52 +0000 |
commit | b72432fdcc59300c6fe7c9d6c8a31ad3447933f5 (patch) | |
tree | b9899162338c2ff3fd83a8aef8831cb119e85cd7 /builtins/type.def | |
parent | bc4cd23ce958feda898c618215f94d8a4e8f4ffa (diff) | |
download | bash-b72432fdcc59300c6fe7c9d6c8a31ad3447933f5.tar.gz |
Imported from ../bash-2.03.tar.gz.
Diffstat (limited to 'builtins/type.def')
-rw-r--r-- | builtins/type.def | 85 |
1 files changed, 61 insertions, 24 deletions
diff --git a/builtins/type.def b/builtins/type.def index 93c8ff80..c9338ba9 100644 --- a/builtins/type.def +++ b/builtins/type.def @@ -62,6 +62,7 @@ $END #endif /* ALIAS */ #include "common.h" +#include "bashgetopt.h" extern int find_reserved_word (); @@ -69,14 +70,14 @@ extern int find_reserved_word (); it as a simple command. i.e., which file would this shell use to execve, or if it is a builtin command, or an alias. Possible flag arguments: - -type Returns the "type" of the object, one of + -t Returns the "type" of the object, one of `alias', `keyword', `function', `builtin', or `file'. - -path Returns the pathname of the file if -type is + -p Returns the pathname of the file if -type is a file. - -all Returns all occurrences of words, whether they + -a Returns all occurrences of words, whether they be a filename in the path, alias, function, or builtin. Order of evaluation: @@ -86,12 +87,14 @@ extern int find_reserved_word (); builtin file */ + int type_builtin (list) WORD_LIST *list; { int path_only, type_only, all, verbose; - int successful_finds; + int successful_finds, opt; + WORD_LIST *prev, *this; if (list == 0) return (EXECUTION_SUCCESS); @@ -99,32 +102,69 @@ type_builtin (list) path_only = type_only = all = 0; successful_finds = 0; - while (list && *(list->word->word) == '-') + /* Handle the obsolescent `-type', `-path', and `-all' by prescanning + the arguments and removing those options from the list before calling + internal_getopt. Recognize `--type', `--path', and `--all' also. + THIS SHOULD REALLY GO AWAY. */ + for (this = list; this && this->word->word[0] == '-'; ) { - char *flag = &(list->word->word[1]); + char *flag = &(this->word->word[1]); - if (flag[0] == 't' && (!flag[1] || strcmp (flag + 1, "ype") == 0)) + if (STREQ (flag, "type") || STREQ (flag, "-type")) { type_only = 1; path_only = 0; } - else if (flag[0] == 'p' && (!flag[1] || strcmp (flag + 1, "ath") == 0)) + else if (STREQ (flag, "path") || STREQ (flag, "-path")) { path_only = 1; type_only = 0; } - else if (flag[0] == 'a' && (!flag[1] || strcmp (flag + 1, "ll") == 0)) + else if (STREQ (flag, "all") || STREQ (flag, "-all")) + all = 1; + else { - all = 1; + prev = this; + this = this->next; + continue; } + + /* We found a long option; remove it from the argument list. Don't + free it if it's the head of the argument list, though -- the + argument list will be freed by the caller. */ + if (this == list) + this = list = list->next; else { - bad_option (flag); + prev->next = this->next; + this->next = (WORD_LIST *)NULL; + dispose_words (this); + this = prev->next; + } + } + + reset_internal_getopt (); + while ((opt = internal_getopt (list, "apt")) != -1) + { + switch (opt) + { + case 't': + type_only = 1; + path_only = 0; + break; + case 'p': + path_only = 1; + type_only = 0; + break; + case 'a': + all = 1; + break; + default: builtin_usage (); return (EX_USAGE); } - list = list->next; } + list = loptend; if (type_only) verbose = 1; @@ -150,10 +190,7 @@ type_builtin (list) fflush (stdout); - if (successful_finds != 0) - return (EXECUTION_SUCCESS); - else - return (EXECUTION_FAILURE); + return ((successful_finds != 0) ? EXECUTION_SUCCESS : EXECUTION_FAILURE); } /* @@ -202,7 +239,7 @@ describe_command (command, verbose, all) found = 1; - if (!all) + if (all == 0) return (1); } #endif /* ALIAS */ @@ -220,7 +257,7 @@ describe_command (command, verbose, all) found = 1; - if (!all) + if (all == 0) return (1); } @@ -251,7 +288,7 @@ describe_command (command, verbose, all) found = 1; - if (!all) + if (all == 0) return (1); } @@ -267,7 +304,7 @@ describe_command (command, verbose, all) found = 1; - if (!all) + if (all == 0) return (1); } @@ -293,9 +330,9 @@ describe_command (command, verbose, all) } } - /* If the user isn't doing "-all", then we might care about + /* If the user isn't doing "-a", then we might care about whether the file is present in our hash table. */ - if (!all) + if (all == 0) { if ((full_path = find_hashed_filename (command)) != (char *)NULL) { @@ -314,7 +351,7 @@ describe_command (command, verbose, all) /* Now search through $PATH. */ while (1) { - if (!all) + if (all == 0) full_path = find_user_command (command); else full_path = @@ -337,7 +374,7 @@ describe_command (command, verbose, all) free (full_path); full_path = (char *)NULL; - if (!all) + if (all == 0) break; } |