mirror of
https://codeberg.org/la-chouette/minishell.git
synced 2025-12-06 07:28:09 +01:00
Expansion: wildcard exp v1.0
Checks still need to be made.
This commit is contained in:
parent
e7f12b54e9
commit
a41f10eda3
3 changed files with 75 additions and 14 deletions
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jguelen <jguelen@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/02/23 15:02:59 by jguelen #+# #+# */
|
||||
/* Updated: 2025/03/08 17:25:03 by jguelen ### ########.fr */
|
||||
/* Updated: 2025/03/10 17:08:25 by jguelen ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -15,7 +15,6 @@
|
|||
|
||||
/*
|
||||
** TODO Pre-process file_pattern worddesc for a congruent marker string
|
||||
** TODO Post-process to sort the resulting list regarding ascii order
|
||||
*/
|
||||
/******************************************************************************/
|
||||
/* NOTE: The use of errno and the setting of it was OKed by Alexandru in this */
|
||||
|
|
@ -52,7 +51,9 @@ DIR *open_current_dir(void)
|
|||
}
|
||||
|
||||
/*
|
||||
**
|
||||
** TODO produce a clean marker string that denotes file_desc as issued from
|
||||
** a pattern expansion or as quoted for possible spaces characters in the
|
||||
** filename not to pose any possible issue.
|
||||
*/
|
||||
static t_wordlist *add_file_to_list(t_wordlist **list, char *filename)
|
||||
{
|
||||
|
|
@ -62,7 +63,7 @@ static t_wordlist *add_file_to_list(t_wordlist **list, char *filename)
|
|||
copy = ft_strdup(filename);
|
||||
if (!copy)
|
||||
return (wordlist_destroy(*list), NULL);
|
||||
file_desc = worddesc_create(copy, '\0', NULL); ///////////CHECK IF CONFLICT
|
||||
file_desc = worddesc_create(copy, '\0', NULL);
|
||||
if (!file_desc)
|
||||
{
|
||||
wordlist_destroy(*list);
|
||||
|
|
@ -96,9 +97,8 @@ 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.
|
||||
** TODO sort the list in growing ascii order. (use of strcmp probable)
|
||||
*/
|
||||
t_wordlist *expand_star(t_worddesc *file_pattern)
|
||||
static t_wordlist *expand_star_core(t_worddesc *file_pattern)
|
||||
{
|
||||
struct dirent *new;
|
||||
DIR *current_dir;
|
||||
|
|
@ -124,5 +124,39 @@ t_wordlist *expand_star(t_worddesc *file_pattern)
|
|||
return (wordlist_destroy(file_wordlist), NULL);
|
||||
if (!file_wordlist)
|
||||
wordlist_push(file_wordlist, file_pattern);
|
||||
return (wordlist_quicksort(file_wordlist));
|
||||
return (wordlist_quicksort_full(file_wordlist));
|
||||
}
|
||||
|
||||
/*
|
||||
** TODO
|
||||
** Pre-processes file_pattern to give it a proper marker chain and remove
|
||||
** unquoted quotes from the pattern.
|
||||
** Returns NULL in case of error.
|
||||
** NOTE: This phase of pre-processing relies partly on processing done before
|
||||
** it therefore checks more loosely (and quote removal still seems not to be
|
||||
** done on string comming from a variable expansion) <-----TO RE-CHECK
|
||||
*/
|
||||
t_wordlist *expand_star(t_worddesc *file_pattern)
|
||||
{
|
||||
size_t i;
|
||||
char *tmp;
|
||||
|
||||
i = 0;
|
||||
while (file_pattern->word[i])
|
||||
{
|
||||
if (file_pattern->marker[i] != '\'' && file_pattern->marker[i] != '"'
|
||||
&& file_pattern->marker[i] != '&' && file_pattern->marker[i] != '$'
|
||||
&& (file_pattern->word[i] == '\'' || file_pattern->word[i] == '"'))
|
||||
{
|
||||
tmp = replace_in_str(file_pattern->word, i, i, NULL);
|
||||
free(file_pattern->word);
|
||||
file_pattern->word = tmp;
|
||||
tmp = replace_in_str(file_pattern->marker, i, i, NULL);
|
||||
free(file_pattern->marker);
|
||||
file_pattern->marker = tmp;
|
||||
continue;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
return (expand_star_core(file_pattern));
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue