Expansion: Fixed inclusions and Norm checked

Now on to remake tests properly.
This commit is contained in:
Jérôme Guélen 2025-03-19 09:20:51 +01:00
parent bed41f4a6f
commit 0f8b18b32f
No known key found for this signature in database
8 changed files with 33 additions and 64 deletions

View file

@ -68,8 +68,8 @@ srcs = \
src/subst/variable_subst.c \
src/subst/variable_subst_utils.c \
src/subst/wildcard_exp.c \
src/subst/wildcard_exp_utils.c \
src/subst/wildcard_exp_utils2.c \
src/subst/wildcard_exp_utils.c \
objs = $(srcs:.c=.o)
export objs

View file

@ -6,7 +6,7 @@
/* By: jguelen <jguelen@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/03/02 13:40:10 by jguelen #+# #+# */
/* Updated: 2025/03/18 18:38:53 by jguelen ### ########.fr */
/* Updated: 2025/03/19 09:01:54 by jguelen ### ########.fr */
/* */
/* ************************************************************************** */
@ -14,31 +14,11 @@
#include "libft.h"
#include "../ft_errno.h"
#include "../env/env_manip.h"
#include "path_split.h"
#include "subst.h"
#include <stdbool.h>
#include <sys/stat.h>
/*
** Returns a malloc-allocated string corresponding to
** "path_dir/name"
*/
char *alloc_path(char *path_dir, char *name)
{
char *path;
size_t dir_len;
size_t name_len;
dir_len = ft_strlen(path_dir);
name_len = ft_strlen(name);
path = malloc((dir_len + name_len + 2) * sizeof(char));
if (!path)
return (NULL);
ft_memcpy(path, path_dir, dir_len);
path[dir_len] = '/';
ft_memcpy(path + dir_len + 1, name, name_len);
path[dir_len + name_len + 1] = '\0';
return (path);
}
/*
** The return value of this function is always safe to destroy with
** path_split_destroy.
@ -118,7 +98,7 @@ static char *deal_with_filled_path(char *filename, char **path,
/*
** Returns NULL on error or if nothing is found.
*/
char *filepath_from_env(char *filename, t_minishell *app)
static char *filepath_from_env(char *filename, t_minishell *app)
{
char *filepath;
char **path;
@ -154,7 +134,7 @@ char *filepath_from_env(char *filename, t_minishell *app)
** NOTE: if name contains a '/' character then name is considered to
** be an absolute path.
*/
char *get_filepath(const char *name, t_minishell *app)
char *get_cmdpath(const char *name, t_minishell *app)
{
char *cmd_path;

View file

@ -3,10 +3,10 @@
/* ::: :::::::: */
/* simple_filename_exp_utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jguelen <marvin@42.fr> +#+ +:+ +#+ */
/* By: jguelen <jguelen@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/03/18 18:40:14 by jguelen #+# #+# */
/* Updated: 2025/03/18 18:40:33 by jguelen ### ########.fr */
/* Updated: 2025/03/19 09:02:22 by jguelen ### ########.fr */
/* */
/* ************************************************************************** */
@ -14,7 +14,9 @@
#include "libft.h"
#include "../ft_errno.h"
#include "../env/env_manip.h"
#include "subst.h"
#include <stdbool.h>
#include <stdlib.h>
#include <sys/stat.h>
/*

View file

@ -6,7 +6,7 @@
/* By: jguelen <jguelen@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/02/23 15:01:40 by jguelen #+# #+# */
/* Updated: 2025/03/14 14:28:20 by jguelen ### ########.fr */
/* Updated: 2025/03/19 09:20:02 by jguelen ### ########.fr */
/* */
/* ************************************************************************** */
@ -16,9 +16,12 @@
# include "../parser/wordlist/wordlist.h"
# include "../parser/wordlist/wordlist_quicksort.h"
# include "../minishell.h"
# include "replace_substr.h"
# include <dirent.h>
# include <unistd.h>
# include <errno.h>
# include <stdlib.h>
# include "../../libft/libft.h"
# define PATH_SIZE_INIT 64
@ -33,4 +36,11 @@ t_wordlist *expand_star(t_worddesc *file_pattern);
char *construct_repeting_char_string(char c, size_t len);
char *ft_get_longest_identifier(char *str);
char *alloc_path(char *path_dir, char *name);
char *get_cmdpath(const char *name, t_minishell *app);
void destroy_pattern_check(char **pattern_check, size_t len);
void build_pattern_checks(char *str, t_worddesc *pattern,
char **checker);
#endif

View file

@ -3,10 +3,10 @@
/* ::: :::::::: */
/* variable_subst_utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
/* By: jguelen <jguelen@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/03/06 13:03/41 by khais #+# #+# */
/* Updated: 2025/03/08 14:06:20 by jguelen ### ########.fr */
/* Created: 2025/03/06 13:03:41 by khais #+# #+# */
/* Updated: 2025/03/19 09:03:31 by jguelen ### ########.fr */
/* */
/* ************************************************************************** */
@ -14,6 +14,7 @@
#include "../minishell.h"
#include "replace_substr.h"
#include "../env/env.h"
#include "../../libft/libft.h"
/*
** Returns a C-compliant malloc-allocated string of length len and composed

View file

@ -6,7 +6,7 @@
/* By: jguelen <jguelen@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/02/23 15:02:59 by jguelen #+# #+# */
/* Updated: 2025/03/18 18:44:05 by jguelen ### ########.fr */
/* Updated: 2025/03/19 09:18:53 by jguelen ### ########.fr */
/* */
/* ************************************************************************** */
@ -14,9 +14,6 @@
#include "subst.h"
#include "replace_substr.h"
/*
** TODO Pre-process file_pattern worddesc for a congruent marker string
*/
/******************************************************************************/
/* NOTE: The use of errno and the setting of it was OKed by Alexandru in this */
/* context. */
@ -25,7 +22,7 @@
** Returns a directory stream corresponding to the current directory.
**
*/
DIR *open_current_dir(void)
static DIR *open_current_dir(void)
{
char *cur_dir_path;
size_t size;
@ -51,11 +48,6 @@ DIR *open_current_dir(void)
return (dir);
}
/*
** 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)
{
t_worddesc *file_desc;
@ -74,20 +66,6 @@ static t_wordlist *add_file_to_list(t_wordlist **list, char *filename)
return (*list);
}
/*
** TODO Check if return value correct regarding the manual specifically the
** following:
** cf Bash scans each word for the character '*'.
**
** If one of these characters appears, and is not quoted, then the word is
** 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
** for the current directory. (? is not asked by the subject).
@ -164,9 +142,6 @@ char fits_pattern(char *str, t_worddesc *pattern)
}
/*
** 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

View file

@ -6,7 +6,7 @@
/* By: jguelen <jguelen@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/03/07 17:10:01 by jguelen #+# #+# */
/* Updated: 2025/03/15 15:33:07 by jguelen ### ########.fr */
/* Updated: 2025/03/19 09:15:13 by jguelen ### ########.fr */
/* */
/* ************************************************************************** */
@ -15,7 +15,7 @@
/*
** Cleanly disposes of a pattern checker two dimensionnal array.
*/
static void destroy_pattern_check(char **pattern_check, size_t len)
void destroy_pattern_check(char **pattern_check, size_t len)
{
size_t i;

View file

@ -3,10 +3,10 @@
/* ::: :::::::: */
/* wildcard_exp_utils2.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jguelen <marvin@42.fr> +#+ +:+ +#+ */
/* By: jguelen <jguelen@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/03/15 15:09:56 by jguelen #+# #+# */
/* Updated: 2025/03/18 18:54:06 by jguelen ### ########.fr */
/* Updated: 2025/03/19 09:07:09 by jguelen ### ########.fr */
/* */
/* ************************************************************************** */
@ -14,7 +14,8 @@
#include "replace_substr.h"
/*
** TODO
** Removes unquoted quotes and from file_pattern->word and keeps
** file_pattern->marker congruent.
*/
void clean_pattern(t_worddesc *file_pattern)
{