Jari Aalto | 726f638 | 1996-08-26 18:22:31 +0000 | [diff] [blame] | 1 | This file is builtin.def, from which is created builtin.c. |
| 2 | It implements the builtin "builtin" in Bash. |
| 3 | |
Jari Aalto | 3185942 | 2009-01-12 13:36:28 +0000 | [diff] [blame] | 4 | Copyright (C) 1987-2009 Free Software Foundation, Inc. |
Jari Aalto | 726f638 | 1996-08-26 18:22:31 +0000 | [diff] [blame] | 5 | |
| 6 | This file is part of GNU Bash, the Bourne Again SHell. |
| 7 | |
Jari Aalto | 3185942 | 2009-01-12 13:36:28 +0000 | [diff] [blame] | 8 | Bash is free software: you can redistribute it and/or modify |
| 9 | it under the terms of the GNU General Public License as published by |
| 10 | the Free Software Foundation, either version 3 of the License, or |
| 11 | (at your option) any later version. |
Jari Aalto | 726f638 | 1996-08-26 18:22:31 +0000 | [diff] [blame] | 12 | |
Jari Aalto | 3185942 | 2009-01-12 13:36:28 +0000 | [diff] [blame] | 13 | Bash is distributed in the hope that it will be useful, |
| 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | GNU General Public License for more details. |
Jari Aalto | 726f638 | 1996-08-26 18:22:31 +0000 | [diff] [blame] | 17 | |
Jari Aalto | 3185942 | 2009-01-12 13:36:28 +0000 | [diff] [blame] | 18 | You should have received a copy of the GNU General Public License |
| 19 | along with Bash. If not, see <http://www.gnu.org/licenses/>. |
Jari Aalto | 726f638 | 1996-08-26 18:22:31 +0000 | [diff] [blame] | 20 | |
| 21 | $PRODUCES builtin.c |
| 22 | |
| 23 | $BUILTIN builtin |
| 24 | $FUNCTION builtin_builtin |
| 25 | $SHORT_DOC builtin [shell-builtin [arg ...]] |
Jari Aalto | 3185942 | 2009-01-12 13:36:28 +0000 | [diff] [blame] | 26 | Execute shell builtins. |
| 27 | |
| 28 | Execute SHELL-BUILTIN with arguments ARGs without performing command |
| 29 | lookup. This is useful when you wish to reimplement a shell builtin |
| 30 | as a shell function, but need to execute the builtin within the function. |
| 31 | |
| 32 | Exit Status: |
| 33 | Returns the exit status of SHELL-BUILTIN, or false if SHELL-BUILTIN is |
| 34 | not a shell builtin.. |
Jari Aalto | 726f638 | 1996-08-26 18:22:31 +0000 | [diff] [blame] | 35 | $END |
Jari Aalto | ccc6cda | 1996-12-23 17:02:34 +0000 | [diff] [blame] | 36 | #include <config.h> |
| 37 | |
| 38 | #if defined (HAVE_UNISTD_H) |
Jari Aalto | cce855b | 1998-04-17 19:52:44 +0000 | [diff] [blame] | 39 | # ifdef _MINIX |
| 40 | # include <sys/types.h> |
| 41 | # endif |
Jari Aalto | ccc6cda | 1996-12-23 17:02:34 +0000 | [diff] [blame] | 42 | # include <unistd.h> |
| 43 | #endif |
Jari Aalto | 726f638 | 1996-08-26 18:22:31 +0000 | [diff] [blame] | 44 | |
| 45 | #include "../shell.h" |
Jari Aalto | 726f638 | 1996-08-26 18:22:31 +0000 | [diff] [blame] | 46 | #include "common.h" |
Jari Aalto | 7117c2d | 2002-07-17 14:10:11 +0000 | [diff] [blame] | 47 | #include "bashgetopt.h" |
Jari Aalto | 726f638 | 1996-08-26 18:22:31 +0000 | [diff] [blame] | 48 | |
| 49 | extern char *this_command_name; |
| 50 | |
| 51 | /* Run the command mentioned in list directly, without going through the |
| 52 | normal alias/function/builtin/filename lookup process. */ |
Jari Aalto | ccc6cda | 1996-12-23 17:02:34 +0000 | [diff] [blame] | 53 | int |
Jari Aalto | 726f638 | 1996-08-26 18:22:31 +0000 | [diff] [blame] | 54 | builtin_builtin (list) |
| 55 | WORD_LIST *list; |
| 56 | { |
Jari Aalto | f73dda0 | 2001-11-13 17:56:06 +0000 | [diff] [blame] | 57 | sh_builtin_func_t *function; |
Jari Aalto | 726f638 | 1996-08-26 18:22:31 +0000 | [diff] [blame] | 58 | register char *command; |
| 59 | |
Jari Aalto | 7117c2d | 2002-07-17 14:10:11 +0000 | [diff] [blame] | 60 | if (no_options (list)) |
| 61 | return (EX_USAGE); |
| 62 | list = loptend; /* skip over possible `--' */ |
| 63 | |
| 64 | if (list == 0) |
Jari Aalto | 726f638 | 1996-08-26 18:22:31 +0000 | [diff] [blame] | 65 | return (EXECUTION_SUCCESS); |
| 66 | |
Jari Aalto | 7117c2d | 2002-07-17 14:10:11 +0000 | [diff] [blame] | 67 | command = list->word->word; |
Jari Aalto | 726f638 | 1996-08-26 18:22:31 +0000 | [diff] [blame] | 68 | #if defined (DISABLED_BUILTINS) |
| 69 | function = builtin_address (command); |
| 70 | #else /* !DISABLED_BUILTINS */ |
| 71 | function = find_shell_builtin (command); |
| 72 | #endif /* !DISABLED_BUILTINS */ |
| 73 | |
| 74 | if (!function) |
| 75 | { |
Jari Aalto | b80f644 | 2004-07-27 13:29:18 +0000 | [diff] [blame] | 76 | sh_notbuiltin (command); |
Jari Aalto | 726f638 | 1996-08-26 18:22:31 +0000 | [diff] [blame] | 77 | return (EXECUTION_FAILURE); |
| 78 | } |
| 79 | else |
| 80 | { |
| 81 | this_command_name = command; |
| 82 | list = list->next; |
| 83 | return ((*function) (list)); |
| 84 | } |
| 85 | } |