void KTexture::mouseMoveEvent(QGraphicsSceneMouseEvent *event) { //fprintf(stderr, "KTexture::mouseMoveEvent\n"); isDrag = true; if (ctx != NULL && sfp != NULL && mouse_move_func != NULL) { const knh_ClassTBL_t *ct1 = ClassTBL(cid); const knh_ClassTBL_t *ct2 = ClassTBL(mouse_event_cid); if (ct1 == NULL || ct2 == NULL) return; knh_RawPtr_t *p1 = (knh_RawPtr_t*)new_hObject_(ctx, ct1); p1->rawptr = this; KNH_SETv(ctx, sfp[5].o, UPCAST(p1)); knh_RawPtr_t *p2 = (knh_RawPtr_t*)new_hObject_(ctx, ct2); p2->rawptr = event; KNH_SETv(ctx, sfp[6].o, UPCAST(p2)); if (mouse_move_func->baseNULL != NULL) { KNH_SETv(ctx, sfp[K_CALLDELTA].o, mouse_move_func->baseNULL); } KNH_SCALL(ctx, sfp, 0, mouse_move_func->mtd, 3); } }
void knh_Stmt_toERR(Ctx *ctx, Stmt *stmt, Term *tm) { if(SP(stmt)->stt == STT_ERR) return; SP(stmt)->stt = STT_ERR; knh_uri_t uri = 0; int line = 0; if(IS_Token(tm)) { uri = SP((Token*)tm)->uri; line = SP((Token*)tm)->line; } else if(IS_Stmt(tm)) { uri = SP((Stmt*)tm)->uri; line = SP((Stmt*)tm)->line; } { char buf[256]; knh_snprintf(buf, sizeof(buf), "Script!!: running errors at %s:%d", URIDN(SP(stmt)->uri), SP(stmt)->line); KNH_SETv(ctx, DP(stmt)->errMsg, new_String(ctx, B(buf), NULL)); KNH_SETv(ctx, DP(stmt)->next, KNH_NULL); } }
knh_InputStream_t* new_BytesInputStream(Ctx *ctx, knh_Bytes_t *ba) { knh_InputStream_t* in = new_(InputStream); DBG_ASSERT(ba != ctx->bufa); DP(in)->fd = IO_NULL; KNH_SETv(ctx, DP(in)->ba, ba); DP(in)->buf = (char*)(ba)->bu.ubuf; DP(in)->bufsiz = BA_size(ba); DP(in)->bufpos = 0; DP(in)->bufend = BA_size(ba); return in; }
static METHOD knh__String_opAdd(Ctx *ctx, knh_sfp_t *sfp) { knh_cwb_t cwbbuf, *cwb = knh_cwb_open(ctx, &cwbbuf); knh_sfp_t *esp = KNH_LOCAL(ctx); if(IS_bString(sfp[0].o)) { knh_Bytes_write(ctx, cwb->ba, knh_String_tobytes(sfp[0].s)); } else { KNH_SETv(ctx, esp[1].o, sfp[0].o); esp[1].data = sfp[0].data; knh_esp1_format(ctx, METHODN__s, cwb->w, KNH_NULL); } if(IS_bString(sfp[1].o)) { knh_Bytes_write(ctx, cwb->ba, knh_String_tobytes(sfp[1].s)); } else { KNH_ASSERT(esp == ctx->esp); KNH_SETv(ctx, esp[1].o, sfp[1].o); esp[1].data = sfp[1].data; knh_esp1_format(ctx, METHODN__s, cwb->w, KNH_NULL); } KNH_RETURN(ctx, sfp, knh_cwb_newString(ctx, cwb)); }
static METHOD knh__String_new(Ctx *ctx, knh_sfp_t *sfp) { String *s; if(IS_NULL(sfp[2].o)) { s = new_String(ctx, knh_Bytes_tobytes(sfp[1].ba), NULL); } else { BytesConv *bc = new_BytesConv__in(ctx, knh_String_tochar(sfp[2].s)); KNH_SETv(ctx, sfp[3].o, bc); s = new_String__bconv(ctx, knh_Bytes_tobytes(sfp[1].ba), bc); } KNH_RETURN(ctx, sfp, s); }
static int knh_runMain(CTX ctx, int argc, const char **argv) { KONOHA_BEGIN(ctx); kMethod *mtd = ClassTBL_getMethodNULL(ctx, O_cTBL(ctx->script), MN_main); int res = 0; if(mtd != NULL) { int thisidx = 1 + K_CALLDELTA; BEGIN_LOCAL(ctx, lsfp, 5); lsfp[1].ivalue = 0; lsfp[thisidx+K_PCIDX].pc = NULL; klr_setmtdNC(ctx,lsfp[thisidx+K_MTDIDX], mtd); KNH_SETv(ctx, lsfp[thisidx].o, ctx->script); KNH_SETv(ctx, lsfp[thisidx+1].o, knh_getPropertyNULL(ctx, STEXT("script.argv"))); klr_setesp(ctx, lsfp + thisidx+2); if(knh_VirtualMachine_launch(ctx, lsfp + thisidx)) { res = (int)lsfp[1].ivalue; } END_LOCAL(ctx, lsfp); } KONOHA_END(ctx); return res; }
//## method @Virtual void Chardev.read(File! file, OutputStream ous); static ssize_t script_read (struct file* filp, char __user *user_buf, size_t count, loff_t *offset) { printk("%s at %d\n",__func__,__LINE__); knh_device_t *dev = filp->private_data; knh_Object_t *self = dev->self; if(*offset > 0) return 0; Ctx *ctx = knh_getCurrentContext(); knh_sfp_t *sfp = KNH_LOCAL(ctx); knh_Method_t *mtd = dev->read; if (!IS_Method(mtd) || knh_Method_isAbstract(mtd)) { knh_bytes_t fname = B("read"); knh_methodn_t mn = knh_getmn(ctx, fname, METHODN_NONAME); mtd = knh_Class_getMethod(ctx, knh_Object_cid(self), mn); KNH_SETv(ctx, dev->read, mtd); } //knh_File_t *f = (knh_File_t*)new_Object_bcid(ctx, CLASS_File, 0); //f->file = filp; if (IS_Method(mtd)) { KNH_MOV(ctx, sfp[0].o, new_ExceptionHandler(ctx)); KNH_TRY(ctx, L_CATCH, sfp, 0); { knh_cwb_t cwbbuf, *cwb = knh_cwb_open(ctx, &cwbbuf); // THIS IS DANGEROUS. DON'T USED by KIMIO // knh_OutputStream_t *o = new_BytesOutputStream(ctx, cwb->ba); // KNH_MOV(ctx, sfp[1].o, self); // //KNH_MOV(ctx, sfp[2].o, f); // KNH_MOV(ctx, sfp[2].o, KNH_NULL); // KNH_MOV(ctx, sfp[3].o, o); // KNH_SCALL(ctx, sfp, 0, mtd, 2); // { // size_t len = knh_cwb_size(cwb); // char *buf = knh_cwb_tochar(ctx, cwb); // if(copy_to_user(user_buf,buf,len)){ // printk(KERN_ALERT "%s: copy_to_user failed\n",__func__); // return -EFAULT; // } // knh_cwb_close(cwb); // knh_Context_clearstack(ctx); // *offset += len; // return len; // } } /* catch */ L_CATCH:; KNH_PRINT_STACKTRACE(ctx, sfp, 0); } return 0; }
knh_InputStream_t* new_StringInputStream(Ctx *ctx, knh_String_t *str, size_t s, size_t e) { knh_InputStream_t* o = new_(InputStream); DP(o)->fd = IO_NULL; DBG_ASSERT(IS_String(str)); KNH_SETv(ctx, DP(o)->str, str); DP(o)->buf = (char*)S_tochar(str); DP(o)->bufsiz = S_size(str); DBG_ASSERT(e <= S_size(str)); DBG_ASSERT(s <= e); DP(o)->bufpos = s; DP(o)->bufend = e; return o; }
static knh_Token_t *knh_Token_toERR(CTX ctx, knh_Token_t *tk, const char *fmt, ...) { if(TT_(tk) != TT_ERR) { knh_String_t *msg; va_list ap; va_start(ap, fmt); ctx->gma->uline = tk->uline; msg = Gamma_vperror(ctx, KC_ERR, fmt, ap); va_end(ap); TT_(tk) = TT_ERR; KNH_SETv(ctx, (tk)->data, msg); } return tk; }
static METHOD knh__String_format(Ctx *ctx, knh_sfp_t *sfp) { knh_bytes_t fmt = knh_String_tobytes(sfp[0].s); knh_sfp_t *param = sfp + 1; int ac = knh_stack_argc(ctx, param); knh_bytes_t mt, expr, next; if(!knh_bytes_findMT(ctx, fmt, &mt, &expr, &next)) { KNH_RETURN(ctx, sfp, sfp[0].s); } knh_cwb_t cwbbuf, *cwb = knh_cwb_open(ctx, &cwbbuf); int count; for(count = 0; ; count++) { if(mt.buf > fmt.buf + 1) { fmt.len = (mt.buf - fmt.buf) - 1; knh_Bytes_write(ctx, cwb->ba, fmt); } int index = count; if(expr.len > 0) { knh_int_t num; if(knh_bytes_parseint(expr, &num)) { index = (int)num; } } if(0 <= index && index < ac) { knh_sfp_t *esp = KNH_LOCAL(ctx); KNH_SETv(ctx, esp[1].o, param[index].o); esp[1].data = param[index].data; Object *m = KNH_NULL; if(knh_bytes_isOptionalMT(mt)) m = UP(new_String(ctx, mt, NULL)); mt.buf = mt.buf - 1; mt.len++; /* 's' == > '%s' */ knh_methodn_t mn = knh_getmn(ctx, mt, METHODN__empty); knh_esp1_format(ctx, mn, cwb->w, m); } else { if(knh_Context_isDebug(ctx)) { KNH_THROW_OUTOFINDEX(ctx, index, ac); } } fmt.buf = next.buf; fmt.len = next.len; if(!knh_bytes_findMT(ctx, fmt, &mt, &expr, &next)) { break; } } if(fmt.len > 0) { knh_Bytes_write(ctx, cwb->ba, fmt); } KNH_RETURN(ctx, sfp, new_StringX__cwb(ctx, knh_Object_cid(sfp[0].o), cwb)); }
static kException* new_Assertion(CTX ctx, kline_t uline) { kException* e = new_(Exception); char buf[256] = {'A', 's', 's', 'e', 'r', 't', 'i', 'o', 'n', '!', '!', ':', ' '}; char *mbuf = buf + 13; knh_readuline(ctx, uline, mbuf, sizeof(buf)-13); if(mbuf[0] == 0) { kuri_t uri = ULINE_uri(uline); size_t line = ULINE_line(uline); knh_snprintf(buf, sizeof(buf), "Assertion!!: %s at line %lu", FILENAME__(uri), line); } KNH_SETv(ctx, e->emsg, new_String2(ctx, CLASS_String, (const char*)buf, knh_strlen(buf), SPOL_ASCII)); e->uline = uline; return e; }
void knh_Iterator_close(CTX ctx, kIterator *it) { DBG_ASSERT(IS_bIterator(it)); if(it->fnext_1 != Fitrnext_end) { KNH_SETv(ctx, DP(it)->source, KNH_NULL); if(DP(it)->m.nfree != NULL) { if(DP(it)->m.nptr != NULL) { DP(it)->m.nfree(DP(it)->m.nptr); } DP(it)->m.nfree = NULL; } DP(it)->m.nptr = NULL; it->fnext_1 = Fitrnext_end; } }
static knh_Token_t *Gamma_perror(CTX ctx, int pe, const char *fmt, ...) { knh_String_t *msg; va_list ap; va_start(ap, fmt); msg = Gamma_vperror(ctx, pe, fmt, ap); va_end(ap); if(pe < KC_DWARN) { knh_Token_t *tkERR = new_(Token); tkERR->tt = TT_ERR; tkERR->uline = (ctx->gma)->uline; KNH_SETv(ctx, (tkERR)->data, msg); return tkERR; } return NULL; }
static METHOD knh__String_getBytes(Ctx *ctx, knh_sfp_t *sfp) { Bytes *ba; if(IS_NULL(sfp[1].o)) { ba = new_Bytes(ctx, (sfp[0].s)->size + 1); knh_Bytes_write(ctx, ba, knh_String_tobytes(sfp[0].s)); } else { knh_bytes_t t = knh_String_tobytes(sfp[0].s); BytesConv *bc = new_BytesConv__out(ctx, knh_String_tochar(sfp[1].s)); KNH_SETv(ctx, sfp[2].o, bc); ba = new_Bytes(ctx, t.len); bc->fbconv(ctx, bc, t, ba); } KNH_RETURN(ctx, sfp, ba); }
void knh_InputStream_setCharset(Ctx *ctx, knh_InputStream_t *in, knh_StringDecoder_t *c) { if(DP(in)->decNULL == NULL) { if(c != NULL) { KNH_INITv(DP(in)->decNULL, c); } } else { if(c != NULL) { KNH_SETv(ctx, DP(in)->decNULL, c); } else { KNH_FINALv(ctx, DP(in)->decNULL); DP(in)->decNULL = c; } } }
knh_InputStream_t* new_InputStreamDSPI(Ctx *ctx, knh_io_t fd, const knh_StreamDSPI_t *dspi) { knh_InputStream_t* in = new_(InputStream); DP(in)->fd = fd; SP(in)->dspi = dspi; DP(in)->bufsiz = dspi->bufsiz; if(DP(in)->bufsiz > 0) { KNH_SETv(ctx, DP(in)->ba, new_Bytes(ctx, DP(in)->bufsiz)); DP(in)->buf = (char*)(DP(in)->ba)->bu.ubuf; } else { knh_InputStream_setFILE(in, 1); } DP(in)->bufpos = 0; DP(in)->bufend = 0; /* empty */ return in; }
int main(int argc, const char *argv[]) { int i, argc_ = argc; const char *argv_[argc_]; const char *fname = parse_option(&argc_, argv, argv_); if (fname == NULL) { fprintf(stderr, "%s [--emit-llvm/--emit-js] file\n", argv[0]); return 1; } konoha_t konoha = konoha_open(); CTX ctx = konoha; kString *s = new_T(fname); knh_DictMap_set(ctx, ctx->share->props, new_T("script.name"), s); kArray *a = new_Array(ctx, CLASS_String, argc_); for(i = 2; i < argc_; i++) { knh_Array_add(ctx, a, new_String2(ctx, CLASS_String, argv_[i], knh_strlen(argv_[i]), SPOL_TEXT|SPOL_POOLALWAYS)); } knh_DictMap_set(ctx, ctx->share->props, new_T("script.argv"), a); kbytes_t t = knh_bytes_nsname(S_tobytes(s)); knh_Script_setNSName(ctx, ctx->script, new_S(t.text, t.len)); kbytes_t pkgname = STEXT("konoha.compiler"); knh_loadPackage(ctx, pkgname); load_codegenerator(ctx); if (!compiler_run_main) { knh_setCompileMode(ctx, 1); } knh_startScript(ctx, (const char*)fname); /* CompilerAPI->dump() */ kMethod *mtd = load_method(ctx, O_cid(ctx->share->konoha_compiler), STEXT("dump")); BEGIN_LOCAL(ctx, lsfp, K_CALLDELTA+1); { KNH_SETv(ctx, lsfp[K_CALLDELTA].o, ctx->share->konoha_compiler); KNH_SCALL(ctx, lsfp, 0, mtd, 0); } END_LOCAL(ctx, lsfp); if (compiler_run_main) { knh_stack_clear(ctx, ctx->stack); knh_runMain(ctx, argc_, argv_); } konoha_close(konoha); return 0; }
static METHOD knh__String_concat(Ctx *ctx, knh_sfp_t *sfp) { int i, ac = knh_stack_argc(ctx, sfp); knh_cwb_t cwbbuf, *cwb = knh_cwb_open(ctx, &cwbbuf); knh_sfp_t *esp = KNH_LOCAL(ctx); for(i = 0; i < ac; i++) { if(IS_bString(sfp[i].o)) { knh_Bytes_write(ctx, cwb->ba, knh_String_tobytes(sfp[i].s)); } else { KNH_ASSERT(esp == ctx->esp); KNH_SETv(ctx, esp[1].o, sfp[i].o); esp[1].data = sfp[i].data; knh_esp1_format(ctx, METHODN__s, cwb->w, KNH_NULL); } } KNH_RETURN(ctx, sfp, knh_cwb_newString(ctx, cwb)); }
static void knh_Actor_invokeMethod(CTX ctx, knh_Actor_t *a, const char *mtd_name, Object *msg) { //knh_MailBox_t *box = a->mailbox; //knh_Message_t *msg = knh_MailBox_popMessage(box); //const char *mtd_name = msg->mtd_name; //Object *o = msg->msg; knh_MethodInfo_t **info = a->mtd_info; int i = 0; for (i = 0; i < MAX_METHOD_NUM; i++) { if (!strncmp(mtd_name, info[i]->mtd_name, sizeof(mtd_name))) { //fprintf(stderr, "find method!!\n"); BEGIN_LOCAL(ctx, lsfp, 6); KNH_SETv(ctx, lsfp[5].o, msg); KNH_SCALL(ctx, lsfp, 0, info[i]->mtd, 2); END_LOCAL_(ctx, lsfp); break; } } }
kPath* new_CurrentPath(CTX ctx) { char buf[K_PATHMAX]; #if defined(K_USING_WINDOWS_) char *ptr = _fullpath(buf, ".", K_PATHMAX); #elif defined(K_USING_POSIX_) char *ptr = realpath(".", buf); #else char *ptr = NULL; buf[0] = '.'; buf[1] = 0; #endif kPath *pth = new_(Path); KNH_SETv(ctx, pth->urn, new_String2(ctx, CLASS_String, buf, knh_strlen(buf), SPOL_POOLALWAYS)); pth->ospath = S_totext(pth->urn); if(ptr != buf && ptr != NULL) { free(ptr); } kObjectoNULL(ctx, pth); return pth; }
static METHOD knh__Regex_new(Ctx *ctx, knh_sfp_t *sfp) { knh_Regex_t *o = (Regex*)sfp[0].o; knh_bytes_t p = knh_String_tobytes(sfp[1].s); knh_index_t loc = knh_bytes_index(p, ':'); KNH_SETv(ctx, o->pattern, sfp[1].s); if(loc == -1) { o->df = knh_System_getRegexDriver(ctx, STEXT("re")); } else { o->df = knh_System_getRegexDriver(ctx, knh_bytes_first(p, loc)); } o->reg = o->df->regmalloc(ctx); { char *ptn = (char*)(knh_bytes_last(p, loc+1).buf); char *opt = IS_NULL(sfp[2].o) ? "" : knh_String_tochar(sfp[2].s); o->df->regcomp(ctx, o->reg, ptn, opt); } KNH_RETURN(ctx, sfp, sfp[0].o); }
static METHOD knh__HashMap_set(Ctx *ctx, knh_sfp_t *sfp) { if(IS_IMM(sfp[0].o)) { if(IS_NULL(sfp[2].o)) { knh__HashMap_remove(ctx, sfp); return ; } knh_Hash_t *o = (knh_Hash_t*)sfp[0].o; knh_hcode_t hcode = knh_stack_hashCode(ctx, sfp + 1); knh_uintptr_t h = hcode % DP(o)->hmax; knh_hashentry_t *e = DP(o)->array[h]; while(e != NULL) { if(e->hcode == hcode && knh_Object_cid(sfp[1].o) == knh_Object_cid(e->key) && knh_stack_equals(ctx, sfp + 1, e->key)) { knh_sfp_boxing(ctx, sfp+2); KNH_SETv(ctx, e->value, sfp[2].o); KNH_RETURN_void(ctx, sfp); } e = e->next; } /* add newentry */ { e = new_hashentry(ctx, o); e->hcode = hcode; knh_sfp_boxing(ctx, sfp+1); KNH_INITv(e->key, sfp[1].o); knh_sfp_boxing(ctx, sfp+2); KNH_INITv(e->value, sfp[2].o); e->next = DP(o)->array[h]; DP(o)->array[h] = e; DP(o)->size++; } } KNH_RETURN_void(ctx, sfp); }
KNHAPI(void) knh_ResultSet_setName(Ctx *ctx, knh_ResultSet_t *o, size_t n, knh_String_t *name) { KNH_ASSERT(n < DP(o)->column_size); KNH_SETv(ctx, DP(o)->column[n].name, name); }
void knh_System_initPath(CTX 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(".")); KNH_SETv(ctx, ctx->share->rootns->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); GetModuleFileNameA(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); }
static void Farray_getO(CTX ctx, kArray *a, size_t n2, ksfp_t *vsfp) { KNH_SETv(ctx, vsfp[0].o, a->list[n2]); }
void knh_System_initPath(CTX ctx, knh_System_t *o) { knh_DictMap_t *sysprops = DP(o)->props; knh_path_t phbuf, *ph = knh_path_open(ctx, NULL, ".", &phbuf); knh_bytes_t home = {{NULL}, 0}, user = {{NULL}, 0}; // current working directory knh_ospath(ctx, ph); KNH_SETv(ctx, ctx->share->rootns->rpath, knh_path_newString(ctx, ph, 0)); 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[FILEPATH_BUFSIZ]; int bufsiz = FILEPATH_BUFSIZ; HMODULE h = LoadLibrary(NULL); GetModuleFileNameA(h, buf, bufsiz); ph = knh_path_open_(ctx, NULL, B(buf), &phbuf); SETPROP("konoha.bin.path", knh_path_newString(ctx, ph, 0)); if(homepath == NULL) { knh_String_t *s; GetModuleFileNameA(h, buf, bufsiz); knh_path_reduce(ctx, ph, '/'); s = knh_path_newString(ctx, ph); SETPROP("konoha.home.path", UPCAST(s)); home = S_tobytes(shome); } } #elif defined(K_USING_LINUX_) // @url(http://shinh.skr.jp/binary/b2con.html) // http://doc.trolltech.com/3.3/qapplication.html#applicationDirPath { char buf[FILEPATH_BUFSIZ]; int bufsiz = FILEPATH_BUFSIZ; size_t size = readlink("/proc/self/exe", buf, bufsiz); ph = knh_path_open_(ctx, NULL, new_bytes2(buf, size), &phbuf); SETPROP("konoha.bin.path", knh_path_newString(ctx, ph, 0)); if(home.text == NULL) { knh_String_t *s; knh_path_reduce(ctx, ph, '/'); knh_path_reduce(ctx, ph, '/'); knh_path_append(ctx, ph, 1/*isSep*/, "konoha"); s = knh_path_newString(ctx, ph, 0/*hasScheme*/); SETPROP("konoha.home.path", UPCAST(s)); home = S_tobytes(s); } } #elif defined(K_USING_MACOSX_) ph = knh_path_open(ctx, NULL, _dyld_get_image_name(0), &phbuf); knh_ospath(ctx, ph); SETPROP("konoha.bin.path", knh_path_newString(ctx, ph, 0/*hasScheme*/)); if(home.text == NULL) { knh_String_t *s; knh_path_reduce(ctx, ph, '/'); knh_path_reduce(ctx, ph, '/'); knh_path_append(ctx, ph, 1/*isSep*/, "konoha"); s = knh_path_newString(ctx, ph, 0/*hasScheme*/); SETPROP("konoha.home.path", UPCAST(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 */ knh_path_reset(ctx, ph, NULL, home); knh_path_append(ctx, ph, 1/*sep*/, "package"); knh_path_append(ctx, ph, 1/*sep*/, LIBK_VERSION); SETPROP("konoha.package.path", knh_path_newString(ctx, ph, 0/*hasScheme*/)); /* $konoha.script.path {$konoha.home.path}/script */ knh_path_reset(ctx, ph, NULL, home); knh_path_append(ctx, ph, 1/*sep*/, "script"); knh_path_append(ctx, ph, 1/*sep*/, LIBK_VERSION); SETPROP("konoha.script.path", knh_path_newString(ctx, ph, 0/*hasScheme*/)); #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_path_reset(ctx, ph, NULL, user); knh_path_append(ctx, ph, 1/*sep*/, K_KONOHAFOLDER); SETPROP("user.path", knh_path_newString(ctx, ph, 0)); knh_ospath(ctx, ph); knh_path_mkdir(ctx, ph); knh_path_reset(ctx, ph, NULL, user); /* user.package.path */ knh_path_append(ctx, ph, 1/*sep*/, K_KONOHAFOLDER); knh_path_append(ctx, ph, 1/*sep*/, "package"); knh_path_append(ctx, ph, 1/*sep*/, LIBK_VERSION); SETPROP("user.package.path", knh_path_newString(ctx, ph, 0)); } knh_path_close(ctx, ph); }