aboutsummaryrefslogtreecommitdiffstats
path: root/builtins/evalstring.c
diff options
context:
space:
mode:
authorJari Aalto <jari.aalto@cante.net>2004-07-27 13:29:18 +0000
committerJari Aalto <jari.aalto@cante.net>2009-09-12 16:46:56 +0000
commitb80f6443b6b7b620c7272664c66ecb0b120a0998 (patch)
tree9f71c98d8fe8fa0f41d95e1eb4227f32a09d43ca /builtins/evalstring.c
parent7117c2d221b2aed4ede8600f6a36b7c1454b4f55 (diff)
downloadandroid_external_bash-b80f6443b6b7b620c7272664c66ecb0b120a0998.tar.gz
android_external_bash-b80f6443b6b7b620c7272664c66ecb0b120a0998.tar.bz2
android_external_bash-b80f6443b6b7b620c7272664c66ecb0b120a0998.zip
Imported from ../bash-3.0.tar.gz.
Diffstat (limited to 'builtins/evalstring.c')
-rw-r--r--builtins/evalstring.c25
1 files changed, 20 insertions, 5 deletions
diff --git a/builtins/evalstring.c b/builtins/evalstring.c
index 860a3de..88d6a9e 100644
--- a/builtins/evalstring.c
+++ b/builtins/evalstring.c
@@ -84,6 +84,7 @@ parse_and_execute_cleanup ()
(flags & SEVAL_INTERACT) -> interactive = 1;
(flags & SEVAL_NOHIST) -> call bash_history_disable ()
(flags & SEVAL_NOFREE) -> don't free STRING when finished
+ (flags & SEVAL_RESETLINE) -> reset line_number to 1
*/
int
@@ -92,7 +93,7 @@ parse_and_execute (string, from_file, flags)
const char *from_file;
int flags;
{
- int code, x;
+ int code, x, lreset;
volatile int should_jump_to_top_level, last_result;
char *orig_string;
COMMAND *volatile command;
@@ -107,6 +108,8 @@ parse_and_execute (string, from_file, flags)
if (flags & (SEVAL_NONINT|SEVAL_INTERACT))
unwind_protect_int (interactive);
+ lreset = flags & SEVAL_RESETLINE;
+
#if defined (HISTORY)
unwind_protect_int (remember_on_history); /* can be used in scripts */
# if defined (BANG_HISTORY)
@@ -129,7 +132,15 @@ parse_and_execute (string, from_file, flags)
end_unwind_frame ();
parse_and_execute_level++;
- push_stream (1); /* reset the line number */
+
+ /* Reset the line number if the caller wants us to. If we don't reset the
+ line number, we have to subtract one, because we will add one just
+ before executing the next command (resetting the line number sets it to
+ 0; the first line number is 1). */
+ push_stream (lreset);
+ if (lreset == 0)
+ line_number--;
+
indirection_level++;
if (flags & (SEVAL_NONINT|SEVAL_INTERACT))
interactive = (flags & SEVAL_NONINT) ? 0 : 1;
@@ -141,11 +152,12 @@ parse_and_execute (string, from_file, flags)
code = should_jump_to_top_level = 0;
last_result = EXECUTION_SUCCESS;
- command = (COMMAND *)NULL;
with_input_from_string (string, from_file);
while (*(bash_input.location.string))
{
+ command = (COMMAND *)NULL;
+
if (interrupt_state)
{
last_result = EXECUTION_FAILURE;
@@ -163,15 +175,18 @@ parse_and_execute (string, from_file, flags)
switch (code)
{
case FORCE_EOF:
+ case ERREXIT:
case EXITPROG:
- run_unwind_frame ("pe_dispose");
+ if (command)
+ run_unwind_frame ("pe_dispose");
/* Remember to call longjmp (top_level) after the old
value for it is restored. */
should_jump_to_top_level = 1;
goto out;
case DISCARD:
- run_unwind_frame ("pe_dispose");
+ if (command)
+ run_unwind_frame ("pe_dispose");
last_result = last_command_exit_value = EXECUTION_FAILURE; /* XXX */
if (subshell_environment)
{