You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

134 lines
3.5 KiB

3 years ago
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* minishell.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mea <marvin@42.fr> +#+ +:+ +#+ */
3 years ago
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/05/02 13:50:44 by narnaud #+# #+# */
/* Updated: 2022/05/16 09:22:48 by narnaud ### ########.fr */
3 years ago
/* */
/* ************************************************************************** */
#ifndef MINISHELL_H
# define MINISHELL_H
# define ENVP_MAX_SIZE 4096
# define STR_MAX_SIZE 4096
3 years ago
# define PATHS_MAX_SIZE 126
# define DEBUG 1
3 years ago
# include "libft/libft.h"
# include <fcntl.h>
# include <stdio.h>
# include <stdlib.h>
# include <readline/readline.h>
# include <readline/history.h>
# include <sys/types.h>
# include <sys/wait.h>
# include <signal.h>
# include <unistd.h>
# include <dirent.h>
# include <errno.h>
# include <termios.h>
3 years ago
# include <dirent.h>
3 years ago
3 years ago
typedef struct s_command
{
pid_t pid;
char **argv;
3 years ago
int argc;
int ope;
int fd[2];
struct s_command *next;
struct s_command *prev;
} t_command;
3 years ago
typedef struct s_datas
{
char **envp;
int exit_code;
int silent;
} t_datas;
3 years ago
// ----------------------------------Utils_1.c
3 years ago
int is_empty(char *line);
int handle_status(t_datas *datas, int status);
3 years ago
void nothing(int sig_num);
void sigs_handler(int sig_num);
void halt(t_datas *datas, int ret_code, int silent);
3 years ago
typedef struct s_lex t_lexer;
// ----------------------------------Utils_2.c
int file_error(char *cmd, char *file, char *msg);
int replace_var(t_datas *datas, char **line, char *tmp, int tmp_i);
char *expend_str(t_datas *datas, char *line);
int set_redir(t_lexer *lex, char **line, char ch);
// ----------------------------------Utils_3.c
int is_valid_identifier(char *ident);
int create_wc(t_lexer *lex, char *tmp);
3 years ago
// ----------------------------------Builtins.c
int is_builtin(char *cmd);
3 years ago
int ft_echo(t_command *cmd);
int ft_pwd(t_command *cmd);
int ft_cd(t_command *cmd);
int ft_exit(t_datas *datas, t_command *cmd);
// ----------------------------------Env.c
3 years ago
int ft_unset(t_datas *datas, t_command *cmd);
int ft_env(t_datas *datas, t_command *cmd);
int ft_export(t_datas *datas, t_command *cmd);
3 years ago
// ----------------------------------Caller.c
int call_builtin(t_datas *datas, t_command *cmd);
int caller(t_datas *datas, t_command *cmd);
3 years ago
3 years ago
// ----------------------------------Parser.c
typedef enum e_type
{
WORD,
OUT,
ADD,
IN,
HD,
3 years ago
PIPE,
AND,
OR,
} t_type;
3 years ago
typedef struct s_token
{
char *value;
t_type type;
struct s_token *next;
3 years ago
} t_token;
3 years ago
t_command *parser(t_datas *datas, t_token *tok, t_command *prev);
3 years ago
// ----------------------------------Lexer.c
typedef enum e_state
{
OLD_ST,
ROOT_ST,
S_QUOTE_ST,
D_QUOTE_ST,
3 years ago
} t_state;
3 years ago
typedef struct s_lex
{
t_state state;
t_type type;
t_type next_type;
t_token *tokens;
3 years ago
int wc;
3 years ago
int deep;
3 years ago
int n_elem;
3 years ago
int empty;
} t_lexer;
3 years ago
3 years ago
t_token *lexer(t_datas *datas, char *line);
int create_token(t_lexer *lex, char str[]);
int create_wc(t_lexer *lex, char *wc);
3 years ago
#endif