summaryrefslogtreecommitdiff
path: root/userland/minibox/utilities/sh/lexer.c
diff options
context:
space:
mode:
authorAnton Kling <anton@kling.gg>2024-12-12 16:03:08 +0100
committerAnton Kling <anton@kling.gg>2024-12-12 16:03:08 +0100
commitb033314bf1901d436dc71d41d5e1f37dda47e511 (patch)
tree120bd137888a7f96904a47af7d20422608ffe225 /userland/minibox/utilities/sh/lexer.c
parentdcbcdbdc5bcfb86eca05fb655e3bf009d89e39e0 (diff)
formatting: Use clang-format on all projects
This commit also add braces to all `if` statements.
Diffstat (limited to 'userland/minibox/utilities/sh/lexer.c')
-rw-r--r--userland/minibox/utilities/sh/lexer.c18
1 files changed, 12 insertions, 6 deletions
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;