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> +#+ +:+ +#+ */
|
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/03/28 14:41:15 by rparodi #+# #+# */
|
/* 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/readline.h>
|
||||||
# include <readline/history.h>
|
# include <readline/history.h>
|
||||||
|
|
||||||
i32 main(void);
|
t_i32 main(void);
|
||||||
i32 ft_strcmp(const char *s1, const char *s2);
|
t_i32 ft_strcmp(const char *s1, const char *s2);
|
||||||
void ft_exit(i8 *str, u8 exit_status);
|
t_i32 ft_check_type_operators(t_i8 **operators);
|
||||||
i8 **ft_split(i8 const *s, i8 c);
|
void ft_exit(t_str str, t_u8 exit_status);
|
||||||
|
t_str *ft_split(t_const_str s, t_i8 c);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -6,33 +6,39 @@
|
||||||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/03/28 14:44:20 by rparodi #+# #+# */
|
/* 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
|
#ifndef TYPE_RUST_H
|
||||||
#define TYPE_RUST_H
|
#define TYPE_RUST_H
|
||||||
|
|
||||||
#include <stddef.h>
|
# include <stdbool.h>
|
||||||
|
# include <stddef.h>
|
||||||
|
# include <unistd.h>
|
||||||
|
|
||||||
# define bool int
|
typedef char *t_str;
|
||||||
# define true 1
|
typedef const char *t_const_str;
|
||||||
# define false 0
|
|
||||||
|
|
||||||
# define u8 unsigned char
|
typedef unsigned char t_u8;
|
||||||
# define u16 unsigned short
|
typedef char t_i8;
|
||||||
# define u32 unsigned int
|
typedef unsigned short t_u16;
|
||||||
# define u64 unsigned long long
|
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
|
typedef float t_f32;
|
||||||
# define i16 short
|
typedef double t_f64;
|
||||||
# define i32 int
|
|
||||||
# define i64 long long
|
|
||||||
|
|
||||||
# define usize size_t
|
typedef int t_file;
|
||||||
# define isize ssize_t
|
|
||||||
|
|
||||||
# define f32 float
|
typedef bool t_error;
|
||||||
# define f64 double
|
|
||||||
|
# define ERROR 1
|
||||||
|
# define NO_ERROR 0
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -6,16 +6,16 @@
|
||||||
/* By: rparodi <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: rparodi <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2023/11/09 13:56:02 by rparodi #+# #+# */
|
/* 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"
|
#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;
|
t_i32 i;
|
||||||
int count;
|
t_i32 count;
|
||||||
|
|
||||||
i = 0;
|
i = 0;
|
||||||
count = 0;
|
count = 0;
|
||||||
|
|
@ -33,13 +33,13 @@ static int count_words(const char *str, char sep)
|
||||||
return (count);
|
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;
|
t_i32 i;
|
||||||
char *str;
|
t_str str;
|
||||||
|
|
||||||
i = 0;
|
i = 0;
|
||||||
str = (char *)malloc((j + 1));
|
str = (t_str)malloc((j + 1));
|
||||||
if (!str)
|
if (!str)
|
||||||
return (NULL);
|
return (NULL);
|
||||||
while (s[i] && i < j)
|
while (s[i] && i < j)
|
||||||
|
|
@ -51,10 +51,10 @@ static char *ft_strndup(const char *s, int j)
|
||||||
return (str);
|
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;
|
t_i32 i;
|
||||||
int j;
|
t_i32 j;
|
||||||
|
|
||||||
i = 0;
|
i = 0;
|
||||||
j = 0;
|
j = 0;
|
||||||
|
|
@ -74,13 +74,13 @@ static char **ext_w(char **words_array, const char *str, char sep, int size)
|
||||||
return (words_array);
|
return (words_array);
|
||||||
}
|
}
|
||||||
|
|
||||||
char **ft_split(char const *s, char c)
|
t_str *ft_split(t_const_str s, t_i8 c)
|
||||||
{
|
{
|
||||||
int size;
|
t_i32 size;
|
||||||
char **words_array;
|
t_str *words_array;
|
||||||
|
|
||||||
size = count_words(s, c);
|
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)
|
if (!words_array)
|
||||||
return (NULL);
|
return (NULL);
|
||||||
if (size == 0)
|
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> +#+ +:+ +#+ */
|
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/03/29 11:35:51 by rparodi #+# #+# */
|
/* 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"
|
#include "../includes/minishell.h"
|
||||||
|
|
||||||
void ft_exit(i8 *str, u8 exit_status)
|
void ft_exit(t_str str, t_u8 exit_status)
|
||||||
{
|
{
|
||||||
free(str);
|
free(str);
|
||||||
printf("exit\n");
|
printf("exit\n");
|
||||||
|
|
|
||||||
|
|
@ -6,55 +6,70 @@
|
||||||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/03/28 14:40:38 by rparodi #+# #+# */
|
/* 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"
|
#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;
|
i = 0;
|
||||||
while (cmd[j])
|
while (operators[i])
|
||||||
{
|
{
|
||||||
if (ft_strcmp(cmd[j], ">") == 0)
|
if (ft_strcmp(operators[i], ">") == 0)
|
||||||
printf("Have to redirect in the file\n");
|
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");
|
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");
|
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");
|
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");
|
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");
|
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");
|
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");
|
printf("Have to execute one more command\n");
|
||||||
else if (ft_strcmp(cmd[j], "|") == 0)
|
else if (ft_strcmp(operators[i], "|") == 0)
|
||||||
printf("I have to pipe a cmd !\n");
|
printf("I have to pipe a operators !\n");
|
||||||
else if (ft_strcmp(cmd[j], "||") == 0)
|
else if (ft_strcmp(operators[i], "||") == 0)
|
||||||
printf("Or something\n");
|
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");
|
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");
|
printf("Parreil mais chelou\n");
|
||||||
else
|
else
|
||||||
printf("Error!\n");
|
return (0);
|
||||||
j++;
|
i++;
|
||||||
}
|
}
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ft_take_cmd(void)
|
void ft_check(char **input)
|
||||||
{
|
{
|
||||||
i32 i;
|
t_usize i;
|
||||||
i8 *user_input = NULL;
|
|
||||||
i8 **args = NULL;
|
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;
|
i = 0;
|
||||||
while (i < 10000000)
|
while (i < 10000000)
|
||||||
|
|
@ -65,14 +80,14 @@ void ft_take_cmd(void)
|
||||||
args = ft_split(user_input, ' ');
|
args = ft_split(user_input, ' ');
|
||||||
if (!user_input)
|
if (!user_input)
|
||||||
exit(1);
|
exit(1);
|
||||||
ft_check_type_cmd(args);
|
ft_check(args);
|
||||||
add_history(user_input);
|
add_history(user_input);
|
||||||
free(user_input);
|
free(user_input);
|
||||||
i++;
|
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