Merge pull request #2 from Savapitech/VARS_T

ENV variables implemented
This commit is contained in:
savalet
2025-04-17 12:33:38 +02:00
committed by GitHub
4 changed files with 23 additions and 3 deletions

View File

@@ -21,7 +21,7 @@ ast_t *parse_arg(ast_ctx_t *ctx, ast_t *node)
if (ctx->act_tok.type == T_SEMICOLON)
return node;
if (ctx->act_tok.type & (T_ARG | T_REDIRECT | T_APPEND |
T_IN_REDIRECT | T_HEREDOC)) {
T_IN_REDIRECT | T_HEREDOC | T_VAR)) {
if (!ensure_node_cap(node))
return NULL;
node->vector.tokens[node->vector.sz] = ctx->act_tok;

View File

@@ -69,8 +69,7 @@ char **parse_args(ef_t *ef, ast_t *node, env_t *env)
if (ef->skip_sz > 0 && i >= ef->skip_i && i < ef->skip_i + ef->skip_sz)
continue;
ensure_args_capacity(&args, sz, &cap);
node->vector.tokens[i].str[node->vector.tokens[i].sz] = '\0';
args[sz] = node->vector.tokens[i].str;
args[sz] = handle_var_case(node, env, &i);
U_DEBUG("Args [%lu] [%s]\n", sz, args[sz]);
sz++;
}

View File

@@ -48,4 +48,5 @@ typedef struct {
__attribute__((nonnull))
int execute(ef_t *ef);
char *handle_var_case(ast_t *node, env_t *env, size_t *i);
#endif /* EXEC_H */

20
src/handle_vars.c Normal file
View File

@@ -0,0 +1,20 @@
/*
** EPITECH PROJECT, 2025
** 42sh
** File description:
** handle_vars
*/
#include "ast.h"
#include "env.h"
char *handle_var_case(ast_t *node, env_t *env, size_t *i)
{
if (node->vector.tokens[*i].type == T_VAR && *i + 1 < node->vector.sz) {
*i += 1;
node->vector.tokens[*i].str[node->vector.tokens[*i].sz] = '\0';
return get_env_value(env, node->vector.tokens[*i].str);
}
node->vector.tokens[*i].str[node->vector.tokens[*i].sz] = '\0';
return node->vector.tokens[*i].str;
}