From e8d6ac902cfa498d066ddc8c4281d9bf6dee761a Mon Sep 17 00:00:00 2001 From: "william.valenduc" Date: Fri, 9 Jan 2026 13:46:37 +0000 Subject: [PATCH 1/3] feat: single quotes expansion --- src/ast/ast.h | 22 +++++++------ src/expansion/expansion.c | 68 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 80 insertions(+), 10 deletions(-) diff --git a/src/ast/ast.h b/src/ast/ast.h index 5bfd8df..b3be544 100644 --- a/src/ast/ast.h +++ b/src/ast/ast.h @@ -1,7 +1,7 @@ #ifndef AST_H #define AST_H -#include "lists.h" +#include "../utils/lists/lists.h" enum ast_type { @@ -10,28 +10,30 @@ enum ast_type AST_CMD }; -union ast_node +struct ast_cmd { - struct ast_if; - struct ast_cmd; + struct list *cmd; }; +union ast_node; + struct ast { enum ast_type type; - union ast_node data; + union ast_node *data; }; struct ast_if { - struct ast* condition; - struct ast* then_clause; - struct ast* else_clause; + struct ast *condition; + struct ast *then_clause; + struct ast *else_clause; }; -struct ast_cmd +union ast_node { - struct list* cmd; + struct ast_if ast_if; + struct ast_cmd ast_cmd; }; #endif /* ! AST_H */ diff --git a/src/expansion/expansion.c b/src/expansion/expansion.c index e69de29..01fa248 100644 --- a/src/expansion/expansion.c +++ b/src/expansion/expansion.c @@ -0,0 +1,68 @@ +#include +#include +#include +#include +#include + +#include "../ast/ast.h" + +struct ast_cmd *expand(struct ast_cmd *cmd) +{ + if (cmd == NULL) + return NULL; + + bool in_quotes = false; + char *str; + size_t len; + struct list *l = cmd->cmd; + + while (l != NULL) + { + in_quotes = false; + str = (char *)l->data; + len = strlen(str); + + for (size_t i = 0; str[i] != '\0'; i++) + { + if (in_quotes) + { + // do nothing + } + else if (str[i] == '\'') + { + in_quotes = !in_quotes; + memmove(&str[i], &str[i + 1], strlen(&str[i + 1]) + 1); + } + // else if (str[i] == '$' && str[i + 1] != '\0' && str[i + 1] != '$' + // && str[i + 1] != ' ') + else if (str[i] == '$' && isalnum(str[i + 1])) + { + // variable expansion + } + } + + if (in_quotes) + { + // error: quote not closed + } + + if (len != strlen(str)) + { + char *new_str = realloc(str, strlen(str) + 1); + if (new_str == NULL) + { + // error: realloc fail + } + l->data = new_str; + } + + l = l->next; + } + return cmd; +} + +int main() +{ + printf("Expansion module test\n"); + return 0; +} From 2f2cdda801f4c98987ad55f53632193965a6c2a9 Mon Sep 17 00:00:00 2001 From: "william.valenduc" Date: Fri, 9 Jan 2026 16:17:38 +0000 Subject: [PATCH 2/3] fix: removed temp main --- src/expansion/expansion.c | 37 ++++++++++++++++++++++++++++--------- 1 file changed, 28 insertions(+), 9 deletions(-) diff --git a/src/expansion/expansion.c b/src/expansion/expansion.c index 01fa248..dccf7b8 100644 --- a/src/expansion/expansion.c +++ b/src/expansion/expansion.c @@ -6,6 +6,14 @@ #include "../ast/ast.h" +// static size_t var_len(char *start) +// { +// char *iter = start; +// while (*iter != ' ' && *iter != 0) +// *iter++; +// return iter - start; +// } + struct ast_cmd *expand(struct ast_cmd *cmd) { if (cmd == NULL) @@ -33,11 +41,14 @@ struct ast_cmd *expand(struct ast_cmd *cmd) in_quotes = !in_quotes; memmove(&str[i], &str[i + 1], strlen(&str[i + 1]) + 1); } - // else if (str[i] == '$' && str[i + 1] != '\0' && str[i + 1] != '$' - // && str[i + 1] != ' ') - else if (str[i] == '$' && isalnum(str[i + 1])) + else if (str[i] == '$' && str[i + 1] != 0 && !isspace(str[i + 1])) { - // variable expansion + // size_t len = var_len(str + i + 1); + // char *end = str + i + len + 1; + // char c = *end; + // *end = 0; + // printf("var: %s\n", str + i + 1); + // *end = c; } } @@ -61,8 +72,16 @@ struct ast_cmd *expand(struct ast_cmd *cmd) return cmd; } -int main() -{ - printf("Expansion module test\n"); - return 0; -} +// int main() +// { +// printf("Expansion module test\n"); +// struct ast_cmd ast_cmd; +// // char str[] = "echo Hello $?"; +// char str[] = "echo Hello $AE86"; +// ast_cmd.cmd = list_append(NULL, str); + +// struct ast_cmd *cmd2 = expand(&ast_cmd); +// printf("cmd2: %s\n", (char *)cmd2->cmd->data); + +// return 0; +// } From 1097e36a47eff61f5bb676e9e9dcd827ed648505 Mon Sep 17 00:00:00 2001 From: "william.valenduc" Date: Fri, 9 Jan 2026 23:12:03 +0000 Subject: [PATCH 3/3] fix:(expansion) ast include path --- src/expansion/expansion.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/expansion/expansion.c b/src/expansion/expansion.c index dccf7b8..406c00b 100644 --- a/src/expansion/expansion.c +++ b/src/expansion/expansion.c @@ -4,7 +4,7 @@ #include #include -#include "../ast/ast.h" +#include "../utils/ast/ast.h" // static size_t var_len(char *start) // {