AAAAAAAAAAAAAA
This commit is contained in:
3
Makefile
3
Makefile
@ -6,7 +6,7 @@
|
|||||||
# By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ #
|
# By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ #
|
||||||
# +#+#+#+#+#+ +#+ #
|
# +#+#+#+#+#+ +#+ #
|
||||||
# Created: 2023/07/28 00:35:01 by tomoron #+# #+# #
|
# Created: 2023/07/28 00:35:01 by tomoron #+# #+# #
|
||||||
# Updated: 2024/02/13 16:22:36 by marde-vr ### ########.fr #
|
# Updated: 2024/02/15 14:44:14 by tomoron ### ########.fr #
|
||||||
# #
|
# #
|
||||||
# **************************************************************************** #
|
# **************************************************************************** #
|
||||||
|
|
||||||
@ -20,6 +20,7 @@ SRCS = main.c\
|
|||||||
echo.c\
|
echo.c\
|
||||||
pwd.c\
|
pwd.c\
|
||||||
parsing.c\
|
parsing.c\
|
||||||
|
debug.c\
|
||||||
parsing_var.c
|
parsing_var.c
|
||||||
|
|
||||||
OBJS = $(SRCS:.c=.o)
|
OBJS = $(SRCS:.c=.o)
|
||||||
|
32
debug.c
Normal file
32
debug.c
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* debug.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: tomoron <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2024/02/15 14:16:47 by tomoron #+# #+# */
|
||||||
|
/* Updated: 2024/02/15 14:45:29 by tomoron ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "minishell.h"
|
||||||
|
|
||||||
|
void print_parsed_cmd(t_cmd *cmd)
|
||||||
|
{
|
||||||
|
while(cmd)
|
||||||
|
{
|
||||||
|
printf("[");
|
||||||
|
if(cmd->type == ARG)
|
||||||
|
printf("ARG : %s",cmd->token);
|
||||||
|
else if(cmd->type == PIPE)
|
||||||
|
printf("PIPE");
|
||||||
|
else if(cmd->type == OR)
|
||||||
|
printf("OR");
|
||||||
|
else if(cmd->type == AND)
|
||||||
|
printf("AND");
|
||||||
|
printf("] ");
|
||||||
|
cmd = cmd->next;
|
||||||
|
}
|
||||||
|
printf("\n");
|
||||||
|
}
|
4
echo.c
4
echo.c
@ -6,7 +6,7 @@
|
|||||||
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/02/07 15:30:37 by tomoron #+# #+# */
|
/* Created: 2024/02/07 15:30:37 by tomoron #+# #+# */
|
||||||
/* Updated: 2024/02/13 16:11:20 by marde-vr ### ########.fr */
|
/* Updated: 2024/02/14 12:36:02 by tomoron ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -22,7 +22,7 @@ int echo(t_cmd *args)
|
|||||||
put_nl = 0;
|
put_nl = 0;
|
||||||
args = args->next;
|
args = args->next;
|
||||||
}
|
}
|
||||||
while (args)
|
while (args && args->type == ARG)
|
||||||
{
|
{
|
||||||
ft_putstr_fd(args->token, STDOUT_FILENO);
|
ft_putstr_fd(args->token, STDOUT_FILENO);
|
||||||
if (args->next)
|
if (args->next)
|
||||||
|
11
exit.c
11
exit.c
@ -6,7 +6,7 @@
|
|||||||
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/02/07 16:04:11 by tomoron #+# #+# */
|
/* Created: 2024/02/07 16:04:11 by tomoron #+# #+# */
|
||||||
/* Updated: 2024/02/13 16:24:18 by marde-vr ### ########.fr */
|
/* Updated: 2024/02/14 12:44:03 by tomoron ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -27,15 +27,16 @@ void ft_exit(t_cmd *args, t_env *env)
|
|||||||
start = args;
|
start = args;
|
||||||
args = args->next;
|
args = args->next;
|
||||||
ft_printf("exit\n");
|
ft_printf("exit\n");
|
||||||
if (args && args->next && ft_strisnbr(args->token))
|
if (args && args->next && args->next->type == ARG
|
||||||
|
&& ft_strisnbr(args->token))
|
||||||
ft_putstr_fd("minishell: exit: too many arguments\n", 2);
|
ft_putstr_fd("minishell: exit: too many arguments\n", 2);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (args && !ft_strisnbr(args->token))
|
if (args && args->type == ARG && !ft_strisnbr(args->token))
|
||||||
print_numeric_arg_err(args->token);
|
print_numeric_arg_err(args->token);
|
||||||
if (args)
|
if (args && args->type == ARG)
|
||||||
exit_code = (unsigned char)ft_atoi(args->token);
|
exit_code = (unsigned char)ft_atoi(args->token);
|
||||||
else if (args && !ft_strisnbr(args->token))
|
else if (args && args->type == ARG && !ft_strisnbr(args->token))
|
||||||
exit_code = 2;
|
exit_code = 2;
|
||||||
else
|
else
|
||||||
exit_code = g_return_code;
|
exit_code = g_return_code;
|
||||||
|
3
main.c
3
main.c
@ -6,7 +6,7 @@
|
|||||||
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/02/02 21:59:20 by tomoron #+# #+# */
|
/* Created: 2024/02/02 21:59:20 by tomoron #+# #+# */
|
||||||
/* Updated: 2024/02/13 16:16:46 by marde-vr ### ########.fr */
|
/* Updated: 2024/02/15 14:13:57 by tomoron ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -81,6 +81,7 @@ int main(int argc, char **argv, char **envp)
|
|||||||
add_history(command);
|
add_history(command);
|
||||||
parsed_cmd = parse_command(command, env);
|
parsed_cmd = parse_command(command, env);
|
||||||
free(command);
|
free(command);
|
||||||
|
print_parsed_cmd(parsed_cmd);//debug
|
||||||
exec_command(parsed_cmd, env);
|
exec_command(parsed_cmd, env);
|
||||||
free_cmd(parsed_cmd);
|
free_cmd(parsed_cmd);
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/02/04 17:31:38 by tomoron #+# #+# */
|
/* Created: 2024/02/04 17:31:38 by tomoron #+# #+# */
|
||||||
/* Updated: 2024/02/13 16:21:55 by marde-vr ### ########.fr */
|
/* Updated: 2024/02/15 14:43:57 by tomoron ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -57,4 +57,5 @@ int get_var_name_len(char *command);
|
|||||||
char *ft_get_env(t_env *env, char *var_name);
|
char *ft_get_env(t_env *env, char *var_name);
|
||||||
int pwd(void);
|
int pwd(void);
|
||||||
int is_cmd_char(char c);
|
int is_cmd_char(char c);
|
||||||
|
void print_parsed_cmd(t_cmd *cmd);//debug
|
||||||
#endif
|
#endif
|
||||||
|
25
parsing.c
25
parsing.c
@ -6,7 +6,7 @@
|
|||||||
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/02/09 15:26:01 by tomoron #+# #+# */
|
/* Created: 2024/02/09 15:26:01 by tomoron #+# #+# */
|
||||||
/* Updated: 2024/02/13 16:25:15 by marde-vr ### ########.fr */
|
/* Updated: 2024/02/13 18:22:38 by tomoron ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
#include "minishell.h"
|
#include "minishell.h"
|
||||||
@ -44,16 +44,25 @@ char *get_token(char **cmd, int *in_quote, int *in_dquote, t_env *env)
|
|||||||
return (res);
|
return (res);
|
||||||
}
|
}
|
||||||
|
|
||||||
t_token_type get_token_type(char *command)
|
t_token_type get_token_type(char **command)
|
||||||
{
|
{
|
||||||
while (ft_isspace(*command))
|
while (ft_isspace(**command))
|
||||||
command++;
|
(*command)++;
|
||||||
if(command[0] == '|' && command[1] == '|')
|
if((*command)[0] == '|' && (*command)[1] == '|')
|
||||||
|
{
|
||||||
|
(*command) += 2;
|
||||||
return(OR);
|
return(OR);
|
||||||
if(command[0] == '&' && command[1] == '&')
|
}
|
||||||
|
if((*command)[0] == '&' && (*command)[1] == '&')
|
||||||
|
{
|
||||||
|
(*command) += 2;
|
||||||
return(AND);
|
return(AND);
|
||||||
if(command[0] == '|')
|
}
|
||||||
|
if((*command)[0] == '|')
|
||||||
|
{
|
||||||
|
(*command) += 1;
|
||||||
return(PIPE);
|
return(PIPE);
|
||||||
|
}
|
||||||
return (ARG);
|
return (ARG);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -70,7 +79,7 @@ t_cmd *parse_command(char *command, t_env *env)
|
|||||||
res = 0;
|
res = 0;
|
||||||
while (command && *command)
|
while (command && *command)
|
||||||
{
|
{
|
||||||
type = get_token_type(command);
|
type = get_token_type(&command);
|
||||||
if (type == ARG)
|
if (type == ARG)
|
||||||
token = get_token(&command, &in_quote, &in_dquote, env);
|
token = get_token(&command, &in_quote, &in_dquote, env);
|
||||||
else
|
else
|
||||||
|
Reference in New Issue
Block a user