-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
70 lines (65 loc) · 1.15 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
#include <stdio.h>
#include <fastdb.h>
#include <string.h>
char *help = "\ncommands:"
"\n -read"
"\n -write"
"\n -delete"
"\n -point"
"\n -rename"
"\n -tree"
"\n -defragment"
"\n -setperms"
"\n -server"
"\n\n";
int main(int argct, char **arge)
{
if (argct > 1 && (!strcmp(arge[1], "-help") || !strcmp(arge[1], "--help")))
{
printf("%s", help);
return 0;
}
else
input_file_path = arge[1];
if (argct > 2 && !strcmp(arge[2], "-console"))
{
printf("FastDB Version 1.0.0\n");
runType = CMD_LINE;
initArgs();
argct--;
char buff[1024];
char *argv[10];
for (int i = 0; arge[i] != NULL; i++)
{
argv[i] = arge[i];
}
for (;;)
{
char *line = buff;
printf("\nfastdb:> ");
scanf("%[^\n]%*c", line);
int argc = argct;
argv[argc] = strtok(line, " ");
while (argv[argc] != NULL)
{
argc++;
argv[argc] = strtok(NULL, " ");
}
startDB(argc, argv);
}
}
else if (argct > 2 && !strcmp(arge[2], "-server"))
{
runType = SINGLE_EXEC;
initArgs();
smain(argct, arge);
}
else
{
runType = SINGLE_EXEC;
initArgs();
startDB(argct, arge);
}
printf("\n");
return 0;
}