Esempio n. 1
0
static void knh_shell(CTX ctx)
{
	void *shell_status = NULL;
	BEGIN_LOCAL(ctx, lsfp, 2);
//	LOCAL_NEW(ctx, lsfp, 0, kInputStream *, bin, new_BytesInputStream(ctx, new_Bytes(ctx, "shell", K_PAGESIZE)));
	{
		CWB_t cwbbuf, *cwb = CWB_open(ctx, &cwbbuf);
		knh_showWelcome(ctx, cwb->w);
		knh_showSecurityAlert(ctx, cwb->w);
		shell_status = shell_init(ctx, CWB_totext(ctx, cwb), NULL);
		CWB_close(ctx, cwb);
	}
	while(1) {
		{
			CWB_t cwbbuf, *cwb = CWB_open(ctx, &cwbbuf);
			kstatus_t status = readstmt(ctx, cwb);
			if(status == K_BREAK) {
				CWB_close(ctx, cwb);
				break;
			}
			if(CWB_size(cwb) == 0) {
				CWB_close(ctx, cwb);
				continue;
			}
			status = shell_command(ctx, CWB_totext(ctx, cwb));
			if(status == K_BREAK) {
				CWB_close(ctx, cwb);
				break;
			}
			if(status == K_REDO) {
				CWB_close(ctx, cwb);
				continue;
			}
#ifdef K_USING_SUGAR
			kString *script = CWB_newString(ctx, cwb, 0);
			KNH_SETv(ctx, lsfp[0].o, script);
			knh_beval2(ctx, S_totext(script), 1);
#else
			kInputStream *bin = new_BytesInputStream(ctx, CWB_totext(ctx, cwb), CWB_size(cwb));
			KNH_SETv(ctx, lsfp[0].o, bin);
			knh_beval(ctx, bin, 1);
#endif
		}
		knh_OutputStream_flush(ctx, ctx->out);
		if(ctx->isEvaled == 1) {
			CWB_t cwbbuf, *cwb = CWB_open(ctx, &cwbbuf);
			knh_write_Object(ctx, cwb->w, ctx->evaled, FMT_dump);
			knh_showSecurityAlert(ctx, cwb->w);
			if(CWB_size(cwb) !=0) {
				shell_display(ctx, shell_status, CWB_totext(ctx, cwb));
			}
			CWB_close(ctx, cwb);
			WCTX(ctx)->isEvaled = 0;
		}
	}
	shell_cleanup(ctx, shell_status);
	END_LOCAL(ctx, lsfp);
}
Esempio n. 2
0
void THROW_ParamTypeError(CTX ctx, ksfp_t *sfp, size_t n, kmethodn_t mn, kclass_t reqt, kclass_t cid)
{
	CWB_t cwbbuf, *cwb = CWB_open(ctx, &cwbbuf);
	char msg[256], mname[256];
	knh_printf(ctx, cwb->w, "Script!!: Type Error: %T.%M(#%d)", cid, mn, (int)n);
	knh_snprintf(msg, sizeof(msg), "%s", CWB_totext(ctx, cwb));
	CWB_close(ctx, cwb);
	knh_printf(ctx, cwb->w, "%C.%M", cid, mn);
	knh_snprintf(mname, sizeof(mname), "%s", CWB_totext(ctx, cwb));
	CWB_close(ctx, cwb);
	KNH_NTHROW2(ctx, sfp, msg, "konoha:type", K_FAILED, KNH_LDATA(LOG_msg(msg), LOG_s("method", mname), LOG_i("argument", n), LOG_t("requested_type", reqt), LOG_t("given_type", cid)));
}
Esempio n. 3
0
void THROW_NoSuchMethod(CTX ctx, ksfp_t *sfp, kclass_t cid, kmethodn_t mn)
{
	CWB_t cwbbuf, *cwb = CWB_open(ctx, &cwbbuf);
	char msg[256], mname[256];
	knh_printf(ctx, cwb->w, "Script!!: No Such Method: %T.%M", cid, mn);
	knh_snprintf(msg, sizeof(msg), "%s", CWB_totext(ctx, cwb));
	CWB_close(ctx, cwb);
	knh_printf(ctx, cwb->w, "%C.%M", cid, mn);
	knh_snprintf(mname, sizeof(mname), "%s", CWB_totext(ctx, cwb));
	CWB_close(ctx, cwb);
	KNH_NTHROW2(ctx, sfp, msg, "konoha:type", K_FAILED, KNH_LDATA(LOG_msg(msg), LOG_s("method", mname)));
}
Esempio n. 4
0
kString* knh_getPropertyNULL(CTX, kbytes_t key)
{
	if(knh_bytes_startsWith_(key, STEXT("env."))) {
		CWB_t cwbbuf, *cwb = CWB_open(_ctx, &cwbbuf);
		CWB_nzenvkey(_ctx, cwb, knh_bytes_last(key, 4));
		char *v = knh_getenv(CWB_totext(_ctx, cwb));
		CWB_close(_ctx, cwb);
		if(v == NULL) return NULL;
		return new_kString(v, knh_strlen(v), SPOL_ASCII|SPOL_POOL);
	}
	return (kString*)knh_DictMap_getNULL(_ctx,  ctx->share->props, key);
}
Esempio n. 5
0
static void load_codegenerator(CTX ctx)
{
    KONOHA_BEGIN(ctx);
    CompilerAPI_disable(ctx);
    if (codegenerator_file[compile_mode]) {
        kbytes_t t = new_bytes((char*)codegenerator_file[compile_mode]);
        knh_loadPackage(ctx, t);
        CWB_t cwbbuf, *cwb = CWB_open(ctx, &cwbbuf);
        kString *s = (kString *) knh_DictMap_getNULL(ctx, ctx->share->props, STEXT("konoha.package.path"));
        CWB_clear(cwb, 0);
        knh_buff_addpath(ctx, cwb->ba, cwb->pos, 0, S_tobytes(s));
        knh_buff_addpath(ctx, cwb->ba, cwb->pos, 1, STEXT("konoha.compiler"));
        knh_buff_addpath(ctx, cwb->ba, cwb->pos, 1, STEXT("compiler"));
        knh_buff_addpath(ctx, cwb->ba, cwb->pos, 0, STEXT(K_OSDLLEXT));
        void *p = knh_dlopen(ctx, CWB_totext(ctx, cwb));
        typedef void (*knh_Fpkgcomplete)(CTX);
        knh_Fpkgcomplete pkgcomplete = (knh_Fpkgcomplete) knh_dlsym(ctx, p, "reset_compiler_api", NULL, 1);
        if (pkgcomplete) pkgcomplete(ctx);
        CWB_close(ctx, cwb);
    }
    CompilerAPI_enable(ctx);
    KONOHA_END(ctx);
}
Esempio n. 6
0
void knh_System_initPath(CTX)
{
	CWB_t cwbbuf, *cwb = CWB_open(_ctx, &cwbbuf);
	kDictMap *sysprops = ctx->share->props;
	kbytes_t home = {{NULL}, 0}, user = {{NULL}, 0};

	// current working directory
	knh_buff_addospath(_ctx, cwb->ba, cwb->pos, 0, STEXT("."));
	KSETv(ctx->share->rootks->path, new_Path(_ctx, knh_buff_newRealPathString(_ctx, cwb->ba, cwb->pos)));

	home.text = (const char*)knh_getenv("KONOHAHOME");
#if defined(K_KONOHAHOME)
	if(home.text == NULL) {
		home.text = K_KONOHAHOME;
	}
#endif
	if(home.text != NULL) {
		home.len = knh_strlen(home.text);
		SETPROP("konoha.home.path", new_T(home.text));
	}
#if defined(K_USING_WINDOWS_)
	{
		char buf[K_PATHMAX];
		int bufsiz = K_PATHMAX;
		HMODULE h = LoadLibrary(NULL);
		GetModuleshortnameA(h, buf, bufsiz);
		CWB_clear(cwb, 0);
		knh_buff_addospath(_ctx, cwb->ba, cwb->pos, 0, B(buf));
		SETPROP("konoha.bin.path", knh_buff_newRealPathString(_ctx, cwb->ba, cwb->pos));
		if(home.text == NULL) {
			kString *s;
			CWB_clear(cwb, 0);
			knh_buff_addpath(_ctx, cwb->ba, cwb->pos, 0, B(buf));
			knh_buff_trim(_ctx, cwb->ba, cwb->pos, '\\');
			knh_buff_trim(_ctx, cwb->ba, cwb->pos, '\\');
			knh_buff_addospath(_ctx, cwb->ba, cwb->pos, 1/*isSep*/, STEXT("konoha"));
			s = CWB_newString(_ctx, cwb, 0);
			SETPROP("konoha.home.path", s);
			home = S_tobytes(s);
		}
	}
#elif defined(K_USING_LINUX_)
	// @url(http://shinh.skr.jp/binary/b2con.html)
	// http://doc.trolltech.com/3.3/qapplication.html#applicationDirPath
	{
		char buf[K_PATHMAX];
		int bufsiz = K_PATHMAX;
		ssize_t size = readlink("/proc/self/exe", buf, bufsiz);
		CWB_clear(cwb, 0);
		knh_buff_addospath(_ctx, cwb->ba, cwb->pos, 0, new_bytes2(buf, size));
		SETPROP("konoha.bin.path", knh_buff_newRealPathString(_ctx, cwb->ba, cwb->pos));
		if(home.text == NULL) {
			kString *s;
			CWB_clear(cwb, 0);
			knh_buff_addpath(_ctx, cwb->ba, cwb->pos, 0, new_bytes2(buf, size));
			knh_buff_trim(_ctx, cwb->ba, cwb->pos, '/');
			knh_buff_trim(_ctx, cwb->ba, cwb->pos, '/');
			knh_buff_addpath(_ctx, cwb->ba, cwb->pos, 1/*isSep*/, STEXT("konoha"));
			s = CWB_newString(_ctx, cwb, 0);
			SETPROP("konoha.home.path", s);
			home = S_tobytes(s);
		}
	}
#elif defined(K_USING_MACOSX_)
	{
		kString *binpath;
		CWB_clear(cwb, 0);
		knh_buff_addospath(_ctx, cwb->ba, cwb->pos, 0, B(_dyld_get_image_name(0)));
		binpath = knh_buff_newRealPathString(_ctx, cwb->ba, cwb->pos);
		SETPROP("konoha.bin.path", binpath);
		if(home.text == NULL) {
			CWB_clear(cwb, 0);
			knh_buff_addpath(_ctx, cwb->ba, cwb->pos, 0, S_tobytes(binpath));
			knh_buff_trim(_ctx, cwb->ba, cwb->pos, '/');
			knh_buff_trim(_ctx, cwb->ba, cwb->pos, '/');
			knh_buff_addpath(_ctx, cwb->ba, cwb->pos, 1/*isSep*/, STEXT("konoha"));
			kString *s = CWB_newString(_ctx, cwb, 0);
			SETPROP("konoha.home.path", s);
			home = S_tobytes(s);
		}
	}
#else
	home = STEXT("/opt/konoha");
	SETPROP("konoha.home.path", new_T("/opt/konoha"));
#endif
	DBG_ASSERT(home.utext != NULL);

	/* $konoha.package.path {$konoha.home.path}/package */
	CWB_clear(cwb, 0);
	knh_buff_addpath(_ctx, cwb->ba, cwb->pos, 0, home);
	knh_buff_addpath(_ctx, cwb->ba, cwb->pos, 1/*sep*/, STEXT("package"));
	knh_buff_addpath(_ctx, cwb->ba, cwb->pos, 1/*sep*/, STEXT(LIBK_VERSION));
	SETPROP("konoha.package.path", CWB_newString(_ctx, cwb, 0));

	/* $konoha.script.path {$konoha.home.path}/script */
	knh_buff_addpath(_ctx, cwb->ba, cwb->pos, 0, home);
	knh_buff_addpath(_ctx, cwb->ba, cwb->pos, 1/*sep*/, STEXT("script"));
	knh_buff_addpath(_ctx, cwb->ba, cwb->pos, 1/*sep*/, STEXT(LIBK_VERSION));
	SETPROP("konoha.script.path", CWB_newString(_ctx, cwb, 0));

#if defined(K_USING_WINDOWS_)
	user.text = knh_getenv("USERPROFILE");
#else
	user.text = knh_getenv("HOME");
#endif
	if(user.text != NULL) {
		/* $user.path */
		user.len = knh_strlen(user.text);
		knh_buff_addpath(_ctx, cwb->ba, cwb->pos, 0, user);
		knh_buff_addpath(_ctx, cwb->ba, cwb->pos, 1, STEXT(K_KONOHAFOLDER));
		SETPROP("user.path", CWB_newString(_ctx, cwb, 0));
		knh_buff_addospath(_ctx, cwb->ba, cwb->pos, 0, user);
		knh_buff_addospath(_ctx, cwb->ba, cwb->pos, 1, STEXT(K_KONOHAFOLDER));
		knh_buff_mkdir(_ctx, cwb->ba, cwb->pos);
		CWB_clear(cwb, 0);
		knh_buff_addospath(_ctx, cwb->ba, cwb->pos, 0, user);
		knh_buff_addospath(_ctx, cwb->ba, cwb->pos, 1/*sep*/, STEXT(K_KONOHAFOLDER));
		knh_buff_addospath(_ctx, cwb->ba, cwb->pos, 1/*sep*/, STEXT("package"));
		knh_buff_addospath(_ctx, cwb->ba, cwb->pos, 1/*sep*/, STEXT(LIBK_VERSION));
		SETPROP("user.package.path", CWB_newString(_ctx, cwb, 0));
	}
	CWB_close(_ctx, cwb);
}