re norm ok
This commit is contained in:
6
Makefile
6
Makefile
@ -6,7 +6,7 @@
|
|||||||
# By: tomoron <marvin@42.fr> +#+ +:+ +#+ #
|
# By: tomoron <marvin@42.fr> +#+ +:+ +#+ #
|
||||||
# +#+#+#+#+#+ +#+ #
|
# +#+#+#+#+#+ +#+ #
|
||||||
# Created: 2023/07/28 00:35:01 by tomoron #+# #+# #
|
# Created: 2023/07/28 00:35:01 by tomoron #+# #+# #
|
||||||
# Updated: 2024/02/08 16:18:42 by tomoron ### ########.fr #
|
# Updated: 2024/02/09 18:13:02 by tomoron ### ########.fr #
|
||||||
# #
|
# #
|
||||||
# **************************************************************************** #
|
# **************************************************************************** #
|
||||||
|
|
||||||
@ -17,7 +17,9 @@ SRCS = main.c\
|
|||||||
ft_lst_env.c\
|
ft_lst_env.c\
|
||||||
ft_exec.c\
|
ft_exec.c\
|
||||||
ft_exit.c\
|
ft_exit.c\
|
||||||
ft_echo.c
|
ft_echo.c\
|
||||||
|
ft_parsing.c\
|
||||||
|
ft_parsing_var.c
|
||||||
|
|
||||||
OBJS = $(SRCS:.c=.o)
|
OBJS = $(SRCS:.c=.o)
|
||||||
|
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* 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/09 16:40:07 by tomoron ### ########.fr */
|
/* Updated: 2024/02/09 18:15:45 by tomoron ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
#include "minishell.h"
|
#include "minishell.h"
|
||||||
@ -32,7 +32,7 @@ char *ft_get_token(char **cmd, int *in_quote, int *in_dquote, t_env *env)
|
|||||||
i += ft_add_var_to_str(res + i, cmd, env);
|
i += ft_add_var_to_str(res + i, cmd, env);
|
||||||
}
|
}
|
||||||
else if (((**cmd == '\'' && *in_dquote) || (**cmd == '"' && *in_quote))
|
else if (((**cmd == '\'' && *in_dquote) || (**cmd == '"' && *in_quote))
|
||||||
|| (**cmd != '\'' && **command != '"'))
|
|| (**cmd != '\'' && **cmd != '"'))
|
||||||
res[i++] = **cmd;
|
res[i++] = **cmd;
|
||||||
(*cmd)++;
|
(*cmd)++;
|
||||||
}
|
}
|
||||||
|
@ -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/09 15:24:43 by tomoron ### ########.fr */
|
/* Updated: 2024/02/09 18:22:16 by tomoron ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -62,3 +62,37 @@ int ft_get_token_len(char *command, t_env *env)
|
|||||||
res++;
|
res++;
|
||||||
else if ((*command == '\'' && in_dquote)
|
else if ((*command == '\'' && in_dquote)
|
||||||
|| (*command == '"' && in_quote))
|
|| (*command == '"' && in_quote))
|
||||||
|
res++;
|
||||||
|
command++;
|
||||||
|
}
|
||||||
|
return (res);
|
||||||
|
}
|
||||||
|
|
||||||
|
int ft_add_var_to_str(char *res, char **command, t_env *env)
|
||||||
|
{
|
||||||
|
char *var_name;
|
||||||
|
char *var;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
i = -1;
|
||||||
|
if (!ft_isalnum(**command) && **command != '_' && **command != '?')
|
||||||
|
{
|
||||||
|
*res = '$';
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
|
if (**command == '?')
|
||||||
|
{
|
||||||
|
var = ft_itoa(g_return_code);
|
||||||
|
while (var && var[++i])
|
||||||
|
res[i] = var[i];
|
||||||
|
free(var);
|
||||||
|
return (i + 1);
|
||||||
|
}
|
||||||
|
var_name = get_var_name(*command);
|
||||||
|
var = ft_getenv(env, var_name);
|
||||||
|
free(var_name);
|
||||||
|
while (var && var[++i])
|
||||||
|
res[i] = var[i];
|
||||||
|
*command += get_var_name_len(*command) - 1;
|
||||||
|
return (i + !var);
|
||||||
|
}
|
||||||
|
@ -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/09 14:58:21 by tomoron ### ########.fr */
|
/* Updated: 2024/02/09 18:17:30 by tomoron ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -40,4 +40,9 @@ void ft_exit(t_cmd *args, t_env *env);
|
|||||||
t_env *ft_env_add_back(t_env *env, char *name, char *value);
|
t_env *ft_env_add_back(t_env *env, char *name, char *value);
|
||||||
void ft_free_env(t_env *env);
|
void ft_free_env(t_env *env);
|
||||||
int ft_print_env(t_env *env);
|
int ft_print_env(t_env *env);
|
||||||
|
t_cmd *ft_parse_command(char *command, t_env *env);
|
||||||
|
int ft_get_token_len(char *cmd, t_env *env);
|
||||||
|
int ft_add_var_to_str(char *res, char **command, t_env *env);
|
||||||
|
int get_var_name_len(char *command);
|
||||||
|
char *ft_getenv(t_env *env, char *var_name);
|
||||||
#endif
|
#endif
|
||||||
|
Reference in New Issue
Block a user