int main(int argc, char *argv[]) { kbool_t ret = 1; int scriptidx = konoha_ginit(argc, argv); if(builtin_test != NULL) { return konoha_builtintest(builtin_test); } if(test_script != NULL) { return konoha_test(test_script); } konoha_t konoha = konoha_open(); if(preimport != NULL) { konoha_preimport((CTX_t)konoha, preimport); } if(startup_script != NULL) { konoha_startup(konoha, startup_script); } if(scriptidx < argc) { ret = konoha_load(konoha, argv[scriptidx]); } if(ret && interactive_flag) { ret = konoha_shell(konoha); } konoha_close(konoha); MODGC_check_malloced_size(); return ret ? konoha_AssertResult: 1; }
int konoha_main(konoha_t konoha, int argc, const char **argv) { CTX ctx = (CTX)konoha; int i, ret = 0, n = knh_parseopt(ctx, argc, argv); knh_linkDynamicReadline(ctx); knh_linkDynamicRegex(ctx); knh_linkDynamicIconv(ctx); for (i = 0; konoha_modules[i].init != NULL; ++i) { konoha_modules[i].init(argc, n, argv); } argc = argc - n; argv = argv + n; if(isActorMode) { char portstr[6] = {0}; knh_snprintf(portstr, sizeof(portstr), "%d", port); const char *argv_actor[3] = {"actsrv", portstr, NULL}; argc = 2; argv = argv_actor; } knh_parsearg(ctx, argc, argv); if(argc == 0) { ret = konoha_shell(ctx, NULL); } else if(isMPIMode) { kMPI_argv0 = argv[0]; knh_loadPackage(ctx, STEXT("konoha.mpi")); knh_eval(ctx, "using konoha.mpi.*; int main(String[] args) { new TaskScript().exec(MPI.vload()); MPI.vmainloop(); return 0 }", 1, NULL); ret = knh_runMain(ctx, argc, argv); } else { if(knh_startScript(ctx, argv[0]) == K_CONTINUE && !knh_isCompileOnly(ctx)) { ret = knh_runMain(ctx, argc, argv); if(isInteractiveMode) { konoha_shell(ctx, NULL); } } } for (i = 0; konoha_modules[i].exit != NULL; ++i) { konoha_modules[i].exit(); } return ret; }
int konoha_main(konoha_t konoha, int argc, const char **argv) { CTX ctx = (CTX)konoha; int i, ret = 0, n = knh_parseopt(ctx, argc, argv); knh_linkDynamicReadline(ctx); knh_linkDynamicRegex(ctx); knh_linkDynamicIconv(ctx); for (i = 0; konoha_modules[i].init != NULL; ++i) { konoha_modules[i].init(argc, n, argv); } argc = argc - n; argv = argv + n; if(isActorMode) { char portstr[6] = {0}; knh_snprintf(portstr, sizeof(portstr), "%d", port); const char *argv_actor[3] = {"actsrv", portstr, NULL}; argc = 2; argv = argv_actor; } knh_parsearg(ctx, argc, argv); if(argc == 0) { ret = konoha_shell(ctx, NULL); } else { if(knh_startScript(ctx, argv[0]) == K_CONTINUE && !knh_isCompileOnly(ctx)) { ret = knh_runMain(ctx, argc, argv); if(isInteractiveMode) { konoha_shell(ctx, NULL); } } } for (i = 0; konoha_modules[i].exit != NULL; ++i) { konoha_modules[i].exit(); } return ret; }
static int konoha_parseopt(konoha_t konoha, kplatform_t *plat, int argc, char **argv) { int ret = true, scriptidx = 0; while (1) { int option_index = 0; int c = getopt_long (argc, argv, "icD:I:S:", long_options2, &option_index); if (c == -1) break; /* Detect the end of the options. */ switch (c) { case 0: /* If this option set a flag, do nothing else now. */ if (long_options2[option_index].flag != 0) break; printf ("option %s", long_options2[option_index].name); if (optarg) printf (" with arg %s", optarg); printf ("\n"); break; case 'c': { compileonly_flag = 1; CTX_setCompileOnly(konoha); } break; case 'i': { interactive_flag = 1; CTX_setInteractive(konoha); } break; case 'B': return konoha_builtintest(konoha, optarg); case 'D': konoha_define(konoha, optarg); break; case 'I': konoha_import(konoha, optarg); break; case 'S': konoha_startup(konoha, optarg); break; case 'T': // DUMP_P ("option --test-with `%s'\n", optarg); verbose_debug = 0; verbose_sugar = 0; verbose_gc = 0; verbose_code = 0; plat->dbg_p = NOP_dbg_p; plat->printf_i = TEST_printf; plat->vprintf_i = TEST_vprintf; plat->begin = TEST_begin; plat->end = TEST_end; return konoha_test(konoha, optarg); case '?': /* getopt_long already printed an error message. */ break; default: return 1; } } scriptidx = optind; konoha_commandline(konoha, argc - scriptidx, argv + scriptidx); if(scriptidx < argc) { ret = konoha_load(konoha, argv[scriptidx]); } else { interactive_flag = 1; CTX_setInteractive(konoha); } if(ret && interactive_flag) { konoha_import(konoha, "konoha.i"); ret = konoha_shell(konoha); } return (ret == true) ? 0 : 1; }