From 4dd10e6f4de22446ea84d7b194d2a18cb6e43c6c Mon Sep 17 00:00:00 2001 From: JozanLeClerc Date: Tue, 8 Sep 2020 18:50:11 +0200 Subject: Names --- src/m_loop.c | 2 +- src/p_lblock.c | 167 +++++++++++++++++++++++++++++++++++++++ src/p_lblock.h | 23 ++++++ src/p_lblock_next.c | 223 ++++++++++++++++++++++++++++++++++++++++++++++++++++ src/p_lblock_next.h | 25 ++++++ src/p_lcom.c | 167 --------------------------------------- src/p_lcom.h | 23 ------ src/p_lcom_next.c | 223 ---------------------------------------------------- src/p_lcom_next.h | 25 ------ src/p_line.c | 2 +- src/s_init.c | 2 + src/s_struct.h | 73 ++++++++--------- 12 files changed, 479 insertions(+), 476 deletions(-) create mode 100644 src/p_lblock.c create mode 100644 src/p_lblock.h create mode 100644 src/p_lblock_next.c create mode 100644 src/p_lblock_next.h delete mode 100644 src/p_lcom.c delete mode 100644 src/p_lcom.h delete mode 100644 src/p_lcom_next.c delete mode 100644 src/p_lcom_next.h (limited to 'src') diff --git a/src/m_loop.c b/src/m_loop.c index 7dc19e0..9d00f2b 100644 --- a/src/m_loop.c +++ b/src/m_loop.c @@ -87,7 +87,7 @@ uint8_t if (fd == STDIN_FILENO) m_prompt_psx(1, msh); gnl = get_next_line(fd, &line); - if (line[0] != '\0') + if (line[0] != C_NUL) { line = m_check_multi_backslash(fd, line, msh); line = m_check_multi_pipe(fd, line, msh); diff --git a/src/p_lblock.c b/src/p_lblock.c new file mode 100644 index 0000000..a8c42ce --- /dev/null +++ b/src/p_lblock.c @@ -0,0 +1,167 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* p_lcom.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rbousset +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/02/14 17:19:27 by rbousset #+# #+# */ +/* Updated: 2020/02/14 17:19:29 by rbousset ### ########lyon.fr */ +/* */ +/* ************************************************************************** */ + +#include +#include +#include +#include +#include +#include + +#include "d_define.h" +#include "f_fail.h" +#include "p_split.h" +#include "s_line.h" +#include "s_lpipes.h" +#include "s_struct.h" + +static void + rdr_err_check(char *ptr, + t_com **com) +{ + if ((*com)->redir == -1 && ft_ischarset("><", *(ptr + 1)) == TRUE) + { + /* TODO: syntax err */ + } + else if ((*com)->redir == 1 && ft_ischarset("<", *(ptr + 1)) == TRUE) + { + /* TODO: syntax err */ + } + else if ((*com)->redir == 2 && ft_ischarset("<>", *(ptr + 1)) == TRUE) + { + /* TODO: syntax err */ + } +} + +static int8_t + get_rdrpath(char *ptr, + t_com **com) +{ + char *p_rdrpath; + + ptr += ((*com)->redir == 2) ? (2) : (1); + if (!((*com)->rdrpath = + (char*)malloc((ft_strlen(ptr) + 1) * sizeof(char)))) + { + return (-1); + } + p_rdrpath = (*com)->rdrpath; + while (*ptr) + { + if (*ptr != ' ') + { + *p_rdrpath = *ptr; + p_rdrpath++; + } + ptr++; + } + *p_rdrpath = '\0'; + return (0); +} + +static void + get_rdrfd(const char *ptr, + t_com **com) +{ + while (ft_isdigit(*ptr) == TRUE) + { + ptr--; + } + if (*ptr != ' ') + (*com)->rdrfd = STDOUT_FILENO; + else + { + ptr += 1; + (*com)->rdrfd = ft_atoi(ptr); + } +} + +int8_t + p_get_redir(const char word[], + t_com **com) +{ + /* TODO: norme */ + char *ptr; + + ptr = (char *)word; + while (*ptr) + { + if (*ptr == '<') + { + (*com)->redir = -1; + break ; + } + if (*ptr == '>') + { + (*com)->redir = (*(ptr + 1) == '>') ? (2) : (1); + break ; + } + ptr++; + /* TODO: handle correctly multiples "msh ~> echo qwe > qwe > asd >> zxc > qweasdzxc" */ + /* hint: bash only handles the last one */ + /* TODO: handle "msh ~> cat < Makefile >qwe" | gl hf */ + } + if ((*com)->redir > 0) + { + if (ft_isdigit(*(ptr - 1)) == TRUE) + get_rdrfd(ptr - 1, com); + else + (*com)->rdrfd = STDOUT_FILENO; + rdr_err_check(ptr, com); + if (get_rdrpath(ptr, com) != 0) + return (-1); + } + return (0); +} + +int8_t + p_lcom(const char line[], + t_msh *msh) +{ + /* TODO: norme */ + uint64_t i; + t_line *link; + char **words; + char *ptr; + uint8_t nextif; + t_bool next; + + i = 0; + if ((words = p_split_line(line)) == NULL) + return (-1); + while (words[i] != NULL) + { + if (words[i][ft_strlen(words[i]) - 1] == ';') + nextif = 0; + else if (words[i][ft_strlen(words[i]) - 1] == '&') + nextif = 1; + else + nextif = 2; + words[i][ft_strlen(words[i]) - 1] = '\0'; + next = FALSE; + if ((ptr = ft_strchr(words[i], '|')) != NULL) + { + if ((link = s_line_new(NULL, msh)) == NULL) + return (-1); + if ((s_split_pipes(words[i], link, msh)) == NULL) + return (-1); + next = TRUE; + } + if (next == FALSE && (link = s_line_new(words[i], msh)) == NULL) + return (-1); + link->nextif = nextif; + s_line_add_back(&msh->curr, link); + i++; + } + ft_delwords(words); + return (0); +} diff --git a/src/p_lblock.h b/src/p_lblock.h new file mode 100644 index 0000000..796c684 --- /dev/null +++ b/src/p_lblock.h @@ -0,0 +1,23 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* p_lcom.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rbousset +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/02/14 17:19:27 by rbousset #+# #+# */ +/* Updated: 2020/02/14 17:19:29 by rbousset ### ########lyon.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef P_LCOM_H +#define P_LCOM_H + +#include + +#include "s_struct.h" + +int8_t p_get_redir(const char word[], t_com **com); +int8_t p_lcom(const char line[], t_msh *msh); + +#endif diff --git a/src/p_lblock_next.c b/src/p_lblock_next.c new file mode 100644 index 0000000..16d8aac --- /dev/null +++ b/src/p_lblock_next.c @@ -0,0 +1,223 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* p_line_next.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rbousset +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/02/14 17:19:27 by rbousset #+# #+# */ +/* Updated: 2020/02/14 17:19:29 by rbousset ### ########lyon.fr */ +/* */ +/* ************************************************************************** */ + +#include +#include +#include +#include + +#include "d_define.h" +#include "s_destroy.h" +#include "f_fail.h" +#include "s_struct.h" +#include "u_utils.h" +#include "u_vars.h" +#include "u_vars_next.h" + +/* TODO: norme */ + +static char + *p_subst_this_var(char **p, int64_t i, char word[], t_msh *msh) +{ + char tmp[4096]; + char varval[4096]; + char *ptr; + size_t varlen; + + ptr = word; + varlen = i + 1; + while (ptr[varlen] != C_NUL && + ft_ischarset("$=\\/@%^*+{}[]<>,.-", ptr[varlen]) == FALSE && + ft_iswhitespace(ptr[varlen]) == FALSE) + varlen += 1; + ft_strlcpy(tmp, ptr + i, varlen + 1 - i); + u_get_var_value(varval, tmp, 4096, msh); + ft_strlcpy(tmp, ptr + varlen, varlen); + word = ft_nrealloc(word, i, i + ft_strlen(varval) + ft_strlen(tmp) + 1); + ft_strlcpy(word + i, varval, ft_strlen(varval) + 1); + ft_strlcpy(word + (i + ft_strlen(varval)), tmp, ft_strlen(tmp) + 1); + *(p) = word + (i + ft_strlen(varval) - 1); + return (word); +} + +char + *p_subst_vars(char word[], t_msh *msh) +{ + char *ptr; + + ptr = word; + while (*ptr != C_NUL) + { + if (*ptr == '$' && u_is_not_escaped(word, ptr) == TRUE) + { + if ((word = p_subst_this_var(&ptr, (ptr - word), word, msh)) == NULL) + { + return (NULL); + } + } + ptr++; + } + return (word); +} + +char + **p_subst_home(char *words[], + t_msh *msh) +{ + char path[PATH_MAX]; + char **ptr; + + u_get_var_value(path, "$HOME", PATH_MAX, msh); + if (path[0] == C_NUL) + return (words); + ptr = words; + while (*ptr != NULL) + { + if (*ptr[0] == '~') + { + *ptr = ft_strsubst(*ptr, "~", path); + } + ptr++; + } + return (words); +} + +static void + p_register_word(char word[], + t_msh *msh) +{ + char name[255]; + char val[255]; + char *ptr; + size_t i; + + name[0] = '$'; + ptr = word; + i = 1; + while (*ptr != '=' && *ptr != '\0') + { + name[i] = *ptr; + i++; + ptr++; + } + name[i] = '\0'; + ptr++; + i = 0; + while (*ptr != '\0') + { + val[i] = *ptr; + i++; + ptr++; + } + val[i] = '\0'; + u_subst_var_value(name, val, msh); +} + +static char + **p_add_to_variables_and_delete(char *words[], + t_bool reg, + int64_t i, + t_msh *msh) +{ + int64_t j; + int64_t k; + char **rewords; + + j = 0; + if (reg == TRUE) + { + while (words[j] && j < i) + { + p_register_word(words[j], msh); + j++; + } + } + j = 0; + while (words[i + j] != NULL) + j++; + if (!(rewords = (char**)malloc((j + 1) * sizeof(char*)))) + { + ft_delwords(words); + f_alloc_and_destroy_msh(msh); + } + k = i; + while (i - k < j) + { + if ((rewords[i - k] = ft_strdup(words[i])) == NULL) + { + ft_delwords(words); + f_alloc_and_destroy_msh(msh); + } + i++; + } + rewords[i - k] = 0; + ft_delwords(words); + i++; + return (rewords); +} + +static void + p_add_to_env_fork(int64_t i, + char *words[], + t_msh *msh) +{ + int64_t j; + + j = 0; + while(j < i) + { + ft_strlcpy(msh->env_fork_tmp[j], words[j], ft_strlen(words[j]) + 1); + j++; + } + msh->env_fork_tmp[j][0] = '\0'; +} + +char + **p_check_args_equals(char *words[], + t_msh *msh) +{ + char *ptr; + t_bool reg; + t_bool isvar; + int64_t i; + + i = 0; + reg = FALSE; + isvar = FALSE; + while (words[i]) + { + ptr = words[i]; + while (*ptr != '\0' && *ptr != '=') + ptr++; + if (*ptr == '=') + { + reg = TRUE; + isvar = TRUE; + } + if (*ptr == '\0' || words[i][0] == '=' || + ft_isdigit(words[i][0]) == TRUE) + { + reg = FALSE; + if (i == 0) + isvar = FALSE; + if (isvar == TRUE) + p_add_to_env_fork(i, words, msh); + else + msh->env_fork_tmp[0][0] = '\0'; + break ; + } + i++; + } + if (isvar == TRUE) + return (p_add_to_variables_and_delete(words, reg, i, msh)); + return (words); +} diff --git a/src/p_lblock_next.h b/src/p_lblock_next.h new file mode 100644 index 0000000..8fbbb99 --- /dev/null +++ b/src/p_lblock_next.h @@ -0,0 +1,25 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* p_line_next.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rbousset +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/02/14 17:19:27 by rbousset #+# #+# */ +/* Updated: 2020/02/14 17:19:29 by rbousset ### ########lyon.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef P_LCOM_NEXT_H +#define P_LCOM_NEXT_H + +#include + +#include "s_struct.h" + +char *p_subst_vars(char word[], t_msh *msh); +char **p_subst_args(const char word[], int8_t redir); +char **p_subst_home(char *word[], t_msh *msh); +char **p_check_args_equals(char *words[], t_msh *msh); + +#endif diff --git a/src/p_lcom.c b/src/p_lcom.c deleted file mode 100644 index a8c42ce..0000000 --- a/src/p_lcom.c +++ /dev/null @@ -1,167 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* p_lcom.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: rbousset +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2020/02/14 17:19:27 by rbousset #+# #+# */ -/* Updated: 2020/02/14 17:19:29 by rbousset ### ########lyon.fr */ -/* */ -/* ************************************************************************** */ - -#include -#include -#include -#include -#include -#include - -#include "d_define.h" -#include "f_fail.h" -#include "p_split.h" -#include "s_line.h" -#include "s_lpipes.h" -#include "s_struct.h" - -static void - rdr_err_check(char *ptr, - t_com **com) -{ - if ((*com)->redir == -1 && ft_ischarset("><", *(ptr + 1)) == TRUE) - { - /* TODO: syntax err */ - } - else if ((*com)->redir == 1 && ft_ischarset("<", *(ptr + 1)) == TRUE) - { - /* TODO: syntax err */ - } - else if ((*com)->redir == 2 && ft_ischarset("<>", *(ptr + 1)) == TRUE) - { - /* TODO: syntax err */ - } -} - -static int8_t - get_rdrpath(char *ptr, - t_com **com) -{ - char *p_rdrpath; - - ptr += ((*com)->redir == 2) ? (2) : (1); - if (!((*com)->rdrpath = - (char*)malloc((ft_strlen(ptr) + 1) * sizeof(char)))) - { - return (-1); - } - p_rdrpath = (*com)->rdrpath; - while (*ptr) - { - if (*ptr != ' ') - { - *p_rdrpath = *ptr; - p_rdrpath++; - } - ptr++; - } - *p_rdrpath = '\0'; - return (0); -} - -static void - get_rdrfd(const char *ptr, - t_com **com) -{ - while (ft_isdigit(*ptr) == TRUE) - { - ptr--; - } - if (*ptr != ' ') - (*com)->rdrfd = STDOUT_FILENO; - else - { - ptr += 1; - (*com)->rdrfd = ft_atoi(ptr); - } -} - -int8_t - p_get_redir(const char word[], - t_com **com) -{ - /* TODO: norme */ - char *ptr; - - ptr = (char *)word; - while (*ptr) - { - if (*ptr == '<') - { - (*com)->redir = -1; - break ; - } - if (*ptr == '>') - { - (*com)->redir = (*(ptr + 1) == '>') ? (2) : (1); - break ; - } - ptr++; - /* TODO: handle correctly multiples "msh ~> echo qwe > qwe > asd >> zxc > qweasdzxc" */ - /* hint: bash only handles the last one */ - /* TODO: handle "msh ~> cat < Makefile >qwe" | gl hf */ - } - if ((*com)->redir > 0) - { - if (ft_isdigit(*(ptr - 1)) == TRUE) - get_rdrfd(ptr - 1, com); - else - (*com)->rdrfd = STDOUT_FILENO; - rdr_err_check(ptr, com); - if (get_rdrpath(ptr, com) != 0) - return (-1); - } - return (0); -} - -int8_t - p_lcom(const char line[], - t_msh *msh) -{ - /* TODO: norme */ - uint64_t i; - t_line *link; - char **words; - char *ptr; - uint8_t nextif; - t_bool next; - - i = 0; - if ((words = p_split_line(line)) == NULL) - return (-1); - while (words[i] != NULL) - { - if (words[i][ft_strlen(words[i]) - 1] == ';') - nextif = 0; - else if (words[i][ft_strlen(words[i]) - 1] == '&') - nextif = 1; - else - nextif = 2; - words[i][ft_strlen(words[i]) - 1] = '\0'; - next = FALSE; - if ((ptr = ft_strchr(words[i], '|')) != NULL) - { - if ((link = s_line_new(NULL, msh)) == NULL) - return (-1); - if ((s_split_pipes(words[i], link, msh)) == NULL) - return (-1); - next = TRUE; - } - if (next == FALSE && (link = s_line_new(words[i], msh)) == NULL) - return (-1); - link->nextif = nextif; - s_line_add_back(&msh->curr, link); - i++; - } - ft_delwords(words); - return (0); -} diff --git a/src/p_lcom.h b/src/p_lcom.h deleted file mode 100644 index 796c684..0000000 --- a/src/p_lcom.h +++ /dev/null @@ -1,23 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* p_lcom.h :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: rbousset +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2020/02/14 17:19:27 by rbousset #+# #+# */ -/* Updated: 2020/02/14 17:19:29 by rbousset ### ########lyon.fr */ -/* */ -/* ************************************************************************** */ - -#ifndef P_LCOM_H -#define P_LCOM_H - -#include - -#include "s_struct.h" - -int8_t p_get_redir(const char word[], t_com **com); -int8_t p_lcom(const char line[], t_msh *msh); - -#endif diff --git a/src/p_lcom_next.c b/src/p_lcom_next.c deleted file mode 100644 index 16d8aac..0000000 --- a/src/p_lcom_next.c +++ /dev/null @@ -1,223 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* p_line_next.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: rbousset +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2020/02/14 17:19:27 by rbousset #+# #+# */ -/* Updated: 2020/02/14 17:19:29 by rbousset ### ########lyon.fr */ -/* */ -/* ************************************************************************** */ - -#include -#include -#include -#include - -#include "d_define.h" -#include "s_destroy.h" -#include "f_fail.h" -#include "s_struct.h" -#include "u_utils.h" -#include "u_vars.h" -#include "u_vars_next.h" - -/* TODO: norme */ - -static char - *p_subst_this_var(char **p, int64_t i, char word[], t_msh *msh) -{ - char tmp[4096]; - char varval[4096]; - char *ptr; - size_t varlen; - - ptr = word; - varlen = i + 1; - while (ptr[varlen] != C_NUL && - ft_ischarset("$=\\/@%^*+{}[]<>,.-", ptr[varlen]) == FALSE && - ft_iswhitespace(ptr[varlen]) == FALSE) - varlen += 1; - ft_strlcpy(tmp, ptr + i, varlen + 1 - i); - u_get_var_value(varval, tmp, 4096, msh); - ft_strlcpy(tmp, ptr + varlen, varlen); - word = ft_nrealloc(word, i, i + ft_strlen(varval) + ft_strlen(tmp) + 1); - ft_strlcpy(word + i, varval, ft_strlen(varval) + 1); - ft_strlcpy(word + (i + ft_strlen(varval)), tmp, ft_strlen(tmp) + 1); - *(p) = word + (i + ft_strlen(varval) - 1); - return (word); -} - -char - *p_subst_vars(char word[], t_msh *msh) -{ - char *ptr; - - ptr = word; - while (*ptr != C_NUL) - { - if (*ptr == '$' && u_is_not_escaped(word, ptr) == TRUE) - { - if ((word = p_subst_this_var(&ptr, (ptr - word), word, msh)) == NULL) - { - return (NULL); - } - } - ptr++; - } - return (word); -} - -char - **p_subst_home(char *words[], - t_msh *msh) -{ - char path[PATH_MAX]; - char **ptr; - - u_get_var_value(path, "$HOME", PATH_MAX, msh); - if (path[0] == C_NUL) - return (words); - ptr = words; - while (*ptr != NULL) - { - if (*ptr[0] == '~') - { - *ptr = ft_strsubst(*ptr, "~", path); - } - ptr++; - } - return (words); -} - -static void - p_register_word(char word[], - t_msh *msh) -{ - char name[255]; - char val[255]; - char *ptr; - size_t i; - - name[0] = '$'; - ptr = word; - i = 1; - while (*ptr != '=' && *ptr != '\0') - { - name[i] = *ptr; - i++; - ptr++; - } - name[i] = '\0'; - ptr++; - i = 0; - while (*ptr != '\0') - { - val[i] = *ptr; - i++; - ptr++; - } - val[i] = '\0'; - u_subst_var_value(name, val, msh); -} - -static char - **p_add_to_variables_and_delete(char *words[], - t_bool reg, - int64_t i, - t_msh *msh) -{ - int64_t j; - int64_t k; - char **rewords; - - j = 0; - if (reg == TRUE) - { - while (words[j] && j < i) - { - p_register_word(words[j], msh); - j++; - } - } - j = 0; - while (words[i + j] != NULL) - j++; - if (!(rewords = (char**)malloc((j + 1) * sizeof(char*)))) - { - ft_delwords(words); - f_alloc_and_destroy_msh(msh); - } - k = i; - while (i - k < j) - { - if ((rewords[i - k] = ft_strdup(words[i])) == NULL) - { - ft_delwords(words); - f_alloc_and_destroy_msh(msh); - } - i++; - } - rewords[i - k] = 0; - ft_delwords(words); - i++; - return (rewords); -} - -static void - p_add_to_env_fork(int64_t i, - char *words[], - t_msh *msh) -{ - int64_t j; - - j = 0; - while(j < i) - { - ft_strlcpy(msh->env_fork_tmp[j], words[j], ft_strlen(words[j]) + 1); - j++; - } - msh->env_fork_tmp[j][0] = '\0'; -} - -char - **p_check_args_equals(char *words[], - t_msh *msh) -{ - char *ptr; - t_bool reg; - t_bool isvar; - int64_t i; - - i = 0; - reg = FALSE; - isvar = FALSE; - while (words[i]) - { - ptr = words[i]; - while (*ptr != '\0' && *ptr != '=') - ptr++; - if (*ptr == '=') - { - reg = TRUE; - isvar = TRUE; - } - if (*ptr == '\0' || words[i][0] == '=' || - ft_isdigit(words[i][0]) == TRUE) - { - reg = FALSE; - if (i == 0) - isvar = FALSE; - if (isvar == TRUE) - p_add_to_env_fork(i, words, msh); - else - msh->env_fork_tmp[0][0] = '\0'; - break ; - } - i++; - } - if (isvar == TRUE) - return (p_add_to_variables_and_delete(words, reg, i, msh)); - return (words); -} diff --git a/src/p_lcom_next.h b/src/p_lcom_next.h deleted file mode 100644 index 8fbbb99..0000000 --- a/src/p_lcom_next.h +++ /dev/null @@ -1,25 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* p_line_next.h :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: rbousset +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2020/02/14 17:19:27 by rbousset #+# #+# */ -/* Updated: 2020/02/14 17:19:29 by rbousset ### ########lyon.fr */ -/* */ -/* ************************************************************************** */ - -#ifndef P_LCOM_NEXT_H -#define P_LCOM_NEXT_H - -#include - -#include "s_struct.h" - -char *p_subst_vars(char word[], t_msh *msh); -char **p_subst_args(const char word[], int8_t redir); -char **p_subst_home(char *word[], t_msh *msh); -char **p_check_args_equals(char *words[], t_msh *msh); - -#endif diff --git a/src/p_line.c b/src/p_line.c index 170d8a8..645c7b6 100644 --- a/src/p_line.c +++ b/src/p_line.c @@ -67,7 +67,7 @@ void { return ; } - if (p_lcom(line, msh) < 0) + if (p_line_block(line, msh) < 0) { f_alloc_and_destroy_msh(msh); } diff --git a/src/s_init.c b/src/s_init.c index 9ef856f..cfe2eeb 100644 --- a/src/s_init.c +++ b/src/s_init.c @@ -174,6 +174,8 @@ t_msh msh->ret = 0; init_buptr(msh); msh->curr = NULL; + msh->com = NULL; + msh->pipes = NULL; msh->vars = NULL; set_cwd(cwd, msh); if ((msh->cwd = ft_strdup(cwd)) == NULL) diff --git a/src/s_struct.h b/src/s_struct.h index 1089dc6..f98f948 100644 --- a/src/s_struct.h +++ b/src/s_struct.h @@ -26,27 +26,27 @@ ** 0: means no redirection */ -typedef struct s_lvars +typedef struct s_lvars { - struct s_lvars *next; - char *name; - char *val; -} t_lvars; + struct s_lvars *next; + char *name; + char *val; +} t_lvars; -typedef struct s_com +typedef struct s_com { - char **argv; - char **env_fork; - char *rdrpath; - char *bin; - int32_t rdrfd; - int8_t redir; -} t_com; + char **argv; + char **env_fork; + char *rdrpath; + char *bin; + int32_t rdrfd; + int8_t redir; +} t_com; -struct s_lpipes +struct s_lpipes { - struct s_com *com; - struct s_lpipes *next; + struct s_com *com; + struct s_lpipes *next; }; /* @@ -57,28 +57,29 @@ struct s_lpipes ** 2: || */ -typedef struct s_line +typedef struct s_line { - struct s_com *com; - struct s_lpipes *pipes; - uint8_t nextif; - struct s_line *next; -} t_line; + char line[4096]; + uint8_t nextif; + struct s_line_block *next; +} t_line; -typedef struct s_msh +typedef struct s_msh { - struct s_line *curr; - struct s_lvars *vars; - char **envp; - char **bu_ref; - char ps[4][1024]; - char env_fork_tmp[128][1024]; - char sqb_ref[FT_ID_SQB_COUNT][4]; - char *shname; - char *cwd; - int32_t fd; - uint8_t (*bu_ptr[FT_BUILTINS_COUNT])(char **, struct s_msh*); - uint8_t ret; -} t_msh; + struct s_line_block *curr; + struct s_com *com; + struct s_lpipes *pipes; + struct s_lvars *vars; + char **envp; + char **bu_ref; + char ps[4][1024]; + char env_fork_tmp[128][1024]; + char sqb_ref[FT_ID_SQB_COUNT][4]; + char *shname; + char *cwd; + int32_t fd; + uint8_t (*bu_ptr[FT_BUILTINS_COUNT])(char **, struct s_msh*); + uint8_t ret; +} t_msh; #endif -- cgit v1.2.3