-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
112 lines (90 loc) · 2.37 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
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
/* References
* http://stackoverflow.com/questions/8390356/c-command-line-arguments-eclipse-cdt
*
*
*
* */
#include <stdio.h>
#include <stdlib.h>
#include "main.h"
#include "global.h"
#include "REPL/repl.h"
#include "REPL/parse.h"
#include "UTILS/memmy.h"
#include "UTILS/utils.h"
/* Commands */
const char* OPEN = "open";
const char* CLOSE = "close";
const char* CREATE = "create";
const char* SIZE = "size";
const char* RM = "rm";
const char* CD = "cd";
const char* LS = "ls";
const char* MKDIR = "mkdir";
const char* RMDIR = "rmdir";
const char* READ = "read";
const char* WRITE = "write";
const char* EXIT = "exit";
/* Global const defines */
const char* _DELIMS = " \n";
const char* PREV_DIR = "..";
const char* CUR_DIR = ".";
const char* ARGS = "ARGS";
const int ACOLS = 255;
/* Globals */
char* cuser;
int margc = 1;
int run = 1;
int exec = 1;
struct fatcat fatcat;
/* File System Globals */
unsigned int BPB_BytesPerSec = 0;
unsigned char BPB_SecPerClus = 0;
unsigned short BPB_RsvdSecCnt = 0;
unsigned char BPB_NumFATs = 0;
unsigned short BPB_RootEntCnt = 0;
unsigned short BPB_TotSec16 = 0;
unsigned int BPB_HiddSec = 0;
unsigned int BPB_TotSec32 = 0;
unsigned int BPB_FATSz32 = 0;
unsigned short BPB_ExtFlags = 0;
unsigned int BPB_FSVer = 0;
unsigned int BPB_RootClus = 0;
unsigned int BPB_FSInfo = 0;
unsigned int BPB_BkBootSec = 0;
unsigned int BPB_Reserved[3] = {0,0,0};
unsigned int BS_DrvNum = 0;
unsigned int BS_Reserved1 = 0;
unsigned int BS_BootSig = 0;
unsigned int BS_VolID = 0;
unsigned char BS_VolLab[11] = {0};
unsigned char BS_FilSysType[8] = {0};
struct directory OPENFILES[2048] = { 0 };
/* ALL EXITING TASKS DONE HERE */
int exit_shell(){
return purge_memmy();
}
int main(int argc, char* args[])
{
char *line;
char cmd[255][255];
fatcat.img = fopen(args[1], "r+"); /* opens file system*/
if(!init_memmy()) return 1; /* Address Mem initialization*/
if(LoadImage(fatcat.img)) return 2; /* File system initialization*/
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)){
_parse(line, cmd);
if (exec) _execute(cmd);
} else {
run = 0;
}
return 0;
}