#line 23 "source.def"
#line 41 "source.def"
#include <config.h>
#include "../bashtypes.h"
#include "posixstat.h"
#include "filecntl.h"
#if ! defined(_MINIX) && defined (HAVE_SYS_FILE_H)
# include <sys/file.h>
#endif
#include <errno.h>
#if defined (HAVE_UNISTD_H)
# include <unistd.h>
#endif
#include "../bashansi.h"
#include "../bashintl.h"
#include "../shell.h"
#include "../flags.h"
#include "../findcmd.h"
#include "common.h"
#include "bashgetopt.h"
#include "../trap.h"
#if !defined (errno)
extern int errno;
#endif
static void maybe_pop_dollar_vars __P((void));
int source_uses_path = 1;
int source_searches_cwd = 1;
static void
maybe_pop_dollar_vars ()
{
if (variable_context == 0 && (dollar_vars_changed () & ARGS_SETBLTIN))
dispose_saved_dollar_vars ();
else
pop_dollar_vars ();
if (debugging_mode)
pop_args ();
set_dollar_vars_unchanged ();
}
int
source_builtin (list)
WORD_LIST *list;
{
int result;
char *filename, *debug_trap;
if (no_options (list))
return (EX_USAGE);
list = loptend;
if (list == 0)
{
builtin_error ("%s", _("filename argument required"));
builtin_usage ();
return (EX_USAGE);
}
#if defined (RESTRICTED_SHELL)
if (restricted && strchr (list->word->word, '/'))
{
sh_restricted (list->word->word);
return (EXECUTION_FAILURE);
}
#endif
filename = (char *)NULL;
if (source_uses_path)
filename = find_path_file (list->word->word);
if (filename == 0)
{
if (source_searches_cwd == 0)
{
builtin_error (_("%s: file not found"), list->word->word);
return (EXECUTION_FAILURE);
}
else
filename = savestring (list->word->word);
}
begin_unwind_frame ("source");
add_unwind_protect ((Function *)xfree, filename);
if (list->next)
{
push_dollar_vars ();
add_unwind_protect ((Function *)maybe_pop_dollar_vars, (char *)NULL);
remember_args (list->next, 1);
if (debugging_mode)
push_args (list->next);
}
set_dollar_vars_unchanged ();
debug_trap = TRAP_STRING (DEBUG_TRAP);
if (debug_trap && function_trace_mode == 0)
{
debug_trap = savestring (debug_trap);
add_unwind_protect (xfree, debug_trap);
add_unwind_protect (set_debug_trap, debug_trap);
restore_default_signal (DEBUG_TRAP);
}
result = source_file (filename, (list && list->next));
run_unwind_frame ("source");
return (result);
}