//main(void) int main(int argc, char *argv[]) { // FIXME: a truly embedded version will not parse command line // arguments. The accessor code will be compiled in. const char *accessorFileName; duk_context *ctx = NULL; int i; int timeout = -1; int foundFile = 0; // Create duktape environment ctx = duk_create_heap_default(); // Register Modules eventloop_register(ctx); // FIXME: fileio_register() should go away eventually. //fileio_register(ctx); modSearch_register(ctx); nofileio_register(ctx); for (i = 1; i < argc; i++) { char *arg = argv[i]; if (!arg) { goto usage; } if (strcmp(arg, "--timeout") == 0) { if (i == argc - 1) { goto usage; } i++; timeout = atoi(argv[i]); } else { foundFile = 1; accessorFileName = arg; } } int returnValue = 0; if (foundFile == 1) { fprintf(stderr, "eduk: About to run %s\n", accessorFileName); returnValue = runAccessorHost(ctx, accessorFileName, timeout); } else { fprintf(stderr, "eduk: No file passed as a command line argument?"); returnValue = 1; } duk_destroy_heap(ctx); return returnValue; usage: duk_destroy_heap(ctx); fprintf(stderr, "Usage: eduk [--timeout time] accessorFileName\n"); return 1; }
int main(int argc, char *argv[]) { duk_context *ctx = NULL; int retval = 0; const char *filename = NULL; int i; #ifndef NO_SIGNAL set_sigint_handler(); /* This is useful at the global level; libraries should avoid SIGPIPE though */ /*signal(SIGPIPE, SIG_IGN);*/ #endif for (i = 1; i < argc; i++) { char *arg = argv[i]; if (!arg) { goto usage; } if (strcmp(arg, "-c") == 0) { c_evloop = 1; } else if (strlen(arg) > 1 && arg[0] == '-') { goto usage; } else { if (filename) { goto usage; } filename = arg; } } if (!filename) { goto usage; } ctx = duk_create_heap_default(); poll_register(ctx); ncurses_register(ctx); socket_register(ctx); fileio_register(ctx); if (c_evloop) { fprintf(stderr, "Using C based eventloop (omit -c to use Ecmascript based eventloop)\n"); fflush(stderr); eventloop_register(ctx); duk_eval_file(ctx, "c_eventloop.js"); } else { fprintf(stderr, "Using Ecmascript based eventloop (give -c to use C based eventloop)\n"); fflush(stderr); duk_eval_file(ctx, "ecma_eventloop.js"); } fprintf(stderr, "Executing code from: '%s'\n", filename); fflush(stderr); if (strcmp(filename, "-") == 0) { if (handle_stdin(ctx) != 0) { retval = 1; goto cleanup; } } else { if (handle_file(ctx, filename) != 0) { retval = 1; goto cleanup; } } cleanup: if (ctx) { duk_destroy_heap(ctx); } return retval; usage: fprintf(stderr, "Usage: evloop [-c] <filename>\n"); fprintf(stderr, "\n"); fprintf(stderr, "Uses an Ecmascript based eventloop (ecma_eventloop.js) by default.\n"); fprintf(stderr, "If -c option given, uses a C based eventloop (c_eventloop.{c,js}).\n"); fprintf(stderr, "If <filename> is '-', the entire STDIN executed.\n"); fflush(stderr); exit(1); }