diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/ft_d_define.h | 4 | ||||
| -rw-r--r-- | src/ft_m_argv.c | 17 | ||||
| -rw-r--r-- | src/ft_m_comm.c | 38 | ||||
| -rw-r--r-- | src/ft_m_comm.h | 23 | ||||
| -rw-r--r-- | src/ft_m_loop.c | 6 | ||||
| -rw-r--r-- | src/ft_m_loop.h | 1 | 
6 files changed, 77 insertions, 12 deletions
diff --git a/src/ft_d_define.h b/src/ft_d_define.h index acb1a29..89e1106 100644 --- a/src/ft_d_define.h +++ b/src/ft_d_define.h @@ -29,8 +29,8 @@  ** ====== OPTIONS ======  */ -#define FT_INTERACT			"-i" -#define FT_COMMAND			"-c" +#define FT_OPT_INTERACT			"-i" +#define FT_OPT_COMMAND			"-c"  /*  ** ====== FAIL MSG ====== diff --git a/src/ft_m_argv.c b/src/ft_m_argv.c index a4da580..389fbe7 100644 --- a/src/ft_m_argv.c +++ b/src/ft_m_argv.c @@ -14,6 +14,7 @@  #include <stdint.h>  #include "ft_d_define.h" +#include "ft_m_comm.h"  #include "ft_m_loop.h"  #include "ft_s_struct.h" @@ -22,19 +23,21 @@ uint8_t  			const char *argv[],  			t_msh *msh)  { -	int32_t	i; - -	(void)argv; +	/* TODO: better argv handling */  	if (argc == 1)  	{  		msh->ret = ft_m_loop(msh);  		return (msh->ret);  	} -	i = 1; -	while (i < argc) +	if (!ft_strncmp(*(argv + 1), FT_OPT_COMMAND, 3))  	{ -		/* if (ft_strncmp(*(argv + i), )) */ -		i++; +		if (*(argv + 2) == NULL) +		{ +			ft_dprintf(2, "%s: %s: option requires an argument", +				msh->shname, FT_OPT_COMMAND); +			return (2); +		} +		msh->ret = ft_m_comm(*(argv + 2), msh);  	}  	return (msh->ret);  } diff --git a/src/ft_m_comm.c b/src/ft_m_comm.c new file mode 100644 index 0000000..5fca253 --- /dev/null +++ b/src/ft_m_comm.c @@ -0,0 +1,38 @@ +/* ************************************************************************** */ +/*                                                                            */ +/*                                                        :::      ::::::::   */ +/*   ft_m_comm.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_d_enum.h" +#include "ft_e_lcom.h" +#include "ft_m_prompt.h" +#include "ft_p_line.h" +#include "ft_s_lcom.h" + +uint8_t +	ft_m_comm(const char line[], +			t_msh *msh) +{ +	if (line[0] != '\0') +	{ +		ft_p_line((char*)line, msh); +		ft_e_lcom(msh); +		ft_lcom_clear(&msh->curr); +	} +	else +	{ +		ft_memdel((void*)&line); +	} +	return (msh->ret); +} + diff --git a/src/ft_m_comm.h b/src/ft_m_comm.h new file mode 100644 index 0000000..5b22f3a --- /dev/null +++ b/src/ft_m_comm.h @@ -0,0 +1,23 @@ +/* ************************************************************************** */ +/*                                                                            */ +/*                                                        :::      ::::::::   */ +/*   ft_m_comm.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_M_COMM_H +#define FT_M_COMM_H + +#include <stdint.h> + +#include "ft_s_struct.h" + +uint8_t	ft_m_comm(const char line[], +				t_msh *msh); + +#endif diff --git a/src/ft_m_loop.c b/src/ft_m_loop.c index d902d93..7f805a2 100644 --- a/src/ft_m_loop.c +++ b/src/ft_m_loop.c @@ -14,9 +14,7 @@  #include <stdint.h>  #include <unistd.h> -#include "ft_d_enum.h"  #include "ft_e_lcom.h" -#include "ft_m_loop.h"  #include "ft_m_prompt.h"  #include "ft_p_line.h"  #include "ft_s_lcom.h" @@ -38,6 +36,8 @@ uint8_t  			ft_memdel((void*)&line);  			ft_e_lcom(msh);  			ft_lcom_clear(&msh->curr); +			/* TODO: segv on ';' terminated lines "msh ~> echo qwe;" */ +			/* TODO: (null): Bad address on "msh ~> echo a > asd; cat < asd" but not on "msh ~> echo a > asd; cat asd" */  			/* TODO: GNL 25 leak on "msh ~> exit" */  			/* TODO: "msh ~> some command \": re GNL into ft_nrealloc */  			/* TODO: the chad pipes | */ @@ -48,5 +48,5 @@ uint8_t  			ft_memdel((void*)&line);  		}  	} -	return (FT_RET_FINE); +	return (msh->ret);  } diff --git a/src/ft_m_loop.h b/src/ft_m_loop.h index b7a6b12..4dd1873 100644 --- a/src/ft_m_loop.h +++ b/src/ft_m_loop.h @@ -14,6 +14,7 @@  #define FT_M_LOOP  #include <stdint.h> +  #include "ft_s_struct.h"  uint8_t	ft_m_loop(t_msh *msh);  | 
