Merge branch 'main' of github.com:gazhonsepaskwa/mmoat

This commit is contained in:
gazhonsepaskwa
2025-02-17 15:52:44 +01:00
4 changed files with 49 additions and 4 deletions

View File

@@ -43,5 +43,7 @@ int execute_command(t_ast_n *node)
node->msh->ex_code = exec_subsh(node->left);
if (node->state == _CMD)
reset_redir(node);
if (node->state == _CMD)
set_var_env("_", node->args[count_args(node->args) - 1], node->msh);
return (node->msh->ex_code);
}

View File

@@ -67,6 +67,8 @@ int execute_shcommand(t_ast_n *node)
node->msh->ex_code = exec_subsh(node->left);
if (node->state == _CMD)
reset_redir(node);
if (node->state == _CMD)
set_var_env("_", node->args[count_args(node->args) - 1], node->msh);
return (node->msh->ex_code);
}

View File

@@ -47,6 +47,32 @@ static char *extract_env(char *str, char **envp)
return (var);
}
int expand_exit(t_ast_n *node, int j, int i)
{
int k;
char *new;
char *ret;
int len;
k = -1;
if (node->args[j][i + 1] && node->args[j][i + 1] == '?')
{
len = ft_strlen(ft_itoa(node->msh->ex_code));
new = ft_calloc(ft_strlen(node->args[j]) + len + 1, 1);
if (!new)
return (0);
ret = new;
while (++k < i)
*new++ = node->args[j][k];
ft_strlcat(new, ft_itoa(node->msh->ex_code), -1);
ft_strlcat(new, &node->args[j][i + 2], -1);
ft_free(&node->args[j]);
node->args[j] = ret;
return (1);
}
return (0);
}
void expander_var(t_ast_n *nd, int j, int i)
{
char *new;
@@ -56,6 +82,8 @@ void expander_var(t_ast_n *nd, int j, int i)
int l;
k = i;
if (expand_exit(nd, j , i))
return ;
new = ft_calloc(ft_strlen(nd->args[j]) + get_var_len(nd, j, &k), 1);
if (!new)
return ;

View File

@@ -13,7 +13,9 @@
#include "../includes/minishell.h"
#include <readline/history.h>
#include <readline/readline.h>
#include <stdlib.h>
#include <termios.h>
#include <time.h>
int g_sig = 0;
@@ -36,10 +38,21 @@ static void add_prevhistory(t_msh *msh)
void handle_sigint(int sig)
{
(void)sig;
write(2, "\n\n", 2);
rl_on_new_line();
rl_replace_line("", 0);
rl_redisplay();
int status;
pid_t pid;
pid = waitpid(-1, &status, 0);
if (pid > 0 && (WIFSIGNALED(status) && WTERMSIG(status) == SIGINT))
{
write(2, "\n", 2);
}
else
{
write(2, "\n\n", 2);
rl_on_new_line();
rl_replace_line("", 0);
rl_redisplay();
}
g_sig = sig;
}