mirror of
https://codeberg.org/la-chouette/minishell.git
synced 2025-12-06 07:28:09 +01:00
Expansion: fix but still a problem matching '.'
Problem in the coherence of behaviour regarding ownership with star expansion fixed.
This commit is contained in:
parent
da06c0d4e0
commit
b58848e091
4 changed files with 43 additions and 7 deletions
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jguelen <jguelen@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/02/13 15:46:02 by khais #+# #+# */
|
||||
/* Updated: 2025/03/21 10:11:30 by jguelen ### ########.fr */
|
||||
/* Updated: 2025/03/21 10:16:55 by jguelen ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -35,6 +35,7 @@ typedef struct s_wordlist
|
|||
} t_wordlist;
|
||||
|
||||
t_wordlist *wordlist_create(t_worddesc *word);
|
||||
t_wordlist *wordlist_independant_create(t_worddesc *word);
|
||||
void wordlist_destroy(t_wordlist *wordlist);
|
||||
t_worddesc *wordlist_get(t_wordlist *wordlist, int idx);
|
||||
t_wordlist *wordlist_push(t_wordlist *wordlist, t_worddesc *worddesc);
|
||||
|
|
|
|||
|
|
@ -6,12 +6,41 @@
|
|||
/* By: jguelen <jguelen@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/03/10 09:51:34 by jguelen #+# #+# */
|
||||
/* Updated: 2025/03/19 13:43:24 by jguelen ### ########.fr */
|
||||
/* Updated: 2025/03/20 14:43:17 by jguelen ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "wordlist.h"
|
||||
#include "../worddesc/worddesc.h"
|
||||
#include <stdlib.h>
|
||||
#include "../../../libft/libft.h"
|
||||
|
||||
/*
|
||||
** Creates a new wordlist composed of only one element. Its next field is NULL
|
||||
** and its word field is a copy of the worddesc passed as a parameter.
|
||||
** Returns NULL in case of error.
|
||||
*/
|
||||
t_wordlist *wordlist_independant_create(t_worddesc *word)
|
||||
{
|
||||
t_wordlist *new;
|
||||
t_worddesc *desc_copy;
|
||||
|
||||
new = ft_calloc(1, sizeof(t_wordlist));
|
||||
if (!new)
|
||||
return (NULL);
|
||||
desc_copy = ft_calloc(1, sizeof(t_worddesc));
|
||||
if (!desc_copy)
|
||||
return (free(new), NULL);
|
||||
desc_copy->word = ft_strdup(word->word);
|
||||
if (!desc_copy->word)
|
||||
return (free(desc_copy), free(new), NULL);
|
||||
desc_copy->flags = word->flags;
|
||||
desc_copy->marker = ft_strdup(word->marker);
|
||||
new->word = desc_copy;
|
||||
if (!desc_copy->marker && word->marker)
|
||||
return (wordlist_destroy(new), NULL);
|
||||
return (new);
|
||||
}
|
||||
|
||||
/*
|
||||
** Returns the number of words present in the wordlist given as parameter.
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jguelen <jguelen@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/02/23 15:02:59 by jguelen #+# #+# */
|
||||
/* Updated: 2025/03/19 16:48:12 by jguelen ### ########.fr */
|
||||
/* Updated: 2025/03/20 14:17:37 by jguelen ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -15,8 +15,10 @@
|
|||
#include "replace_substr.h"
|
||||
|
||||
/******************************************************************************/
|
||||
/* */
|
||||
/* NOTE: The use of errno and the setting of it was OKed by Alexandru in this */
|
||||
/* context. */
|
||||
/* */
|
||||
/******************************************************************************/
|
||||
/*
|
||||
** Returns a directory stream corresponding to the current directory.
|
||||
|
|
@ -76,6 +78,9 @@ static t_wordlist *add_file_to_list(t_wordlist **list, char *filename)
|
|||
** that matches pattern->word if any file matches in the current directory.
|
||||
** Otherwise return file_pattern itself if nothing matches the perceived
|
||||
** pattern. This list should be alphabetically sorted.
|
||||
** Can return NULL only in case of error.
|
||||
** NOTE: this function never becomes the owner of file_pattern to maintain
|
||||
** coherency of use.
|
||||
*/
|
||||
static t_wordlist *expand_star_core(t_worddesc *file_pattern)
|
||||
{
|
||||
|
|
@ -102,7 +107,7 @@ static t_wordlist *expand_star_core(t_worddesc *file_pattern)
|
|||
if (errno)
|
||||
return (wordlist_destroy(file_wordlist), NULL);
|
||||
if (!file_wordlist)
|
||||
wordlist_push(file_wordlist, file_pattern);
|
||||
file_wordlist = wordlist_independant_create(file_pattern);
|
||||
return (wordlist_quicksort_full(file_wordlist));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/03/19 17:52/50 by khais #+# #+# */
|
||||
/* Updated: 2025/03/20 10:36:23 by jguelen ### ########.fr */
|
||||
/* Updated: 2025/03/20 14:47:23 by jguelen ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -167,7 +167,7 @@ static void test_filename_star_expansion(void)
|
|||
//test ., .. and .plop
|
||||
filepattern = create_single_word(".*");
|
||||
expanded = expand_star(filepattern);
|
||||
//assert(wordlist_size(expanded) == 3);
|
||||
assert(wordlist_size(expanded) == 3);
|
||||
//assert_strequal(".", expanded->word->word);
|
||||
//assert_strequal("..", expanded->next->word->word);
|
||||
//assert_strequal(".plop", expanded->next->next->word->word);
|
||||
|
|
@ -176,8 +176,9 @@ static void test_filename_star_expansion(void)
|
|||
//test zero result
|
||||
filepattern = create_single_word("e*x***p*b");
|
||||
expanded = expand_star(filepattern);
|
||||
assert(expanded);
|
||||
assert_strequal(filepattern->word, expanded->word->word);
|
||||
worddesc_destroy(filepattern);
|
||||
assert(!expanded);
|
||||
wordlist_destroy(expanded);
|
||||
do_leak_check();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue