mirror of
https://codeberg.org/la-chouette/minishell.git
synced 2025-12-06 07:28:09 +01:00
some pair debugging
This commit is contained in:
parent
46c288c858
commit
41c9548934
3 changed files with 63 additions and 12 deletions
|
|
@ -3,14 +3,14 @@
|
|||
/* ::: :::::::: */
|
||||
/* wildcard_exp.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jguelen <jguelen@student.42.fr> +#+ +:+ +#+ */
|
||||
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/02/23 15:02:59 by jguelen #+# #+# */
|
||||
/* Updated: 2025/03/20 14:17:37 by jguelen ### ########.fr */
|
||||
/* Created: 2025/03/20 15:01/38 by khais #+# #+# */
|
||||
/* Updated: 2025/03/20 15:01:38 by khais ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_printf.h"
|
||||
#include "libft.h"
|
||||
#include "subst.h"
|
||||
#include "replace_substr.h"
|
||||
|
||||
|
|
@ -96,6 +96,7 @@ static t_wordlist *expand_star_core(t_worddesc *file_pattern)
|
|||
new = readdir(current_dir);
|
||||
while (new)
|
||||
{
|
||||
ft_printf("[dbg] read dir entry: %s\n", new->d_name);
|
||||
if (fits_pattern(new->d_name, file_pattern))
|
||||
{
|
||||
if (add_file_to_list(&file_wordlist, new->d_name) == NULL)
|
||||
|
|
@ -127,6 +128,8 @@ char fits_pattern(char *str, t_worddesc *pattern)
|
|||
size_t i;
|
||||
char ret;
|
||||
|
||||
if (ft_strcmp(".", str) == 0)
|
||||
ft_printf("[dbg] currently matching .\n");
|
||||
pattern_len = ft_strlen(pattern->word);
|
||||
str_len = ft_strlen(str);
|
||||
pattern_check = ft_calloc(str_len + 1, sizeof(char *));
|
||||
|
|
|
|||
|
|
@ -3,14 +3,16 @@
|
|||
/* ::: :::::::: */
|
||||
/* wildcard_exp_utils.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jguelen <jguelen@student.42.fr> +#+ +:+ +#+ */
|
||||
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/03/07 17:10:01 by jguelen #+# #+# */
|
||||
/* Updated: 2025/03/19 09:15:13 by jguelen ### ########.fr */
|
||||
/* Created: 2025/03/20 15:45/36 by khais #+# #+# */
|
||||
/* Updated: 2025/03/20 15:45:36 by khais ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_printf.h"
|
||||
#include "subst.h"
|
||||
#include <stdbool.h>
|
||||
|
||||
/*
|
||||
** Cleanly disposes of a pattern checker two dimensionnal array.
|
||||
|
|
@ -56,11 +58,12 @@ static int same_character_or_one_char_wild(char *str, t_worddesc *pattern,
|
|||
static int at_star_in_pattern(char *str, t_worddesc *pattern,
|
||||
size_t i, size_t j)
|
||||
{
|
||||
(void)i;
|
||||
(void)str;
|
||||
return (pattern->word[j - 1] == '*'
|
||||
&& pattern->marker[j - 1] != '\''
|
||||
&& pattern->marker[j - 1] != '"'
|
||||
&& pattern->marker[j - 1] != '&'
|
||||
&& !(i == 1 && str[i - 1] == '.'));
|
||||
&& pattern->marker[j - 1] != '&');
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
@ -83,6 +86,40 @@ static void init_pattern_checker(t_worddesc *pattern, char **checker)
|
|||
}
|
||||
}
|
||||
|
||||
static void checker_debug(char **checker, char *str, char *pattern)
|
||||
{
|
||||
size_t i;
|
||||
size_t j;
|
||||
size_t str_len;
|
||||
size_t pattern_len;
|
||||
|
||||
str_len = ft_strlen(str);
|
||||
pattern_len = ft_strlen(pattern);
|
||||
i = 0;
|
||||
ft_printf("str=[%s] pattern=[%s]\n", str, pattern);
|
||||
ft_printf(" %s\n", pattern);
|
||||
while (i <= str_len)
|
||||
{
|
||||
j = 0;
|
||||
if (i == 0)
|
||||
ft_printf(" ");
|
||||
else if (str[i - 1])
|
||||
ft_printf("%c", str[i - 1]);
|
||||
else
|
||||
ft_printf(" ");
|
||||
while (j <= pattern_len)
|
||||
{
|
||||
if (checker[i][j])
|
||||
ft_printf("█");
|
||||
else
|
||||
ft_printf("░");
|
||||
j++;
|
||||
}
|
||||
ft_printf("\n");
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
** Fills the table which contains in its most low and right cell 0 if
|
||||
** str does not match the pattern and 1 otherwise.
|
||||
|
|
@ -99,21 +136,30 @@ void build_pattern_checks(char *str, t_worddesc *pattern,
|
|||
size_t j;
|
||||
size_t str_len;
|
||||
size_t pattern_len;
|
||||
bool only_saw_unquoted_stars;
|
||||
|
||||
i = 1;
|
||||
str_len = ft_strlen(str);
|
||||
pattern_len = ft_strlen(pattern->word);
|
||||
init_pattern_checker(pattern, checker);
|
||||
only_saw_unquoted_stars = true;
|
||||
while (i <= str_len)
|
||||
{
|
||||
j = 1;
|
||||
while (j <= pattern_len)
|
||||
{
|
||||
if (same_character_or_one_char_wild(str, pattern, i, j))
|
||||
{
|
||||
only_saw_unquoted_stars = false;
|
||||
checker[i][j] = checker[i - 1][j - 1];
|
||||
else if (at_star_in_pattern(str, pattern, i, j))
|
||||
}
|
||||
else if (at_star_in_pattern(str, pattern, i, j) && !(only_saw_unquoted_stars || (i == 1 && str[0] == '.')))
|
||||
checker[i][j] = !!(checker[i - 1][j] + checker[i][j - 1]
|
||||
+ checker[i - 1][j - 1]);
|
||||
if (at_star_in_pattern(str, pattern, i, j) == 0)
|
||||
only_saw_unquoted_stars = false;
|
||||
ft_printf("at i=%d j=%d\n", i, j);
|
||||
checker_debug(checker, str, pattern->word);
|
||||
j++;
|
||||
}
|
||||
i++;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue