diff --git a/Makefile b/Makefile index 6f03bfa..996e9c7 100755 --- a/Makefile +++ b/Makefile @@ -1,6 +1,7 @@ -NAME = minishell +NAME = minishell LIBFT = libft.a -SRCS = minishell.c lexer.c parser.c caller.c built-in.c env.c utils.c utils_2.c +SRCS = minishell.c lexer.c parser.c caller.c built-in.c env.c +SRCS += utils_1.c utils_2.c utils_3.c OBJS = ${SRCS:.c=.o} @@ -16,7 +17,7 @@ endif $(NAME): $(LIBFT) $(OBJS) gcc -g ${OBJS} ${LIB} -o ${NAME} -$(LIBFT): +$(LIBFT): ${MAKE} -C ./libft cp ./libft/libft.a . diff --git a/README.md b/README.md index 9e16cc3..b262875 100755 --- a/README.md +++ b/README.md @@ -9,6 +9,10 @@ - ## Issues : - cat | ls ; cat | cat | ls ... - +- syntax error for unclosed quotes +- stderror syntax +- export without arg -> env + declare. +- segfault when last cmd empty +- too many pipes is a problem ## Notes : diff --git a/caller.c b/caller.c index e798bed..e459464 100755 --- a/caller.c +++ b/caller.c @@ -6,7 +6,7 @@ /* By: mea +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/05/03 11:48:16 by narnaud #+# #+# */ -/* Updated: 2022/05/12 11:34:26 by mea ### ########.fr */ +/* Updated: 2022/05/12 13:36:30 by mea ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/env.c b/env.c index 65e6249..3a6f115 100755 --- a/env.c +++ b/env.c @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* env.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: narnaud +#+ +:+ +#+ */ +/* By: mea +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/02/16 09:41:29 by narnaud #+# #+# */ -/* Updated: 2022/05/07 23:38:40 by narnaud@stude ### ########.fr */ +/* Updated: 2022/05/12 14:32:41 by mea ### ########.fr */ /* */ /* ************************************************************************** */ @@ -61,8 +61,6 @@ int ft_env(t_datas *datas, t_command *cmd) return (0); } -static int is_valid_identifier(char *ident); - int ft_export(t_datas *datas, t_command *cmd) { char **new; @@ -114,30 +112,3 @@ static void clean_env(t_datas *datas, int i) i++; } } - -static int is_valid_identifier(char *ident) -{ - int i; - - i = 0; - if (ft_isalpha(ident[0]) || ident[0] == '_') - { - while (ident[i]) - { - if (!ft_isalpha(ident[i]) && !ft_isdigit(ident[i]) \ - && ident[i] != '_') - { - ft_putstr_fd("export: not an identifier: ", 2); - ft_putstr_fd(ident, 2); - ft_putchar_fd('\n', 2); - return (0); - } - i++; - } - return (1); - } - ft_putstr_fd("export: not an identifier: ", 2); - ft_putstr_fd(ident, 2); - ft_putchar_fd('\n', 2); - return (0); -} diff --git a/lexer.c b/lexer.c index 382c8ca..5640283 100755 --- a/lexer.c +++ b/lexer.c @@ -6,15 +6,13 @@ /* By: mea +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/05/02 13:44:57 by narnaud #+# #+# */ -/* Updated: 2022/05/12 13:07:38 by narnaud ### ########.fr */ +/* Updated: 2022/05/12 14:53:06 by mea ### ########.fr */ /* */ /* ************************************************************************** */ #include "minishell.h" -static int create_wc(t_lexer *lex, char *tmp); static int check_state(t_lexer *lex, char **line); -static int create_token(t_lexer *lex, char str[]); static int check_register(t_lexer *lex, char **line, char *tmp); t_token *lexer(t_datas *datas, char *line) @@ -32,8 +30,12 @@ t_token *lexer(t_datas *datas, char *line) { if (check_state(lex, &line)) continue ; - if (lex->state != S_QUOTE_ST && lex->deep == 0 && *line == '$') + if (lex->state != S_QUOTE_ST && lex->deep == 0 && *line == '$' + && (line[1] != '\0' && !isspace(line[1]))) + { tmp_i = replace_var(datas, &line, tmp, tmp_i); + lex->empty = 1; + } else if (check_register(lex, &line, tmp)) tmp_i = (ft_bzero(tmp, STR_MAX_SIZE), 0); else @@ -80,7 +82,7 @@ static int check_state(t_lexer *lex, char **line) return (0); } -static int create_token(t_lexer *lex, char str[]) +int create_token(t_lexer *lex, char str[]) { t_token *tok; t_token *tmp; @@ -166,44 +168,3 @@ static int check_register(t_lexer *lex, char **line, char *tmp) } return (0); } - -int create_wc(t_lexer *lex, char *tmp) -{ - int i; - int j; - int skip ; - DIR * direct; - struct dirent *file; - - direct = opendir("."); - file = readdir(direct); - file = readdir(direct); - file = readdir(direct); - while (file) - { - i = 0; - j = 0; - skip = (tmp[0] != '.' && file->d_name[0] == '.'); - while (tmp[i] && !skip) - { - if (tmp[i] == '*') - { - while (file->d_name[j] && file->d_name[j] != tmp[i + 1]) - j++; - } - if (tmp[i] != '*' && file->d_name[j] != tmp[i]) - skip = 1; - else - { - i++; - j++; - } - } - if (!skip) - create_token(lex, file->d_name); - file = readdir(direct); - } - closedir(direct); - lex->wc = 0; - return (1); -} diff --git a/minishell.h b/minishell.h index 6a03a36..a04f5af 100755 --- a/minishell.h +++ b/minishell.h @@ -6,16 +6,16 @@ /* By: mea +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/05/02 13:50:44 by narnaud #+# #+# */ -/* Updated: 2022/05/12 11:33:39 by mea ### ########.fr */ +/* Updated: 2022/05/12 14:52:06 by mea ### ########.fr */ /* */ /* ************************************************************************** */ #ifndef MINISHELL_H # define MINISHELL_H -# define ENVP_MAX_SIZE 1024 -# define STR_MAX_SIZE 1024 +# define ENVP_MAX_SIZE 4096 +# define STR_MAX_SIZE 4096 # define PATHS_MAX_SIZE 126 -# define DEBUG 1 +# define DEBUG 0 # include "libft/libft.h" # include @@ -49,7 +49,7 @@ typedef struct s_datas int silent; } t_datas; -// ----------------------------------Utils.c +// ----------------------------------Utils_1.c int is_empty(char *line); int handle_status(t_datas *datas, int status); void nothing(int sig_num); @@ -62,6 +62,9 @@ int file_error(char *cmd, char *file, char *msg); int replace_var(t_datas *datas, char **line, char *tmp, int tmp_i); char *expend_str(t_datas *datas, char *line); int set_redir(t_lexer *lex, char **line, char ch); +// ----------------------------------Utils_3.c +int is_valid_identifier(char *ident); +int create_wc(t_lexer *lex, char *tmp); // ----------------------------------Builtins.c int ft_echo(t_command *cmd); @@ -123,5 +126,6 @@ typedef struct s_lex } t_lexer; t_token *lexer(t_datas *datas, char *line); +int create_token(t_lexer *lex, char str[]); #endif diff --git a/utils.c b/utils_1.c old mode 100755 new mode 100644 similarity index 100% rename from utils.c rename to utils_1.c diff --git a/utils_2.c b/utils_2.c index 65f566d..364d054 100755 --- a/utils_2.c +++ b/utils_2.c @@ -6,7 +6,7 @@ /* By: mea +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/05/06 13:15:59 by narnaud #+# #+# */ -/* Updated: 2022/05/10 10:16:58 by mea ### ########.fr */ +/* Updated: 2022/05/12 14:29:56 by mea ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/utils_3.c b/utils_3.c new file mode 100644 index 0000000..a39ceeb --- /dev/null +++ b/utils_3.c @@ -0,0 +1,76 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* utils_3.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mea +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/05/12 14:33:58 by mea #+# #+# */ +/* Updated: 2022/05/12 14:51:17 by mea ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "minishell.h" + + + +int is_valid_identifier(char *ident) +{ + int i; + + i = 0; + if (ft_isalpha(ident[0]) || ident[0] == '_') + { + while (ident[i]) + { + if (!ft_isalpha(ident[i]) && !ft_isdigit(ident[i] + && ident[i] != '_')) + { + ft_putstr_fd("export: not an identifier: ", 2); + ft_putstr_fd(ident, 2); + ft_putchar_fd('\n', 2); + return (0); + } + i++; + } + return (1); + } + ft_putstr_fd("export: not an identifier: ", 2); + ft_putstr_fd(ident, 2); + ft_putchar_fd('\n', 2); + return (0); +} + +int create_wc(t_lexer *lex, char *tmp) +{ + int i; + int j; + int skip ; + DIR * direct; + struct dirent *file; + + direct = opendir("."); + file = (readdir(direct), readdir(direct), readdir(direct)); + while (file) + { + i = 0; + j = 0; + skip = (tmp[0] != '.' && file->d_name[0] == '.'); + while (tmp[i] && !skip) + { + if (tmp[i] == '*') + while (file->d_name[j] && file->d_name[j] != tmp[i + 1]) + j++; + if (tmp[i] != '*' && file->d_name[j] != tmp[i]) + skip = 1; + else if (++i) + ++j; + } + if (!skip) + create_token(lex, file->d_name); + file = readdir(direct); + } + closedir(direct); + lex->wc = 0; + return (1); +} \ No newline at end of file