mirror of
https://github.com/KeyZox71/ft_minipowershell.git
synced 2025-05-11 06:58:47 +02:00
「🔨」 fix: parsing reworked
This commit is contained in:
@ -6,7 +6,7 @@
|
||||
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/04/29 13:20:22 by mmoussou #+# #+# */
|
||||
/* Updated: 2024/08/01 16:39:11 by mmoussou ### ########.fr */
|
||||
/* Updated: 2024/08/06 17:00:05 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -16,7 +16,6 @@
|
||||
# include "env.h"
|
||||
# include "libft.h"
|
||||
# include "parsing.h"
|
||||
# include "tokenizer.h"
|
||||
|
||||
typedef struct s_exec
|
||||
{
|
||||
@ -26,7 +25,7 @@ typedef struct s_exec
|
||||
int pipe_fd[2];
|
||||
} t_exec;
|
||||
|
||||
int format_quotes(t_list *list_cmd);
|
||||
void format_quotes(char **content);
|
||||
|
||||
int exec_single_cmd_execution(t_cmd *cmd, char **env,
|
||||
t_env *env_t, t_exec exec);
|
||||
@ -52,7 +51,7 @@ void __fork_single_cmd(t_cmd *cmd, char **env, t_env *env_t, t_exec exec);
|
||||
*
|
||||
* @return (int) fd of a file containing the user's input, or -1 on error
|
||||
*/
|
||||
int ft_heredoc(char *delimiter, t_cmd *cmd);
|
||||
int ft_heredoc(char *delimiter);
|
||||
int __open_fd_here(char *path, int mode);
|
||||
void ft_lstclear_till_nxt(t_list **lst, void (*del)(void *));
|
||||
int get_fd_heredoc(int in);
|
||||
|
@ -29,10 +29,10 @@
|
||||
# include <stdbool.h>
|
||||
# include "libft.h"
|
||||
|
||||
# include "parsing.h"
|
||||
# include "error_msg.h"
|
||||
# include "env.h"
|
||||
# include "prompt.h"
|
||||
# include "parsing.h"
|
||||
# include "execution.h"
|
||||
|
||||
void free_redir(void *redir_v);
|
||||
@ -41,7 +41,7 @@ void free_cmd(void *content);
|
||||
|
||||
t_env **get_env(t_env **env);
|
||||
t_list **get_list(t_list **list);
|
||||
t_list **get_list2(t_list **list);
|
||||
void *get_void(void *in);
|
||||
int get_exit_code(int in);
|
||||
size_t ft_arrlen(char **a);
|
||||
char **get_rl(char **rl);
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/04/25 12:20:26 by adjoly #+# #+# */
|
||||
/* Updated: 2024/08/02 17:17:39 by adjoly ### ########.fr */
|
||||
/* Updated: 2024/08/06 15:14:32 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -14,9 +14,23 @@
|
||||
# define PARSING_H
|
||||
|
||||
# include "libft.h"
|
||||
# include "tokenizer.h"
|
||||
# include "env.h"
|
||||
|
||||
typedef enum s_redir_sign
|
||||
{
|
||||
ERROR = -1,
|
||||
INFILE,
|
||||
HEREDOC,
|
||||
OUTFILE,
|
||||
OUT_APPEND,
|
||||
} t_redir_sign;
|
||||
|
||||
typedef struct s_redir
|
||||
{
|
||||
int fd;
|
||||
t_redir_sign sign;
|
||||
} t_redir;
|
||||
|
||||
typedef struct s_cmd
|
||||
{
|
||||
char *cmd;
|
||||
@ -33,10 +47,6 @@ typedef enum s_quote
|
||||
DOUBLE = 34
|
||||
} t_quote;
|
||||
|
||||
t_cmd *get_redir_fd(void *content, t_list *tmp);
|
||||
t_list *get_cmd_list(t_list *list);
|
||||
void open_redir(t_redirection *redir, t_cmd *cmd, t_redir_sign sign[2]);
|
||||
|
||||
/**
|
||||
* @brief Take a string and a character and return the lengh
|
||||
* until the given character
|
||||
@ -46,13 +56,13 @@ void open_redir(t_redirection *redir, t_cmd *cmd, t_redir_sign sign[2]);
|
||||
*
|
||||
* @return (size_t) The lengh until the given character
|
||||
*/
|
||||
size_t strlen_till_char(char *s, int c);
|
||||
size_t strlen_till_char(char *s, int c);
|
||||
|
||||
bool check_quote(char *readline);
|
||||
bool check_syntax(char *readline);
|
||||
bool check_redir(t_list *redir);
|
||||
bool check_argv(t_list *token);
|
||||
bool check_wspace(char *readline);
|
||||
bool check_quote(char *readline);
|
||||
bool check_syntax(char *readline);
|
||||
bool check_redir(t_list *redir);
|
||||
bool check_argv(t_list *token);
|
||||
bool check_wspace(char *readline);
|
||||
/**
|
||||
* @brief Take the readline output and check if all the pipe
|
||||
* a command after them
|
||||
@ -61,7 +71,7 @@ bool check_wspace(char *readline);
|
||||
*
|
||||
* @return (bool) A boolean of whether or not there is an error
|
||||
*/
|
||||
bool check_pipe(char *readline);
|
||||
bool check_pipe(char *readline);
|
||||
|
||||
/**
|
||||
* @brief Take the readline output and split it into an argv
|
||||
@ -71,7 +81,7 @@ bool check_pipe(char *readline);
|
||||
*
|
||||
* @return (char **) The argv of the command
|
||||
*/
|
||||
char **split_argv(char *readline);
|
||||
char **split_argv(char *readline);
|
||||
|
||||
/**
|
||||
* @brief Take the argv of a command a split the argv and the
|
||||
@ -81,7 +91,7 @@ char **split_argv(char *readline);
|
||||
*
|
||||
* @return (t_cmd *) cmd and argv splited into a struct
|
||||
*/
|
||||
t_cmd *split_cmd(char *cmd_av, t_cmd *cmd);
|
||||
t_cmd *split_cmd(char *cmd_av, t_cmd *cmd);
|
||||
|
||||
/**
|
||||
* @brief Take a string and an index and check if the character
|
||||
@ -93,7 +103,7 @@ t_cmd *split_cmd(char *cmd_av, t_cmd *cmd);
|
||||
* @return (t_quote) The type of quote if between, if not return FALSE or
|
||||
* NOT_CLOSED if the quote is not closed
|
||||
*/
|
||||
t_quote is_inquote(char *s, size_t i);
|
||||
t_quote is_inquote(char *s, size_t i);
|
||||
|
||||
/**
|
||||
* @brief Take a character and check if it is a quote and return
|
||||
@ -103,7 +113,7 @@ t_quote is_inquote(char *s, size_t i);
|
||||
*
|
||||
* @return (t_quote) The type of quote or FALSE
|
||||
*/
|
||||
t_quote __is_quote(char c);
|
||||
t_quote __is_quote(char c);
|
||||
|
||||
/**
|
||||
* @brief Take a string and a quote type and return the pointer to
|
||||
@ -114,7 +124,7 @@ t_quote __is_quote(char c);
|
||||
*
|
||||
* @return (char *) A pointer to the next quote
|
||||
*/
|
||||
char *search_for_next_quote(char *s, t_quote quote_type);
|
||||
char *search_for_next_quote(char *s, t_quote quote_type);
|
||||
|
||||
/**
|
||||
* @brief Take the readline output and the env and replace all the
|
||||
@ -125,8 +135,36 @@ char *search_for_next_quote(char *s, t_quote quote_type);
|
||||
*
|
||||
* @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);
|
||||
size_t strlen_till_notalnum(char *s);
|
||||
char *env_var_replace(char *readline, t_env *env);
|
||||
size_t get_size_with_env(char *readline, t_env *env);
|
||||
size_t strlen_till_notalnum(char *s);
|
||||
|
||||
t_cmd *__to_cmd(char **content);
|
||||
|
||||
/**
|
||||
* @brief Split a readline output into an argv
|
||||
*
|
||||
* @param The readline output
|
||||
*
|
||||
* @return (t_list *) A linked lst of all the command splited
|
||||
*
|
||||
*/
|
||||
t_list *__split_pipe(char *readline);
|
||||
|
||||
/**
|
||||
* @brief Convert the readline output, split all command and put
|
||||
* it in linked list of t_token (given by t_token function)
|
||||
*
|
||||
* @param readline The readline output
|
||||
*
|
||||
* @return (t_list *) Linked list of t_token
|
||||
*
|
||||
*/
|
||||
t_list *tokenizer(char *readline, t_env *env);
|
||||
|
||||
t_redir_sign __to_redir_sign(char *redir_sign);
|
||||
t_redir *__open_heredoc(char *filename);
|
||||
t_redir *__to_redir(char *filename, t_redir_sign sign);
|
||||
void __get_fd(t_list *list, t_cmd *cmd);
|
||||
char **__get_argv(char **content);
|
||||
#endif
|
||||
|
@ -1,89 +0,0 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* tokenizer.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/18 20:14:15 by adjoly #+# #+# */
|
||||
/* Updated: 2024/07/20 16:52:51 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef TOKENIZER_H
|
||||
# define TOKENIZER_H
|
||||
|
||||
# include "libft.h"
|
||||
|
||||
typedef enum s_redir_sign
|
||||
{
|
||||
INFILE,
|
||||
HEREDOC,
|
||||
OUTFILE,
|
||||
OUT_APPEND,
|
||||
} t_redir_sign;
|
||||
|
||||
typedef struct s_redirection
|
||||
{
|
||||
char *file_name;
|
||||
t_redir_sign sign;
|
||||
} t_redirection;
|
||||
|
||||
typedef struct s_token
|
||||
{
|
||||
char *argv;
|
||||
t_list *redirection;
|
||||
} t_token;
|
||||
|
||||
/**
|
||||
* @brief Take a string and tell what type of redirect it is
|
||||
*
|
||||
* @param A string that contain a redirection sign
|
||||
*
|
||||
* @return (t_redirection_sign) The sign of the redirecition
|
||||
*/
|
||||
t_redir_sign __to_redir_sign(char *redir_sign);
|
||||
|
||||
/**
|
||||
* @brief Take a string and split the filename and the redirect
|
||||
* sign
|
||||
*
|
||||
* @param redir_s A string that contain a redirection
|
||||
*
|
||||
* @return (t_redirection) The splited redirection
|
||||
*/
|
||||
t_redirection *__to_redir(char *redir_s);
|
||||
|
||||
/**
|
||||
* @brief Convert the raw command into a t_token that contains
|
||||
* the argv of the command an a linked list of redirection
|
||||
*
|
||||
* @param cmd A string that contain the command to tokenize
|
||||
*
|
||||
* @return (t_token *) The tokenized version of the command
|
||||
*
|
||||
*/
|
||||
t_token *__to_token(char *cmd);
|
||||
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
* @param The readline output
|
||||
*
|
||||
* @return (t_list *) A linked lst of all the command splited
|
||||
*
|
||||
*/
|
||||
t_list *__split_pipe(char *readline);
|
||||
|
||||
/**
|
||||
* @brief Convert the readline output, split all command and put
|
||||
* it in linked list of t_token (given by t_token function)
|
||||
*
|
||||
* @param readline The readline output
|
||||
*
|
||||
* @return (t_list *) Linked list of t_token
|
||||
*
|
||||
*/
|
||||
t_list *tokenizer(char *readline);
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user