summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJozanLeClerc <bousset.rudy@gmail.com>2020-09-11 16:56:23 +0200
committerJozanLeClerc <bousset.rudy@gmail.com>2020-09-11 16:56:23 +0200
commit0ab424df075f09aac376890a9a5a73cb74e053bf (patch)
tree7dab35480c6005f3bbc7ed864410bf04da9dd0bd
parentTODO update (diff)
download42-minishell-0ab424df075f09aac376890a9a5a73cb74e053bf.tar.gz
42-minishell-0ab424df075f09aac376890a9a5a73cb74e053bf.tar.bz2
42-minishell-0ab424df075f09aac376890a9a5a73cb74e053bf.tar.xz
42-minishell-0ab424df075f09aac376890a9a5a73cb74e053bf.tar.zst
42-minishell-0ab424df075f09aac376890a9a5a73cb74e053bf.zip
alias in progress
-rw-r--r--Makefile3
-rw-r--r--src/b_alias.c23
-rw-r--r--src/b_alias.h22
-rw-r--r--src/b_builtins.h1
-rw-r--r--src/d_define.h2
-rw-r--r--src/d_enum.h1
-rw-r--r--src/m_funptr.c3
-rw-r--r--src/s_init.c6
-rw-r--r--src/s_struct.h22
9 files changed, 70 insertions, 13 deletions
diff --git a/Makefile b/Makefile
index 4e890fe..16aa45a 100644
--- a/Makefile
+++ b/Makefile
@@ -15,7 +15,8 @@ LFT_SRCS_DIR = ${LFT_DIR}src/
#==============================================================================#
#--------------------------------- FILES --------------------------------------#
#==============================================================================#
-SRCS_NAME = b_cd
+SRCS_NAME = b_alias
+SRCS_NAME += b_cd
SRCS_NAME += b_echo
SRCS_NAME += b_env
SRCS_NAME += b_exit
diff --git a/src/b_alias.c b/src/b_alias.c
new file mode 100644
index 0000000..6848b68
--- /dev/null
+++ b/src/b_alias.c
@@ -0,0 +1,23 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* b_alias.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/14 17:19:27 by rbousset #+# #+# */
+/* Updated: 2020/02/14 17:19:29 by rbousset ### ########lyon.fr */
+/* */
+/* ************************************************************************** */
+
+#include <stdint.h>
+
+#include "s_struct.h"
+
+uint8_t
+ b_alias(char *args[], t_msh *msh)
+{
+ (void)args;
+ (void)msh;
+ return (0);
+}
diff --git a/src/b_alias.h b/src/b_alias.h
new file mode 100644
index 0000000..a4aa1d8
--- /dev/null
+++ b/src/b_alias.h
@@ -0,0 +1,22 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* b_alias.h :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/14 17:19:27 by rbousset #+# #+# */
+/* Updated: 2020/02/14 17:19:29 by rbousset ### ########lyon.fr */
+/* */
+/* ************************************************************************** */
+
+#ifndef B_ALIAS_H
+#define B_ALIAS_H
+
+#include <stdint.h>
+
+#include "s_struct.h"
+
+uint8_t b_alias(char *args[], t_msh *msh);
+
+#endif
diff --git a/src/b_builtins.h b/src/b_builtins.h
index 0cb430a..62b2a41 100644
--- a/src/b_builtins.h
+++ b/src/b_builtins.h
@@ -13,6 +13,7 @@
#ifndef B_BUILTINS_H
#define B_BUILTINS_H
+#include "b_alias.h"
#include "b_cd.h"
#include "b_echo.h"
#include "b_env.h"
diff --git a/src/d_define.h b/src/d_define.h
index 0e62f36..897b720 100644
--- a/src/d_define.h
+++ b/src/d_define.h
@@ -19,7 +19,7 @@
** ====== CLASSICS ======
*/
-#define FT_BUILTINS "echo|cd|pwd|export|unset|env|exit|type|["
+#define FT_BUILTINS "echo|cd|pwd|export|unset|env|exit|type|[|alias"
/*
** ====== PSX ======
diff --git a/src/d_enum.h b/src/d_enum.h
index e5078a7..69d34c9 100644
--- a/src/d_enum.h
+++ b/src/d_enum.h
@@ -50,6 +50,7 @@ enum
FT_ID_EXIT,
FT_ID_TYPE,
FT_ID_SQB,
+ FT_ID_ALIAS,
FT_BUILTINS_COUNT
};
diff --git a/src/m_funptr.c b/src/m_funptr.c
index a6b31f2..1983e73 100644
--- a/src/m_funptr.c
+++ b/src/m_funptr.c
@@ -31,7 +31,8 @@ void
msh->bu_ptr[FT_ID_EXIT] = b_exit;
msh->bu_ptr[FT_ID_TYPE] = b_type;
msh->bu_ptr[FT_ID_SQB] = b_sqb;
- if (!(msh->bu_ref = ft_split(FT_BUILTINS, '|')))
+ msh->bu_ptr[FT_ID_ALIAS] = b_alias;
+ if ((msh->bu_ref = ft_split(FT_BUILTINS, '|')) == NULL)
{
f_alloc_and_destroy_msh(msh);
}
diff --git a/src/s_init.c b/src/s_init.c
index cfe2eeb..fb63548 100644
--- a/src/s_init.c
+++ b/src/s_init.c
@@ -163,11 +163,10 @@ t_msh
char cwd[PATH_MAX];
t_msh *msh;
- if (!(msh = (t_msh*)malloc(sizeof(t_msh))))
+ if ((msh = (t_msh*)malloc(sizeof(t_msh))) == NULL)
return (NULL);
- if (!(msh->shname = ft_strdup(argv[0])))
+ if ((msh->shname = ft_strdup(argv[0])) == NULL)
return (NULL);
- /* TODO: shname: care about "./", try with symlinks */
msh->envp = NULL;
if ((msh->envp = dupenv(envp)) == NULL)
return (NULL);
@@ -177,6 +176,7 @@ t_msh
msh->com = NULL;
msh->pipes = NULL;
msh->vars = NULL;
+ msh->alias = NULL;
set_cwd(cwd, msh);
if ((msh->cwd = ft_strdup(cwd)) == NULL)
return (NULL);
diff --git a/src/s_struct.h b/src/s_struct.h
index 31c80fc..b45af9f 100644
--- a/src/s_struct.h
+++ b/src/s_struct.h
@@ -18,6 +18,20 @@
#include "d_define.h"
+typedef struct s_lalias
+{
+ char *name;
+ char *value;
+ struct s_lalias *next;
+} t_lalias;
+
+typedef struct s_lvars
+{
+ struct s_lvars *next;
+ char *name;
+ char *val;
+} t_lvars;
+
/*
** redir(int8_t) index
** -------------------
@@ -27,13 +41,6 @@
** 0: means no redirection
*/
-typedef struct s_lvars
-{
- struct s_lvars *next;
- char *name;
- char *val;
-} t_lvars;
-
typedef struct s_com
{
char **argv;
@@ -71,6 +78,7 @@ typedef struct s_msh
struct s_com *com;
struct s_lpipes *pipes;
struct s_lvars *vars;
+ struct s_lalias *alias;
char **envp;
char **bu_ref;
char ps[4][1024];