static int FilePwdCmd(Jsi_Interp *interp, Jsi_Value *args, Jsi_Value *_this, Jsi_Value **ret, Jsi_Func *funcPtr) { Jsi_DString dStr = {}; Jsi_ValueMakeString(interp, *ret, Jsi_Strdup(Jsi_GetCwd(interp, &dStr))); Jsi_DSFree(&dStr); return JSI_OK; }
char *Jsi_SubstrDup(const char *a, int start, int len) { if (len == 0) return Jsi_Strdup(""); int lenofa = Jsi_Strlen(a); while (start < 0) start += lenofa; if (start >= lenofa) return Jsi_Strdup(""); int maxcpy = lenofa - start; if (len > 0) { maxcpy = maxcpy < len ? maxcpy : len; } char *r = Jsi_Malloc(maxcpy + 1); Jsi_Strncpy(r, a + start, maxcpy + 1); return r; }
char* jsi_KeyFind(Jsi_Interp *interp, const char *str, int nocreate, int *isKey) { Jsi_HashEntry *hPtr; if (isKey) *isKey = 0; if (!nocreate) { *isKey = 1; if (isKey) *isKey = 1; return (char*)Jsi_KeyAdd(interp, str); } hPtr = Jsi_HashEntryFind(interp->strKeyTbl, str); if (!hPtr) { return Jsi_Strdup(str);; } if (isKey) *isKey = 1; *isKey = 1; return (char*)Jsi_HashKeyGet(hPtr); }
/* * Returns the strdup of the string value and resets the DString in the same way as Jsi_DSFree. * This just avoids the user having to do an extra malloc/free when the DString was already malloced. * It is the responsibility of the caller to free the returned value. * RETURNS: previous string value malloced. */ char* Jsi_DSFreeDup(Jsi_DString *dsPtr) { char *cp; if (DSNotInit(dsPtr)) InitStr(dsPtr); if (dsPtr->staticSpace == dsPtr->str) { cp = Jsi_Strdup(dsPtr->str); Jsi_DSSetLength(dsPtr, 0); return cp; } cp = dsPtr->str; dsPtr->str = dsPtr->staticSpace; dsPtr->staticSpace[0] = 0; dsPtr->spaceAvl = dsPtr->staticSize; dsPtr->len = 0; dsPtr->str = NULL; return cp; }