diff options
author | JozanLeClerc <bousset.rudy@gmail.com> | 2020-04-20 22:24:25 +0200 |
---|---|---|
committer | JozanLeClerc <bousset.rudy@gmail.com> | 2020-04-20 22:24:25 +0200 |
commit | fe24a254415b38952eeef8f0ca4e830549360850 (patch) | |
tree | f51808f7ed9ccc7840878de4d1c9d5408c6eaa45 | |
parent | Wrong address (diff) | |
download | 42-minishell-fe24a254415b38952eeef8f0ca4e830549360850.tar.gz 42-minishell-fe24a254415b38952eeef8f0ca4e830549360850.tar.bz2 42-minishell-fe24a254415b38952eeef8f0ca4e830549360850.tar.xz 42-minishell-fe24a254415b38952eeef8f0ca4e830549360850.tar.zst 42-minishell-fe24a254415b38952eeef8f0ca4e830549360850.zip |
Pretty good start
Diffstat (limited to '')
-rw-r--r-- | Makefile | 1 | ||||
-rw-r--r-- | src/ft_b_echo.c | 28 | ||||
-rw-r--r-- | src/ft_b_echo.h | 22 | ||||
-rw-r--r-- | src/ft_b_env.c | 13 | ||||
-rw-r--r-- | src/ft_b_env.h | 3 | ||||
-rw-r--r-- | src/ft_e_lcom.c | 13 | ||||
-rw-r--r-- | src/ft_e_lcom.h | 3 | ||||
-rw-r--r-- | src/ft_m_funptr.c | 3 | ||||
-rw-r--r-- | src/ft_m_loop.c | 4 | ||||
-rw-r--r-- | src/ft_p_lcom.c | 10 | ||||
-rw-r--r-- | src/ft_p_lcom.h | 2 | ||||
-rw-r--r-- | src/ft_p_line.c | 17 | ||||
-rw-r--r-- | src/ft_s_struct.h | 3 |
13 files changed, 94 insertions, 28 deletions
@@ -15,6 +15,7 @@ LFT_SRCS_DIR = ${LFT_DIR}src/ #--------------------------------- FILES --------------------------------------# #==============================================================================# SRCS_NAME = minishell.c +SRCS_NAME += ft_b_echo.c SRCS_NAME += ft_b_env.c SRCS_NAME += ft_e_lcom.c SRCS_NAME += ft_m_funptr.c diff --git a/src/ft_b_echo.c b/src/ft_b_echo.c new file mode 100644 index 0000000..f7b83a2 --- /dev/null +++ b/src/ft_b_echo.c @@ -0,0 +1,28 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_b_echo.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 <libft.h> +#include <stdint.h> +#include "ft_s_struct.h" + +int32_t + ft_b_echo(char *args[], + t_msh *msh) +{ + (void)msh; + while (*args) + { + ft_printf("%s\n", *args); + args++; + } + return (0); +} diff --git a/src/ft_b_echo.h b/src/ft_b_echo.h new file mode 100644 index 0000000..07da189 --- /dev/null +++ b/src/ft_b_echo.h @@ -0,0 +1,22 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_b_echo.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 FT_B_ECHO_H +#define FT_B_ECHO_H + +#include <stdint.h> +#include "ft_s_struct.h" + +int32_t ft_b_echo(char *args[], + t_msh *msh); + +#endif diff --git a/src/ft_b_env.c b/src/ft_b_env.c index e3aa710..4f26788 100644 --- a/src/ft_b_env.c +++ b/src/ft_b_env.c @@ -16,12 +16,17 @@ #include "ft_s_struct.h" int32_t - ft_b_env(t_msh *msh) + ft_b_env(char *args[], + t_msh *msh) { - while (*msh->envp) + char **ptr; + + (void)args; + ptr = msh->envp; + while (*ptr) { - ft_printf("%s\n", *msh->envp); - msh->envp++; + ft_printf("%s\n", *ptr); + ptr++; } return (0); } diff --git a/src/ft_b_env.h b/src/ft_b_env.h index b54bc8e..3e843b0 100644 --- a/src/ft_b_env.h +++ b/src/ft_b_env.h @@ -16,6 +16,7 @@ #include <stdint.h> #include "ft_s_struct.h" -int32_t ft_b_env(t_msh *msh); +int32_t ft_b_env(char *args[], + t_msh *msh); #endif diff --git a/src/ft_e_lcom.c b/src/ft_e_lcom.c index 5624457..c592f3c 100644 --- a/src/ft_e_lcom.c +++ b/src/ft_e_lcom.c @@ -30,23 +30,22 @@ static uint8_t } int32_t - ft_e_lcom(t_lcom *lcom, - t_msh *msh) + ft_e_lcom(t_msh *msh) { uint8_t bu_id; - while (lcom != NULL) + while (msh->lcom_head != NULL) { - ft_printf("qwe\n"); - if ((bu_id = ft_get_builtin_id(lcom->com, msh)) < FT_BUILTINS_COUNT) + if ((bu_id = ft_get_builtin_id(msh->lcom_head->com, msh)) + < FT_BUILTINS_COUNT) { - msh->bu_ptr[bu_id](msh); + msh->bu_ptr[bu_id](msh->lcom_head->args, msh); } else { /* TODO: exec path stuff */ } - lcom = lcom->next; + msh->lcom_head = msh->lcom_head->next; } return (0); } diff --git a/src/ft_e_lcom.h b/src/ft_e_lcom.h index a273388..ccb1db4 100644 --- a/src/ft_e_lcom.h +++ b/src/ft_e_lcom.h @@ -16,7 +16,6 @@ #include <stdint.h> #include "ft_s_struct.h" -int32_t ft_e_lcom(t_lcom *lcom, - t_msh *msh); +int32_t ft_e_lcom(t_msh *msh); #endif diff --git a/src/ft_m_funptr.c b/src/ft_m_funptr.c index ac40491..a9e7882 100644 --- a/src/ft_m_funptr.c +++ b/src/ft_m_funptr.c @@ -12,6 +12,7 @@ #include <libft.h> #include <stdlib.h> +#include "ft_b_echo.h" #include "ft_b_env.h" #include "ft_d_enum.h" #include "ft_m_funptr.h" @@ -20,7 +21,7 @@ void ft_init_buptr(t_msh *msh) { - /* msh->bu_ptr[0] = ft_b_echo; */ + msh->bu_ptr[0] = ft_b_echo; /* msh->bu_ptr[1] = ft_b_cd; */ /* msh->bu_ptr[2] = ft_b_pwd; */ /* msh->bu_ptr[3] = ft_b_export; */ diff --git a/src/ft_m_loop.c b/src/ft_m_loop.c index 557a9b0..4c22009 100644 --- a/src/ft_m_loop.c +++ b/src/ft_m_loop.c @@ -24,7 +24,6 @@ int32_t { int8_t gnl; char *line; - t_lcom *head; gnl = 1; while (gnl > 0) @@ -33,10 +32,9 @@ int32_t gnl = get_next_line(STDIN_FILENO, &line); if (line[0] != '\0') { - head = msh->lcom; ft_p_line(line, msh); ft_memdel((void*)&line); - ft_e_lcom(head, msh); + ft_e_lcom(msh); /* TODO: memdel lcom - INSTALL VALGRIND */ } else diff --git a/src/ft_p_lcom.c b/src/ft_p_lcom.c index f965555..6711b85 100644 --- a/src/ft_p_lcom.c +++ b/src/ft_p_lcom.c @@ -17,21 +17,25 @@ int8_t ft_p_lcom(const char line[], - const int64_t count, + const uint64_t count, t_msh *msh) { - int64_t i; + uint64_t i; char **words; i = 0; if (!(words = ft_split(line, ';'))) return (-1); - while (i < count) + while (i <= count) { if (!(msh->lcom = ft_lcom_new(words[i]))) { return (-1); } + if (i < 1) + { + msh->lcom_head = msh->lcom; + } msh->lcom = msh->lcom->next; i++; } diff --git a/src/ft_p_lcom.h b/src/ft_p_lcom.h index 245e206..556045b 100644 --- a/src/ft_p_lcom.h +++ b/src/ft_p_lcom.h @@ -17,7 +17,7 @@ #include "ft_s_struct.h" int8_t ft_p_lcom(const char line[], - const int64_t count, + const uint64_t count, t_msh *msh); #endif diff --git a/src/ft_p_line.c b/src/ft_p_line.c index ddaf0bd..606408b 100644 --- a/src/ft_p_line.c +++ b/src/ft_p_line.c @@ -21,14 +21,21 @@ void ft_p_line(char line[], t_msh *msh) { - int64_t ret; + uint64_t i; + uint64_t count; - if ((ret = ft_strlchr(line, ';') < 0)) + i = 0; + count = 0; + while (line[i] != '\0') { - if (ft_p_lcom(line, 1, msh) < 0) + if (line[i] == ';') { - exit(FT_RET_ALLOC); + count++; } + i++; + } + if (ft_p_lcom(line, count, msh) < 0) + { + exit(FT_RET_ALLOC); } - /* TODO: fun */ } diff --git a/src/ft_s_struct.h b/src/ft_s_struct.h index 603b885..34a3182 100644 --- a/src/ft_s_struct.h +++ b/src/ft_s_struct.h @@ -29,7 +29,8 @@ typedef struct s_msh char **envp; int32_t ret; char **bu_ref; - int32_t (*bu_ptr[FT_BUILTINS_COUNT])(struct s_msh*); + int32_t (*bu_ptr[FT_BUILTINS_COUNT])(char **, struct s_msh*); + struct s_lcom *lcom_head; struct s_lcom *lcom; } t_msh; |