-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
75 lines (62 loc) · 1.44 KB
/
main.c
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
#include <stdio.h>
#include <stdlib.h>
#include "global.h"
#include "REPL/setup.h"
#include "REPL/prompt.h"
#include "REPL/parse.h"
#include "REPL/read.h"
#include "REPL/execute.h"
#include "UTILS/memmy.h"
#include "main.h"
/* Global const defines */
const char* EXIT = "exit";
const char* ECHO = "echo";
const char* ETIME = "etime";
const char* LIMITS = "limits";
const char* EXPORT = "export";
const char* CD = "cd";
const char* _DELIMS = " \n";
const char* _PIPES = "|<>";
const char* PREV_DIR_I = "..";
const char* PREV_DIR_II = "./";
const char* ARGS = "ARGS";
const int ACOLS = 255;
/* Globals */
char* cuser;
int margc = 1;
int run = 1;
int exec = 1;
int runbg = 0;
pid_t bgproc = 0;
/* ALL EXITING TASKS DONE HERE */
int exit_shell(){
return purge_memmy();
}
int main(int argc, char* args[])
{
char *line;
char cmd[255][255];
if(!init_memmy()) return 1; /* Address Mem intialization*/
cuser = set_string(255); /* User handle */
cuser = getenv("USER");
line = set_string(255); /* current command line init */
while(run)
{
shell_loop(line, cmd);
}
return exit_shell();
}
int shell_loop(char * line, char cmd[255][255]) {
_setup(cmd);
_prompt();
if(_read(line)){
/* Transform input
Match against patterns */
_parse(line, cmd);
if (exec) _execute(cmd);
/* cleanup */
} else {
run = 0;
}
return 0;
}