KNHAPI(knh_bytes_t) knh_bytes_substringURLpath(knh_bytes_t url) { knh_index_t loc = knh_bytes_index(url, ':'); if(loc > 0 && url.buf[loc+1] == '/' && url.buf[loc+2] == '/') { knh_bytes_t t = knh_bytes_last(url, loc+3); loc = knh_bytes_index(t, '@'); if(loc > 0) t = knh_bytes_last(t, loc+1); loc = knh_bytes_index(t, '/'); if(loc > 0) { return t = knh_bytes_last(t, loc); } } return STEXT("/"); }
ksymbol_t knh_getfnq(CTX, kbytes_t tname, ksymbol_t def) { ksymbol_t mask = 0; kindex_t idx = knh_bytes_index(tname, ':'); if(idx > 0) { tname = knh_bytes_first(tname, idx); } else if(knh_bytes_startsWith_(tname, STEXT("super."))) { mask = (def == FN_NONAME) ? 0 : KFLAG_FN_SUPER; tname = knh_bytes_last(tname, 6); } else if(!knh_bytes_endsWith_(tname, STEXT("__"))) { if(tname.utext[0] == '_' && def != FN_NONAME) { mask = KFLAG_FN_U1; tname = knh_bytes_last(tname, 1); } if(tname.utext[0] == '_' && def != FN_NONAME) { mask = KFLAG_FN_U2; tname = knh_bytes_last(tname, 1); } while(tname.utext[0] == '_') { tname = knh_bytes_last(tname, 1); } } return getSymbol(_ctx, tname, def) | mask; }
KNHAPI(int) knh_bytes_parseURLpath(knh_bytes_t url, char *buf, size_t bufsiz) { knh_index_t loc = knh_bytes_index(url, ':'); if(loc > 0 && url.buf[loc+1] == '/' && url.buf[loc+2] == '/') { knh_bytes_t t = knh_bytes_last(url, loc+3); loc = knh_bytes_index(t, '@'); if(loc > 0) t = knh_bytes_last(t, loc+1); loc = knh_bytes_index(t, '/'); if(loc > 0) { knh_format_bytes(buf, bufsiz, knh_bytes_last(t, loc)); } return 1; } knh_format_bytes(buf, bufsiz, STEXT("/")); return 0; }
KNHAPI(knh_bytes_t) knh_bytes_skipscheme(knh_bytes_t t) { knh_index_t loc = knh_bytes_index(t, ':'); if(loc >= 0) { return knh_bytes_last(t, loc + 1); } return t; }
KNHAPI(int) knh_bytes_parseURL(knh_bytes_t url, char *buf, size_t bufsiz) { knh_index_t loc = knh_bytes_index(url, '?'); if(loc > 0) url = knh_bytes_first(url, loc); loc = knh_bytes_index(url, ':'); if(loc > 0 && url.buf[loc+1] == '/' && url.buf[loc+2] == '/') { knh_bytes_t scheme = knh_bytes_first(url, loc + 3); knh_bytes_t t = knh_bytes_last(url, loc+3); loc = knh_bytes_index(t, '@'); if(loc > 0) { knh_bytes_t t = knh_bytes_last(t, loc+1); } knh_format_join2(buf, bufsiz, scheme, t); return 1; } knh_format_bytes(buf, bufsiz, url); // default return 0; }
KNHAPI(int) knh_bytes_parseURLuname(knh_bytes_t url, char *buf, size_t bufsiz) { knh_index_t loc = knh_bytes_index(url, ':'); if(loc > 0 && url.buf[loc+1] == '/' && url.buf[loc+2] == '/') { knh_bytes_t t = knh_bytes_last(url, loc+3); loc = knh_bytes_index(t, '@'); if(loc > 0) { t = knh_bytes_first(t, loc); loc = knh_bytes_index(t, ':'); if(loc > 0) { t = knh_bytes_first(t, loc); } knh_format_bytes(buf, bufsiz, t); return 1; } } knh_format_bytes(buf, bufsiz, STEXT("konoha")); // default return 0; }
KNHAPI(int) knh_bytes_parseURLscheme(knh_bytes_t url, char *buf, size_t bufsiz) { knh_index_t loc = knh_bytes_index(url, ':'); if(loc > 0 && url.buf[loc+1] == '/' && url.buf[loc+2] == '/') { knh_format_bytes(buf, bufsiz, knh_bytes_first(url, loc)); return 1; } knh_format_bytes(buf, bufsiz, STEXT("http")); // default return 0; }
KNHAPI(int) knh_bytes_parseURLport(knh_bytes_t url, int *port) { knh_index_t loc = knh_bytes_index(url, ':'); if(loc > 0 && url.buf[loc+1] == '/' && url.buf[loc+2] == '/') { knh_bytes_t t = knh_bytes_last(url, loc+3); loc = knh_bytes_index(t, '@'); if(loc > 0) t = knh_bytes_last(t, loc+1); loc = knh_bytes_index(t, '/'); if(loc > 0) t = knh_bytes_first(t, loc); loc = knh_bytes_index(t, ':'); if(loc > 0) { knh_int_t n = *port; if(knh_bytes_parseint(knh_bytes_last(t, loc+1), &n)) { *port = (int)n; return 1; } } } return 0; }
void knh_path_reset(CTX ctx, knh_path_t *ph, const char *scheme, knh_bytes_t t) { knh_index_t idx = knh_bytes_index(t, ':'); char *buf = P_buf(ph); if(t.len + 1 > K_PATHMAX) t.len = K_PATHMAX - 1; if(idx > 0 || scheme == NULL) { knh_memcpy(buf, t.text, t.len); buf[t.len] = 0; ph->pbody = idx + 1; ph->plen = t.len; } else { knh_snprintf(buf, K_PATHMAX, "%s:%s", scheme, t.text); ph->pbody = knh_strlen(scheme) + 1; ph->plen = t.len + ph->pbody; } DBG_ASSERT(buf[ph->plen] == 0); ph->isRealPath = 0; }
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); }
// snprintf(buf, 128, "/usr/local/bin/konoha %s/%s", dir_name, script_name); // if (pid == 0) { // system(buf); // exit(0); // } //} /* ======================================================================== */ // [KMETHODS] //## @Hidden Actor Actor.opLINK(String path, NameSpace _); KMETHOD Actor_opLINK(CTX ctx, knh_sfp_t *sfp _RIX) { knh_bytes_t host_port = knh_bytes_next(S_tobytes(sfp[1].s), ':'); knh_bytes_t host; knh_index_t idx = knh_bytes_index(host_port, ':'); if (idx == -1) { LOGDATA = {sDATA("path", host_port.text)}; LIB_Failed("Actor.opLINK", "Script!!"); knh_Object_toNULL(ctx, sfp[0].o); RETURN_(sfp[0].o); } host = new_bytes2(host_port.text, idx); knh_int_t port; if (!knh_bytes_parseint(knh_bytes_next(host_port, ':'), &port)) { LOGDATA = {sDATA("path", host_port.text)}; LIB_Failed("Actor.opLINK", "Script!!"); knh_Object_toNULL(ctx, sfp[0].o); RETURN_(sfp[0].o); } knh_Actor_t *actor = knh_Actor_new(ctx, STEXT(""), host, port);
int knh_bytes_parsefloat(knh_bytes_t t, knh_float_t *value) { if(t.buf[0] == '0' && (t.buf[1] == 'x' || t.buf[1] == 'b')) { knh_int_t n = 0; int res = knh_bytes_parseint(t, &n); *value = (knh_float_t)n; return res; } knh_index_t loc = knh_bytes_index(t, 'E'); if(loc == -1) loc = knh_bytes_index(t, 'e'); if(loc != -1) { t = knh_bytes_first(t, loc); } size_t i = 0; knh_float_t v = 0.0, prev = 0.0, c = 1.0; if(t.buf[0] == '-') i = 1; for(;i < t.len; i++) { if('0' <= t.buf[i] && t.buf[i] <= '9') { prev = v; v = v * 10 + (t.buf[i] - '0'); #if defined(KNH_USING_MATH) && !defined(KONOHA_ON_WINDOWS) if(isinf(v)||isnan(v)) { *value = 0.0; return 1; } #endif } else if(t.buf[i] == '.') { i++; break; } else { *value = (t.buf[0] == '-') ? -v : v; return 1; } } for(; i < t.len; i++) { if('0' <= t.buf[i] && t.buf[i] <= '9') { prev = v; c *= 10; #if defined(KNH_USING_MATH) && !defined(KONOHA_ON_WINDOWS) if(isinf(c)||isnan(c)) { break; } #endif v = v + ((t.buf[i] - '0') / c); }else { break; } } v = (t.buf[0] == '-') ? -v : v ; if(loc != -1) { knh_bytes_t t2 = knh_bytes_last(t, loc + 1); knh_intptr_t scale = knh_bytes_toint(t2); int j; if(scale > 0) { for(j = 0; j < scale; j++) { v *= 10; } } else if(scale < 0) { scale = -scale; for(j = 0; j < scale; j++) { v /= 10; } } } *value = v; return 1; }