Compare commits

...

2 Commits

Author SHA1 Message Date
Etienne Rey-bethbeder
882a39fc94 Merge branch 'master' of https://git.chauvet.pro/starnakin/42_minishell 2023-04-14 15:54:27 +02:00
Etienne Rey-bethbeder
59d9ed3514 Enfin 2023-04-14 15:54:13 +02:00

View File

@ -6,7 +6,7 @@
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */ /* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2023/04/11 14:50:26 by erey-bet #+# #+# */ /* Created: 2023/04/11 14:50:26 by erey-bet #+# #+# */
/* Updated: 2023/04/14 14:14:25 by erey-bet ### ########.fr */ /* Updated: 2023/04/14 15:53:49 by erey-bet ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -30,30 +30,38 @@ int get_strs(const char *to_split, const char *charset, char ***strs, int *i)
int j; int j;
int x; int x;
int y; int y;
int check;
x = -1; x = -1;
j = 0; j = 0;
while (to_split[++x]) while (to_split[++x])
{ {
y = -1; y = -1;
check = 1;
while (charset[++y]) while (charset[++y])
{ {
if (to_split[x] == charset[y] && !ft_is_in_quote(to_split, x)) if (to_split[x] == charset[y] && !ft_is_in_quote(to_split, x))
{ {
y = 0; check = 0;
if (to_split[x + 1]) if (new_strs(strs, to_split, i, &j))
{ return (1);
x++;
if (new_strs(strs, to_split, i, &j))
return (1);
}
} }
} }
(*strs)[(*i)][j++] = to_split[x]; if (check)
(*strs)[(*i)][j++] = to_split[x];
} }
return (0); return (0);
} }
void free_set_null(char ***strs, int i)
{
if (ft_strlen((*strs)[i]) == 0)
{
free((*strs)[i]);
(*strs)[i] = NULL;
}
}
char **ft_split_charset_quoted(const char *to_split, const char *charset) char **ft_split_charset_quoted(const char *to_split, const char *charset)
{ {
char **strs; char **strs;
@ -77,18 +85,6 @@ char **ft_split_charset_quoted(const char *to_split, const char *charset)
free(strs); free(strs);
return (NULL); return (NULL);
} }
free_set_null(&strs, i);
return (strs); return (strs);
} }
/*#include <stdio.h>
int main(int argc, char **argv)
{
char **strs;
if (argc == 3)
strs = ft_split_charset_quoted(argv[1], argv[2]);
int i = -1;
while (strs[++i])
printf("%s\n", strs[i]);
return (0);
}*/