diff options
author | Anton Kling <anton@kling.gg> | 2024-12-12 16:03:08 +0100 |
---|---|---|
committer | Anton Kling <anton@kling.gg> | 2024-12-12 16:03:08 +0100 |
commit | b033314bf1901d436dc71d41d5e1f37dda47e511 (patch) | |
tree | 120bd137888a7f96904a47af7d20422608ffe225 /userland/minibox/utilities/sh/ast.c | |
parent | dcbcdbdc5bcfb86eca05fb655e3bf009d89e39e0 (diff) |
formatting: Use clang-format on all projects
This commit also add braces to all `if` statements.
Diffstat (limited to 'userland/minibox/utilities/sh/ast.c')
-rw-r--r-- | userland/minibox/utilities/sh/ast.c | 18 |
1 files changed, 12 insertions, 6 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; |