wildcards
This commit is contained in:
3
Makefile
3
Makefile
@ -6,7 +6,7 @@
|
|||||||
# By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ #
|
# By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ #
|
||||||
# +#+#+#+#+#+ +#+ #
|
# +#+#+#+#+#+ +#+ #
|
||||||
# Created: 2023/07/28 00:35:01 by tomoron #+# #+# #
|
# Created: 2023/07/28 00:35:01 by tomoron #+# #+# #
|
||||||
# Updated: 2024/04/13 12:56:12 by tomoron ### ########.fr #
|
# Updated: 2024/04/15 16:41:54 by tomoron ### ########.fr #
|
||||||
# #
|
# #
|
||||||
# **************************************************************************** #
|
# **************************************************************************** #
|
||||||
|
|
||||||
@ -32,6 +32,7 @@ SRCS_RAW = main.c\
|
|||||||
input_redirections.c\
|
input_redirections.c\
|
||||||
output_redirections.c\
|
output_redirections.c\
|
||||||
builtins.c\
|
builtins.c\
|
||||||
|
wildcards.c\
|
||||||
commands.c\
|
commands.c\
|
||||||
pipe.c\
|
pipe.c\
|
||||||
utils.c\
|
utils.c\
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/02/04 17:31:38 by tomoron #+# #+# */
|
/* Created: 2024/02/04 17:31:38 by tomoron #+# #+# */
|
||||||
/* Updated: 2024/04/13 13:31:40 by babonnet ### ########.fr */
|
/* Updated: 2024/04/15 16:42:28 by tomoron ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -24,6 +24,7 @@
|
|||||||
# include <signal.h>
|
# include <signal.h>
|
||||||
# include <stdint.h>
|
# include <stdint.h>
|
||||||
# include <termios.h>
|
# include <termios.h>
|
||||||
|
# include <dirent.h>
|
||||||
|
|
||||||
typedef enum e_cmd_type
|
typedef enum e_cmd_type
|
||||||
{
|
{
|
||||||
@ -100,6 +101,7 @@ t_token *parsing_syntax_error(t_token *res);
|
|||||||
t_cmd *parsing_bonus(char *cmd);
|
t_cmd *parsing_bonus(char *cmd);
|
||||||
int file_access(t_msh *msh, int *found);
|
int file_access(t_msh *msh, int *found);
|
||||||
void remove_command_from_msh(t_msh *msh);
|
void remove_command_from_msh(t_msh *msh);
|
||||||
|
t_token *expand_wildcards(t_token *res, char *value);
|
||||||
void ft_exit(t_msh *msh, int error_code);
|
void ft_exit(t_msh *msh, int error_code);
|
||||||
void signal_handler_command(int signum);
|
void signal_handler_command(int signum);
|
||||||
void ft_exit(t_msh *msh, int exit_code);
|
void ft_exit(t_msh *msh, int exit_code);
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/02/09 15:26:01 by tomoron #+# #+# */
|
/* Created: 2024/02/09 15:26:01 by tomoron #+# #+# */
|
||||||
/* Updated: 2024/04/02 00:42:36 by tomoron ### ########.fr */
|
/* Updated: 2024/04/15 15:56:17 by tomoron ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
#include "minishell.h"
|
#include "minishell.h"
|
||||||
@ -73,7 +73,7 @@ t_token *parse_command(char *command, t_env *env)
|
|||||||
value = get_token(&command, &in_quote, &in_dquote, env);
|
value = get_token(&command, &in_quote, &in_dquote, env);
|
||||||
if (!value)
|
if (!value)
|
||||||
return (free_token(res));
|
return (free_token(res));
|
||||||
res = token_add_back(res, value);
|
res = expand_wildcards(res, value);
|
||||||
while (ft_isspace(*command))
|
while (ft_isspace(*command))
|
||||||
command++;
|
command++;
|
||||||
}
|
}
|
||||||
|
62
srcs/wildcards.c
Normal file
62
srcs/wildcards.c
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* wildcards.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: tomoron <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2024/04/15 12:53:29 by tomoron #+# #+# */
|
||||||
|
/* Updated: 2024/04/15 18:54:15 by tomoron ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
#include "minishell.h"
|
||||||
|
|
||||||
|
int filename_corresponds(char *wildcard, char *value)
|
||||||
|
{
|
||||||
|
if(*value == '.' && *wildcard != '.')
|
||||||
|
return(0);
|
||||||
|
while(*wildcard && *value && (*wildcard == '*' || *wildcard == *value))
|
||||||
|
{
|
||||||
|
if(*wildcard == '*')
|
||||||
|
{
|
||||||
|
while(*wildcard && *value && *value != wildcard[1])
|
||||||
|
value++;
|
||||||
|
wildcard++;
|
||||||
|
}
|
||||||
|
while(*wildcard && *value && *value == *wildcard && *wildcard != '*')
|
||||||
|
{
|
||||||
|
wildcard++;
|
||||||
|
value++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return(!*wildcard);
|
||||||
|
}
|
||||||
|
|
||||||
|
t_token *expand_wildcards(t_token *res, char *value)
|
||||||
|
{
|
||||||
|
DIR *dir;
|
||||||
|
char *cwd;
|
||||||
|
struct dirent *content;
|
||||||
|
|
||||||
|
if(!ft_strchr(value, '*'))
|
||||||
|
return(token_add_back(res, value));
|
||||||
|
cwd = getcwd(NULL, 100000);
|
||||||
|
if(!cwd)
|
||||||
|
return(token_add_back(res, value));
|
||||||
|
dir = opendir(cwd);
|
||||||
|
free(cwd);
|
||||||
|
if(!dir)
|
||||||
|
return(token_add_back(res, value));
|
||||||
|
content = readdir(dir);
|
||||||
|
while(content)
|
||||||
|
{
|
||||||
|
if(filename_corresponds(value, content->d_name))
|
||||||
|
res = token_add_back(res,ft_strdup(content->d_name));
|
||||||
|
content = readdir(dir);
|
||||||
|
}
|
||||||
|
closedir(dir);
|
||||||
|
if(!res)
|
||||||
|
return(token_add_back(res, value));
|
||||||
|
free(value);
|
||||||
|
return(res);
|
||||||
|
}
|
Reference in New Issue
Block a user