Skip to content

Commit b4917b7

Browse files
authored
Merge pull request #32 from cuajarsaki/refactor/#7-norm-errors
Refactor/#7 norm errors
2 parents bee9142 + 744e473 commit b4917b7

26 files changed

+1226
-1015
lines changed

Makefile

+9-1
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,14 @@ SRC = $(SRC_DIR)/$(CMD_DIR)/shell_cd.c \
1212
$(SRC_DIR)/main.c \
1313
$(SRC_DIR)/env/env.c \
1414
$(SRC_DIR)/env/env_2.c \
15+
$(SRC_DIR)/env/env_3.c \
1516
$(SRC_DIR)/termcaps/termcaps.c \
1617
$(SRC_DIR)/signal/signal.c \
1718
$(SRC_DIR)/signal/signal_2.c \
1819
$(SRC_DIR)/terminal/terminal.c \
1920
$(SRC_DIR)/free/free.c \
2021
$(SRC_DIR)/free/free_2.c \
22+
$(SRC_DIR)/free/free_3.c \
2123
$(SRC_DIR)/cmd_tokenizer/cmd_tokenizer.c \
2224
$(SRC_DIR)/parser/parser_ast.c \
2325
$(SRC_DIR)/parser/parser_cmd.c \
@@ -29,11 +31,17 @@ SRC = $(SRC_DIR)/$(CMD_DIR)/shell_cd.c \
2931
$(SRC_DIR)/executor/executor_ast.c \
3032
$(SRC_DIR)/executor/executor_builtin_check.c \
3133
$(SRC_DIR)/executor/executor_command_group.c \
32-
$(SRC_DIR)/executor/executor_command_execution.c \
34+
$(SRC_DIR)/executor/executor_command_execution1.c \
35+
$(SRC_DIR)/executor/executor_command_execution2.c \
36+
$(SRC_DIR)/executor/executor_child.c \
37+
$(SRC_DIR)/executor/executor_command_path.c \
38+
$(SRC_DIR)/executor/executor_command_pipe.c \
39+
$(SRC_DIR)/executor/executor_command_buildin.c \
3340
$(SRC_DIR)/executor/executor_file_desc.c \
3441
$(SRC_DIR)/executor/executor_parent.c \
3542
$(SRC_DIR)/executor/executor_path.c \
3643
$(SRC_DIR)/executor/executor_utility.c \
44+
$(SRC_DIR)/executor/executor_redirections.c \
3745

3846
OBJ = $(SRC:.c=.o)
3947

shell.h

+107-82
Original file line numberDiff line numberDiff line change
@@ -1,118 +1,143 @@
1+
/* ************************************************************************** */
2+
/* */
3+
/* ::: :::::::: */
4+
/* shell.h :+: :+: :+: */
5+
/* +:+ +:+ +:+ */
6+
/* By: pchung <[email protected]> +#+ +:+ +#+ */
7+
/* +#+#+#+#+#+ +#+ */
8+
/* Created: 2025/03/09 03:36:43 by pchung #+# #+# */
9+
/* Updated: 2025/03/09 03:58:39 by pchung ### ########.fr */
10+
/* */
11+
/* ************************************************************************** */
12+
113
#ifndef SHELL_H
2-
#define SHELL_H
3-
4-
#include "libft/libft.h"
5-
#include <signal.h>
6-
#include <stdio.h>
7-
#include <stdlib.h>
8-
#include <unistd.h>
9-
#include <glob.h>
10-
#include <string.h>
11-
#include <errno.h>
12-
#include <dirent.h>
13-
#include <readline/readline.h>
14-
#include <readline/history.h>
15-
#include <fcntl.h>
16-
#include <stdbool.h>
17-
#include <sys/wait.h>
18-
#include <term.h>
19-
#include <termios.h>
20-
21-
#define HISTORY_SIZE 10
22-
#define NOTSIG 1
23-
#define RSTSIG 0
24-
25-
extern volatile sig_atomic_t g_signal_received;
14+
# define SHELL_H
15+
16+
# include "libft/libft.h"
17+
# include <dirent.h>
18+
# include <errno.h>
19+
# include <fcntl.h>
20+
# include <glob.h>
21+
# include <readline/history.h>
22+
# include <readline/readline.h>
23+
# include <signal.h>
24+
# include <stdbool.h>
25+
# include <stdio.h>
26+
# include <stdlib.h>
27+
# include <string.h>
28+
# include <sys/wait.h>
29+
# include <term.h>
30+
# include <termios.h>
31+
# include <unistd.h>
32+
33+
# define HISTORY_SIZE 10
34+
# define NOTSIG 1
35+
# define RSTSIG 0
36+
# define SHELL_BUF_SIZE 8192
37+
# define SIGINT_ 42
38+
39+
extern volatile sig_atomic_t g_signal_received;
2640

2741
typedef struct s_ast
2842
{
29-
t_list *command_groups;
30-
} t_ast;
43+
t_list *command_groups;
44+
} t_ast;
3145

3246
typedef struct s_command_group
3347
{
34-
t_list *cmds;
35-
int cmd_amount;
36-
int **pipes;
37-
t_list *pids;
38-
int return_value;
39-
} t_command_group;
48+
t_list *cmds;
49+
int cmd_amount;
50+
int **pipes;
51+
t_list *pids;
52+
int return_value;
53+
} t_command_group;
4054

