forked from zserge/partcl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tcl.c
61 lines (46 loc) · 1021 Bytes
/
tcl.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
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "tcl.h"
#ifndef TCL_TEST
#ifdef TCL_STANDALONE
#define CHUNK 1024
int main() {
struct tcl tcl;
int buflen = CHUNK;
char* buf = malloc(buflen);
int i = 0;
tcl_init(&tcl);
while (1) {
int inp = fgetc(stdin);
if (i > buflen - 1)
buf = realloc(buf, buflen += CHUNK);
if (inp == 0 || inp == EOF)
break;
buf[i++] = inp;
tcl_each(buf, i, 1) {
if (p.token == TERROR && (p.to - buf) != i) {
memset(buf, 0, buflen);
i = 0;
} else if (p.token == TCMD && *(p.from) != '\0') {
int r = tcl_eval(&tcl, buf, strlen(buf));
if (r != FERROR) {
printf("result> %.*s\n", tcl_length(tcl.result),
tcl_string(tcl.result));
} else {
printf("?!\n");
}
memset(buf, 0, buflen);
i = 0;
break;
}
}
}
if(i) {
printf("incomplete input\n");
return -1;
}
return 0;
}
#endif
#endif