diff -c -r bash-2.05/bashhist.c bash-2.05-spwncmd/bashhist.c *** bash-2.05/bashhist.c Mon Sep 24 13:18:04 2001 --- bash-2.05-spwncmd/bashhist.c Mon Sep 24 13:18:49 2001 *************** *** 544,549 **** --- 544,568 ---- first_line_saved = 0; } + /** + * Global variable that holds the portion of the command-line + * that has been parsed up to this point. + */ + char *global_command_line = NULL; + + /** + * Add the current line to the + */ + void + set_command_line (line) + char *line; + { + if (global_command_line) { + xfree (global_command_line); + } + global_command_line = savestring (line); + } + /* Add a line to the history list. The variable COMMAND_ORIENTED_HISTORY controls the style of history remembering; when non-zero, and LINE is not the first line of a *************** *** 587,592 **** --- 606,612 ---- sprintf (new_line, "%s%s%s", current->line, chars_to_add, line); offset = where_history (); old = replace_history_entry (offset, new_line, current->data); + set_command_line (new_line); free (new_line); if (old) *************** *** 603,608 **** --- 623,629 ---- hist_last_line_added = 1; add_history (line); history_lines_this_session++; + set_command_line (line); } using_history (); } diff -c -r bash-2.05/eval.c bash-2.05-spwncmd/eval.c *** bash-2.05/eval.c Mon Sep 24 13:18:04 2001 --- bash-2.05-spwncmd/eval.c Mon Sep 24 13:18:49 2001 *************** *** 136,142 **** executing = 1; stdin_redir = 0; ! execute_command (current_command); exec_done: if (current_command) --- 136,144 ---- executing = 1; stdin_redir = 0; ! if (EXECUTION_SUCCESS == execute_spawn_command ()) { ! execute_command (current_command); ! } exec_done: if (current_command) diff -c -r bash-2.05/execute_cmd.c bash-2.05-spwncmd/execute_cmd.c *** bash-2.05/execute_cmd.c Mon Sep 24 13:18:04 2001 --- bash-2.05-spwncmd/execute_cmd.c Mon Sep 24 13:18:49 2001 *************** *** 400,405 **** --- 400,473 ---- #define DESCRIBE_PID(pid) do { if (interactive) describe_pid (pid); } while (0) + extern int no_spawn_cmd; + extern char *global_command_line; + /** + * If SPAWN_COMMAND is set, put command-line into variable + * CMD_LINE and execute this hook. If the hook fails, abort + * the execution of the command itself. (If you don't want + * this functionality, you can always || the command with + * /bin/true). + * The command-line option --no-spawn-command disables this + * feature altogether, for backwards compatability with the + * scripts that uses the variable SPAWN_COMMAND. + */ + int + execute_spawn_command () + { + char* spawn_cmd; + char* cmd_line; + char* tmp; + int result; + + if (!global_command_line) { + return (EXECUTION_SUCCESS); + } + if (no_spawn_cmd) { + return (EXECUTION_SUCCESS); + } + + /** + * get_string_value() seems to return a pointer to a global + * area that will be overwritten by later invocations, so + * we copy the contents (only if there are any -- NULL values + * are not sent to savestring() + */ + spawn_cmd = (spawn_cmd = get_string_value ("SPAWN_COMMAND"), spawn_cmd) ? savestring (spawn_cmd) : NULL; + if (spawn_cmd) { + cmd_line = (cmd_line = get_string_value ("CMD_LINE"), cmd_line) ? savestring (cmd_line) : NULL; + + /** + * Bind the variable CMD_LINE to the current command to be + * executed, only for the duration of the SPAWN_COMMAND. + * Funny enough, we must savestring() the command to be + * executed once more for parse_and_execute() + */ + bind_variable ("CMD_LINE", savestring (global_command_line)); + result = parse_and_execute ( savestring(spawn_cmd), "SPAWN_COMMAND", SEVAL_NONINT|SEVAL_NOHIST); + unbind_variable ("CMD_LINE"); + + /** + * Restore the old value of CMD_LINE if it were set. We + * only need to cleanup memory. + */ + if (cmd_line) { + bind_variable ("CMD_LINE", cmd_line); + xfree (cmd_line); + } + /** + * We have to cleanup SPAWN_COMMAND memory whenever there + * was something to execute (otherwise we wouldn't be in this + * 'if', but there wouldn't be any memory allocated either. + */ + xfree (spawn_cmd); + return (result); + } + else { + return (EXECUTION_SUCCESS); + } + } + /* Execute the command passed in COMMAND, perhaps doing it asynchrounously. COMMAND is exactly what read_command () places into GLOBAL_COMMAND. ASYNCHROUNOUS, if non-zero, says to do this command in the background. diff -c -r bash-2.05/shell.c bash-2.05-spwncmd/shell.c *** bash-2.05/shell.c Mon Sep 24 13:18:04 2001 --- bash-2.05-spwncmd/shell.c Mon Sep 24 13:18:49 2001 *************** *** 183,188 **** --- 183,189 ---- static int make_login_shell; /* Make this shell be a `-bash' shell. */ static int want_initial_help; /* --help option */ + int no_spawn_cmd = 0; /* Don't run SPAWN_COMMAND */ int no_line_editing = 0; /* Don't do fancy line editing. */ int posixly_correct = 0; /* Non-zero means posix.2 superset. */ int dump_translatable_strings; /* Dump strings in $"...", don't execute. */ *************** *** 205,210 **** --- 206,212 ---- { "init-file", Charp, (int *)0x0, &bashrc_file }, { "login", Int, &make_login_shell, (char **)0x0 }, { "noediting", Int, &no_line_editing, (char **)0x0 }, + { "no-spawn-command", Int, &no_spawn_cmd, (char **)0x0 }, { "noprofile", Int, &no_profile, (char **)0x0 }, { "norc", Int, &no_rc, (char **)0x0 }, { "posix", Int, &posixly_correct, (char **)0x0 },