static MprList *expandWild(Ejs *ejs, int argc, char **argv) { MprList *list; EjsArray *files; EjsPath *path, *dir; cchar *arg; int i, j; if ((list = mprCreateList(-1, 0)) == 0) { return 0; } for (i = 0; i < argc; i++) { if (schr(argv[i], '*')) { arg = mprNormalizePath(argv[i]); dir = ejsCreatePathFromAsc(ejs, mprGetPathDir(arg)); path = ejsCreatePathFromAsc(ejs, mprGetPathBase(arg)); if ((files = ejsGetPathFiles(ejs, dir, 1, (EjsObj**) (void*) &path)) == 0) { ejsClearException(ejs); mprAddItem(list, sclone(argv[i])); } else { for (j = 0; j < files->length; j++) { mprAddItem(list, ((EjsPath*) files->data[j])->value); } } } else { mprAddItem(list, sclone(argv[i])); } } return list; }
EjsArray *ejsCaptureStack(Ejs *ejs, int uplevels) { EjsFrame *fp; EjsState *state; EjsArray *stack; wchar *source; EjsObj *frame; char *filename; int index, lineNumber; assert(ejs); stack = ejsCreateArray(ejs, 0); index = 0; for (state = ejs->state; state; state = state->prev) { for (fp = state->fp; fp; fp = fp->caller) { if (uplevels-- <= 0) { frame = ejsCreateEmptyPot(ejs); if (ejsGetDebugInfo(ejs, (EjsFunction*) fp, fp->pc, &filename, &lineNumber, &source) >= 0) { ejsSetPropertyByName(ejs, frame, EN("filename"), ejsCreatePathFromAsc(ejs, filename)); ejsSetPropertyByName(ejs, frame, EN("lineno"), ejsCreateNumber(ejs, lineNumber)); ejsSetPropertyByName(ejs, frame, EN("code"), ejsCreateString(ejs, source, wlen(source))); } else { ejsSetPropertyByName(ejs, frame, EN("filename"), EST(undefined)); } ejsSetPropertyByName(ejs, frame, EN("func"), fp->function.name); ejsSetProperty(ejs, stack, index++, frame); } } } return stack; }
/* function get tmpdir(): Path */ static EjsPath *system_tmpdir(Ejs *ejs, EjsObj *unused, int argc, EjsObj **argv) { cchar *dir; #if WINCE dir = "/Temp"; #elif BIT_WIN_LIKE { MprFileSystem *fs; fs = mprLookupFileSystem("/"); dir = sclone(getenv("TEMP")); #if UNUSED mprMapSeparators(dir, defaultSep(fs)); #endif } #elif VXWORKS dir = "."; #else dir = "/tmp"; #endif return ejsCreatePathFromAsc(ejs, dir); }
/* Get the application's executable filename. static function get exePath(): Path */ static EjsPath *app_exePath(Ejs *ejs, EjsObj *unused, int argc, EjsObj **argv) { return ejsCreatePathFromAsc(ejs, mprGetAppPath()); }
/* Get the current working directory function get dir(): Path */ static EjsPath *app_dir(Ejs *ejs, EjsObj *unused, int argc, EjsObj **argv) { return ejsCreatePathFromAsc(ejs, mprGetCurrentPath(ejs)); }
/* function get hostedHome(): Path */ static EjsPath *hs_hostedHome(Ejs *ejs, EjsHttpServer *sp, int argc, EjsObj **argv) { return ejsCreatePathFromAsc(ejs, ejs->hostedHome); }
/* Get a path object for the file function get path(): Path */ static EjsObj *getFilePath(Ejs *ejs, EjsFile *fp, int argc, EjsObj **argv) { return (EjsObj*) ejsCreatePathFromAsc(ejs, fp->path); }