diff options
Diffstat (limited to 'userland/minibox/utilities/sh')
-rw-r--r-- | userland/minibox/utilities/sh/ast.c | 18 | ||||
-rw-r--r-- | userland/minibox/utilities/sh/lexer.c | 18 | ||||
-rw-r--r-- | userland/minibox/utilities/sh/sh.c | 9 |
3 files changed, 30 insertions, 15 deletions
diff --git a/userland/minibox/utilities/sh/ast.c b/userland/minibox/utilities/sh/ast.c index 2b9c151..2a8d775 100644 --- a/userland/minibox/utilities/sh/ast.c +++ b/userland/minibox/utilities/sh/ast.c @@ -11,8 +11,9 @@ void free_ast_command(struct AST *ast) { void free_ast(struct AST *ast) { for (; ast;) { - if (AST_COMMAND == ast->type) + if (AST_COMMAND == ast->type) { free_ast_command(ast); + } struct AST *old = ast; ast = ast->next; free(old); @@ -27,8 +28,9 @@ struct AST *allocate_ast(void) { int parse_command(struct TOKEN **token_ptr, struct AST *cur) { struct TOKEN *token = *token_ptr; - if (TOKEN_CHARS != token->type) + if (TOKEN_CHARS != token->type) { return 0; + } cur->type = AST_COMMAND; cur->val.type = AST_VALUE_STRING; cur->val.string = token->string_rep; @@ -41,10 +43,12 @@ int parse_command(struct TOKEN **token_ptr, struct AST *cur) { child->type = AST_EXPRESSION; child->val.type = AST_VALUE_STRING; child->val.string = token->string_rep; - if (!token->next) + if (!token->next) { break; - if (TOKEN_CHARS != token->next->type) + } + if (TOKEN_CHARS != token->next->type) { break; + } token = token->next; child->next = allocate_ast(); child = child->next; @@ -87,8 +91,9 @@ struct AST *generate_ast(struct TOKEN *token) { struct AST *prev = NULL; for (; token;) { struct AST *cur = allocate_ast(); - if (prev) + if (prev) { prev->next = cur; + } if (parse_command(&token, cur)) { } else if (TOKEN_AND == token->type) { cur->type = AST_CONDITIONAL_AND; @@ -99,8 +104,9 @@ struct AST *generate_ast(struct TOKEN *token) { } else { token = token->next; } - if (!head) + if (!head) { head = cur; + } prev = cur; } return head; diff --git a/userland/minibox/utilities/sh/lexer.c b/userland/minibox/utilities/sh/lexer.c index d7f00c7..09fc2ff 100644 --- a/userland/minibox/utilities/sh/lexer.c +++ b/userland/minibox/utilities/sh/lexer.c @@ -15,19 +15,23 @@ void free_tokens(struct TOKEN *token) { } int is_special_char(char c) { - if (!isprint(c)) + if (!isprint(c)) { return 1; - if (isspace(c)) + } + if (isspace(c)) { return 1; - if (isalnum(c)) + } + if (isalnum(c)) { return 0; + } return !(('>' != c && '|' != c && '&' != c)); } int parse_chars(struct sv *code_ptr, struct TOKEN *cur) { struct sv code = *code_ptr; - if (is_special_char(sv_peek(code))) + if (is_special_char(sv_peek(code))) { return 0; + } cur->type = TOKEN_CHARS; cur->string_rep = sv_split_function(code, &code, is_special_char); *code_ptr = code; @@ -83,16 +87,18 @@ struct TOKEN *lex(struct sv code) { struct TOKEN *cur = malloc(sizeof(struct TOKEN)); cur->next = NULL; - if (prev) + if (prev) { prev->next = cur; + } if (parse_chars(&code, cur)) { } else if (parse_operand(&code, cur)) { } else { free(cur); assert(0 && "Unknown token"); } - if (!head) + if (!head) { head = cur; + } prev = cur; } return head; diff --git a/userland/minibox/utilities/sh/sh.c b/userland/minibox/utilities/sh/sh.c index b00b440..3643d99 100644 --- a/userland/minibox/utilities/sh/sh.c +++ b/userland/minibox/utilities/sh/sh.c @@ -68,8 +68,9 @@ int execute_binary(struct AST *ast, int input_fd) { } if (ast->pipe_rhs) { - if (out >= 0) + if (out >= 0) { close(out); + } return execute_command(ast->pipe_rhs, slave_input); } @@ -135,14 +136,16 @@ void execute_ast(struct AST *ast) { } else if (AST_CONDITIONAL_AND == ast->type) { if (0 != rc) { ast = ast->next; - if (!ast) + if (!ast) { break; + } } } else if (AST_CONDITIONAL_NOT == ast->type) { if (0 == rc) { ast = ast->next; - if (!ast) + if (!ast) { break; + } } } ast = ast->next; |