small adjust in files

This commit is contained in:
LuckyLaszlo
2021-12-16 05:05:25 +01:00
parent 20c71bccbb
commit 06f1987ae4
6 changed files with 60 additions and 72 deletions

35
srcs/debug.c Normal file
View 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);
}
}

View File

@@ -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);
}

View File

@@ -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);
}

View File

@@ -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