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; }
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; }