Add backslash

This commit is contained in:
savalet
2025-04-28 20:06:35 +02:00
parent 376a3293de
commit 5c113af0ba
5 changed files with 17 additions and 8 deletions

View File

@@ -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 {

View File

@@ -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;

View File

@@ -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" }
};

View File

@@ -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;

View File

@@ -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;