Repository navigation
Expand file tree
/
Copy pathcmd_parse.h
More file actions
72 lines (60 loc) · 1.64 KB
/
Copy pathcmd_parse.h
File metadata and controls
72 lines (60 loc) · 1.64 KB
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
//cmd_parse.h
//Drake Wheeler
#ifndef _CMD_PARSE_H
# define _CMD_PARSE_H
# define MAX_STR_LEN 2000
# define CD_CMD "cd"
# define CWD_CMD "cwd"
# define ECHO_CMD "echo"
# define BYE_CMD "bye"
# define HISTORY_CMD "history"
# define PIPE_DELIM "|"
# define SPACE_DELIM " "
# define REDIR_IN "<"
# define REDIR_OUT ">"
//# define BACKGROUND_CHAR "&"
# define PROMPT_STR "PSUsh"
// This enumeration is used when determining if the re direction
// characters (the < and >) were used on a command.
typedef enum {
REDIRECT_NONE
, REDIRECT_FILE
, REDIRECT_PIPE
, BACKGROUND_PROC
} redir_t;
// A list of param_t elements.
typedef struct param_s {
char *param;
struct param_s *next;
} param_t;
// A linked list that has a linked list as a member.
typedef struct cmd_s {
char *raw_cmd;
char *cmd;
int param_count;
param_t *param_list;
redir_t input_src;
redir_t output_dest;
char *input_file_name;
char *output_file_name;
int list_location; // zero based
struct cmd_s *next;
} cmd_t;
typedef struct cmd_list_s {
cmd_t *head;
cmd_t *tail;
int count;
} cmd_list_t;
void parse_commands(cmd_list_t *cmd_list);
void free_list(struct cmd_list_s *);
void print_list(struct cmd_list_s *);
void free_cmd(struct cmd_s *);
void print_cmd(struct cmd_s *);
void exec_commands(cmd_list_t *cmds);
int process_user_input_simple(void);
void simple_argv(int argc, char *argv[]);
void display_history(void);
void update_history(const char* new_command);
void execute_external_command(cmd_t* cmd, cmd_list_t* cmd_list);
void sigint_handler(__attribute__ ((unused)) int sig);
#endif // _CMD_PARSE_H