small adjust in files
This commit is contained in:
1
Makefile
1
Makefile
@@ -40,7 +40,6 @@ SRCS = main.c \
|
||||
exec_cmd_line.c pipeline.c \
|
||||
find_access.c subshell_exec.c subshell_wait.c simple_cmd_builtin.c \
|
||||
cd.c pwd.c export.c unset.c exit.c env.c echo.c \
|
||||
generic.c \
|
||||
ft_split_quotes.c ft_strdup_quotes.c \
|
||||
ft_strjoinfree.c ft_lst_func.c ft_isinset_str.c ft_is_posix_name.c \
|
||||
ft_getenv.c ft_free_null.c ft_2d_arr_func.c \
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
/* By: lperrey <lperrey@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2021/10/08 02:59:58 by lperrey #+# #+# */
|
||||
/* Updated: 2021/12/11 20:59:40 by lperrey ### ########.fr */
|
||||
/* Updated: 2021/12/16 04:50:31 by lperrey ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -72,6 +72,7 @@ typedef void (*t_free_f)(void *); // generic
|
||||
// Error wrappers
|
||||
int shell_error(char *s1, char *s2, char *s3, int ret_val);
|
||||
int shell_perror(char *s1, char *s2, char *s3, int ret_val);
|
||||
int ft_reti_perror_io(int ret, char *err_str, char *io_file);
|
||||
|
||||
// Generic
|
||||
char *ft_strjoinfree(char *s1, char *s2);
|
||||
@@ -82,12 +83,10 @@ int ft_isinset_str(char *str, char *set);
|
||||
size_t ft_2d_arrlen(void *ptr); // Replace ft_arrlen()
|
||||
char **ft_dup_2d_char_arr(char **ptr);
|
||||
void *ft_resize_2d_arr(void *ptr, size_t add_nbr);
|
||||
void print_matrix(char **matrix, char *sep);
|
||||
t_list *ft_lstbeforelast(t_list *lst);
|
||||
void *ft_lstnew_generic(size_t lst_size, size_t content_size);
|
||||
typedef void *(*t_dup_f)(void *);
|
||||
void *ft_dup_2d_arr(void *ptr, void *(*dup_func)(void *));
|
||||
int ft_reti_perror_io(int ret, char *err_str, char *io_file);
|
||||
void ft_free_null(void *ptr);
|
||||
char *ft_getenv(char *env_var);
|
||||
size_t ft_getenv_position(char *env_var);
|
||||
@@ -96,7 +95,7 @@ int ft_is_posix_name(char *str);
|
||||
char **ft_split_quotes(char const *s, char c);
|
||||
char *ft_strdup_quotes(const char *s);
|
||||
|
||||
// signals.c
|
||||
// Signals handler
|
||||
void sigint_handler_interactive(int signum);
|
||||
void sigint_handler_heredoc(int signum);
|
||||
|
||||
|
||||
35
srcs/debug.c
Normal file
35
srcs/debug.c
Normal file
@@ -0,0 +1,35 @@
|
||||
|
||||
#include "minishell.h"
|
||||
|
||||
// pour imprimer une char ** en precisant comment separer les char *
|
||||
void print_matrix(char **matrix, char *sep)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
while (matrix[i])
|
||||
{
|
||||
printf("%s", matrix[i]);
|
||||
if (matrix[i + 1])
|
||||
printf("%s", sep);
|
||||
//fflush(stdout);
|
||||
i++;
|
||||
}
|
||||
write(1, "\n", 1);
|
||||
}
|
||||
|
||||
void print_pipeline(t_cmd **pipeline)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
while (pipeline[i])
|
||||
{
|
||||
printf("CMD %i, fd_in=%i, fd_out=%i\n", i, pipeline[i]->fd_in, pipeline[i]->fd_out);
|
||||
ft_putstr_fd(" |", 1);
|
||||
print_matrix(pipeline[i]->argv, "|\n |");
|
||||
i++;
|
||||
if (pipeline[i])
|
||||
ft_putstr_fd("----------------\n", 1);
|
||||
}
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* generic.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: lperrey <lperrey@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2021/10/08 09:25:35 by lperrey #+# #+# */
|
||||
/* Updated: 2021/12/16 03:50:35 by lperrey ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "minishell.h"
|
||||
|
||||
// pour imprimer une char ** en precisant comment separer les char *
|
||||
void print_matrix(char **matrix, char *sep)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
while (matrix[i])
|
||||
{
|
||||
printf("%s", matrix[i]);
|
||||
if (matrix[i + 1])
|
||||
printf("%s", sep);
|
||||
fflush(stdout);
|
||||
i++;
|
||||
}
|
||||
write(1, "\n", 1);
|
||||
}
|
||||
|
||||
int ft_reti_perror_io(int ret, char *err_str, char *io_file)
|
||||
{
|
||||
ft_putstr_fd(err_str, STDERR_FILENO);
|
||||
perror(io_file);
|
||||
return (ret);
|
||||
}
|
||||
@@ -6,7 +6,7 @@
|
||||
/* By: lperrey <lperrey@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2021/12/01 17:16:30 by lperrey #+# #+# */
|
||||
/* Updated: 2021/12/05 16:26:48 by lperrey ### ########.fr */
|
||||
/* Updated: 2021/12/16 04:38:05 by lperrey ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -43,3 +43,10 @@ int shell_perror(char *s1, char *s2, char *s3, int ret_val)
|
||||
perror(NULL);
|
||||
return (ret_val);
|
||||
}
|
||||
|
||||
int ft_reti_perror_io(int ret, char *err_str, char *io_file)
|
||||
{
|
||||
ft_putstr_fd(err_str, STDERR_FILENO);
|
||||
perror(io_file);
|
||||
return (ret);
|
||||
}
|
||||
|
||||
@@ -6,14 +6,13 @@
|
||||
/* By: lperrey <lperrey@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2021/10/24 10:52:40 by lperrey #+# #+# */
|
||||
/* Updated: 2021/12/12 21:18:52 by lperrey ### ########.fr */
|
||||
/* Updated: 2021/12/16 04:58:12 by lperrey ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "minishell.h"
|
||||
|
||||
void save_redirections_words(t_token *t);
|
||||
void print_pipeline(t_cmd **pipeline);
|
||||
|
||||
t_cmd **parsing(t_token *token_list)
|
||||
{
|
||||
@@ -24,32 +23,19 @@ t_cmd **parsing(t_token *token_list)
|
||||
|
||||
// 2.9.1 - 1) Save Words
|
||||
save_redirections_words(token_list);
|
||||
|
||||
// Struct CMD alloc
|
||||
pipeline = pipeline_alloc(1 + count_pipes(token_list));
|
||||
if (!pipeline)
|
||||
return (NULL);
|
||||
|
||||
// 2.9.1 - 2) Expansion
|
||||
// TEST TOKENS PRINT
|
||||
/* ft_putstr_fd("TOKENS LIST :\n-----------\n", STDERR_FILENO);
|
||||
ft_lstprint((t_list *)token_list, STDERR_FILENO); */
|
||||
//
|
||||
if (!expansions(token_list, pipeline))
|
||||
return (ft_retp_free(NULL, &pipeline, (t_free_f)free_pipeline));
|
||||
//
|
||||
/* ft_putstr_fd("TOKENS LIST EXPANDED :\n-----------\n", STDERR_FILENO);
|
||||
ft_lstprint((t_list *)token_list, STDERR_FILENO); */
|
||||
|
||||
// 2.9.1 - 3) Redirection
|
||||
if (!redirections(token_list, pipeline))
|
||||
return (ft_retp_free(NULL, &pipeline, (t_free_f)free_pipeline));
|
||||
|
||||
// Struct CMD fill
|
||||
if (!pipeline_fill_argv(token_list, pipeline))
|
||||
return (ft_retp_free(NULL, &pipeline, (t_free_f)free_pipeline));
|
||||
//print_pipeline(pipeline);
|
||||
|
||||
return (pipeline);
|
||||
}
|
||||
|
||||
@@ -67,21 +53,20 @@ void save_redirections_words(t_token *t)
|
||||
}
|
||||
}
|
||||
|
||||
void print_pipeline(t_cmd **pipeline)
|
||||
{
|
||||
int i;
|
||||
/*
|
||||
2.9.1 Simple Commands
|
||||
2.9.1 - 1) Save Words
|
||||
2.9.1 - 2) Expansion
|
||||
2.9.1 - 3) Redirection
|
||||
https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html
|
||||
#tag_18_09_01
|
||||
*/
|
||||
|
||||
i = 0;
|
||||
while (pipeline[i])
|
||||
{
|
||||
printf("CMD %i, fd_in=%i, fd_out=%i\n", i, pipeline[i]->fd_in, pipeline[i]->fd_out);
|
||||
ft_putstr_fd(" |", 1);
|
||||
print_matrix(pipeline[i]->argv, "|\n |");
|
||||
i++;
|
||||
if (pipeline[i])
|
||||
ft_putstr_fd("----------------\n", 1);
|
||||
}
|
||||
}
|
||||
/*
|
||||
2.10 Shell Grammar
|
||||
https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html
|
||||
#tag_18_10
|
||||
*/
|
||||
|
||||
/* -------------------------------------------------------
|
||||
The grammar symbols
|
||||
|
||||
Reference in New Issue
Block a user