4155
typedef struct s_cmd
4256
{
43-
t_list *tokens;
44-
t_list *redirs;
45-
} t_cmd;
57+
t_list *tokens;
58+
t_list *redirs;
59+
} t_cmd;
4660

4761
typedef struct s_redir
4862
{
49-
char *direction;
50-
char type[2];
51-
} t_redir;
63+
char *direction;
64+
char type[2];
65+
} t_redir;
5266

5367
typedef struct s_env
5468
{
55-
char *key;
56-
char *value;
57-
struct s_env *next;
58-
} t_env;
69+
char *key;
70+
char *value;
71+
struct s_env *next;
72+
} t_env;
5973

6074
typedef struct s_token
6175
{
62-
char *value;
63-
int is_single_quoted;
64-
} t_token;
65-
76+
char *value;
77+
int is_single_quoted;
78+
} t_token;
6679

67-
t_ast *get_ast(const char *input, t_env *env_list, int *exit_status);
68-
t_env *init_env_list(char ** environ);
80+
t_ast *get_ast(const char *input, t_env *env_list,
81+
int *exit_status);
82+
t_env *init_env_list(char **environ);
6983

7084
// Utility Functions
71-
void run_shell(t_env *env_list, char **envp);
72-
char *get_env_value(t_env *env_list, const char *key);
73-
void set_env_value(t_env **env_list, const char *key, const char *value);
74-
void unset_env_value(t_env **env_list, const char *key);
75-
void free_env_list(t_env **env_list);
76-
int exec_ast(t_ast *ast, t_env *env_list, char **envp);
77-
char **convert_env_list_to_array(t_env *env_list);
78-
void free_env_array(char **envp);;
79-
void shell_unknown_command(char *cmd);
80-
int is_parent_builtin(t_cmd *cmd);
85+
void run_shell(t_env *env_list, char **envp);
86+
char *get_env_value(t_env *env_list,
87+
const char *key);
88+
void set_env_value(t_env **env_list, const char *key,
89+
const char *value);
90+
void unset_env_value(t_env **env_list,
91+
const char *key);
92+
void free_env_list(t_env **env_list);
93+
int exec_ast(t_ast *ast, t_env *env_list,
94+
char **envp);
95+
char **convert_env_list_to_array(t_env *env_list);
96+
void free_env_array(char **envp);
97+
;
98+
void shell_unknown_command(char *cmd);
99+
int is_parent_builtin(t_cmd *cmd);
81100

82101
// FREE FUNCTIONS
83-
void free_ast(t_ast *ast);
84-
void free_cmd(t_cmd *cmd);
85-
void free_command_group(t_command_group *command_group);
86-
void free_redir(void *ptr);
87-
void free_argv(char **argv);
102+
void free_ast(t_ast *ast);
103+
void free_cmd(t_cmd *cmd);
104+
void free_command_group(
105+
t_command_group *command_group);
106+
void free_redir(void *ptr);
107+
void free_argv(char **argv);
108+
void free_paths(char **paths);
109+
void free_tokens(char **tokens);
88110

89111
// BUILD-IN FUNCTIONS
90-
int shell_env(t_env *env_list);
91-
int shell_export(char **args, t_env *env_list);
92-
int shell_unset(char **args, t_env *env_list);
93-
int shell_clear(void);
94-
int shell_cd(char **argv, t_env *env_list);
95-
int shell_pwd(void);
96-
int shell_echo(char **args);
97-
int shell_exit(char **argv);
112+
int shell_env(t_env *env_list);
113+
int shell_export(char **args, t_env *env_list);
114+
int shell_unset(char **args, t_env *env_list);
115+
int shell_clear(void);
116+
int shell_cd(char **argv, t_env *env_list);
117+
int shell_pwd(void);
118+
int shell_echo(char **args);
119+
int shell_exit(char **argv);
98120

99121
// TERMINAL SETTINGS
100-
void reset_terminal_settings(const struct termios *old_termios);
101-
void setup_terminal(struct termios *old_termios);
102-
void term_clear_screen();
122+
void reset_terminal_settings(
123+
const struct termios *old_termios);
124+
void setup_terminal(struct termios *old_termios);
125+
void term_clear_screen(void);
103126

104127
// TERMCAP FUNCTIONS
105-
void handle_input(char *buf, size_t *len, size_t max_len);
128+
void handle_input(char *buf, size_t *len,
129+
size_t max_len);
106130

107131
// SINGAL FUNCTIONS
108-
void init_readline_for_signal(void);
109-
void setup_signals(void);
110-
void handle_sigint(int sig);
111-
void set_signal(int signum, void (*handler)(int), int flags);
112-
void init_signal(void (*handler_for_sigint)(int),
113-
void (*handler_for_sigquit)(int));
132+
void init_readline_for_signal(void);
133+
void setup_signals(void);
134+
void handle_sigint(int sig);
135+
void set_signal(int signum, void (*handler)(int),
136+
int flags);
137+
void init_signal(void (*handler_for_sigint)(int),
138+
void (*handler_for_sigquit)(int));
114139

115140
// PARSER FUNCTIONS
116-
char **token_list_to_argv(t_cmd *cmd);
141+
char **token_list_to_argv(t_cmd *cmd);
117142

118143
#endif

0 commit comments

Comments
 (0)