static void* shell_init(CTX ctx, const char *msg, const char *optstr) { fputs(msg, stdout); CTX_setInteractive(ctx, 1); CTX_setDebug(ctx, 1); return NULL; // nostatus }
static int konoha_shell(CTX ctx, char *optstr) { KONOHA_BEGIN(ctx); knh_loadScriptPackageList(ctx, "konoha.i?"); #ifdef K_USING_SECURITY_ALERT knh_askSecurityAlert(ctx); #endif CTX_setInteractive(ctx, 1); knh_shell(ctx); KONOHA_END(ctx); return 0; }
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; }
static void shell_cleanup(CTX ctx, void *status) { CTX_setInteractive(ctx, 0); }