-
Notifications
You must be signed in to change notification settings - Fork 2
/
shell.h
143 lines (121 loc) · 3.08 KB
/
shell.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#ifndef _SHELL_H_
#define _SHELL_H_
#include <unistd.h>
/* delimeter macros */
#define NORM_DELIMS " \t\a\r\n"
#define PATH_DELIMS ":"
/* external environmental variable array */
extern char **environ;
/**
* struct command_s - Structure of each node
*
* @prev_valid: Check if previous command
* was successful
*
* @separator: Used for character that
* that separates each command
*
* @command: Points to the first char
* in the stream
*
* @next: Address of next node
*
*/
typedef struct command_s
{
int prev_valid;
char separator;
char **command;
struct command_s *next;
} command_t;
/**
* struct queue_s - Structure of queue
*
* @front: Pointer to the first node
*
* @rear: Pointer to the front+1 node
*
*/
typedef struct queue_s
{
command_t *front, *rear;
} queue_t;
/**
* struct history_s - Structure of history queue
*
* @command: Holds the command from getline()
*
* @priority_number: Holds the number coorelated
* to the command input order
*
* @next: Pointer to the next node
*
*/
typedef struct history_s
{
char *command;
int priority_number;
struct history_s *next;
} history_t;
/**
* struct his_q_s - Structure of queue
*
* @front: Pointer to the first node
*
* @rear: Pointer to the front+1 node
*
*/
typedef struct his_q_s
{
history_t *front, *rear;
} his_q_t;
/* main functionality */
int start_shell(char **environ, char *exec_name);
queue_t *parse_string(char *input_str);
int execute_commands(his_q_t *his_q, queue_t *command_q,
char *envp[], char *exec_name);
char *get_file_path(char *filename, char *envp[]);
/* free memory */
void free_token_list(char **tokens);
void free_command_queue(queue_t *command_q);
void free_command(command_t *command);
/* build the queue of commands */
command_t *create_command(char separator, char **command);
char **strtow(char *str, char *delims);
int is_delim(char ch, char *delims);
queue_t *create_queue();
/* using our queue */
int enqueue(queue_t *q, char separator, char **command);
command_t *dequeue(queue_t *q);
void print_queue(queue_t *q);
/* history queue */
history_t *create_history_t(char *command, int set_p_no);
void free_history_node(history_t *node);
void free_history_queue(his_q_t *q);
/* history enqueue/dequeue */
his_q_t *get_history();
his_q_t *create_h_queue();
int h_enqueue(his_q_t *q, char *command);
history_t *h_dequeue(his_q_t *q);
void write_h_queue(his_q_t *q, int fd);
/* writing/loading history file */
void write_queue_to_file(his_q_t *q, char **env);
/* custom functions for custom commands */
void exit_shell(his_q_t *his_q, queue_t *q, int status, char **env);
int print_env(char *envp[]);
/* handling signals */
void signal_handler(int sig_no);
int register_signal_handlers(void);
/* custom stdlib */
int _atoi(char *str);
int _strlen(char *str);
char *get_int(int num);
char *_getenv(char *env_name, char **environ);
char *combine_path(char *dir, char *file);
/* print errors */
void print_no_file_error(char *executable_name);
void print_perm_denied(char *executable_name);
void print_signal_reg_error(void);
void print_prompt(void);
void print_newline(void);
#endif /* _SHELL_H_ */