-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathforce_cmdline_param.patch
179 lines (179 loc) · 4.08 KB
/
force_cmdline_param.patch
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
21a22,27
> #undef HAVE_LIBREADLINE
> #undef HAVE_READLINE_READLINE_H
> #undef HAVE_READLINE_HISTORY_H
>
> #include <emscripten/emscripten.h>
> #include <assert.h>
38a45
> FILE* query_file = 0;
117d123
< dl_free(a);
131c137
< printf("\n"); /* Print zero arity predicate. */
---
> printf("%% TSV \n"); /* Print zero arity predicate. */
133a140
> printf("%% TSV ");
144d150
< dl_free(a);
155,158c161,164
< if (print_as_tsv)
< return print_answers_as_tab_separated_values(a);
< else
< return print_answers_as_datalog(a);
---
> int rc = print_answers_as_tab_separated_values(a) |
> (print_answers_as_datalog(a) << 16);
> dl_free(a);
> return rc;
252,254c258,260
< fputs(prompt, stdout); /* Show prompt */
< fflush(stdout); /* then get a line */
< buf = fgets(lb->buffer, LINE_SIZE, stdin);
---
> //fputs(prompt, stdout); /* Show prompt */
> //fflush(stdout); /* then get a line */
> buf = fgets(lb->buffer, LINE_SIZE, query_file);
268c274,277
< else if (!nofiles && buf[0] == '=') { /* File loading requested. */
---
> if (buf != 0) { printf("%% QUERY %s", buf); // incl newline
> if (buf[strlen(buf)-1] != '\n') puts("");
> }
> if (!nofiles && buf[0] == '=') { /* File loading requested. */
320,321c329,330
< if (package != NULL) /* Show welcome message. */
< printf("%s %s\n\n", package, version);
---
> // if (package != NULL) /* Show welcome message. */
> // printf("%s %s\n\n", package, version);
353,354c362,373
< int
< main(int argc, char **argv)
---
> void write_file(char* path, char* from, unsigned int len) {
> FILE* fp = fopen(path, "w");
> if(!fp) fprintf(stderr, "could not open");
> while (len--) {
> //putchar(*from);
> fwrite(from++, 1, 1, fp);
> }
> fclose(fp);
> }
>
> void
> johnmandog(char* data, int size)
356,357c375,380
< extern char *optarg;
< extern int optind;
---
> freopen( "file.txt", "w", stdout );
>
> unsigned int s1 = *((unsigned int*) (data+0));
> unsigned int s2 = *((unsigned int*) (data+4));
> unsigned int s3 = *((unsigned int*) (data+8));
> //printf("%d %d %d\n", s1, s2, s3);
359,362c382,390
< int interact = 0;
< char *input = NULL;
< char *output = NULL;
< char *lua = NULL;
---
> char* lua = "/lib.lua";
> char* input = "/datalog.dl";
> char* q_f = "/queries.dl";
>
> write_file(lua, data+12, s1);
> write_file(input, data+12+s1, s2);
> write_file(q_f, data+12+s1+s2, s3);
>
> query_file = fopen(q_f,"r");
369,404d396
< for (;;) {
< int c = getopt(argc, argv, "o:il:tvh");
< if (c == -1)
< break;
< switch (c) {
< case 'o':
< output = optarg;
< break;
< case 'i':
< interact = 1;
< break;
< case 'l':
< lua = optarg;
< break;
< case 't':
< print_as_tsv = 1;
< break;
< case 'v':
< print_version(argv[0]);
< return 0;
< case 'h':
< usage(argv[0]);
< return 0;
< default:
< usage(argv[0]);
< return 1;
< }
< }
<
< switch (argc - optind) {
< case 0: /* Use stdin */
< interact = 1;
< break;
< case 1:
< input = argv[optind];
< if (strcmp(STDIN_NAME, input)) {
408c400,402
< return 1;
---
> rc = 9003;
> emscripten_worker_respond(&rc, 4);
> return;
410,423d403
< }
< else
< in = stdin;
< break;
< default:
< fprintf(stderr, "Bad arg count\n");
< usage(argv[0]);
< return 1;
< }
<
< if (output && !freopen(output, "w", stdout)) {
< perror(output);
< return 1;
< }
428c408,410
< return 1;
---
> rc = 9002;
> emscripten_worker_respond(&rc, 4);
> return;
431d412
< if (lua) { /* Load Lua extensions if present */
439c420,421
< return 1;
---
> emscripten_worker_respond(&rc, 4);
> return;
441d422
< }
446c427,428
< if (interact && !rc)
---
> if (rc) fprintf(stderr, "err loading\n");
> if (!rc)
449c431,437
< return rc;
---
>
> int c;
> FILE* fp = fopen("file.txt", "r");
> while ((c = getc(fp)) != EOF) emscripten_worker_respond_provisionally(&c, 1);
> fclose(fp);
>
> emscripten_worker_respond(&rc, 4);