summaryrefslogtreecommitdiffstats
path: root/src/ft_p_lcom.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/ft_p_lcom.c64
1 files changed, 58 insertions, 6 deletions
diff --git a/src/ft_p_lcom.c b/src/ft_p_lcom.c
index ec30f43..9a4ebad 100644
--- a/src/ft_p_lcom.c
+++ b/src/ft_p_lcom.c
@@ -11,36 +11,87 @@
/* ************************************************************************** */
#include <libft.h>
+#include <stdlib.h>
#include <stdint.h>
#include "ft_s_lcom.h"
#include "ft_s_struct.h"
-void
- ft_check_redir_file()
+/* void */
+/* ft_check_redir_file() */
+/* { */
+/* } */
+
+static void
+ ft_rdr_err_check(char *ptr,
+ t_lcom **link)
+{
+ if ((*link)->redir == -1 && ft_ischarset(">", *(ptr + 1)))
+ {
+ /* TODO: syntax err */
+ }
+ else if ((*link)->redir == 1 && ft_ischarset("<", *(ptr + 1)))
+ {
+ }
+ else if ((*link)->redir == 1 && ft_ischarset("<>", *(ptr + 1)))
+ {
+ }
+}
+
+static int8_t
+ ft_get_rdrpath(char *ptr,
+ t_lcom **link)
{
+ char *p_rdrpath;
+
+ ptr += ((*link)->redir == 2) ? (2) : (1);
+ if (!((*link)->rdrpath =
+ (char*)malloc((ft_strlen(ptr) + 1) * sizeof(char))))
+ {
+ return (-1);
+ }
+ p_rdrpath = (*link)->rdrpath;
+ while (*ptr)
+ {
+ if (*ptr != ' ')
+ {
+ *p_rdrpath = *ptr;
+ p_rdrpath++;
+ }
+ ptr++;
+ }
+ *(p_rdrpath) = '\0';
+ return (0);
}
-void
+int8_t
ft_get_redir(const char word[],
t_lcom **link)
{
char *ptr;
- ptr = word;
+ ptr = (char *)word;
while (*ptr)
{
if (*ptr == '<')
{
- *link->redir = -1;
+ (*link)->redir = -1;
break ;
}
if (*ptr == '>')
{
- *link->redir = (*(ptr + 1) == '>') ? (2) : (1);
+ (*link)->redir = (*(ptr + 1) == '>') ? (2) : (1);
break ;
}
ptr++;
+ /* TODO: handle correctly multiples "msh ~> echo qwe > qwe > asd >> zxc > qweasdzxc" */
}
+ if ((*link)->redir != 0)
+ {
+ ft_rdr_err_check(ptr, link);
+ if (ft_get_rdrpath(ptr, link) != 0)
+ return (-1);
+ }
+ return (0);
}
int8_t
@@ -62,6 +113,7 @@ int8_t
return (-1);
}
ft_lcom_add_back(&msh->curr, link);
+ ft_printf("%s\n", msh->curr->rdrpath);
i++;
}
ft_delwords(words);