maxishell
Implementation of a shell for Linux-like systems
Loading...
Searching...
No Matches
clean.c File Reference
#include "tokens.h"
#include "env.h"
#include "exit_status.h"
Include dependency graph for clean.c:

Go to the source code of this file.

Functions

void free_args (char **args)
 
void free_env_list (t_env *env)
 
void free_ms_data (t_ms_data *data)
 
void loop_cleanup (t_loop_data *loop_data, t_token *tokens_head)
 
void free_ast (t_ast *node)
 
void free_all_tokens (t_token *tokens)
 

Function Documentation

◆ free_all_tokens()

void free_all_tokens ( t_token tokens)

Definition at line 17 of file clean_utils.c.

18{
19 t_token *temp;
20
21 while (tokens)
22 {
23 temp = tokens;
24 tokens = tokens->next;
25 if (temp)
26 {
27 if (temp->data)
28 {
29 free(temp->data);
30 temp->data = NULL;
31 }
32 }
33 free(temp);
34 temp = NULL;
35 }
36}
struct s_token * next
Definition tokens.h:45
char * data
Definition tokens.h:44

Referenced by loop_cleanup().

Here is the caller graph for this function:

◆ free_args()

void free_args ( char **  args)

Definition at line 24 of file clean.c.

25{
26 int i;
27
28 i = 0;
29 if (args)
30 {
31 while (args[i] != NULL)
32 free(args[i++]);
33 free(args);
34 }
35}

◆ free_ast()

void free_ast ( t_ast node)

Definition at line 74 of file clean.c.

75{
76 int i;
77
78 i = 0;
79 if (!node)
80 return ;
81 if (node->args)
82 {
83 while (node->args && node->args[i])
84 {
85 free(node->args[i]);
86 i++;
87 }
88 free(node->args);
89 }
90 free_ast(node->left);
91 free_ast(node->right);
92 free(node);
93}
void free_ast(t_ast *node)
Definition clean.c:74
char ** args
Definition tokens.h:52
struct s_ast * right
Definition tokens.h:54
struct s_ast * left
Definition tokens.h:53

References s_ast::args, free_ast(), s_ast::left, and s_ast::right.

Referenced by free_ast(), and loop_cleanup().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ free_env_list()

void free_env_list ( t_env env)

Definition at line 37 of file clean.c.

38{
39 t_env *temp;
40
41 while (env)
42 {
43 temp = env;
44 env = env->next;
45 free(env->key);
46 free(env->value);
47 free(temp);
48 }
49}
Definition env.h:17
struct s_env * next
Definition env.h:20
char * key
Definition env.h:18
char * value
Definition env.h:19

References s_env::key, s_env::next, and s_env::value.

◆ free_ms_data()

void free_ms_data ( t_ms_data data)

Definition at line 51 of file clean.c.

52{
53 if (data)
54 {
57 free(data->current_dir);
58 if (data->std_in >= 0)
59 close(data->std_in);
60 if (data->std_out >= 0)
61 close(data->std_out);
62 if (data->std_err >= 0)
63 close(data->std_err);
64 }
65}
void free_shell_var_list(t_env *shell_var)
t_env * envp
Definition shell.h:24
int std_err
Definition shell.h:28
int std_out
Definition shell.h:27
t_env * shell_variables
Definition shell.h:25
char * current_dir
Definition shell.h:29
int std_in
Definition shell.h:26

References s_ms_data::current_dir, s_ms_data::envp, free_shell_var_list(), s_ms_data::shell_variables, s_ms_data::std_err, s_ms_data::std_in, and s_ms_data::std_out.

Referenced by handle_exit(), and main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ loop_cleanup()

void loop_cleanup ( t_loop_data loop_data,
t_token tokens_head 
)

Definition at line 67 of file clean.c.

68{
69 free(loop_data->trimmed_input);
70 free_all_tokens(tokens_head);
71 free_ast(loop_data->tree);
72}
void free_all_tokens(t_token *tokens)
Definition clean_utils.c:17
char * trimmed_input
Definition tokens.h:61
t_ast * tree
Definition tokens.h:63

References free_all_tokens(), free_ast(), s_loop_data::tree, and s_loop_data::trimmed_input.

Referenced by process_ast_and_io(), and status_handler().

Here is the call graph for this function:
Here is the caller graph for this function: