mirror of
https://codeberg.org/la-chouette/minishell.git
synced 2025-12-06 07:28:09 +01:00
Expansion: refactor in progress
This commit is contained in:
parent
ce24304e34
commit
95d9f6282a
11 changed files with 270 additions and 47 deletions
|
|
@ -3,20 +3,22 @@
|
|||
/* ::: :::::::: */
|
||||
/* wildcard_exp.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* By: jguelen <jguelen@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/02/23 15:02:59 by jguelen #+# #+# */
|
||||
/* Updated: 2025/03/06 17:40:42 by jguelen ### ########.fr */
|
||||
/* Updated: 2025/03/08 17:25:03 by jguelen ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_printf.h"
|
||||
#include "subst.h"
|
||||
#include "unistd.h"
|
||||
#include "minishell.h"
|
||||
|
||||
/*
|
||||
** TODO Pre-process file_pattern worddesc for a congruent marker string
|
||||
** TODO Post-process to sort the resulting list regarding ascii order
|
||||
*/
|
||||
/******************************************************************************/
|
||||
/* NOTE: Use of errno and the setting of it was OKed by Alexandru in this */
|
||||
/* NOTE: The use of errno and the setting of it was OKed by Alexandru in this */
|
||||
/* context. */
|
||||
/******************************************************************************/
|
||||
/*
|
||||
|
|
@ -60,7 +62,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');
|
||||
file_desc = worddesc_create(copy, '\0', NULL); ///////////CHECK IF CONFLICT
|
||||
if (!file_desc)
|
||||
{
|
||||
wordlist_destroy(*list);
|
||||
|
|
@ -71,20 +73,7 @@ static t_wordlist *add_file_to_list(t_wordlist **list, char *filename)
|
|||
}
|
||||
|
||||
/*
|
||||
** Returns true if and only if filename is recognized by pattern, false
|
||||
** otherwise.
|
||||
** Takes only into account the * wildcard or ?, those characters
|
||||
** NOTE: for a pattern to accept '.' as the first character of a filename
|
||||
** it must be explicitly matched (only for the first character though).
|
||||
** Similarly, '/' is never to be matched except if given explicitly.
|
||||
*/
|
||||
bool fits_pattern(char *string, char *pattern)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** TODO Check if return value correct regarding the manual specifacally the
|
||||
** TODO Check if return value correct regarding the manual specifically the
|
||||
** following:
|
||||
** cf Bash scans each word for the character '*'.
|
||||
**
|
||||
|
|
@ -92,6 +81,10 @@ bool fits_pattern(char *string, char *pattern)
|
|||
** regarded as a PATTERN, and replaced with an alphabetically sorted list
|
||||
** of filenames matching the pattern (see: Pattern Matching). If no matching
|
||||
** filenames are found, the word is left unchanged.
|
||||
** --> TODO this function should be provided with a properly pre-processed
|
||||
** file_pattern where file_pattern->matcher denotes the quoted wildcards
|
||||
** but the quotes themselves unquoted have been removed from word in a manner
|
||||
** keeping the relationship between word and marker coherent.
|
||||
*/
|
||||
/*
|
||||
** A function designed to present all possible * or ? filename expansions
|
||||
|
|
@ -99,9 +92,13 @@ bool fits_pattern(char *string, char *pattern)
|
|||
** Does not take into account any other wildcard and does only search the
|
||||
** current working directory.
|
||||
** @PARAM A C compliant character string representing a pattern for a filename.
|
||||
** @RETURN
|
||||
** @RETURN Returns a wordlist for which each entry corresponds to a 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(char *file_pattern)
|
||||
t_wordlist *expand_star(t_worddesc *file_pattern)
|
||||
{
|
||||
struct dirent *new;
|
||||
DIR *current_dir;
|
||||
|
|
@ -110,8 +107,8 @@ t_wordlist *expand_star(char *file_pattern)
|
|||
current_dir = open_current_dir();
|
||||
if (current_dir == NULL)
|
||||
return (NULL);
|
||||
errno = 0;
|
||||
file_wordlist = NULL;
|
||||
errno = 0;
|
||||
new = readdir(current_dir);
|
||||
while (new)
|
||||
{
|
||||
|
|
@ -126,6 +123,6 @@ t_wordlist *expand_star(char *file_pattern)
|
|||
if (errno)
|
||||
return (wordlist_destroy(file_wordlist), NULL);
|
||||
if (!file_wordlist)
|
||||
add_file_to list(&file_wordlist, file_pattern);
|
||||
return (file_wordlist);
|
||||
wordlist_push(file_wordlist, file_pattern);
|
||||
return (wordlist_quicksort(file_wordlist));
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue