Starting the separation between commands & args and the operators
This commit is contained in:
parent
70c9c5aac1
commit
9c4dfafdf7
6 changed files with 89 additions and 66 deletions
|
|
@ -6,7 +6,7 @@
|
|||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/03/28 14:41:15 by rparodi #+# #+# */
|
||||
/* Updated: 2024/03/31 19:52:56 by rparodi ### ########.fr */
|
||||
/* Updated: 2024/03/31 21:04:32 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -27,9 +27,10 @@
|
|||
# include <readline/readline.h>
|
||||
# include <readline/history.h>
|
||||
|
||||
i32 main(void);
|
||||
i32 ft_strcmp(const char *s1, const char *s2);
|
||||
void ft_exit(i8 *str, u8 exit_status);
|
||||
i8 **ft_split(i8 const *s, i8 c);
|
||||
t_i32 main(void);
|
||||
t_i32 ft_strcmp(const char *s1, const char *s2);
|
||||
t_i32 ft_check_type_operators(t_i8 **operators);
|
||||
void ft_exit(t_str str, t_u8 exit_status);
|
||||
t_str *ft_split(t_const_str s, t_i8 c);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -6,33 +6,39 @@
|
|||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/03/28 14:44:20 by rparodi #+# #+# */
|
||||
/* Updated: 2024/03/29 11:44:40 by rparodi ### ########.fr */
|
||||
/* Updated: 2024/03/31 20:53:56 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef TYPE_RUST_H
|
||||
#define TYPE_RUST_H
|
||||
|
||||
#include <stddef.h>
|
||||
# include <stdbool.h>
|
||||
# include <stddef.h>
|
||||
# include <unistd.h>
|
||||
|
||||
# define bool int
|
||||
# define true 1
|
||||
# define false 0
|
||||
typedef char *t_str;
|
||||
typedef const char *t_const_str;
|
||||
|
||||
# define u8 unsigned char
|
||||
# define u16 unsigned short
|
||||
# define u32 unsigned int
|
||||
# define u64 unsigned long long
|
||||
typedef unsigned char t_u8;
|
||||
typedef char t_i8;
|
||||
typedef unsigned short t_u16;
|
||||
typedef short t_i16;
|
||||
typedef int t_i32;
|
||||
typedef unsigned int t_u32;
|
||||
typedef unsigned long long t_u64;
|
||||
typedef long long t_i64;
|
||||
typedef ssize_t t_isize;
|
||||
typedef size_t t_usize;
|
||||
|
||||
# define i8 char
|
||||
# define i16 short
|
||||
# define i32 int
|
||||
# define i64 long long
|
||||
typedef float t_f32;
|
||||
typedef double t_f64;
|
||||
|
||||
# define usize size_t
|
||||
# define isize ssize_t
|
||||
typedef int t_file;
|
||||
|
||||
# define f32 float
|
||||
# define f64 double
|
||||
typedef bool t_error;
|
||||
|
||||
# define ERROR 1
|
||||
# define NO_ERROR 0
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -6,16 +6,16 @@
|
|||
/* By: rparodi <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/09 13:56:02 by rparodi #+# #+# */
|
||||
/* Updated: 2024/03/31 19:35:26 by rparodi ### ########.fr */
|
||||
/* Updated: 2024/03/31 21:07:40 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../includes/minishell.h"
|
||||
|
||||
static int count_words(const char *str, char sep)
|
||||
static t_i32 count_words(t_const_str str, t_i8 sep)
|
||||
{
|
||||
int i;
|
||||
int count;
|
||||
t_i32 i;
|
||||
t_i32 count;
|
||||
|
||||
i = 0;
|
||||
count = 0;
|
||||
|
|
@ -33,13 +33,13 @@ static int count_words(const char *str, char sep)
|
|||
return (count);
|
||||
}
|
||||
|
||||
static char *ft_strndup(const char *s, int j)
|
||||
static t_str ft_strndup(t_const_str s, t_i32 j)
|
||||
{
|
||||
int i;
|
||||
char *str;
|
||||
t_i32 i;
|
||||
t_str str;
|
||||
|
||||
i = 0;
|
||||
str = (char *)malloc((j + 1));
|
||||
str = (t_str)malloc((j + 1));
|
||||
if (!str)
|
||||
return (NULL);
|
||||
while (s[i] && i < j)
|
||||
|
|
@ -51,10 +51,10 @@ static char *ft_strndup(const char *s, int j)
|
|||
return (str);
|
||||
}
|
||||
|
||||
static char **ext_w(char **words_array, const char *str, char sep, int size)
|
||||
static t_str *ext_w(t_str *words_array, t_const_str str, t_i8 sep, t_i32 size)
|
||||
{
|
||||
int i;
|
||||
int j;
|
||||
t_i32 i;
|
||||
t_i32 j;
|
||||
|
||||
i = 0;
|
||||
j = 0;
|
||||
|
|
@ -74,13 +74,13 @@ static char **ext_w(char **words_array, const char *str, char sep, int size)
|
|||
return (words_array);
|
||||
}
|
||||
|
||||
char **ft_split(char const *s, char c)
|
||||
t_str *ft_split(t_const_str s, t_i8 c)
|
||||
{
|
||||
int size;
|
||||
char **words_array;
|
||||
t_i32 size;
|
||||
t_str *words_array;
|
||||
|
||||
size = count_words(s, c);
|
||||
words_array = (char **)malloc(sizeof(char *) * (size + 1));
|
||||
words_array = (t_str *)malloc(sizeof(char *) * (size + 1));
|
||||
if (!words_array)
|
||||
return (NULL);
|
||||
if (size == 0)
|
||||
|
|
|
|||
1
note_raph.txt
Normal file
1
note_raph.txt
Normal file
|
|
@ -0,0 +1 @@
|
|||
Alors pour le coup, il faut que j'arrive a separer les strings par commande puis a chaque sep regarder les autres cmd (bisous lpb si tu passe par la ;))
|
||||
|
|
@ -6,13 +6,13 @@
|
|||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/03/29 11:35:51 by rparodi #+# #+# */
|
||||
/* Updated: 2024/03/29 14:46:18 by rparodi ### ########.fr */
|
||||
/* Updated: 2024/03/31 20:54:49 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../includes/minishell.h"
|
||||
|
||||
void ft_exit(i8 *str, u8 exit_status)
|
||||
void ft_exit(t_str str, t_u8 exit_status)
|
||||
{
|
||||
free(str);
|
||||
printf("exit\n");
|
||||
|
|
|
|||
|
|
@ -6,55 +6,70 @@
|
|||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/03/28 14:40:38 by rparodi #+# #+# */
|
||||
/* Updated: 2024/03/31 20:08:28 by rparodi ### ########.fr */
|
||||
/* Updated: 2024/03/31 21:02:40 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../includes/minishell.h"
|
||||
|
||||
i32 ft_check_type_cmd(i8 **cmd)
|
||||
t_i32 ft_check_type_operators(t_str *operators)
|
||||
{
|
||||
usize j;
|
||||
t_usize i;
|
||||
|
||||
j = 0;
|
||||
while (cmd[j])
|
||||
i = 0;
|
||||
while (operators[i])
|
||||
{
|
||||
if (ft_strcmp(cmd[j], ">") == 0)
|
||||
if (ft_strcmp(operators[i], ">") == 0)
|
||||
printf("Have to redirect in the file\n");
|
||||
else if (ft_strcmp(cmd[j], ">>") == 0)
|
||||
else if (ft_strcmp(operators[i], ">>") == 0)
|
||||
printf("Have to redirect at the end of the file after\n");
|
||||
else if (ft_strcmp(cmd[j], ">&") == 0)
|
||||
else if (ft_strcmp(operators[i], ">&") == 0)
|
||||
printf("Have to redirect the stdout in the file\n");
|
||||
else if (ft_strcmp(cmd[j], "<") == 0)
|
||||
else if (ft_strcmp(operators[i], "<") == 0)
|
||||
printf("Have to redirect at the end of the file before\n");
|
||||
else if (ft_strcmp(cmd[j], "<<") == 0)
|
||||
else if (ft_strcmp(operators[i], "<<") == 0)
|
||||
printf("Have to redirect at the end of the file after\n");
|
||||
else if (ft_strcmp(cmd[j], "<&") == 0)
|
||||
else if (ft_strcmp(operators[i], "<&") == 0)
|
||||
printf("Have to redirect the stdout in the file\n");
|
||||
else if (ft_strcmp(cmd[j], ";") == 0)
|
||||
else if (ft_strcmp(operators[i], ";") == 0)
|
||||
printf("Have to execute one more command\n");
|
||||
else if (ft_strcmp(cmd[j], ";") == 0)
|
||||
else if (ft_strcmp(operators[i], ";") == 0)
|
||||
printf("Have to execute one more command\n");
|
||||
else if (ft_strcmp(cmd[j], "|") == 0)
|
||||
printf("I have to pipe a cmd !\n");
|
||||
else if (ft_strcmp(cmd[j], "||") == 0)
|
||||
else if (ft_strcmp(operators[i], "|") == 0)
|
||||
printf("I have to pipe a operators !\n");
|
||||
else if (ft_strcmp(operators[i], "||") == 0)
|
||||
printf("Or something\n");
|
||||
else if (ft_strcmp(cmd[j], "&&") == 0)
|
||||
else if (ft_strcmp(operators[i], "&&") == 0)
|
||||
printf("Only if the first has exit status 0\n");
|
||||
else if (ft_strcmp(cmd[j], "&") == 0)
|
||||
else if (ft_strcmp(operators[i], "&") == 0)
|
||||
printf("Parreil mais chelou\n");
|
||||
else
|
||||
printf("Error!\n");
|
||||
j++;
|
||||
return (0);
|
||||
i++;
|
||||
}
|
||||
return (1);
|
||||
}
|
||||
|
||||
void ft_take_cmd(void)
|
||||
void ft_check(char **input)
|
||||
{
|
||||
i32 i;
|
||||
i8 *user_input = NULL;
|
||||
i8 **args = NULL;
|
||||
t_usize i;
|
||||
|
||||
i = 0;
|
||||
while (input[i] != NULL)
|
||||
{
|
||||
if (ft_check_type_operators(input) == 1)
|
||||
printf("Operateur\n");
|
||||
else
|
||||
printf("Commande ou args\n");
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
void ft_take_args(void)
|
||||
{
|
||||
t_i32 i;
|
||||
t_str user_input = NULL;
|
||||
t_str *args = NULL;
|
||||
|
||||
i = 0;
|
||||
while (i < 10000000)
|
||||
|
|
@ -65,14 +80,14 @@ void ft_take_cmd(void)
|
|||
args = ft_split(user_input, ' ');
|
||||
if (!user_input)
|
||||
exit(1);
|
||||
ft_check_type_cmd(args);
|
||||
ft_check(args);
|
||||
add_history(user_input);
|
||||
free(user_input);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
i32 main(void)
|
||||
t_i32 main(void)
|
||||
{
|
||||
ft_take_cmd();
|
||||
ft_take_args();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue