diff options
author | JozanLeClerc <bousset.rudy@gmail.com> | 2020-04-20 14:51:45 +0200 |
---|---|---|
committer | JozanLeClerc <bousset.rudy@gmail.com> | 2020-04-20 14:51:45 +0200 |
commit | c9e4fb6e2ad07e13cf41d6ce6afad30b04011765 (patch) | |
tree | 74d816c107c959315ae52166dac96fe2fe0c2a5e | |
parent | Well well well that wasn't too bad, now remake everything (diff) | |
download | 42-minishell-c9e4fb6e2ad07e13cf41d6ce6afad30b04011765.tar.gz 42-minishell-c9e4fb6e2ad07e13cf41d6ce6afad30b04011765.tar.bz2 42-minishell-c9e4fb6e2ad07e13cf41d6ce6afad30b04011765.tar.xz 42-minishell-c9e4fb6e2ad07e13cf41d6ce6afad30b04011765.tar.zst 42-minishell-c9e4fb6e2ad07e13cf41d6ce6afad30b04011765.zip |
Solid base
Diffstat (limited to '')
-rw-r--r-- | .gitignore | 3 | ||||
-rw-r--r-- | Makefile | 96 | ||||
-rw-r--r-- | inc/minishell.h | 30 | ||||
-rw-r--r-- | libft/Makefile | 31 | ||||
-rw-r--r-- | src/ft_d_enum.h | 29 | ||||
-rw-r--r-- | src/ft_echo.c | 40 | ||||
-rw-r--r-- | src/ft_error.c | 34 | ||||
-rw-r--r-- | src/ft_exec.c | 39 | ||||
-rw-r--r-- | src/ft_exit.c | 39 | ||||
-rw-r--r-- | src/ft_history.c | 123 | ||||
-rw-r--r-- | src/ft_process_arg.c | 51 | ||||
-rw-r--r-- | src/ft_pwd.c | 26 | ||||
-rw-r--r-- | src/ft_s_destroy.c | 20 | ||||
-rw-r--r-- | src/ft_s_destroy.h | 20 | ||||
-rw-r--r-- | src/ft_s_init.c | 25 | ||||
-rw-r--r-- | src/ft_s_init.h | 21 | ||||
-rw-r--r-- | src/ft_s_struct.h | 21 | ||||
-rw-r--r-- | src/main.c | 41 | ||||
-rw-r--r-- | src/minishell.c | 48 | ||||
-rw-r--r-- | src/minishell.h | 20 |
20 files changed, 264 insertions, 493 deletions
@@ -123,4 +123,5 @@ flycheck_*.el # End of https://www.gitignore.io/api/c,linux,emacs minishell -joe-sh_history
\ No newline at end of file +minishell_history +*.core
\ No newline at end of file @@ -1,78 +1,80 @@ -# **************************************************************************** # -# LE - / # -# / # -# Makefile .:: .:/ . .:: # -# +:+:+ +: +: +:+:+ # -# By: rbousset <marvin@le-101.fr> +:+ +: +: +:+ # -# #+# #+ #+ #+# # -# Created: 2019/10/08 15:04:55 by rbousset #+# ## ## #+# # -# Updated: 2019/10/13 14:01:21 by rbousset ### #+. /#+ ###.fr # -# / # -# / # -# **************************************************************************** # -.DEFAULT_GOAL := all +default: all #==============================================================================# -#--------------------------------- Shell --------------------------------------# +#--------------------------------- SHELL --------------------------------------# #==============================================================================# SHELL := /bin/sh #==============================================================================# -#------------------------------ Directories -----------------------------------# +#------------------------------ DIRECTORIES -----------------------------------# #==============================================================================# SRCS_DIR = src/ OBJS_DIR = obj/ LFT_DIR = libft/ -INCS_DIR = inc/ -LFT_INCS_DIR = ${LFT_DIR}/inc/ +LFT_INCS_DIR = ${LFT_DIR}inc/ +LFT_SRCS_DIR = ${LFT_DIR}src/ #==============================================================================# -#--------------------------------- Files --------------------------------------# +#--------------------------------- FILES --------------------------------------# #==============================================================================# -LFT = ft -#------------------------------------------------------------------------------# -SRCS_NAME = main.c -SRCS_NAME += ft_process_arg.c -SRCS_NAME += ft_error.c -SRCS_NAME += ft_exit.c -SRCS_NAME += ft_echo.c -SRCS_NAME += ft_pwd.c -SRCS_NAME += ft_exec.c -SRCS_NAME += ft_history.c +SRCS_NAME = minishell.c +SRCS_NAME += ft_s_init.c +SRCS_NAME += ft_s_destroy.c +#------------------------------------------------------------------------------# SRCS = $(addprefix ${SRCS_DIR}, ${SRCS_NAME}) #------------------------------------------------------------------------------# +INCS_NAME = ft_s_struct.h +INCS_NAME += ft_d_enum.h +INCS_NAME += $(patsubst %.c,%.h,${SRCS_NAME}) +#------------------------------------------------------------------------------# +INCS = $(addprefix ${SRCS_DIR}, ${INCS_NAME}) +#------------------------------------------------------------------------------# OBJS = $(patsubst ${SRCS_DIR}%.c,${OBJS_DIR}%.o,${SRCS}) #------------------------------------------------------------------------------# +NAME = minishell +#------------------------------------------------------------------------------# +HISTFILE = minishell_history +#------------------------------------------------------------------------------# +LFT_SRCS = $(shell find ${LFT_SRCS_DIR} -name "*.c") #==============================================================================# -#-------------------------------- Compiler ------------------------------------# +#-------------------------------- COMPILER ------------------------------------# #==============================================================================# CC = clang -CFLAGS = -Wall +CFLAGS = -std=c89 +CFLAGS += -Wall CFLAGS += -Wextra CFLAGS += -Werror -CFLAGS += ${DEBUG} -CFLAGS += ${FSANITIZE} +CFLAGS += -pedantic #------------------------------------------------------------------------------# -DEBUG = -glldb -FSANITIZE = -fsanitize=address +CDEFS = -DFT_HISTFILE=${HISTFILE} #------------------------------------------------------------------------------# -NAME = minishell +LDFLAGS = -L${LFT_DIR} +LDFLAGS += -lft #==============================================================================# #--------------------------------- UNIX ---------------------------------------# #==============================================================================# RM = rm -rf MKDIR = mkdir -p #==============================================================================# -#--------------------------------- Rules --------------------------------------# +#--------------------------------- RULES --------------------------------------# #==============================================================================# -${OBJS_DIR}%.o: ${SRCS_DIR}%.c ${INCS_DIR}minishell.h ${LFT_INCS_DIR}libft.h +LFTRULE = all +#------------------------------------------------------------------------------# +${OBJS_DIR}%.o: ${SRCS_DIR}%.c ${INCS} @${MKDIR} ${OBJS_DIR} - ${CC} ${CFLAGS} -I${INCS_DIR} -I${LFT_INCS_DIR} -o $@ -c $< + ${CC} -c ${CFLAGS} ${CDEFS} -I${SRCS_DIR} -I${LFT_INCS_DIR} -o $@ $< +#------------------------------------------------------------------------------# +${NAME}: ${OBJS} ${LFT_SRCS} ${LFT_INCS_DIR}libft.h + @$(MAKE) --no-print-directory -C ${LFT_DIR} ${LFTRULE} + ${CC} ${CFLAGS} -o ${NAME} ${OBJS} ${LDFLAGS} +#------------------------------------------------------------------------------# +all: ${NAME} #------------------------------------------------------------------------------# -$(NAME): ${OBJS} - ${CC} ${CFLAGS} -o ${NAME} ${OBJS} -L${LFT_DIR} -l${LFT} +debug: CFLAGS += -ggdb +debug: LFTRULE = debug +debug: all #------------------------------------------------------------------------------# -all: - @$(MAKE) --no-print-directory -C ${LFT_DIR} all - @printf "\n" - @$(MAKE) --no-print-directory ${NAME} +asan: CFLAGS += -ggdb +asan: CFLAGS += -fsanitize=address +asan: LFTRULE = asan +asan: all #------------------------------------------------------------------------------# clean: @$(MAKE) --no-print-directory -C ${LFT_DIR} clean @@ -80,10 +82,8 @@ clean: #------------------------------------------------------------------------------# fclean: clean @$(MAKE) --no-print-directory -C ${LFT_DIR} fclean - ${RM} ${NAME} - ${RM} ${NAME}.dSYM/ - ${RM} joe-sh_history + ${RM} ${NAME} ${NAME}.dSYM/ ${HISTFILE} #------------------------------------------------------------------------------# re: fclean all #------------------------------------------------------------------------------# -.PHONY: all clean clean fclean re +.PHONY: all clean clean fclean re debug asan diff --git a/inc/minishell.h b/inc/minishell.h deleted file mode 100644 index fd207de..0000000 --- a/inc/minishell.h +++ /dev/null @@ -1,30 +0,0 @@ -/* ************************************************************************** */ -/* LE - / */ -/* / */ -/* minishell.h .:: .:/ . .:: */ -/* +:+:+ +: +: +:+:+ */ -/* By: rbousset <marvin@le-101.fr> +:+ +: +: +:+ */ -/* #+# #+ #+ #+# */ -/* Created: 2019/11/01 18:46:43 by rbousset #+# ## ## #+# */ -/* Updated: 2019/11/01 18:46:44 by rbousset ### #+. /#+ ###.fr */ -/* / */ -/* / */ -/* ************************************************************************** */ - -#ifndef _MINISHELL_H__ -#define _MINISHELL_H__ - -#include <inttypes.h> - -#define FT_PS1 "joe-sh~> " - -int ft_process_arg(char *arg); -int ft_echo(char **com, uint8_t n); -int ft_pwd(void); -uint8_t ft_exit(char **com); -int ft_error(const char *com, int errno); -int ft_exec(char **com); -int ft_history(char *arg); -char *ft_get_last_line(void); - -#endif diff --git a/libft/Makefile b/libft/Makefile index 2bd6342..ec87186 100644 --- a/libft/Makefile +++ b/libft/Makefile @@ -119,13 +119,6 @@ OS = $(shell uname) #-------------------------------- Compiler ------------------------------------# #==============================================================================# ifeq (${OS}, Linux) - DBG = -ggdb -else - DBG = -glldb -endif -FSANITIZE = -fsanitize=address -#------------------------------------------------------------------------------# -ifeq (${OS}, Linux) CC = gcc else CC = clang @@ -136,14 +129,6 @@ CFLAGS += -Wall CFLAGS += -Wextra CFLAGS += -Werror CFLAGS += -pedantic -ifdef DEBUG - CFLAGS += ${DBG} -endif -#------------------------------------------------------------------------------# -ifdef ASAN - CFLAGS += ${DBG} - CFLAGS += ${FSANITIZE} -endif #------------------------------------------------------------------------------# NAME = libft.a #==============================================================================# @@ -160,18 +145,22 @@ ${OBJS_DIR}%.o: ${SRCS_DIR}%.c ${INCS_DIR}${INCS} ${NAME}: ${OBJS} ${AR} ${NAME} ${OBJS} #------------------------------------------------------------------------------# -all: ${NAME} +all: ${NAME} +#------------------------------------------------------------------------------# +debug: CFLAGS += -ggdb +debug: all +#------------------------------------------------------------------------------# +asan: CFLAGS += -ggdb +asan: CFLAGS += -fsanitize=address +asan: all #------------------------------------------------------------------------------# clean: ${RM} ${OBJS_DIR} #------------------------------------------------------------------------------# -fclean: clean +fclean: clean ${RM} ${NAME} #------------------------------------------------------------------------------# -re: fclean all -#------------------------------------------------------------------------------# -run: ${OBJS} - ${CC} ${CFLAGS} -Iinc/ -o a.out ${OBJS} ${SRCS_DIR}main.c +re: fclean all #------------------------------------------------------------------------------# .PHONY: all clean clean fclean re run default #==================================== EOF =====================================# diff --git a/src/ft_d_enum.h b/src/ft_d_enum.h new file mode 100644 index 0000000..ef276c8 --- /dev/null +++ b/src/ft_d_enum.h @@ -0,0 +1,29 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_d_enum.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/02/14 17:19:27 by rbousset #+# #+# */ +/* Updated: 2020/02/14 17:19:29 by rbousset ### ########lyon.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef FT_D_ENUM_H +#define FT_D_ENUM_H + +/* +** ret vals: +** --------- +** 0: cool +** 1: alloc err +*/ + +enum +{ + FT_RET_FINE, + FT_RET_ALLOC +} + +#endif diff --git a/src/ft_echo.c b/src/ft_echo.c deleted file mode 100644 index e8ef75c..0000000 --- a/src/ft_echo.c +++ /dev/null @@ -1,40 +0,0 @@ -/* ************************************************************************** */ -/* LE - / */ -/* / */ -/* ft_echo.c .:: .:/ . .:: */ -/* +:+:+ +: +: +:+:+ */ -/* By: rbousset <marvin@le-101.fr> +:+ +: +: +:+ */ -/* #+# #+ #+ #+# */ -/* Created: 2019/11/01 18:46:54 by rbousset #+# ## ## #+# */ -/* Updated: 2019/11/01 18:46:55 by rbousset ### #+. /#+ ###.fr */ -/* / */ -/* / */ -/* ************************************************************************** */ - -#include <libft.h> -#include <minishell.h> -#include <inttypes.h> - -int -ft_echo(char **com, uint8_t n) -{ - uint8_t i; - int fd; - - i = 1; - fd = 1; - if (!com[1]) - ft_dprintf(fd, "\n"); - else if (!ft_strncmp(com[1], "-n", ft_strlen(com[1]))) - i = 2; - while (i < n) - { - ft_dprintf(fd, "%s", ft_strtrim(com[i], "\"")); - if (i != n - 1) - ft_dprintf(fd, " "); - i++; - } - if (ft_strncmp(com[1], "-n", ft_strlen(com[1]))) - ft_dprintf(fd, "\n"); - return (0); -} diff --git a/src/ft_error.c b/src/ft_error.c deleted file mode 100644 index 933a22b..0000000 --- a/src/ft_error.c +++ /dev/null @@ -1,34 +0,0 @@ -/* ************************************************************************** */ -/* LE - / */ -/* / */ -/* ft_error.c .:: .:/ . .:: */ -/* +:+:+ +: +: +:+:+ */ -/* By: rbousset <marvin@le-101.fr> +:+ +: +: +:+ */ -/* #+# #+ #+ #+# */ -/* Created: 2019/10/30 17:21:53 by rbousset #+# ## ## #+# */ -/* Updated: 2019/11/01 18:47:03 by rbousset ### #+. /#+ ###.fr */ -/* / */ -/* / */ -/* ************************************************************************** */ - -#include <libft.h> -#include <minishell.h> - -int -ft_error(const char *com, int err) -{ - ft_putstr("joe-sh: "); - ft_putstr(com); - if (err == 1) - ft_putendl(": too many arguments"); - else if (err == 127) - { - if (!ft_strncmp(com, "./", 2)) - ft_putendl(": no such file or directory"); - else - ft_putendl(": command not found"); - } - else if (err == 255) - ft_putendl(": numeric argument required"); - return (err); -} diff --git a/src/ft_exec.c b/src/ft_exec.c deleted file mode 100644 index 408697d..0000000 --- a/src/ft_exec.c +++ /dev/null @@ -1,39 +0,0 @@ -/* ************************************************************************** */ -/* LE - / */ -/* / */ -/* ft_exec.c .:: .:/ . .:: */ -/* +:+:+ +: +: +:+:+ */ -/* By: rbousset <marvin@le-101.fr> +:+ +: +: +:+ */ -/* #+# #+ #+ #+# */ -/* Created: 2019/11/01 18:46:50 by rbousset #+# ## ## #+# */ -/* Updated: 2019/11/01 18:47:21 by rbousset ### #+. /#+ ###.fr */ -/* / */ -/* / */ -/* ************************************************************************** */ - -#include <libft.h> -#include <stdlib.h> -#include <minishell.h> -#include <unistd.h> - -int -ft_exec(char **com) -{ - uint8_t i; - - i = 0; - while (com[i]) - i++; - if (fork() == 0) - { - if (!ft_strncmp(com[0], "./", 2)) - { - if ((execve(com[0] + 2, com, NULL)) != 0) - return (ft_error(com[0], 127)); - } - else - if ((execve(com[0], com, NULL)) != 0) - return (ft_error(com[0], 127)); - } - return (0); -} diff --git a/src/ft_exit.c b/src/ft_exit.c deleted file mode 100644 index 5285289..0000000 --- a/src/ft_exit.c +++ /dev/null @@ -1,39 +0,0 @@ -/* ************************************************************************** */ -/* LE - / */ -/* / */ -/* ft_exit.c .:: .:/ . .:: */ -/* +:+:+ +: +: +:+:+ */ -/* By: rbousset <marvin@le-101.fr> +:+ +: +: +:+ */ -/* #+# #+ #+ #+# */ -/* Created: 2019/10/30 16:05:48 by rbousset #+# ## ## #+# */ -/* Updated: 2019/11/01 18:47:18 by rbousset ### #+. /#+ ###.fr */ -/* / */ -/* / */ -/* ************************************************************************** */ - -#include <libft.h> -#include <minishell.h> -#include <stdlib.h> - -uint8_t -ft_exit(char **com) -{ - uint8_t i; - - i = 0; - while (com[i]) - i++; - if (i == 2) - { - i = 0; - while (ft_isdigit(com[1][i])) - i++; - if (i != ft_strlen(com[1])) - exit(ft_error(com[0], 255)); - else - exit((uint8_t)ft_atoi(com[1])); - } - else if (i > 2) - return (ft_error(com[0], 1)); - exit(0); -} diff --git a/src/ft_history.c b/src/ft_history.c deleted file mode 100644 index 936b9a2..0000000 --- a/src/ft_history.c +++ /dev/null @@ -1,123 +0,0 @@ -/* ************************************************************************** */ -/* LE - / */ -/* / */ -/* ft_history.c .:: .:/ . .:: */ -/* +:+:+ +: +: +:+:+ */ -/* By: rbousset <marvin@le-101.fr> +:+ +: +: +:+ */ -/* #+# #+ #+ #+# */ -/* Created: 2019/10/30 20:36:05 by rbousset #+# ## ## #+# */ -/* Updated: 2019/10/30 20:36:07 by rbousset ### #+. /#+ ###.fr */ -/* / */ -/* / */ -/* ************************************************************************** */ - -#include <libft.h> -#include <minishell.h> -#include <stddef.h> -#include <stdlib.h> -#include <stdio.h> -#include <fcntl.h> -#include <unistd.h> -#include <sys/types.h> -#include <sys/stat.h> - -static size_t -ft_count_lines(int fd) -{ - char c; - size_t lines; - - lines = 0; - while (read(fd, &c, 1) > 0) - if (c == '\n') - lines++; - return (lines); -} - -static size_t -ft_last_line_len(int fd, size_t lines_max) -{ - char c; - size_t len; - size_t lines; - - len = 0; - lines = 0; - while (read(fd, &c, 1) > 0) - { - if (c == '\n') - lines++; - if (lines == lines_max - 1) - break ; - } - while (read(fd, &c, 1) > 0) - len++; - return (len); -} - - -char -*ft_get_last_line(void) -{ - char *line; - char c; - int fd; - size_t lines; - size_t i; - - if ((fd = open("joe-sh_history", O_CREAT | O_RDWR, 0644)) == -1) - return (NULL); - i = 0; - lines = ft_count_lines(fd); - close(fd); - if ((fd = open("joe-sh_history", O_CREAT | O_RDWR, 0644)) == -1) - return (NULL); - if (!(line = (char*)malloc(ft_last_line_len(fd, lines) * sizeof(char)))) - return (NULL); - close(fd); - if ((fd = open("joe-sh_history", O_CREAT | O_RDWR, 0644)) == -1) - return (NULL); - while (read(fd, &c, 1) > 0) - { - if (c == '\n') - i++; - if (i == lines - 1) - break ; - } - i = 0; - while (read(fd, &c, 1) > 0) - { - line[i] = c; - i++; - } - line[i - 1] = '\0'; - close(fd); - return (line); -} - -/* -** Prints user-given line into -** joe-sh_hisotry file -*/ - -int -ft_history(char *arg) -{ - char *buff; - int fd; - int ret; - struct stat info; - - if (!*arg) - return (0); - if ((fd = open("joe-sh_history", O_CREAT | O_RDWR, 0644)) == -1) - return (1); - fstat(fd, &info); - if (!(buff = (char*)malloc(info.st_size * sizeof(char)))) - return (0); - ret = read(fd, buff, info.st_size); - ft_putendl_fd(arg, fd); - free(buff); - close(fd); - return (ret); -} diff --git a/src/ft_process_arg.c b/src/ft_process_arg.c deleted file mode 100644 index 8057e42..0000000 --- a/src/ft_process_arg.c +++ /dev/null @@ -1,51 +0,0 @@ -/* ************************************************************************** */ -/* LE - / */ -/* / */ -/* ft_process_arg.c .:: .:/ . .:: */ -/* +:+:+ +: +: +:+:+ */ -/* By: rbousset <marvin@le-101.fr> +:+ +: +: +:+ */ -/* #+# #+ #+ #+# */ -/* Created: 2019/11/01 18:47:30 by rbousset #+# ## ## #+# */ -/* Updated: 2019/11/01 18:47:32 by rbousset ### #+. /#+ ###.fr */ -/* / */ -/* / */ -/* ************************************************************************** */ - -#include <libft.h> -#include <stdlib.h> -#include <minishell.h> -#include <inttypes.h> - -int -ft_process_arg(char *arg) -{ - char **com; - char *prev; - uint8_t i; - - if (arg[0] == '\0') - return (0); - if (ft_strncmp(arg, "r", 1)) - ft_history(arg); - i = 0; - com = ft_split(arg, ' '); - while (com[i]) - i++; - if (!ft_strncmp(com[0], "exit", ft_strlen(com[0]))) - return (ft_exit(com)); - else if (!ft_strncmp(com[0], "echo", ft_strlen(com[0]))) - return (ft_echo(com, i)); - else if (!ft_strncmp(com[0], "pwd", ft_strlen(com[0]))) - return (ft_pwd()); - else if (!ft_strncmp(com[0], "r", 1)) - { - prev = ft_get_last_line(); - ft_putendl(prev); - ft_history("r"); - ft_process_arg(prev); - free(prev); - } - else - return (ft_exec(com)); - return (0); -} diff --git a/src/ft_pwd.c b/src/ft_pwd.c deleted file mode 100644 index 07e5622..0000000 --- a/src/ft_pwd.c +++ /dev/null @@ -1,26 +0,0 @@ -/* ************************************************************************** */ -/* LE - / */ -/* / */ -/* ft_pwd.c .:: .:/ . .:: */ -/* +:+:+ +: +: +:+:+ */ -/* By: rbousset <marvin@le-101.fr> +:+ +: +: +:+ */ -/* #+# #+ #+ #+# */ -/* Created: 2019/11/01 18:47:41 by rbousset #+# ## ## #+# */ -/* Updated: 2019/11/01 18:47:47 by rbousset ### #+. /#+ ###.fr */ -/* / */ -/* / */ -/* ************************************************************************** */ - -#include <libft.h> -#include <stddef.h> -#include <unistd.h> - -int -ft_pwd(void) -{ - char *buff; - - buff = NULL; - ft_putendl(getcwd(buff, 1000)); - return (0); -} diff --git a/src/ft_s_destroy.c b/src/ft_s_destroy.c new file mode 100644 index 0000000..ffb8381 --- /dev/null +++ b/src/ft_s_destroy.c @@ -0,0 +1,20 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_s_destroy.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/02/14 17:19:27 by rbousset #+# #+# */ +/* Updated: 2020/02/14 17:19:29 by rbousset ### ########lyon.fr */ +/* */ +/* ************************************************************************** */ + +#include <libft.h> +#include "ft_s_destroy.h" + +void +ft_s_destroy(t_data *data) +{ + ft_memdel((void*)&data); +} diff --git a/src/ft_s_destroy.h b/src/ft_s_destroy.h new file mode 100644 index 0000000..0d6d030 --- /dev/null +++ b/src/ft_s_destroy.h @@ -0,0 +1,20 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_s_destroy.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/02/14 17:19:27 by rbousset #+# #+# */ +/* Updated: 2020/02/14 17:19:29 by rbousset ### ########lyon.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef FT_S_DESTROY_H +#define FT_S_DESTROY_H + +#include "ft_s_struct.h" + +void ft_s_destroy(t_data *data); + +#endif diff --git a/src/ft_s_init.c b/src/ft_s_init.c new file mode 100644 index 0000000..82293be --- /dev/null +++ b/src/ft_s_init.c @@ -0,0 +1,25 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_s_init.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/02/14 17:19:27 by rbousset #+# #+# */ +/* Updated: 2020/02/14 17:19:29 by rbousset ### ########lyon.fr */ +/* */ +/* ************************************************************************** */ + +#include <ft_s_init.h> + +t_data +*ft_init_data(void) +{ + t_data *data; + + if (!(data = (t_data*)malloc(sizeof(t_data)))) + { + return (NULL); + } + return (data); +} diff --git a/src/ft_s_init.h b/src/ft_s_init.h new file mode 100644 index 0000000..8297a5e --- /dev/null +++ b/src/ft_s_init.h @@ -0,0 +1,21 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_s_init.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/02/14 17:19:27 by rbousset #+# #+# */ +/* Updated: 2020/02/14 17:19:29 by rbousset ### ########lyon.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef FT_S_INIT_H +#define FT_S_INIT_H + +#include <ft_s_struct.h> +#include <stdlib.h> + +t_data *ft_init_data(void); + +#endif diff --git a/src/ft_s_struct.h b/src/ft_s_struct.h new file mode 100644 index 0000000..3d3d8a7 --- /dev/null +++ b/src/ft_s_struct.h @@ -0,0 +1,21 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_s_struct.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/02/14 17:19:27 by rbousset #+# #+# */ +/* Updated: 2020/02/14 17:19:29 by rbousset ### ########lyon.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef FT_S_STRUCT_H +#define FT_S_STRUCT_H + +typedef struct s_data +{ + char **envp; +} t_data; + +#endif diff --git a/src/main.c b/src/main.c deleted file mode 100644 index beafbb5..0000000 --- a/src/main.c +++ /dev/null @@ -1,41 +0,0 @@ -/* ************************************************************************** */ -/* LE - / */ -/* / */ -/* main.c .:: .:/ . .:: */ -/* +:+:+ +: +: +:+:+ */ -/* By: rbousset <marvin@le-101.fr> +:+ +: +: +:+ */ -/* #+# #+ #+ #+# */ -/* Created: 2019/10/29 08:47:37 by rbousset #+# ## ## #+# */ -/* Updated: 2019/10/29 08:47:39 by rbousset ### #+. /#+ ###.fr */ -/* / */ -/* / */ -/* ************************************************************************** */ - -#include <libft.h> -#include <minishell.h> -#include <stdlib.h> -#include <stddef.h> -#include <stdint.h> -#include <unistd.h> - -int -main(int argc, - const char *argv[], - const char *envp[]) -{ - char *arg; - int8_t gnlret; - - (void)argc; - (void)argv; - (void)envp; - ft_printf(FT_PS1); - while ((gnlret = get_next_line(STDIN_FILENO, &arg)) > 0) - { - ft_process_arg(arg); - ft_memdel((void*)&arg); - ft_printf(FT_PS1); - } - free(arg); - return (0); -} diff --git a/src/minishell.c b/src/minishell.c new file mode 100644 index 0000000..e5b4777 --- /dev/null +++ b/src/minishell.c @@ -0,0 +1,48 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* minishell.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/02/14 17:19:27 by rbousset #+# #+# */ +/* Updated: 2020/02/14 17:19:29 by rbousset ### ########lyon.fr */ +/* */ +/* ************************************************************************** */ + +#include <libft.h> +#include "minishell.h" + +int +main(int argc, + const char *argv[], + char *envp[]) +{ + t_data *data; + + (void)argc; + (void)argv; + (void)envp; + if (!(data = ft_init_data())) + { + return (1); + } + data->envp = envp; + while (*data->envp) + { + ft_printf("%s\n", *data->envp); + data->envp++; + } + ft_s_destroy(data); + return (0); +} + +/* +** ====== INFO ====== +** Files prefixes info +** ------------------- +** ft_ -> 42 +** s_ -> structs related +** d_ -> defines related +** p_ -> parse related +*/ diff --git a/src/minishell.h b/src/minishell.h new file mode 100644 index 0000000..5e50303 --- /dev/null +++ b/src/minishell.h @@ -0,0 +1,20 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* minishell.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/02/14 17:19:27 by rbousset #+# #+# */ +/* Updated: 2020/02/14 17:19:29 by rbousset ### ########lyon.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef MINISHELL_H +#define MINISHELL_H + +#include "ft_s_struct.h" +#include "ft_s_init.h" +#include "ft_s_destroy.h" + +#endif |