|
@@ -744,48 +744,22 @@ static int run_duktape(const char *file_name)
|
|
char idx;
|
|
char idx;
|
|
int ch;
|
|
int ch;
|
|
|
|
|
|
|
|
+#ifdef WIN32
|
|
|
|
+ (void)MakeConsole();
|
|
|
|
+#endif
|
|
|
|
+
|
|
ctx = duk_create_heap_default();
|
|
ctx = duk_create_heap_default();
|
|
if (!ctx) {
|
|
if (!ctx) {
|
|
fprintf(stderr, "Failed to create a Duktape heap.\n");
|
|
fprintf(stderr, "Failed to create a Duktape heap.\n");
|
|
- exit(1);
|
|
|
|
|
|
+ goto finished;
|
|
}
|
|
}
|
|
|
|
|
|
if (duk_peval_file(ctx, file_name) != 0) {
|
|
if (duk_peval_file(ctx, file_name) != 0) {
|
|
- fprintf(stderr, "Error: %s\n", duk_safe_to_string(ctx, -1));
|
|
|
|
|
|
+ fprintf(stderr, "%s\n", duk_safe_to_string(ctx, -1));
|
|
goto finished;
|
|
goto finished;
|
|
}
|
|
}
|
|
duk_pop(ctx); /* ignore result */
|
|
duk_pop(ctx); /* ignore result */
|
|
|
|
|
|
- memset(line, 0, sizeof(line));
|
|
|
|
- idx = 0;
|
|
|
|
- for (;;) {
|
|
|
|
- if (idx >= sizeof(line)) {
|
|
|
|
- fprintf(stderr, "Line too long\n");
|
|
|
|
- exit(1);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- ch = fgetc(stdin);
|
|
|
|
- if (ch == 0x0a) {
|
|
|
|
- line[idx++] = '\0';
|
|
|
|
-
|
|
|
|
- duk_push_global_object(ctx);
|
|
|
|
- duk_get_prop_string(ctx, -1 /*index*/, "processLine");
|
|
|
|
- duk_push_string(ctx, line);
|
|
|
|
- if (duk_pcall(ctx, 1 /*nargs*/) != 0) {
|
|
|
|
- fprintf(stderr, "Error: %s\n", duk_safe_to_string(ctx, -1));
|
|
|
|
- } else {
|
|
|
|
- fprintf(stdout, "%s\n", duk_safe_to_string(ctx, -1));
|
|
|
|
- }
|
|
|
|
- duk_pop(ctx); /* pop result/error */
|
|
|
|
-
|
|
|
|
- idx = 0;
|
|
|
|
- } else if (ch == EOF) {
|
|
|
|
- break;
|
|
|
|
- } else {
|
|
|
|
- line[idx++] = (char)ch;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
finished:
|
|
finished:
|
|
duk_destroy_heap(ctx);
|
|
duk_destroy_heap(ctx);
|
|
|
|
|
|
@@ -981,6 +955,7 @@ static void start_civetweb(int argc, char *argv[])
|
|
/* Call Duktape, if -E option is specified */
|
|
/* Call Duktape, if -E option is specified */
|
|
if (argc > 1 && !strcmp(argv[1], "-E")) {
|
|
if (argc > 1 && !strcmp(argv[1], "-E")) {
|
|
|
|
|
|
|
|
+ fprintf(stdout, "asd\n");
|
|
#ifdef USE_DUKTAPE
|
|
#ifdef USE_DUKTAPE
|
|
if (argc != 3) {
|
|
if (argc != 3) {
|
|
show_usage_and_exit(argv[0]);
|
|
show_usage_and_exit(argv[0]);
|