void fxLoadModuleXML(txMachine* the, txString path, txID moduleID) { FskFileMapping map = NULL; txFileMapStream fileMapStream; txStringStream stringStream; txScript* script = NULL; mxTry(the) { fxBeginHost(the); 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; script = fxParseScript(the, &stringStream, fxStringGetter, mxDebugFlag); fxEndHost(the); } mxCatch(the) { break; } FskFileDisposeMap(map); fxResolveModule(the, moduleID, script, NULL, NULL); }
void fxLoadModuleJS(txMachine* the, txString path, txID moduleID) { FskErr err = kFskErrNone; FskFileMapping map = NULL; txFileMapStream stream; txParser _parser; txParser* parser = &_parser; txParserJump jump; txScript* script = NULL; bailIfError(FskFileMap(path, (unsigned char**)&(stream.buffer), &(stream.size), 0, &map)); stream.offset = 0; fxInitializeParser(parser, the, 32*1024, 1993); parser->firstJump = &jump; parser->path = fxNewParserSymbol(parser, path); if (c_setjmp(jump.jmp_buf) == 0) { fxParserTree(parser, &stream, fxFileMapGetter, 2, NULL); fxParserHoist(parser); fxParserBind(parser); script = fxParserCode(parser); } fxTerminateParser(parser); bail: FskFileDisposeMap(map); if (err && script) { fxDeleteScript(script); script = NULL; } fxResolveModule(the, moduleID, script, NULL, NULL); }
void fxUnmapArchive(void* it) { txArchive* archive = it; if (archive) { if (archive->scripts) FskMemPtrDispose(archive->scripts); if (archive->symbols) FskMemPtrDispose(archive->symbols); if (archive->library) FskLibraryUnload(archive->library); FskFileDisposeMap(archive->map); FskMemPtrDispose(archive); } }
void KPR_system_get_backGesture(xsMachine *the) { FskErr err = kFskErrNone; char* path = NULL; char* pathName = NULL; FskFileMapping map = NULL; unsigned char *data; FskInt64 size; #if MINITV pathName = TOUCHD_CONF; #else bailIfError(FskDirectoryGetSpecialPath(kFskDirectorySpecialTypeApplicationPreference, true, NULL, &path)); pathName = FskStrDoCat(path, "touchd.conf"); bailIfNULL(pathName); #endif bailIfError(FskFileMap(pathName, &data, &size, 0, &map)); xsResult = xsStringBuffer((xsStringValue)data, (xsIntegerValue)size); bail: FskFileDisposeMap(map); if (path) { FskMemPtrDispose(path); FskMemPtrDispose(pathName); } }
FskErr FskTextFreeTypeInstallFonts(char* fontsPath, char* defaultFont) { FskErr err = kFskErrNone; FskTextEngine fte; char *fromDirectory = NULL; char* fromPath = NULL; FskDirectoryIterator iterator = NULL; char *name = NULL; UInt32 type; #if TARGET_OS_ANDROID char *toDirectory = NULL; char* toPath = NULL; FskFileInfo itemInfo; FskFileMapping map = NULL; unsigned char *data; FskInt64 dataSize; FskFile file = NULL; #endif err = FskTextEngineNew(&fte, NULL); if (err) goto bail; fromDirectory = FskEnvironmentDoApply(FskStrDoCopy(fontsPath)); if (!fromDirectory) { err = kFskErrMemFull; goto bail; } #if TARGET_OS_ANDROID if (!FskStrCompareWithLength(fromDirectory, "/data/app/", 10)) { err = FskDirectoryGetSpecialPath(kFskDirectorySpecialTypeApplicationPreference, false, NULL, &toDirectory); if (err) goto bail; } #endif err = FskDirectoryIteratorNew(fromDirectory, &iterator, 0); if (err) goto bail; while (kFskErrNone == FskDirectoryIteratorGetNext(iterator, &name, &type)) { if (type == kFskDirectoryItemIsFile) { fromPath = FskStrDoCat(fromDirectory, name); if (!fromPath) { err = kFskErrMemFull; goto bail; } FskDebugStr("from %s", fromPath); #if TARGET_OS_ANDROID if (toDirectory) { toPath = FskStrDoCat(toDirectory, name); FskDebugStr("to %s", toPath); if (kFskErrNone != FskFileGetFileInfo(toPath, &itemInfo)) { err = FskFileMap(fromPath, &data, &dataSize, 0, &map); if (err) goto bail; err = FskFileCreate(toPath); if (err) goto bail; err = FskFileOpen(toPath, kFskFilePermissionReadWrite, &file); if (err) goto bail; err = FskFileWrite(file, dataSize, data, NULL); if (err) goto bail; FskFileClose(file); file = NULL; FskFileDisposeMap(map); map = NULL; } FskDebugStr("add %s", toPath); FskTextAddFontFile(fte, toPath); FskMemPtrDisposeAt(&toPath); } else #endif FskTextAddFontFile(fte, fromPath); FskMemPtrDisposeAt(&fromPath); } FskMemPtrDisposeAt(&name); } #if TARGET_OS_ANDROID if (gAndroidCallbacks->getModelInfoCB) { char* osVersion; gAndroidCallbacks->getModelInfoCB(NULL, &osVersion, NULL, NULL, NULL); if ((FskStrStr(osVersion, "android.5") == osVersion) // for KPR applications || (FskStrStr(osVersion, "5.") == osVersion)) { // for tests BAIL_IF_ERR(err = FskFTAddMapping("/system/etc/fonts.xml")); } if ((FskStrStr(osVersion, "android.4") == osVersion) // for KPR applications || (FskStrStr(osVersion, "4.") == osVersion)) { // for tests BAIL_IF_ERR(err = FskFTAddMapping("/system/etc/system_fonts.xml")); err = FskFTAddMapping("/vendor/etc/fallback_fonts.xml"); if (err != kFskErrFileNotFound) BAIL(err); BAIL_IF_ERR(err = FskFTAddMapping("/system/etc/fallback_fonts.xml")); } else { defaultFont = "Droid Sans"; BAIL_IF_ERR(err = FskFTAddMapping(NULL)); } } #endif if (defaultFont) FskTextDefaultFontSet(fte, defaultFont); bail: #if TARGET_OS_ANDROID if (file) FskFileClose(file); if (map) FskFileDisposeMap(map); FskMemPtrDispose(toPath); FskMemPtrDispose(toDirectory); #endif FskMemPtrDispose(name); FskDirectoryIteratorDispose(iterator); FskMemPtrDispose(fromPath); FskMemPtrDispose(fromDirectory); FskTextEngineDispose(fte); return 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); }