mirror of
https://github.com/KeyZox71/ft_minipowershell.git
synced 2025-03-15 03:16:51 +01:00
「✏️」 norm: Normed heredoc
This commit is contained in:
@ -16,7 +16,9 @@
|
||||
|
||||
# include <stdio.h>
|
||||
# include <readline/readline.h>
|
||||
# include <readline/history.h>
|
||||
# include <stdlib.h>
|
||||
# include <signal.h>
|
||||
# include <stdint.h>
|
||||
# include <sys/types.h>
|
||||
# include <sys/stat.h>
|
||||
@ -24,17 +26,15 @@
|
||||
# include <fcntl.h>
|
||||
# include <unistd.h>
|
||||
# include <dirent.h>
|
||||
# include <stdbool.h>
|
||||
# include "libft.h"
|
||||
|
||||
# include "error_msg.h"
|
||||
# include "env.h"
|
||||
# include "prompt.h"
|
||||
# include "parsing.h"
|
||||
# include "execution.h"
|
||||
|
||||
char set_env(char **env, const char *name, char *content);
|
||||
bool is_str(char *src, char *dst);
|
||||
void print_cmd(t_cmd *cmd);
|
||||
|
||||
|
||||
void free_redir(void *redir_v);
|
||||
void free_token(void *token_v);
|
||||
void free_cmd(void *content);
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/04/25 12:20:26 by adjoly #+# #+# */
|
||||
/* Updated: 2024/07/06 18:06:23 by adjoly ### ########.fr */
|
||||
/* Updated: 2024/07/07 14:37:59 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -33,22 +33,46 @@ typedef enum s_quote
|
||||
DOUBLE = 34
|
||||
} t_quote;
|
||||
|
||||
bool check_syntax(char *readline);
|
||||
void send_error(char *msg, char **argv);
|
||||
bool check_redir(t_list *redir);
|
||||
bool check_argv(t_list *token);
|
||||
t_cmd *get_redir_fd(void *content, t_env *env);
|
||||
t_list *get_cmd_list(t_list *list, t_env *env);
|
||||
void open_redir(t_redirection *redir, t_cmd *cmd, t_redir_sign sign[2]);
|
||||
char **split_argv(char *readline);
|
||||
char *env_var_replace(char *readline, t_env *env);
|
||||
size_t get_size_with_env(char *readline, t_env *env);
|
||||
|
||||
/**
|
||||
* @brief Take a string and a character and return the lengh
|
||||
* until the given character
|
||||
*
|
||||
* @param s The string
|
||||
* @param The character the lengh stops at
|
||||
*
|
||||
* @return (size_t) The lengh until the given character
|
||||
*/
|
||||
size_t strlen_till_char(char *s, int c);
|
||||
|
||||
|
||||
bool check_quote(char *readline);
|
||||
t_quote __is_quote(char c);
|
||||
char *search_for_next_quote(char *s, t_quote quote_type);
|
||||
bool check_syntax(char *readline);
|
||||
bool check_redir(t_list *redir);
|
||||
bool check_argv(t_list *token);
|
||||
/**
|
||||
* @brief Take the readline output and check if all the pipe
|
||||
* a command after them
|
||||
*
|
||||
* @param The readline output
|
||||
*
|
||||
* @return (bool) A boolean of whether or not there is an error
|
||||
*/
|
||||
bool check_pipe(char *readline);
|
||||
|
||||
/**
|
||||
* @brief Take the readline output and split it into an argv
|
||||
* while taking into account quotes
|
||||
*
|
||||
* @param The readline output
|
||||
*
|
||||
* @return (char **) The argv of the command
|
||||
*/
|
||||
char **split_argv(char *readline);
|
||||
|
||||
/**
|
||||
* @brief Take the argv of a command a split the argv and the
|
||||
* command it self
|
||||
@ -81,12 +105,35 @@ t_quote is_inquote(char *s, size_t i);
|
||||
*/
|
||||
t_quote __is_quote(char c);
|
||||
|
||||
/**
|
||||
* @brief Take a string and a quote type and return the pointer to
|
||||
* the next quote
|
||||
*
|
||||
* @param s A pointer to a string
|
||||
* @param quote_type A type of quote
|
||||
*
|
||||
* @return (char *) A pointer to the next quote
|
||||
*/
|
||||
char *search_for_next_quote(char *s, t_quote quote_type);
|
||||
|
||||
/**
|
||||
* @brief Take the readline output and the env and replace all the
|
||||
* $("variable") by their variable content
|
||||
*
|
||||
* @param readline The readline output
|
||||
* @param env The env
|
||||
*
|
||||
* @return (char *) The curated string
|
||||
*/
|
||||
char *env_var_replace(char *readline, t_env *env);
|
||||
size_t get_size_with_env(char *readline, t_env *env);
|
||||
|
||||
/*
|
||||
* ONLY FOR DEBUG TO BE REMOVED
|
||||
*/
|
||||
void print_quote_type(t_quote type);
|
||||
void print_redir_sign(t_redir_sign redir_sign);
|
||||
void print_token(t_token *token);
|
||||
void print_redir(t_redirection *redir);
|
||||
void print_quote_type(t_quote type);
|
||||
void print_redir_sign(t_redir_sign redir_sign);
|
||||
void print_token(t_token *token);
|
||||
void print_redir(t_redirection *redir);
|
||||
|
||||
#endif
|
||||
|
@ -6,24 +6,23 @@
|
||||
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/20 09:19:39 by mmoussou #+# #+# */
|
||||
/* Updated: 2024/07/03 10:08:18 by mmoussou ### ########.fr */
|
||||
/* Updated: 2024/07/09 11:05:31 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "minishell.h"
|
||||
|
||||
/*
|
||||
# mode
|
||||
0: ouvre un nouveau fichier
|
||||
1: réouvre le fichier pour la lecture
|
||||
-1: pour signifier qu'il faut decrémenter la static
|
||||
* # mode
|
||||
* 0: ouvre un nouveau fichier
|
||||
* 1: réouvre le fichier pour la lecture
|
||||
* -1: pour signifier qu'il faut decrémenter la static
|
||||
*/
|
||||
int fd_manager(int mode)
|
||||
{
|
||||
static int index = 0;
|
||||
char *index_itoa;
|
||||
char *path;
|
||||
int fd;
|
||||
|
||||
if (mode < 0)
|
||||
index--;
|
||||
@ -42,10 +41,9 @@ int fd_manager(int mode)
|
||||
ft_strlcat(path, index_itoa, ft_strlen(index_itoa));
|
||||
free(index_itoa);
|
||||
if (mode > 0)
|
||||
fd = open(path, O_RDONLY);
|
||||
return (open(path, O_RDONLY));
|
||||
else
|
||||
fd = open(path, O_WRONLY | O_TRUNC | O_CREAT, 0644);
|
||||
return (fd);
|
||||
return (open(path, O_WRONLY | O_TRUNC | O_CREAT, 0644));
|
||||
}
|
||||
|
||||
static int get_input(char *delimiter, int fd)
|
||||
@ -60,12 +58,12 @@ static int get_input(char *delimiter, int fd)
|
||||
if (status == -1)
|
||||
fd_manager(fd);
|
||||
if (status == -1)
|
||||
return (-1);
|
||||
break ;
|
||||
status = write(fd, "\n", 1);
|
||||
if (status == -1)
|
||||
fd_manager(fd);
|
||||
if (status == -1)
|
||||
return (-1);
|
||||
break ;
|
||||
free(line);
|
||||
line = readline("heredoc> ");
|
||||
}
|
||||
|
35
src/main.c
35
src/main.c
@ -6,23 +6,11 @@
|
||||
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/04/24 11:18:04 by adjoly #+# #+# */
|
||||
/* Updated: 2024/07/06 18:07:24 by adjoly ### ########.fr */
|
||||
/* Updated: 2024/07/07 14:50:45 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <readline/readline.h>
|
||||
#include "error_msg.h"
|
||||
#include <readline/history.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
#include <fcntl.h>
|
||||
#include "libft.h"
|
||||
#include "builtins.h"
|
||||
#include "minishell.h"
|
||||
#include "parsing.h"
|
||||
#include "prompt.h"
|
||||
|
||||
void sig_c(int code)
|
||||
{
|
||||
@ -33,6 +21,19 @@ void sig_c(int code)
|
||||
rl_redisplay();
|
||||
}
|
||||
|
||||
bool run_checks(char *rl)
|
||||
{
|
||||
if (!*rl)
|
||||
return (true);
|
||||
if (check_syntax(rl))
|
||||
return (true);
|
||||
if (check_quote(rl))
|
||||
return (true);
|
||||
if (check_pipe(rl))
|
||||
return (true);
|
||||
return (false);
|
||||
}
|
||||
|
||||
int main(int ac, char **av, char **env)
|
||||
{
|
||||
char *rl;
|
||||
@ -53,13 +54,7 @@ int main(int ac, char **av, char **env)
|
||||
free(prompt);
|
||||
if (!rl)
|
||||
exit(727);
|
||||
if (!*rl)
|
||||
continue ;
|
||||
if (check_syntax(rl))
|
||||
continue ;
|
||||
if (check_quote(rl))
|
||||
continue ;
|
||||
if (check_pipe(rl))
|
||||
if (run_checks(rl))
|
||||
continue ;
|
||||
piped = tokenizer(rl);
|
||||
if (check_argv(piped))
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/30 10:48:41 by adjoly #+# #+# */
|
||||
/* Updated: 2024/07/06 18:06:14 by adjoly ### ########.fr */
|
||||
/* Updated: 2024/07/07 14:57:54 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
Reference in New Issue
Block a user