forked from unitpoint/objectscript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
46 lines (34 loc) · 952 Bytes
/
main.cpp
File metadata and controls
46 lines (34 loc) · 952 Bytes
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
#include "objectscript.h"
#include <histedit.h>
#include <stdio.h>
#ifndef OS_HISTORY_SIZE
#define OS_HISTORY_SIZE 1000
#endif /* !OS_HISTORY_SIZE */
static char*
prompt_cb(EditLine*)
{
static char promptstr[] = "(os) ";
return promptstr;
}
int main(int argc, char *argv[])
{
HistEvent hevent;
History *hh(history_init());
history(hh, &hevent, H_SETUNIQUE, 1);
history(hh, &hevent, H_SETSIZE, OS_HISTORY_SIZE);
EditLine *el(el_init("os", stdin, stdout, stderr));
el_set(el, EL_SIGNAL, 1);
el_set(el, EL_EDITOR, "emacs");
el_set(el, EL_PROMPT, prompt_cb);
el_set(el, EL_HIST, history, hh);
ObjectScript::OS *shell(ObjectScript::OS::create());
const char *line = NULL;
int linelen = -1;
while ((line = el_gets(el, &linelen)) && linelen > 0) {
shell->eval(line);
history(hh, &hevent, H_ENTER, line);
}
el_end(el);
history_end(hh);
shell->release();
}