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.

118 lines
2.8 KiB

3 years ago
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* minishell.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/05/02 13:50:44 by narnaud #+# #+# */
3 years ago
/* Updated: 2022/05/03 20:22:29 by narnaud ### ########.fr */
3 years ago
/* */
/* ************************************************************************** */
#ifndef MINISHELL_H
# define MINISHELL_H
# define PIPE_MAX_SIZE 8192
# define PATHS_MAX_SIZE 126
# define PROMPT_PREFIX 0
3 years ago
# define DEBUG 0
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
extern char **g_env;
// ----------------------------------Utils.c
int ft_echo(char **argv);
int ft_pwd(char **argv);
int ft_cd(char **argv);
int close_minishell(int exit_code);
// ----------------------------------Utils.c
int ft_unset(char **argv);
int ft_env(char **argv);
int is_valid_identifier(char *ident);
int ft_export(char **argv);
3 years ago
// ----------------------------------Utils.c
void halt(int ret_code);
int is_empty(char *line);
void termios(int ctl);
void sigs_handler(int sig_num);
3 years ago
3 years ago
// ----------------------------------Caller.c
3 years ago
typedef struct s_command
{
3 years ago
int argc;
3 years ago
char **argv;
char **envp;
int fd[2];
char *heredoc;
struct s_command *next;
struct s_command *prev;
} t_command;
3 years ago
void exe(char *argv[], char *const envp[]);
3 years ago
int command_call(char *argv[]);
3 years ago
// ----------------------------------Parser.c
typedef enum e_type
{
WORD,
PIPE,
OUT,
ADD,
IN,
HD,
} t_type;
3 years ago
typedef struct s_token
{
char *value;
t_type type;
struct s_token *next;
} t_token;
size_t count_arguments(t_token *tok);
void update_redir(t_command *cmd, t_token *tok);
3 years ago
// ----------------------------------Lexer.c
typedef enum e_state
{
OLD_ST,
ROOT_ST,
S_QUOTE_ST,
D_QUOTE_ST,
} t_state;
typedef struct s_lex
{
t_state state;
t_type type;
t_type next_type;
t_token *tokens;
int n_elem;
} t_lexer;
int create_token(t_lexer *lex, char str[]);
int check_register(t_lexer *lex, char **line, char *tmp);
int replace_var(char **line, char *tmp, int tmp_i);
int check_state(t_lexer *lex, char **line);
3 years ago
#endif