1 diff --git a/builtins.h b/builtins.h
2 index dac95fd..5b7e811 100644
6 #define ASSIGNMENT_BUILTIN 0x10 /* This builtin takes assignment statements. */
7 #define POSIX_BUILTIN 0x20 /* This builtins is special in the Posix command search order. */
8 #define LOCALVAR_BUILTIN 0x40 /* This builtin creates local variables */
9 +#define REQUIRES_BUILTIN 0x80 /* This builtin requires other files. */
13 diff --git a/builtins/mkbuiltins.c b/builtins/mkbuiltins.c
14 index 4f51201..91c25db 100644
15 --- a/builtins/mkbuiltins.c
16 +++ b/builtins/mkbuiltins.c
17 @@ -69,10 +69,15 @@ extern char *strcpy ();
18 #define whitespace(c) (((c) == ' ') || ((c) == '\t'))
20 /* Flag values that builtins can have. */
21 +/* These flags are for the C code generator,
22 + the C which is produced (./builtin.c)
23 + includes the flags definitions found
25 #define BUILTIN_FLAG_SPECIAL 0x01
26 #define BUILTIN_FLAG_ASSIGNMENT 0x02
27 #define BUILTIN_FLAG_LOCALVAR 0x04
28 #define BUILTIN_FLAG_POSIX_BUILTIN 0x08
29 +#define BUILTIN_FLAG_REQUIRES 0x10
33 @@ -173,11 +178,19 @@ char *posix_builtins[] =
37 +/* The builtin commands that cause requirements on other files. */
38 +static char *requires_builtins[] =
40 + ".", "command", "exec", "source", "inlib",
44 /* Forward declarations. */
45 static int is_special_builtin ();
46 static int is_assignment_builtin ();
47 static int is_localvar_builtin ();
48 static int is_posix_builtin ();
49 +static int is_requires_builtin ();
51 #if !defined (HAVE_RENAME)
53 @@ -831,6 +844,8 @@ builtin_handler (self, defs, arg)
54 new->flags |= BUILTIN_FLAG_LOCALVAR;
55 if (is_posix_builtin (name))
56 new->flags |= BUILTIN_FLAG_POSIX_BUILTIN;
57 + if (is_requires_builtin (name))
58 + new->flags |= BUILTIN_FLAG_REQUIRES;
60 array_add ((char *)new, defs->builtins);
62 @@ -1250,12 +1265,13 @@ write_builtins (defs, structfile, externfile)
64 fprintf (structfile, "(sh_builtin_func_t *)0x0, ");
66 - fprintf (structfile, "%s%s%s%s%s, %s_doc,\n",
67 + fprintf (structfile, "%s%s%s%s%s%s, %s_doc,\n",
68 "BUILTIN_ENABLED | STATIC_BUILTIN",
69 (builtin->flags & BUILTIN_FLAG_SPECIAL) ? " | SPECIAL_BUILTIN" : "",
70 (builtin->flags & BUILTIN_FLAG_ASSIGNMENT) ? " | ASSIGNMENT_BUILTIN" : "",
71 (builtin->flags & BUILTIN_FLAG_LOCALVAR) ? " | LOCALVAR_BUILTIN" : "",
72 (builtin->flags & BUILTIN_FLAG_POSIX_BUILTIN) ? " | POSIX_BUILTIN" : "",
73 + (builtin->flags & BUILTIN_FLAG_REQUIRES) ? " | REQUIRES_BUILTIN" : "",
74 document_name (builtin));
76 /* Don't translate short document summaries that are identical
77 @@ -1645,6 +1661,13 @@ is_posix_builtin (name)
78 return (_find_in_table (name, posix_builtins));
82 +is_requires_builtin (name)
85 + return (_find_in_table (name, requires_builtins));
88 #if !defined (HAVE_RENAME)
91 diff --git a/doc/bash.1 b/doc/bash.1
92 index d91f1fd..111a66d 100644
95 @@ -239,6 +239,14 @@ The shell becomes restricted (see
100 +Produce the list of files that are required for the
101 +shell script to run. This implies '-n' and is subject
102 +to the same limitations as compile time error checking checking;
103 +Command substitutions, Conditional expressions and
105 +builtin are not parsed so some dependencies may be missed.
108 Equivalent to \fB\-v\fP.
110 diff --git a/doc/bashref.texi b/doc/bashref.texi
111 index d33cd57..6fc4d18 100644
112 --- a/doc/bashref.texi
113 +++ b/doc/bashref.texi
114 @@ -6453,6 +6453,13 @@ standard. @xref{Bash POSIX Mode}, for a description of the Bash
116 Make the shell a restricted shell (@pxref{The Restricted Shell}).
118 +@item --rpm-requires
119 +Produce the list of files that are required for the
120 +shell script to run. This implies '-n' and is subject
121 +to the same limitations as compile time error checking checking;
122 +Command substitutions, Conditional expressions and @command{eval}
123 +are not parsed so some dependencies may be missed.
126 Equivalent to @option{-v}. Print shell input lines as they're read.
128 diff --git a/eval.c b/eval.c
129 index f02d6e4..76c1e8d 100644
132 @@ -142,7 +142,8 @@ reader_loop ()
134 if (read_command () == 0)
136 - if (interactive_shell == 0 && read_but_dont_execute)
138 + if (interactive_shell == 0 && (read_but_dont_execute && !rpm_requires))
140 last_command_exit_value = EXECUTION_SUCCESS;
141 dispose_command (global_command);
142 diff --git a/execute_cmd.c b/execute_cmd.c
143 index 8b3c83a..4eae19c 100644
146 @@ -538,6 +538,8 @@ async_redirect_stdin ()
148 #define DESCRIBE_PID(pid) do { if (interactive) describe_pid (pid); } while (0)
150 +extern int rpm_requires;
152 /* Execute the command passed in COMMAND, perhaps doing it asynchronously.
153 COMMAND is exactly what read_command () places into GLOBAL_COMMAND.
154 ASYNCHROUNOUS, if non-zero, says to do this command in the background.
155 @@ -569,7 +571,13 @@ execute_command_internal (command, asynchronous, pipe_in, pipe_out,
157 if (breaking || continuing)
158 return (last_command_exit_value);
159 - if (command == 0 || read_but_dont_execute)
160 + if (command == 0 || (read_but_dont_execute && !rpm_requires))
161 + return (EXECUTION_SUCCESS);
162 + if (rpm_requires && command->type == cm_function_def)
163 + return last_command_exit_value =
164 + execute_intern_function (command->value.Function_def->name,
165 + command->value.Function_def);
166 + if (read_but_dont_execute)
167 return (EXECUTION_SUCCESS);
170 @@ -2813,7 +2821,7 @@ execute_for_command (for_command)
171 save_line_number = line_number;
172 if (check_identifier (for_command->name, 1) == 0)
174 - if (posixly_correct && interactive_shell == 0)
175 + if (posixly_correct && interactive_shell == 0 && rpm_requires == 0)
177 last_command_exit_value = EX_BADUSAGE;
178 jump_to_top_level (ERREXIT);
179 diff --git a/execute_cmd.h b/execute_cmd.h
180 index dc2f15e..506fff4 100644
184 #define _EXECUTE_CMD_H_
187 +#include "variables.h"
188 +#include "command.h"
191 #if defined (ARRAY_VARS)
192 struct func_array_state
193 diff --git a/make_cmd.c b/make_cmd.c
194 index ecbbfd6..3d8bfa4 100644
197 @@ -828,6 +828,27 @@ make_coproc_command (name, command)
198 return (make_command (cm_coproc, (SIMPLE_COM *)temp));
202 +output_requirement (deptype, filename)
203 +const char *deptype;
206 + if (strchr(filename, '$') || (filename[0] != '/' && strchr(filename, '/')))
210 + if the executable is called via variable substitution we can
211 + not dermine what it is at compile time.
213 + if the executable consists only of characters not in the
214 + alphabet we do not consider it a dependency just an artifact
215 + of shell parsing (ex "exec < ${infile}").
218 + if (strpbrk(filename, alphabet_set))
219 + printf ("%s(%s)\n", deptype, filename);
222 /* Reverse the word list and redirection list in the simple command
223 has just been parsed. It seems simpler to do this here the one
224 time then by any other method that I can think of. */
225 @@ -845,6 +866,28 @@ clean_simple_command (command)
226 REVERSE_LIST (command->value.Simple->redirects, REDIRECT *);
229 + if (rpm_requires && command->value.Simple->words)
235 + cmd0 = command->value.Simple->words->word->word;
236 + b = builtin_address_internal (cmd0, 0);
238 + if (command->value.Simple->words->next)
239 + cmd1 = command->value.Simple->words->next->word->word;
242 + if ( (b->flags & REQUIRES_BUILTIN) && cmd1)
243 + output_requirement ("executable", cmd1);
245 + if (!assignment(cmd0, 0))
246 + output_requirement (find_function(cmd0) ? "function" : "executable", cmd0);
251 parser_state &= ~PST_REDIRLIST;
254 diff --git a/shell.c b/shell.c
255 index a2b2a55..c5d99b3 100644
258 @@ -193,6 +193,9 @@ int have_devfd = 0;
259 /* The name of the .(shell)rc file. */
260 static char *bashrc_file = DEFAULT_BASHRC;
262 +/* Non-zero if we are finding the scripts requirements. */
265 /* Non-zero means to act more like the Bourne shell on startup. */
266 static int act_like_sh;
268 @@ -259,6 +262,7 @@ static const struct {
269 { "protected", Int, &protected_mode, (char **)0x0 },
271 { "rcfile", Charp, (int *)0x0, &bashrc_file },
272 + { "rpm-requires", Int, &rpm_requires, (char **)0x0 },
273 #if defined (RESTRICTED_SHELL)
274 { "restricted", Int, &restricted, (char **)0x0 },
276 @@ -496,6 +500,12 @@ main (argc, argv, env)
277 if (dump_translatable_strings)
278 read_but_dont_execute = 1;
282 + read_but_dont_execute = 1;
283 + initialize_shell_builtins ();
286 if (running_setuid && privileged_mode == 0)
287 disable_priv_mode ();
289 diff --git a/shell.h b/shell.h
290 index 8072605..6c4149d 100644
295 #include "unwind_prot.h"
296 #include "dispose_cmd.h"
297 +#include "execute_cmd.h"
298 #include "make_cmd.h"
302 #include "pathnames.h"
304 +#include "builtins.h"
305 +#include "builtins/common.h"
307 extern int EOF_Reached;
309 @@ -99,6 +102,9 @@ extern int interactive, interactive_shell;
310 extern int startup_state;
311 extern int reading_shell_script;
312 extern int shell_initialized;
313 +extern int rpm_requires;
314 +static char *alphabet_set = "abcdefghijklmnopqrstuvwxyz"
315 + "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
316 extern int bash_argv_initialized;
317 extern int subshell_environment;
318 extern int current_command_number;