-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathshell.h
162 lines (142 loc) · 3.7 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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
#ifndef SHELL
#define SHELL
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <signal.h>
#include <string.h>
#include <sys/wait.h>
#include <sys/types.h>
#include <ctype.h>
#include <errno.h>
#include <sys/stat.h>
#include <fcntl.h>
#define HSTRYLIMIT 4096
#define BUFRSIZE 1024
#define UNUSED(x) (void)(x)
#define RESET "\033[0m"
#define BLK "\033[30m"
#define RED "\033[31m"
#define GRN "\033[32m"
#define YLW "\033[33m"
#define BLU "\033[34m"
#define MAG "\033[35m"
#define CYN "\033[36m"
#define WHI "\033[37m"
#define BBLK "\033[1m\033[30m"
#define BRED "\033[1m\033[31m"
#define BGRN "\033[1m\033[32m"
#define BYLW "\033[1m\033[33m"
#define BBLU "\033[1m\033[34m"
#define BMAG "\033[1m\033[35m"
#define BCYN "\033[1m\033[36m"
#define BWHI "\033[1m\033[37m"
/**
* struct in_built - define a struct for builtins
* @s: pointer to commands
* @func: pointer to command function
**/
typedef struct in_built
{
char *s;
void (*func) (char **);
} in_built;
/**
* struct alias - define a struct for saving alias in a linkedlist
* @key: alias name
* @value: alias value
* @next: pointer to next alias
**/
typedef struct alias
{
char *key;
char *value;
struct alias *next;
} alias;
/**
* struct hstory - define a struct for saving history in a linkedlist
* @input: user input
* @next: pointer to next history node
**/
typedef struct hstory
{
char *input;
struct hstory *next;
} hstory;
/**
* struct help_struct - define a struct for commands help page
* @cmd: builtin command
* @synopsis: description of command
* @func: pointer to command functions
**/
typedef struct help_struct
{
char *cmd;
char *synopsis;
void (*func) ();
} help_struct;
/**
* struct save_mem - define a struct for saving refernces to allocated memory
* @loc: address of memory area
* @next: pointer to next memory area
**/
typedef struct save_mem
{
void *loc;
struct save_mem *next;
} save_mem;
hstory **getHistoryHead(void);
alias **getAliasHead(void);
ssize_t _getline(char **lineptr, int fd);
char *linep_withoutspaces(char *line);
char **tokenize(char *lineptr, char dlimtr);
char **parse_path(char *path, char dlimtr);
int find_builtins(char **tokens);
void check_path(char **tokens, char *p);
void excute(char **tokens);
void promptUser(void);
int _strlen(char *str);
char *_strcpy(char *strng, int i);
int _strcmp(char *s1, char *s2);
char *_strcat2(char *s1, char *s2);
char *_strcat(char *str1, char *str2, char formatter);
void _puts(char *buffer);
void _putchar(char c);
void _puts_num(int n);
int _atoi(char *s);
char **deepDupe(char **args);
void *_realloc(void *ptr, unsigned int old_size, unsigned int new_size);
int add_mem(void **p, save_mem **head);
int remove_child_mem(void **p, save_mem **head);
int remove_mem(void **p, save_mem **head);
int _ref_mem(void *p, char *action);
void *_malloc(unsigned int size);
void _free(void *ptr);
void alias_data(void);
void cd_data(void);
void env_data(char *cmd);
void exit_data(void);
void help_data(void);
void history_data(void);
void setenv_data(void);
void unsetenv_data(void);
void whichAlias(char **tokens);
alias *resetAlias(alias **head, char *key, char *value);
alias *addAlias(alias **head, char *key, char *value);
void printAlias(alias **head);
alias *findAlias(alias **head, char *key);
alias *find_aliasToalias(alias **head, char *key);
void chng_dr(char **str);
void ext(char **str);
void hlp(char **str);
int checkEnv(char *name);
char *_getenv(char *name);
void _setenv(char **str);
void _unsetenv(char **str);
void printEnv(char **str);
hstory *addHistory(hstory **head, char *input, int *nodeCount);
hstory *popHead(hstory **head, int *nodeCount);
int readFromFile(char *file, hstory **head, int *nodeCount);
int writeHstorytofile(char *file);
void printHistory(char **str);
#endif