From 5c113af0ba00c0b797ea607e2b0fc5bf56303c9b Mon Sep 17 00:00:00 2001 From: savalet Date: Mon, 28 Apr 2025 20:06:35 +0200 Subject: [PATCH] Add backslash --- src/ast.h | 7 ++++--- src/ast/ast.c | 6 +++++- src/ast/tokeniser.c | 1 + src/globbing.c | 6 +++++- src/shell.c | 5 ++--- 5 files changed, 17 insertions(+), 8 deletions(-) diff --git a/src/ast.h b/src/ast.h index 4187be7..df882ae 100644 --- a/src/ast.h +++ b/src/ast.h @@ -41,9 +41,10 @@ typedef enum { T_THEN = 1 << 18, // then T_ELSE = 1 << 19, // else T_ENDIF = 1 << 20, // endif - T_EOF = 1 << 21, // \0 - T_ARG = 1 << 22, - T_INVALID = 1 << 23 + T_STAR = 1 << 21, // * + T_EOF = 1 << 22, // \0 + T_ARG = 1 << 23, + T_INVALID = 1 << 24 } token_type_t; typedef enum { diff --git a/src/ast/ast.c b/src/ast/ast.c index 115e2d6..bd45218 100644 --- a/src/ast/ast.c +++ b/src/ast/ast.c @@ -20,8 +20,12 @@ ast_t *parse_arg(ast_ctx_t *ctx, ast_t *node) ctx->act_tok = get_next_token(ctx); if (ctx->act_tok.type == T_SEMICOLON) return node; + if (*ctx->act_tok.str == '\\') { + ctx->act_tok = get_next_token(ctx); + ctx->act_tok.type = T_ARG; + } if (ctx->act_tok.type & (T_ARG | T_REDIRECT | T_APPEND | - T_IN_REDIRECT | T_HEREDOC | T_VAR)) { + T_IN_REDIRECT | T_HEREDOC | T_VAR | T_STAR)) { if (!ensure_node_cap(node)) return NULL; node->vector.tokens[node->vector.sz] = ctx->act_tok; diff --git a/src/ast/tokeniser.c b/src/ast/tokeniser.c index de25f5d..5cd1b5b 100644 --- a/src/ast/tokeniser.c +++ b/src/ast/tokeniser.c @@ -33,6 +33,7 @@ const tokens_list_t TOKENS_LIST[] = { { T_THEN, "then", 4, "T_THEN"}, { T_ELSE, "else", 4, "T_ELSE"}, { T_ENDIF, "endif", 5, "T_ENDIF"}, + { T_STAR, "*", 1, "T_STAR"}, { T_EOF, "\0", 1, "T_EOF" } }; diff --git a/src/globbing.c b/src/globbing.c index 2b78391..346daff 100644 --- a/src/globbing.c +++ b/src/globbing.c @@ -48,7 +48,11 @@ bool process_args(ast_t *node, args_t *args, size_t *toks_i, ef_t *ef) { token_t tok = node->vector.tokens[*toks_i]; - if (strcspn(tok.str, "*[]?") != strlen(tok.str)) + if (strchr(tok.str, '\\') != NULL) { + args->args[args->sz] = tok.str; + return true; + } + if (tok.type == T_STAR || strcspn(tok.str, "[]?") != strlen(tok.str)) return (process_globbing(tok.str, args)); if (!ensure_args_capacity(args)) return false; diff --git a/src/shell.c b/src/shell.c index 5f25136..a6d7387 100644 --- a/src/shell.c +++ b/src/shell.c @@ -16,10 +16,9 @@ #include "debug.h" #include "env.h" #include "history.h" +#include "local.h" #include "shell.h" #include "u_str.h" -#include "local.h" -#include "loop.h" __attribute__((unused)) static @@ -75,7 +74,7 @@ bool change_shell_command(char **buffer, exec_ctx_t *exec_ctx, free(tmp_buff); return false; } - U_DEBUG("Buffer [%lu] [%s]\n", buffer_len, buffer); + U_DEBUG("Buffer [%lu] [%s]\n", buffer_len, tmp_buff); visitor(tmp_buff, exec_ctx); free(tmp_buff); return false;