aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--builtin.cpp42
-rw-r--r--builtin_set.cpp2
-rw-r--r--exec.cpp6
-rw-r--r--highlight.cpp2
-rw-r--r--parser.cpp34
-rw-r--r--parser.h12
6 files changed, 27 insertions, 71 deletions
diff --git a/builtin.cpp b/builtin.cpp
index 19c7e412..8c347111 100644
--- a/builtin.cpp
+++ b/builtin.cpp
@@ -3380,7 +3380,7 @@ static int builtin_else( parser_t &parser, wchar_t **argv )
{
if_block = static_cast<if_block_t *>(parser.current_block);
/* Ensure that we're past IF but not up to an ELSE */
- if (if_block->if_expr_evaluated && ! if_block->has_reached_else())
+ if (if_block->if_expr_evaluated && ! if_block->else_evaluated)
{
block_ok = true;
}
@@ -3399,7 +3399,7 @@ static int builtin_else( parser_t &parser, wchar_t **argv )
/* Run the else block if the IF expression was false and so were all the ELSEIF expressions (if any) */
bool run_else = ! if_block->any_branch_taken;
if_block->skip = ! run_else;
- if_block->if_state = if_block_t::if_state_else;
+ if_block->else_evaluated = true;
env_pop();
env_push(0);
}
@@ -3410,44 +3410,6 @@ static int builtin_else( parser_t &parser, wchar_t **argv )
return proc_get_last_status();
}
-static int builtin_elseif( parser_t &parser, wchar_t **argv )
-{
- puts("BULITIN ELSEIF");
- bool block_ok = false;
- if_block_t *if_block = NULL;
- if (parser.current_block != NULL && parser.current_block->type() == IF)
- {
- if_block = static_cast<if_block_t *>(parser.current_block);
- /* Make sure that we're past IF, but not up to an ELSE */
- if (if_block->if_expr_evaluated && ! if_block->has_reached_else())
- {
- block_ok = true;
- }
- }
-
- if( ! block_ok )
- {
- append_format(stderr_buffer,
- _( L"%ls: Not inside of 'if' block\n" ),
- argv[0] );
- builtin_print_help( parser, argv[0], stderr_buffer );
- return STATUS_BUILTIN_ERROR;
- }
- else
- {
- /* Run this elseif if the IF expression was false, and so were all ELSEIF expressions thus far. */
- bool run_elseif = ! if_block->any_branch_taken;
- if_block->skip = ! run_elseif;
- env_pop();
- env_push(0);
- }
-
- /*
- If everything goes ok, return status of last command to execute.
- */
- return proc_get_last_status();
-}
-
/**
This function handles both the 'continue' and the 'break' builtins
that are used for loop control.
diff --git a/builtin_set.cpp b/builtin_set.cpp
index c9b0b4b6..a4a2d53e 100644
--- a/builtin_set.cpp
+++ b/builtin_set.cpp
@@ -288,7 +288,7 @@ static int update_values( wcstring_list_t &list,
{
return 1;
}
- if ( ind >= list.size() )
+ if ( (size_t)ind >= list.size() )
{
list.resize( ind+1 );
}
diff --git a/exec.cpp b/exec.cpp
index f7ab4970..00abd5d9 100644
--- a/exec.cpp
+++ b/exec.cpp
@@ -116,7 +116,7 @@ void exec_close( int fd )
}
/* Maybe remove this from our set of open fds */
- if (fd < open_fds.size()) {
+ if ((size_t)fd < open_fds.size()) {
open_fds[fd] = false;
}
}
@@ -125,7 +125,7 @@ int exec_pipe( int fd[2])
{
int res;
- while( ( res=pipe( fd ) ) )
+ while ((res=pipe(fd)))
{
if( errno != EINTR )
{
@@ -137,7 +137,7 @@ int exec_pipe( int fd[2])
debug( 4, L"Created pipe using fds %d and %d", fd[0], fd[1]);
int max_fd = std::max(fd[0], fd[1]);
- if (open_fds.size() <= max_fd) {
+ if (max_fd >= 0 && open_fds.size() <= (size_t)max_fd) {
open_fds.resize(max_fd + 1, false);
}
open_fds.at(fd[0]) = true;
diff --git a/highlight.cpp b/highlight.cpp
index ed575928..2feef184 100644
--- a/highlight.cpp
+++ b/highlight.cpp
@@ -1314,7 +1314,7 @@ void highlight_shell( const wcstring &buff, std::vector<int> &color, size_t pos,
// highlight the end of the subcommand
assert(end >= subbuff);
- if ((end - subbuff) < length) {
+ if ((size_t)(end - subbuff) < length) {
color.at(end-subbuff)=HIGHLIGHT_OPERATOR;
}
diff --git a/parser.cpp b/parser.cpp
index cbc3bd4d..6c195199 100644
--- a/parser.cpp
+++ b/parser.cpp
@@ -3308,6 +3308,9 @@ int parser_t::test( const wchar_t * buff,
command.c_str());
print_errors( *out, prefix );
+
+ /* Don't complain about elseif missing a command for elseif if we already complained about elseif being out of place */
+ if (needs_cmd) had_cmd = true;
}
}
@@ -3716,12 +3719,11 @@ block_t::~block_t()
/* Various block constructors */
if_block_t::if_block_t() :
+ block_t(IF),
if_expr_evaluated(false),
- any_branch_taken(false),
is_elseif_entry(false),
- else_evaluated(false),
- if_state(if_state_if),
- block_t(IF)
+ any_branch_taken(false),
+ else_evaluated(false)
{
}
@@ -3732,35 +3734,35 @@ event_block_t::event_block_t(const event_t *evt) :
}
function_block_t::function_block_t(process_t *p, const wcstring &n, bool shadows) :
+ block_t( shadows ? FUNCTION_CALL : FUNCTION_CALL_NO_SHADOW ),
process(p),
- name(n),
- block_t( shadows ? FUNCTION_CALL : FUNCTION_CALL_NO_SHADOW )
+ name(n)
{
}
source_block_t::source_block_t(const wchar_t *src) :
- source_file(src),
- block_t(SOURCE)
+ block_t(SOURCE),
+ source_file(src)
{
}
for_block_t::for_block_t(const wcstring &var) :
+ block_t(FOR),
variable(var),
- sequence(),
- block_t(FOR)
+ sequence()
{
}
while_block_t::while_block_t() :
- status(0),
- block_t(WHILE)
+ block_t(WHILE),
+ status(0)
{
}
switch_block_t::switch_block_t(const wcstring &sv) :
+ block_t(SWITCH),
switch_taken(false),
- switch_value(sv),
- block_t(SWITCH)
+ switch_value(sv)
{
}
@@ -3770,8 +3772,8 @@ fake_block_t::fake_block_t() :
}
function_def_block_t::function_def_block_t() :
- function_data(),
- block_t(FUNCTION_DEF)
+ block_t(FUNCTION_DEF),
+ function_data()
{
}
diff --git a/parser.h b/parser.h
index 31f08b7b..de59a0d1 100644
--- a/parser.h
+++ b/parser.h
@@ -140,19 +140,11 @@ struct block_t
struct if_block_t : public block_t
{
- bool if_expr_evaluated; // whether the clause of the if statement has been tested
+ bool if_expr_evaluated; // whether we've evaluated the if expression
+ bool is_elseif_entry; // whether we're at the beginning of an active branch (IF or ELSEIF)
bool any_branch_taken; // whether the clause of the if statement or any elseif has been found to be true
- bool is_elseif_entry; // whether we're the first command in an elseif.
bool else_evaluated; // whether we've encountered a terminal else block
- enum {
- if_state_if,
- if_state_elseif,
- if_state_else
- } if_state;
-
- bool has_reached_else() const { return if_state == if_state_else; }
-
if_block_t();
};