summaryrefslogtreecommitdiffstats
path: root/src/ft_s_lcom.c
diff options
context:
space:
mode:
authorJozanLeClerc <bousset.rudy@gmail.com>2020-07-27 18:55:07 +0200
committerJozanLeClerc <bousset.rudy@gmail.com>2020-07-27 18:55:07 +0200
commit487a66394061f2d14a2fa421302966b5442d643f (patch)
tree34237d4e9cb85f94bcefd46f399d2224dff3f6b3 /src/ft_s_lcom.c
parentCorrect shell prompt (diff)
download42-minishell-487a66394061f2d14a2fa421302966b5442d643f.tar.gz
42-minishell-487a66394061f2d14a2fa421302966b5442d643f.tar.bz2
42-minishell-487a66394061f2d14a2fa421302966b5442d643f.tar.xz
42-minishell-487a66394061f2d14a2fa421302966b5442d643f.tar.zst
42-minishell-487a66394061f2d14a2fa421302966b5442d643f.zip
I couldn't see shit
Diffstat (limited to 'src/ft_s_lcom.c')
-rw-r--r--src/ft_s_lcom.c145
1 files changed, 0 insertions, 145 deletions
diff --git a/src/ft_s_lcom.c b/src/ft_s_lcom.c
deleted file mode 100644
index d56ba7f..0000000
--- a/src/ft_s_lcom.c
+++ /dev/null
@@ -1,145 +0,0 @@
-/* ************************************************************************** */
-/* */
-/* ::: :::::::: */
-/* ft_s_lcom.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 <stdlib.h>
-#include <stdint.h>
-
-#include "ft_p_lcom.h"
-#include "ft_p_lcom_next.h"
-#include "ft_s_struct.h"
-
-static int8_t
- ft_fill_lcom(char *words[],
- t_lcom **lcom)
-{
- /* TODO: norme */
- uint64_t i;
- uint64_t j;
-
- i = 0;
- if (words[0])
- {
- if (!((*lcom)->com = (char*)malloc((ft_strlen(words[0]) + 1) *
- sizeof(char))))
- return (-1);
- ft_strlcpy((*lcom)->com, words[0], ft_strlen(words[0]) + 1);
- }
- else
- return (0);
- while(words[i])
- {
- /* TODO: cut fd number "msh ~> echo a 2>file" */
- /* ^ */
- if (ft_ischarset("<>", words[i][0]))
- break ;
- i++;
- }
- if (!((*lcom)->argv = (char**)malloc((i + 1) * sizeof(char*))))
- return (-1);
- j = 0;
- while (i > 0 && j < i)
- {
- if (!((*lcom)->argv[j] =
- (char*)malloc((ft_strlen(words[j]) + 1) * sizeof(char))))
- return (-1);
- ft_strlcpy((*lcom)->argv[j], words[j],
- ft_strlen(words[j]) + 1);
- j++;
- }
- (*lcom)->argv[j] = 0;
- return (0);
-}
-
-t_lcom
- *ft_lcom_last(t_lcom *lcom)
-{
- while (lcom->next != NULL)
- lcom = lcom->next;
- return (lcom);
-}
-
-void
- ft_lcom_add_back(t_lcom **alcom,
- t_lcom *new)
-{
- t_lcom *tmp;
-
- if (!*alcom)
- *alcom = new;
- else
- {
- tmp = ft_lcom_last(*alcom);
- tmp->next = new;
- }
-}
-
-void
- ft_lcom_clear(t_lcom **lcom)
-{
- t_lcom *tmp;
- t_lcom *renext;
-
- if (!lcom)
- return ;
- tmp = *lcom;
- while (tmp)
- {
- renext = tmp->next;
- ft_memdel((void*)&tmp->com);
- if (tmp->argv)
- ft_delwords(tmp->argv);
- if (tmp->redir != 0)
- ft_memdel((void*)&tmp->rdrpath);
- ft_memdel((void*)&tmp);
- tmp = renext;
- }
- *lcom = NULL;
-}
-
-t_lcom
- *ft_lcom_new(const char word[],
- t_msh *msh)
-{
- /* TODO: norme */
- t_lcom *link;
- char **words;
-
- if (!(link = (t_lcom*)malloc(sizeof(t_lcom))))
- return (NULL);
- link->redir = 0;
- link->com = NULL;
- link->argv = NULL;
- link->rdrfd = 0;
- link->rdrpath = NULL;
- link->pipes = NULL;
- if (!word)
- {
- link->next = NULL;
- return (link);
- }
- link->pipes = NULL;
- if (ft_get_redir(word, &link) != 0)
- return (NULL);
- if (!(words = ft_subst_args(word, link->redir)))
- return (NULL);
- if (!(words = ft_subst_vars(words, msh)))
- return (NULL);
- if (ft_fill_lcom(words, &link) < 0)
- {
- ft_delwords(words);
- return (NULL);
- }
- link->next = NULL;
- ft_delwords(words);
- return (link);
-}