-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.c
55 lines (42 loc) · 944 Bytes
/
test.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
#include "src/repl.h"
repl_session_opts opts;
static char *
eval (repl_session_t *sess, char *buf);
static void
print (repl_session_t *sess, char *buf);
static void
error (repl_session_t *sess, char *err);
int
main (void) {
int rc;
// opts
opts.prompt = "repl>";
opts.eval_cb = eval;
opts.print_cb = print;
opts.error_cb = error;
// initiate
repl_session_t *sess = repl_session_new(&opts);
// start
rc = repl_session_start(sess);
// destroy
repl_session_destroy(sess);
printf("\n");
return (-1 == rc || 0 == rc)? 0 : rc;
}
static char *
eval (repl_session_t *sess, char *buf) {
// got nothing
if (feof(sess->stdin)) sess->rc = 0;
else return buf;
return NULL;
}
static void
print (repl_session_t *sess, char *buf) {
fprintf(sess->stdout, "%s", buf);
repl_loop(sess);
}
static void
error (repl_session_t *sess, char *err) {
fprintf(sess->stderr, "error: '%s'\n", err);
repl_loop(sess);
}