void KPR_system_saveFile(xsMachine* the) { FskErr err; xsIntegerValue argc = xsToInteger(xsArgc); xsStringValue name = NULL; xsStringValue prompt = NULL; xsStringValue initialPath = NULL; xsStringValue path = NULL; xsStringValue url = NULL; if ((argc > 0) && xsTest(xsArg(0))) { if (xsFindResult(xsArg(0), xsID_name)) name = xsToStringCopy(xsResult); if (xsFindResult(xsArg(0), xsID_prompt)) prompt = xsToStringCopy(xsResult); if (xsFindResult(xsArg(0), xsID_url)) KprURLToPath(xsToString(xsResult), &initialPath); } err = FskFileChooseSave(name, prompt, initialPath, &path); if ((kFskErrNone == err) && (NULL != path)) { KprPathToURL(path, &url); (void)xsCallFunction1(xsArg(1), xsNull, xsString(url)); } FskMemPtrDispose(url); FskMemPtrDispose(path); FskMemPtrDispose(initialPath); FskMemPtrDispose(prompt); FskMemPtrDispose(name); }
void KPR_host_get_profilingDirectory(xsMachine* the) { KprHost self = xsGetHostData(xsThis); KprApplication application = (KprApplication)self->first; FskErr err = kFskErrNone; char* directory = NULL; xsBeginHost(application->the); { xsResult = xsCall0(xsGet(xsGlobal, xsID("xs")), xsID("getProfilingDirectory")); if (xsTest(xsResult)) err = KprPathToURL(xsToString(xsResult), &directory); } xsEndHost(application->the); if (directory) { xsResult = xsString(directory); FskMemPtrDispose(directory); } else { xsThrowIfFskErr(err); } }
void fxIncludeScript(txParser* parser, txString string) { txBoolean done = 0; char* base = NULL; char name[PATH_MAX]; char* slash = NULL; char* dot = NULL; char* extension = NULL; char* url = NULL; char* path = NULL; FskFileInfo fileInfo; FskFileMapping map= NULL; txFileMapStream fileMapStream; txStringStream stringStream; txMachine* the = parser->console; fxBeginHost(the); { mxTry(the) { xsThrowIfFskErr(KprPathToURL(parser->path->string, &base)); FskStrCopy(name, string); slash = FskStrRChr(name, '/'); if (!slash) slash = name; dot = FskStrRChr(slash, '.'); if (dot) extension = dot; else extension = name + FskStrLen(name); if (!dot) FskStrCopy(extension, ".js"); if (!FskStrCompare(extension, ".js")) { xsThrowIfFskErr(KprURLMerge(base, name, &url)); xsThrowIfFskErr(KprURLToPath(url, &path)); if (kFskErrNone == FskFileGetFileInfo(path, &fileInfo)) { xsThrowIfFskErr(FskFileMap(path, (unsigned char**)&(fileMapStream.buffer), &(fileMapStream.size), 0, &map)); fileMapStream.offset = 0; fxIncludeTree(parser, &fileMapStream, fxFileMapGetter, parser->flags, path); done = 1; FskFileDisposeMap(map); map = NULL; } FskMemPtrDisposeAt(&path); FskMemPtrDisposeAt(&url); } if (!dot) FskStrCopy(extension, ".xml"); if (!FskStrCompare(extension, ".xml")) { xsThrowIfFskErr(KprURLMerge(base, name, &url)); xsThrowIfFskErr(KprURLToPath(url, &path)); if (kFskErrNone == FskFileGetFileInfo(path, &fileInfo)) { xsThrowIfFskErr(FskFileMap(path, &fileMapStream.buffer, &fileMapStream.size, 0, &map)); fileMapStream.offset = 0; mxPushInteger(0); mxPushInteger(0); mxPushInteger(0); mxPushInteger(0); mxPushInteger(3); fxParse(the, &fileMapStream, fxFileMapGetter, path, 1, xsSourceFlag | xsDebugFlag); fxCallID(the, fxID(the, "generate")); fxToString(the, the->stack); stringStream.slot = the->stack; stringStream.size = c_strlen(stringStream.slot->value.string); stringStream.offset = 0; fxIncludeTree(parser, &stringStream, fxStringGetter, parser->flags, path); done = 1; FskFileDisposeMap(map); map = NULL; } FskMemPtrDisposeAt(&path); FskMemPtrDisposeAt(&url); } FskMemPtrDispose(base); } mxCatch(the) { FskFileDisposeMap(map); FskMemPtrDispose(path); FskMemPtrDispose(url); FskMemPtrDispose(base); break; } } fxEndHost(the); if (!done) fxReportParserError(parser, "include file not found: %s", string); }