diff --git a/Makefile b/Makefile index ea373c24..7884d5d6 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,7 @@ # By: rparodi +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2023/11/12 11:05:05 by rparodi #+# #+# # -# Updated: 2024/03/25 15:30:19 by maiboyer ### ########.fr # +# Updated: 2024/03/28 15:17:18 by rparodi ### ########.fr # # # # **************************************************************************** # @@ -23,12 +23,13 @@ CC = cc RM = rm -rf # Flags -CFLAGS = -Werror -Wextra -Wall -Wno-unused-command-line-argument -g3 -MMD +CFLAGS = -Werror -Wextra -Wall -Wno-unused-command-line-argument -g3 -MMD -lreadline # Sources -LIB = +LIB = ./libft/get_next_line.c \ + ./libft/get_next_line_utils.c -SRC = +SRC = ./sources/main.c # Objects OBJDIRNAME = ./objects @@ -54,7 +55,7 @@ bonus: header $(OBJ) $(LIB_OBJ) footer @mkdir -p $(OBJDIRNAME)/$(SRCDIRNAME) @printf '$(GREY) Creating $(END)$(GREEN)$(OBJDIRNAME)$(END)\n' @printf '$(GREY) Be Carefull ur in $(END)$(GREEN)Debug Mode$(END)\n' - @cc $(CFLAGS) -D DEBUG=42 -o $(NAME) $(OBJ) $(LIB_OBJ) + @cc $(CFLAGS) -D DEBUG=42 -o $(NAME) $(OBJ) ./stdme/build/libft.a # Clean (make clean) clean: diff --git a/includes/minishell.h b/includes/minishell.h new file mode 100644 index 00000000..28bda83a --- /dev/null +++ b/includes/minishell.h @@ -0,0 +1,32 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* minishell.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rparodi +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/03/28 14:41:15 by rparodi #+# #+# */ +/* Updated: 2024/03/28 15:21:29 by rparodi ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef MINISHELL_H +#define MINISHELL_H + +# include "./type_rust.h" +# include "../libft/get_next_line.h" + +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +i32 main(void); + +#endif diff --git a/includes/type_rust.h b/includes/type_rust.h new file mode 100644 index 00000000..4c8d7f87 --- /dev/null +++ b/includes/type_rust.h @@ -0,0 +1,38 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* type_rust.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rparodi +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/03/28 14:44:20 by rparodi #+# #+# */ +/* Updated: 2024/03/28 15:01:47 by rparodi ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef TYPE_RUST_H +#define TYPE_RUST_H + +#include + +# define bool int +# define true 1 +# define false 0 + +# define u8 unsigned char +# define u16 unsigned short +# define u32 unsigned int +# define u64 unsigned long long + +# define i8 char +# define i16 short +# define i32 int +# define i64 long long + +# define usize size_t +# define isize ssize_t + +# define f32 float +# define f64 double + +#endif diff --git a/libft/get_next_line.c b/libft/get_next_line.c new file mode 100644 index 00000000..b4c2928d --- /dev/null +++ b/libft/get_next_line.c @@ -0,0 +1,78 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* get_next_line.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rparodi +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/11/18 17:12:02 by rparodi #+# #+# */ +/* Updated: 2023/11/22 13:31:13 by rparodi ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "get_next_line.h" + +char *ft_check(char *memory, int fd) +{ + char *buffer; + int bytescopy; + + bytescopy = 1; + buffer = (char *)malloc(sizeof(char) * (BUFFER_SIZE + 1)); + if (!buffer) + return (NULL); + while (ft_strchr(memory, '\n') <= 0 && bytescopy) + { + bytescopy = read(fd, buffer, BUFFER_SIZE); + if (bytescopy == -1) + return (ft_free(buffer)); + buffer[bytescopy] = '\0'; + memory = ft_strjoin(memory, buffer, 0, -1); + } + free(buffer); + return (memory); +} + +char *file_converted(int fd) +{ + size_t i; + int read_bits; + char *str; + char c; + + i = 0; + c = 1; + read_bits = 1; + str = (char *)malloc(sizeof(char) * BUFFER_SIZE); + if (!str) + return (NULL); + while (read_bits != 0 && i < BUFFER_SIZE) + { + read_bits = read(fd, &c, 1); + str[i] = c; + i++; + } + str[i] = '\0'; + return (str); +} + +char *ft_free(char *str) +{ + free(str); + return (NULL); +} + +char *get_next_line(int fd) +{ + static char *memory = NULL; + char *line; + + if (fd < 0 || BUFFER_SIZE <= 0) + return (NULL); + memory = ft_check(memory, fd); + if (!memory) + return (ft_free(memory)); + line = ft_get_line(memory); + memory = ft_get_next(memory); + return (line); +} diff --git a/libft/get_next_line.h b/libft/get_next_line.h new file mode 100644 index 00000000..3f76342e --- /dev/null +++ b/libft/get_next_line.h @@ -0,0 +1,33 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* get_next_line.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rparodi +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/11/18 17:12:04 by rparodi #+# #+# */ +/* Updated: 2023/11/23 18:15:34 by rparodi ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef GET_NEXT_LINE_H +# define GET_NEXT_LINE_H +# ifndef BUFFER_SIZE +# define BUFFER_SIZE 420 +# endif + +# include +# include + +char *ft_get_line(char *str); +char *get_next_line(int fd); +int ft_strchr(char *str, char c); +char *ft_get_next(char *str); +char *ft_get_line(char *str); +char *ft_strjoin(char *s1, char *s2, int i, int j); +size_t ft_strlen(char const *str); +char *file_converted(int fd); +char *ft_free(char *str); +char *ft_check(char *memory, int fd); + +#endif diff --git a/libft/get_next_line_utils.c b/libft/get_next_line_utils.c new file mode 100644 index 00000000..b4ad6c49 --- /dev/null +++ b/libft/get_next_line_utils.c @@ -0,0 +1,119 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* get_next_line_utils.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rparodi +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/11/18 17:14:47 by rparodi #+# #+# */ +/* Updated: 2023/11/22 13:35:03 by rparodi ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "get_next_line.h" + +size_t ft_strlen(char const *str) +{ + size_t i; + + i = 0; + if (str) + { + while (str[i]) + i++; + } + return (i); +} + +char *ft_strjoin(char *s1, char *s2, int i, int j) +{ + char *temp; + + if (!s1) + { + s1 = (char *)malloc(1); + s1[i] = '\0'; + } + if (!s2 || !s1) + return (NULL); + temp = (char *)malloc((ft_strlen(s1) + ft_strlen(s2) + 1)); + if (!temp) + return (NULL); + while (s1[i]) + { + temp[i] = s1[i]; + i++; + } + while (s2[++j]) + temp[i + j] = s2[j]; + temp[i + j] = '\0'; + free(s1); + return (temp); +} + +char *ft_get_line(char *str) +{ + char *temp; + int i; + + i = 0; + if (!str[i]) + return (NULL); + while (str[i] && str[i] != '\n') + i++; + temp = (char *)malloc((i + 2)); + if (!temp) + return (NULL); + i = 0; + while (str[i] && str[i] != '\n') + { + temp[i] = str[i]; + i++; + } + if (str[i] == '\n') + { + temp[i] = str[i]; + i++; + } + temp[i] = '\0'; + return (temp); +} + +char *ft_get_next(char *str) +{ + char *temp; + int i; + int j; + + i = 0; + while (str[i] && str[i] != '\n') + i++; + if (!str[i]) + return (ft_free(str)); + temp = (char *)malloc((ft_strlen(str) - i)); + if (!temp) + return (NULL); + j = i + 1; + while (str[++i]) + temp[i - j] = str[i]; + temp[i - j] = '\0'; + free(str); + return (temp); +} + +int ft_strchr(char *str, char c) +{ + int i; + + i = 0; + if (str) + { + while (str[i]) + { + if (str[i] == c) + return (i); + i++; + } + } + return (-1); +} diff --git a/libft/main.c b/libft/main.c new file mode 100644 index 00000000..88ea8631 --- /dev/null +++ b/libft/main.c @@ -0,0 +1,20 @@ +#include "get_next_line.h" +#include +#include + +int main(void) +{ + int fd = open("get_next_line.c", O_RDONLY); + int i = 0; + char *next_line = NULL; + while (i < 10000000) + { + next_line = get_next_line(fd); + if (!next_line) + return (printf("next_line[%d] = %s\n", i, next_line)); + printf("next_line[%d] = %s", i, next_line); + free(next_line); + i++; + } + return (0); +} diff --git a/minishell b/minishell new file mode 100755 index 00000000..963606ae Binary files /dev/null and b/minishell differ diff --git a/other/pipex/include/app/main.h b/other/pipex/include/app/main.h index 77345084..bd8f66f1 100644 --- a/other/pipex/include/app/main.h +++ b/other/pipex/include/app/main.h @@ -6,15 +6,15 @@ /* By: maiboyer +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/01/06 18:51:07 by maiboyer #+# #+# */ -/* Updated: 2024/01/06 18:52:58 by maiboyer ### ########.fr */ +/* Updated: 2024/03/28 12:37:04 by rparodi ### ########.fr */ /* */ /* ************************************************************************** */ #ifndef MAIN_H # define MAIN_H -# include "me/fs/open.h" -# include "me/fs/read.h" +# include "../me/fs/open.h" +# include "../me/fs/read.h" # include "me/fs/write.h" # include "me/gnl/gnl.h" # include "me/mem/mem_find_bytes.h" diff --git a/rust/parser/src/adapt_in_c/includes/enum.h b/rust/parser/src/adapt_in_c/includes/enum.h new file mode 100644 index 00000000..d0f360e0 --- /dev/null +++ b/rust/parser/src/adapt_in_c/includes/enum.h @@ -0,0 +1,31 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* enum.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rparodi +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/03/28 12:44:05 by rparodi #+# #+# */ +/* Updated: 2024/03/28 13:09:06 by rparodi ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef ENUM_H +#define ENUM_H + +#include "./rust_type.h" + +enum e_separator_op +{ + Semi, + Fork, +}; + +enum e_pipeline_kind +{ + Or, + And, +}; + + +#endif diff --git a/rust/parser/src/adapt_in_c/includes/rust_type.h b/rust/parser/src/adapt_in_c/includes/rust_type.h new file mode 100644 index 00000000..1f08c5c8 --- /dev/null +++ b/rust/parser/src/adapt_in_c/includes/rust_type.h @@ -0,0 +1,33 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* rust_type.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rparodi +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/03/28 12:50:51 by rparodi #+# #+# */ +/* Updated: 2024/03/28 12:52:53 by rparodi ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef RUST_TYPE_H +#define RUST_TYPE_H + +# define bool int +# define true 1 +# define false 0 +# define u8 unsigned char +# define u16 unsigned short +# define u32 unsigned int +# define u64 unsigned long long +# define i8 char +# define i16 short +# define i32 int +# define i64 long long +# define usize size_t +# define isize ssize_t +# define f32 float +# define f64 double + +#endif + diff --git a/rust/parser/src/adapt_in_c/includes/shcat.h b/rust/parser/src/adapt_in_c/includes/shcat.h new file mode 100644 index 00000000..36effa7f --- /dev/null +++ b/rust/parser/src/adapt_in_c/includes/shcat.h @@ -0,0 +1,29 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* shcat.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rparodi +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/03/28 12:42:55 by rparodi #+# #+# */ +/* Updated: 2024/03/28 12:53:50 by rparodi ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef SHCAT_H +#define SHCAT_H + +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include + +# include "./enum.h" +# include "./rust_type.h" +#endif diff --git a/sources/main.c b/sources/main.c new file mode 100644 index 00000000..2c98d471 --- /dev/null +++ b/sources/main.c @@ -0,0 +1,35 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* main.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rparodi +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/03/28 14:40:38 by rparodi #+# #+# */ +/* Updated: 2024/03/28 15:20:38 by rparodi ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "../includes/minishell.h" + +void ft_take_cmd(void) +{ + int i = 0; + char *next_line = NULL; + while (i < 10000000) + { + next_line = readline("shcat > "); + if (!next_line) + exit(1); + printf("%s\n", next_line); + add_history(next_line); + free(next_line); + i++; + } +} + +int main(void) +{ + printf("Welcome to our Minishell !\n"); + ft_take_cmd(); +}