summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJozanLeClerc <bousset.rudy@gmail.com>2020-09-12 15:07:22 +0200
committerJozanLeClerc <bousset.rudy@gmail.com>2020-09-12 15:07:22 +0200
commit477ea057edf32486e944ef4e33023e9ab6636e07 (patch)
treee8d6996c27b5bb6fde380eadea0c751bb9c2e117
parenthow tf will I norm this (diff)
download42-minishell-477ea057edf32486e944ef4e33023e9ab6636e07.tar.gz
42-minishell-477ea057edf32486e944ef4e33023e9ab6636e07.tar.bz2
42-minishell-477ea057edf32486e944ef4e33023e9ab6636e07.tar.xz
42-minishell-477ea057edf32486e944ef4e33023e9ab6636e07.tar.zst
42-minishell-477ea057edf32486e944ef4e33023e9ab6636e07.zip
Aliases work, fucker
-rw-r--r--src/b_export_next.c11
-rw-r--r--src/e_builtins.c3
-rw-r--r--src/p_lblock_next.c13
-rw-r--r--src/s_com.c2
4 files changed, 18 insertions, 11 deletions
diff --git a/src/b_export_next.c b/src/b_export_next.c
index 059fbc6..1fc732e 100644
--- a/src/b_export_next.c
+++ b/src/b_export_next.c
@@ -13,6 +13,7 @@
#include <libft.h>
#include <stdlib.h>
+#include "d_define.h"
#include "b_export_next.h"
#include "f_fail.h"
#include "s_lvars.h"
@@ -21,8 +22,7 @@
#include "u_vars.h"
static char
- **b_get_var(const char arg[],
- t_msh *msh)
+ **b_get_var(const char arg[], t_msh *msh)
{
size_t len;
char **var;
@@ -44,8 +44,7 @@ static char
}
static int64_t
- b_is_it_in_env(const char varname[],
- t_msh *msh)
+ b_is_it_in_env(const char varname[], t_msh *msh)
{
char **env_dup;
size_t i;
@@ -66,8 +65,7 @@ static int64_t
}
static void
- b_add_to_env(const char arg[],
- t_msh *msh)
+ b_add_to_env(const char arg[], t_msh *msh)
{
size_t i;
char **nenvp;
@@ -98,6 +96,7 @@ void
char **var;
int64_t env_i;
+ varval[0] = C_NUL;
var = b_get_var(arg, msh);
if ((env_i = b_is_it_in_env(var[FT_VAR_NAME] + 1, msh)) != -1)
{
diff --git a/src/e_builtins.c b/src/e_builtins.c
index fb7b0ba..7c86a5f 100644
--- a/src/e_builtins.c
+++ b/src/e_builtins.c
@@ -21,6 +21,7 @@
#include "b_export_mute.h"
#include "m_loop.h"
#include "m_redirs.h"
+#include "s_com.h"
#include "s_destroy.h"
#include "s_line.h"
#include "s_struct.h"
@@ -66,7 +67,6 @@ static void
int32_t status;
int32_t ret;
- (void)ptr;
while (wait(&status) != pid)
;
ret = WEXITSTATUS(status);
@@ -83,6 +83,7 @@ static void
{
if (msh->fd == STDIN_FILENO)
m_dump_hist(msh);
+ s_com_destroy(&msh->com);
s_line_clear(&msh->curr);
s_destroy(msh);
exit(ret);
diff --git a/src/p_lblock_next.c b/src/p_lblock_next.c
index 8b755da..707acc0 100644
--- a/src/p_lblock_next.c
+++ b/src/p_lblock_next.c
@@ -113,13 +113,13 @@ static t_bool
void
p_subst_alias(char word[], t_msh *msh)
{
- char *ptr;
+ char value[ARG_MAX];
char tmp[255];
size_t locat[2];
+ char *ptr;
t_bool good;
t_quote_mode mode;
- (void)msh;
mode = Q_NONE;
ptr = word;
ptr = p_skip_whitespace(ptr);
@@ -157,7 +157,14 @@ void
ft_strlcpy(tmp,
word + locat[0],
((locat[1] - locat[0] < 253) ? (locat[1] - locat[0]) : (254)) + 1);
- ft_printf("(%s)\n", tmp);
+ if (u_get_alias_value(value, tmp, ARG_MAX, msh) != 0)
+ return ;
+ (void)ft_memmove(word + (locat[0] + ft_strlen(value)),
+ word + locat[1],
+ ft_strlen(word + locat[1]) + 1 * sizeof(char));
+ (void)ft_memmove(word + locat[0],
+ value,
+ ft_strlen(value) * sizeof(char));
}
}
diff --git a/src/s_com.c b/src/s_com.c
index b85905e..a5c594a 100644
--- a/src/s_com.c
+++ b/src/s_com.c
@@ -116,7 +116,7 @@ t_com
ft_strlcpy(nword, word, ARG_MAX);
if (p_get_redir(nword, &com) != 0)
return (NULL);
- /* if (msh->alias != NULL) */
+ if (msh->alias != NULL)
p_subst_alias(nword, msh);
p_subst_vars(nword, msh);
if ((words = p_split_args(nword, com->redir)) == NULL)