-
Notifications
You must be signed in to change notification settings - Fork 36
/
Copy pathmain.cpp
67 lines (60 loc) · 1.23 KB
/
main.cpp
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
#include "config.h"
#include <iostream>
#include <sstream>
#include <vector>
#include <string>
#include <time.h>
extern "C" {
#include "cafe_shell.h"
#include <utils_string.h>
}
#include "cafe_commands.h"
#include "Globals.h"
#ifdef HAVE_READLINE_HISTORY_H
#include <readline/history.h>
#endif
#ifdef HAVE_READLINE_READLINE_H
#include <readline/readline.h>
#endif
const char* __date__ = __DATE__;
int main(int argc, char* argv[])
{
//int i = 0;
Globals globals;
srand((unsigned int)time(NULL));
int shell = 0;
if ( argc == 2 )
{
std::vector<std::string> tokens;
if (strcmp(argv[1], "-v") == 0 || strcmp(argv[1], "--version") == 0)
{
write_version(std::cout);
}
else
{
tokens.push_back(argv[0]);
tokens.push_back(argv[1]);
cafe_cmd_source(globals, tokens);
cafe_cmd_exit(globals, tokens);
}
}
else
{
while(shell != CAFE_SHELL_EXIT )
{
#if defined(HAVE_READLINE_HISTORY_H) && defined(HAVE_READLINE_READLINE_H)
char *prompt = readline("# ");
if (prompt == NULL)
return -1;
add_history(prompt);
#else
char prompt[STRING_BUF_SIZE];
printf("%s", "# ");
if (!fgets(prompt,STRING_BUF_SIZE,stdin))
return -1;
#endif
shell = cafe_shell_dispatch_command(globals, prompt);
}
}
return 0;
}