From 686ea5d0dbe29f5058ab5be16b1f4c0492234906 Mon Sep 17 00:00:00 2001 From: Camille Chauvet Date: Mon, 6 Mar 2023 13:21:22 +0100 Subject: [PATCH] fix: infile/outfile work as well now --- infile.c | 16 ++++++++----- outfile.c | 21 +++++++++-------- syntatics.c | 2 +- utils/tags | 68 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 90 insertions(+), 17 deletions(-) create mode 100644 utils/tags diff --git a/infile.c b/infile.c index 8582856..e229209 100644 --- a/infile.c +++ b/infile.c @@ -28,13 +28,17 @@ static int ft_infile_is_valid(const char *line) if (tab[0] == NULL) return (1); i = 0; - while (tab[i + 1] != NULL) - i++; - if (tab[i][0] == '<') + while (tab[i] != NULL) { - ft_eprintf("minishell: %s: must be followed by an infile\n", tab[i]); - ft_freer_tab_ultimate(1, tab); - return (0); + if (tab[i][0] == '<') + { + if (tab[i + 1] != NULL && !ft_contain_only_str(tab[i + 1], "| <>")) + continue ; + ft_eprintf("minishell: %s: must be followed by an infile\n", tab[i]); + ft_freer_tab_ultimate(1, tab); + return (0); + } + i++; } ft_freer_tab_ultimate(1, tab); return (1); diff --git a/outfile.c b/outfile.c index 70d3697..de4f3ca 100644 --- a/outfile.c +++ b/outfile.c @@ -10,7 +10,6 @@ /* */ /* ************************************************************************** */ -#include "libftx/libftx.h" #include "minishell.h" static int ft_outfile_is_valid(const char *line) @@ -27,13 +26,17 @@ static int ft_outfile_is_valid(const char *line) if (tab[0] == NULL) return (1); i = 0; - while (tab[i + 1] != NULL) - i++; - if (tab[i][0] == '>') + while (tab[i] != NULL) { - ft_eprintf("minishell: %s: must be followed by an infile\n", tab[i]); - ft_freer_tab_ultimate(1, tab); - return (0); + if (tab[i][0] == '>') + { + if (tab[i + 1] != NULL && !ft_contain_only_str(tab[i + 1], "| <>")) + continue ; + ft_eprintf("minishell: %s: must be followed by an outfile\n", tab[i]); + ft_freer_tab_ultimate(1, tab); + return (0); + } + i++; } ft_freer_tab_ultimate(1, tab); return (1); @@ -85,10 +88,8 @@ static int ft_remove_outfile(char *line) while (tab[i] != NULL) { if (tab[i][0] == '>') - { ft_strshift(line + y, - (-1) * (ft_strlen(tab[i]) + ft_strlen(tab[i + 1]) + 1 + (line[ft_strlen(tab[i]) + ft_strlen(tab[i + 1]) + 1] != '\0'))); - } + (-1) * (ft_strlen(tab[i]) + ft_strlen(tab[i + 1]) + 1 + (line[ft_strlen(tab[i]) + ft_strlen(tab[i + 1]) + 1] != '\0'))); else y = y + ft_strlen(tab[i]) + (y != 0); i++; diff --git a/syntatics.c b/syntatics.c index ae25a1e..e12fbfd 100644 --- a/syntatics.c +++ b/syntatics.c @@ -80,7 +80,7 @@ static int ft_special_char_dub(const char *str) if ((y > 2 && (str[i] == '>' || str[i] == '<')) || (y > 1 && str[i] == '|')) { - ft_eprintf("minishell: too many %c in a row\n", str, str[i]); + ft_eprintf("minishell: too many %s in a row\n", str); return (1); } i = i + y; diff --git a/utils/tags b/utils/tags new file mode 100644 index 0000000..8a77676 --- /dev/null +++ b/utils/tags @@ -0,0 +1,68 @@ +!_TAG_EXTRA_DESCRIPTION anonymous /Include tags for non-named objects like lambda/ +!_TAG_EXTRA_DESCRIPTION fileScope /Include tags of file scope/ +!_TAG_EXTRA_DESCRIPTION pseudo /Include pseudo tags/ +!_TAG_EXTRA_DESCRIPTION subparser /Include tags generated by subparsers/ +!_TAG_FIELD_DESCRIPTION epoch /the last modified time of the input file (only for F\/file kind tag)/ +!_TAG_FIELD_DESCRIPTION file /File-restricted scoping/ +!_TAG_FIELD_DESCRIPTION input /input file/ +!_TAG_FIELD_DESCRIPTION name /tag name/ +!_TAG_FIELD_DESCRIPTION pattern /pattern/ +!_TAG_FIELD_DESCRIPTION typeref /Type and name of a variable or typedef/ +!_TAG_FIELD_DESCRIPTION!C++ name /aliased names/ +!_TAG_FILE_FORMAT 2 /extended format; --format=1 will not append ;" to lines/ +!_TAG_FILE_SORTED 1 /0=unsorted, 1=sorted, 2=foldcase/ +!_TAG_KIND_DESCRIPTION!C d,macro /macro definitions/ +!_TAG_KIND_DESCRIPTION!C e,enumerator /enumerators (values inside an enumeration)/ +!_TAG_KIND_DESCRIPTION!C f,function /function definitions/ +!_TAG_KIND_DESCRIPTION!C g,enum /enumeration names/ +!_TAG_KIND_DESCRIPTION!C h,header /included header files/ +!_TAG_KIND_DESCRIPTION!C m,member /struct, and union members/ +!_TAG_KIND_DESCRIPTION!C s,struct /structure names/ +!_TAG_KIND_DESCRIPTION!C t,typedef /typedefs/ +!_TAG_KIND_DESCRIPTION!C u,union /union names/ +!_TAG_KIND_DESCRIPTION!C v,variable /variable definitions/ +!_TAG_KIND_DESCRIPTION!C++ c,class /classes/ +!_TAG_KIND_DESCRIPTION!C++ d,macro /macro definitions/ +!_TAG_KIND_DESCRIPTION!C++ e,enumerator /enumerators (values inside an enumeration)/ +!_TAG_KIND_DESCRIPTION!C++ f,function /function definitions/ +!_TAG_KIND_DESCRIPTION!C++ g,enum /enumeration names/ +!_TAG_KIND_DESCRIPTION!C++ h,header /included header files/ +!_TAG_KIND_DESCRIPTION!C++ m,member /class, struct, and union members/ +!_TAG_KIND_DESCRIPTION!C++ n,namespace /namespaces/ +!_TAG_KIND_DESCRIPTION!C++ s,struct /structure names/ +!_TAG_KIND_DESCRIPTION!C++ t,typedef /typedefs/ +!_TAG_KIND_DESCRIPTION!C++ u,union /union names/ +!_TAG_KIND_DESCRIPTION!C++ v,variable /variable definitions/ +!_TAG_OUTPUT_EXCMD mixed /number, pattern, mixed, or combineV2/ +!_TAG_OUTPUT_FILESEP slash /slash or backslash/ +!_TAG_OUTPUT_MODE u-ctags /u-ctags or e-ctags/ +!_TAG_OUTPUT_VERSION 0.0 /current.age/ +!_TAG_PARSER_VERSION!C 0.0 /current.age/ +!_TAG_PARSER_VERSION!C++ 0.0 /current.age/ +!_TAG_PATTERN_LENGTH_LIMIT 96 /0 for no limit/ +!_TAG_PROC_CWD /nfs/homes/cchauvet/42/minishell/utils/ // +!_TAG_PROGRAM_AUTHOR Universal Ctags Team // +!_TAG_PROGRAM_NAME Universal Ctags /Derived from Exuberant Ctags/ +!_TAG_PROGRAM_URL https://ctags.io/ /official site/ +!_TAG_PROGRAM_VERSION 6.0.0 // +!_TAG_ROLE_DESCRIPTION!C!header local /local header/ +!_TAG_ROLE_DESCRIPTION!C!header system /system header/ +!_TAG_ROLE_DESCRIPTION!C!macro undef /undefined/ +!_TAG_ROLE_DESCRIPTION!C++!header local /local header/ +!_TAG_ROLE_DESCRIPTION!C++!header system /system header/ +!_TAG_ROLE_DESCRIPTION!C++!macro undef /undefined/ +UTILS_H utils.h /^# define UTILS_H$/;" d +ft_atoi_check ft_atoi_check.c /^int ft_atoi_check(const char *nptr)$/;" f typeref:typename:int +ft_change_exit_code ft_change_exit_code.c /^int ft_change_exit_code(t_data *data, int new_value)$/;" f typeref:typename:int +ft_is_in_quote ft_is_in_quote.c /^int ft_is_in_quote(const char *str, size_t n)$/;" f typeref:typename:int +ft_isspace ft_atoi_check.c /^static int ft_isspace(char c)$/;" f typeref:typename:int file: +ft_printn ft_printn.c /^void ft_printn(const char *str, size_t n)$/;" f typeref:typename:void +ft_quote_remover ft_quote_remover.c /^char *ft_quote_remover(char *str)$/;" f typeref:typename:char * +ft_seglen_quoted ft_split_quoted.c /^size_t ft_seglen_quoted(const char *str, char c)$/;" f typeref:typename:size_t +ft_segsplitter ft_split_quoted.c /^static char **ft_segsplitter(char **tab, size_t len, const char *s, char c)$/;" f typeref:typename:char ** file: +ft_split_quoted ft_split_quoted.c /^char **ft_split_quoted(const char *s, char c)$/;" f typeref:typename:char ** +ft_str_is_empty ft_str_is_empty.c /^int ft_str_is_empty(const char *str)$/;" f typeref:typename:int +ft_strnchr ft_strnchr.c /^ssize_t ft_strnchr(const char *str, char c)$/;" f typeref:typename:ssize_t +ft_strncpy ft_strncpy.c /^size_t ft_strncpy(char *dst, const char *src, size_t n)$/;" f typeref:typename:size_t +ft_strreplace ft_strreplace.c /^char *ft_strreplace(const char *str, const char *fill,$/;" f typeref:typename:char * +ft_strshift ft_strshift.c /^void ft_strshift(char *str, int shift)$/;" f typeref:typename:void