commit
This commit is contained in:
18
ft_parsing.c
18
ft_parsing.c
@ -6,11 +6,16 @@
|
|||||||
/* By: tomoron <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: tomoron <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/02/09 15:26:01 by tomoron #+# #+# */
|
/* Created: 2024/02/09 15:26:01 by tomoron #+# #+# */
|
||||||
/* Updated: 2024/02/12 14:52:13 by tomoron ### ########.fr */
|
/* Updated: 2024/02/13 15:50:08 by tomoron ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
#include "minishell.h"
|
#include "minishell.h"
|
||||||
|
|
||||||
|
int ft_is_cmd_char(char c)
|
||||||
|
{
|
||||||
|
return(!ft_isspace(c) && c != '|' && c != '&');
|
||||||
|
}
|
||||||
|
|
||||||
char *ft_get_token(char **cmd, int *in_quote, int *in_dquote, t_env *env)
|
char *ft_get_token(char **cmd, int *in_quote, int *in_dquote, t_env *env)
|
||||||
{
|
{
|
||||||
char *res;
|
char *res;
|
||||||
@ -20,7 +25,7 @@ char *ft_get_token(char **cmd, int *in_quote, int *in_dquote, t_env *env)
|
|||||||
while (ft_isspace(**cmd))
|
while (ft_isspace(**cmd))
|
||||||
(*cmd)++;
|
(*cmd)++;
|
||||||
res = ft_calloc(ft_get_token_len(*cmd, env) + 1, 1);
|
res = ft_calloc(ft_get_token_len(*cmd, env) + 1, 1);
|
||||||
while (res && **cmd && (!ft_isspace(**cmd) || *in_quote || *in_dquote))
|
while (res && **cmd && (ft_is_cmd_char(**cmd) || *in_quote || *in_dquote))
|
||||||
{
|
{
|
||||||
if (**cmd == '"' && !*in_quote)
|
if (**cmd == '"' && !*in_quote)
|
||||||
*in_dquote = !*in_dquote;
|
*in_dquote = !*in_dquote;
|
||||||
@ -41,7 +46,14 @@ char *ft_get_token(char **cmd, int *in_quote, int *in_dquote, t_env *env)
|
|||||||
|
|
||||||
t_token_type ft_get_token_type(char *command)
|
t_token_type ft_get_token_type(char *command)
|
||||||
{
|
{
|
||||||
(void)command;
|
while (ft_isspace(*command))
|
||||||
|
command++;
|
||||||
|
if(command[0] == '|' && command[1] == '|')
|
||||||
|
return(OR);
|
||||||
|
if(command[0] == '&' && command[1] == '&')
|
||||||
|
return(AND);
|
||||||
|
if(command[0] == '|')
|
||||||
|
return(PIPE);
|
||||||
return (ARG);
|
return (ARG);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: tomoron <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: tomoron <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/02/09 15:24:36 by tomoron #+# #+# */
|
/* Created: 2024/02/09 15:24:36 by tomoron #+# #+# */
|
||||||
/* Updated: 2024/02/12 20:11:18 by tomoron ### ########.fr */
|
/* Updated: 2024/02/13 15:47:33 by tomoron ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -50,7 +50,7 @@ int ft_get_token_len(char *command, t_env *env)
|
|||||||
in_quote = 0;
|
in_quote = 0;
|
||||||
in_dquote = 0;
|
in_dquote = 0;
|
||||||
res = 0;
|
res = 0;
|
||||||
while (*command && (!ft_isspace(*command) || in_quote || in_dquote))
|
while (*command && (ft_is_cmd_char(*command) || in_quote || in_dquote))
|
||||||
{
|
{
|
||||||
if (*command == '"' && !in_quote)
|
if (*command == '"' && !in_quote)
|
||||||
in_dquote = !in_dquote;
|
in_dquote = !in_dquote;
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: tomoron <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: tomoron <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/02/04 17:31:38 by tomoron #+# #+# */
|
/* Created: 2024/02/04 17:31:38 by tomoron #+# #+# */
|
||||||
/* Updated: 2024/02/11 22:54:49 by tomoron ### ########.fr */
|
/* Updated: 2024/02/13 15:49:02 by tomoron ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -56,4 +56,5 @@ int ft_add_var_to_str(char *res, char **command, t_env *env);
|
|||||||
int get_var_name_len(char *command);
|
int get_var_name_len(char *command);
|
||||||
char *ft_getenv(t_env *env, char *var_name);
|
char *ft_getenv(t_env *env, char *var_name);
|
||||||
int ft_pwd(void);
|
int ft_pwd(void);
|
||||||
|
int ft_is_cmd_char(char c);
|
||||||
#endif
|
#endif
|
||||||
|
Reference in New Issue
Block a user