/** Starts a new file search: finds the first file/directory that will match to the given pattern (ex: /bin/foo*) * @param[in] _zSearchPattern Pattern used for file/directory search * @param[out] _pstFileInfo Information about the first file found * @return orxSTATUS_SUCCESS / orxSTATUS_FAILURE */ orxSTATUS orxFASTCALL orxFile_FindFirst(const orxSTRING _zSearchPattern, orxFILE_INFO *_pstFileInfo) { orxSTATUS eResult = orxSTATUS_FAILURE; #ifdef __orxWINDOWS__ struct _finddata_t stData; orxHANDLE hHandle; /* Checks */ orxASSERT((sstFile.u32Flags & orxFILE_KU32_STATIC_FLAG_READY) == orxFILE_KU32_STATIC_FLAG_READY); orxASSERT(_zSearchPattern != orxNULL); orxASSERT(_pstFileInfo != orxNULL); /* Opens the search */ hHandle = (orxHANDLE)_findfirst(_zSearchPattern, &stData); /* Valid? */ if(orxFILE_CAST_HELPER hHandle > 0) { const orxSTRING zFileName; /* Gets base file name */ zFileName = orxString_SkipPath(_zSearchPattern); /* Has directory? */ if(zFileName != _zSearchPattern) { orxU32 u32Length; /* Updates path & full name base */ u32Length = (orxU32)orxMIN(zFileName - _zSearchPattern, sizeof(_pstFileInfo->zPath) - 1); orxString_NCopy(_pstFileInfo->zPath, _zSearchPattern, u32Length); _pstFileInfo->zPath[u32Length] = orxCHAR_NULL; orxString_Copy(_pstFileInfo->zFullName, _pstFileInfo->zPath); /* Stores pattern */ u32Length = orxMIN(orxString_GetLength(zFileName), sizeof(_pstFileInfo->zPattern) - 1); orxString_NCopy(_pstFileInfo->zPattern, zFileName, u32Length); _pstFileInfo->zPattern[u32Length] = orxCHAR_NULL; } else { orxU32 u32Length; /* Clears vars */ _pstFileInfo->zPath[0] = orxCHAR_NULL; _pstFileInfo->zFullName[0] = orxCHAR_NULL; /* Stores pattern */ u32Length = orxMIN(orxString_GetLength(_zSearchPattern), sizeof(_pstFileInfo->zPattern) - 1); orxString_NCopy(_pstFileInfo->zPattern, _zSearchPattern, u32Length); _pstFileInfo->zPattern[u32Length] = orxCHAR_NULL; } /* Tranfers file info */ orxFile_GetInfoFromData(&stData, _pstFileInfo); /* Stores handle */ _pstFileInfo->hInternal = hHandle; /* Updates result */ eResult = orxSTATUS_SUCCESS; } #else /* __orxWINDOWS__ */ const orxSTRING zFileName; DIR *pDir; /* Checks */ orxASSERT((sstFile.u32Flags & orxFILE_KU32_STATIC_FLAG_READY) == orxFILE_KU32_STATIC_FLAG_READY); orxASSERT(_pstFileInfo != orxNULL); /* Gets base file name */ zFileName = orxString_SkipPath(_zSearchPattern); /* Has directory? */ if(zFileName != _zSearchPattern) { orxU32 u32Length; /* Updates path & full name base */ u32Length = orxMIN((orxU32)(zFileName - _zSearchPattern), sizeof(_pstFileInfo->zPath) - 1); orxString_NCopy(_pstFileInfo->zPath, _zSearchPattern, u32Length); _pstFileInfo->zPath[u32Length] = orxCHAR_NULL; orxString_Copy(_pstFileInfo->zFullName, _pstFileInfo->zPath); /* Stores pattern */ u32Length = orxMIN(orxString_GetLength(zFileName), sizeof(_pstFileInfo->zPattern) - 1); orxString_NCopy(_pstFileInfo->zPattern, zFileName, u32Length); _pstFileInfo->zPattern[u32Length] = orxCHAR_NULL; } else { orxU32 u32Length; /* Stores pattern */ u32Length = orxMIN(orxString_GetLength(_zSearchPattern), sizeof(_pstFileInfo->zPattern) - 1); orxString_NCopy(_pstFileInfo->zPattern, _zSearchPattern, u32Length); _pstFileInfo->zPattern[u32Length] = orxCHAR_NULL; /* Clears vars */ orxString_Print(_pstFileInfo->zPath, "./"); orxString_Print(_pstFileInfo->zFullName, "./"); } /* Open directory */ pDir = opendir(_pstFileInfo->zPath); /* Valid ? */ if(pDir != orxNULL) { /* Stores the DIR handle */ _pstFileInfo->hInternal = (orxHANDLE)pDir; /* Retrieves info */ eResult = orxFile_FindNext(_pstFileInfo); /* Failure? */ if(eResult == orxSTATUS_FAILURE) { /* Closes directory */ closedir(pDir); /* Clears handle */ _pstFileInfo->hInternal = 0; } } #endif /* __orxWINDOWS__ */ /* Done! */ return eResult; }
static orxSTATUS orxFASTCALL ParseTextFile(const orxSTRING _zFileName) { orxFILE *pstFile; orxSTATUS eResult; // Opens file pstFile = orxFile_Open(_zFileName, orxFILE_KU32_FLAG_OPEN_READ | orxFILE_KU32_FLAG_OPEN_BINARY); // Success? if(pstFile) { orxCHAR acBuffer[orxFONTGEN_KU32_BUFFER_SIZE]; orxU32 u32Size, u32Offset, u32Counter; orxBOOL bFirst; // While file isn't empty for(u32Size = (orxU32)orxFile_Read(acBuffer, sizeof(orxCHAR), orxFONTGEN_KU32_BUFFER_SIZE, pstFile), u32Offset = 0, u32Counter = 0, bFirst = orxTRUE; u32Size > 0; u32Size = (orxU32)orxFile_Read(acBuffer + u32Offset, sizeof(orxCHAR), orxFONTGEN_KU32_BUFFER_SIZE - u32Offset, pstFile) + u32Offset, bFirst = orxFALSE) { orxCHAR *pc, *pcNext; // Has UTF-8 BOM? if((bFirst != orxFALSE) && (orxString_NCompare(acBuffer, orxFONTGEN_KZ_UTF8_BOM, orxFONTGEN_KU32_UTF8_BOM_LENGTH) == 0)) { // Skips it pc = acBuffer + orxFONTGEN_KU32_UTF8_BOM_LENGTH; } else { // Starts at the beginning of the buffer pc = acBuffer; } // For all characters for(pcNext = orxNULL; pc < acBuffer + u32Size; pc = pcNext) { orxU32 u32CharacterCodePoint; // Reads it u32CharacterCodePoint = orxString_GetFirstCharacterCodePoint(pc, (const orxSTRING *)&pcNext); // Non EOL? if((u32CharacterCodePoint != orxCHAR_CR) && (u32CharacterCodePoint != orxCHAR_LF)) { // Valid? if(u32CharacterCodePoint != orxU32_UNDEFINED) { // Not already in table? if(orxHashTable_Get(sstFontGen.pstCharacterTable, u32CharacterCodePoint) == orxNULL) { orxU32 u32GlyphIndex; // Gets character's glyph index u32GlyphIndex = (orxU32)FT_Get_Char_Index(sstFontGen.pstFontFace, (FT_ULong)u32CharacterCodePoint); // Valid? if(u32GlyphIndex) { orxFONTGEN_GLYPH *pstGlyph; // Allocates glyph pstGlyph = (orxFONTGEN_GLYPH *)orxBank_Allocate(sstFontGen.pstGlyphBank); // Checks orxASSERT(pstGlyph); // Inits it pstGlyph->u32Index = u32GlyphIndex; pstGlyph->u32CodePoint = u32CharacterCodePoint; // Adds it if(orxHashTable_Add(sstFontGen.pstCharacterTable, u32CharacterCodePoint, (void *)pstGlyph) != orxSTATUS_FAILURE) { orxFONTGEN_GLYPH *pstSearchGlyph; // Finds position for(pstSearchGlyph = (orxFONTGEN_GLYPH *)orxLinkList_GetFirst(&sstFontGen.stGlyphList); pstSearchGlyph && (u32CharacterCodePoint > pstSearchGlyph->u32CodePoint); pstSearchGlyph = (orxFONTGEN_GLYPH *)orxLinkList_GetNext(&pstSearchGlyph->stNode)); // Valid? if(pstSearchGlyph) { // Adds it before orxLinkList_AddBefore(&pstSearchGlyph->stNode, &pstGlyph->stNode); } else { // Adds it at the end orxLinkList_AddEnd(&sstFontGen.stGlyphList, &pstGlyph->stNode); } // Updates counter u32Counter++; } else { // Logs message orxFONTGEN_LOG(LOAD, "Character '0x%X': couldn't add to table, skipping.", u32CharacterCodePoint); } } else { // Adds it orxHashTable_Add(sstFontGen.pstCharacterTable, u32CharacterCodePoint, (void *)sstFontGen.pstCharacterTable); // Logs message orxFONTGEN_LOG(LOAD, "Character '0x%X': glyph not found in font, skipping.", u32CharacterCodePoint); } } } else { // End of buffer? if(pcNext >= acBuffer + u32Size) { // Stops break; } else { // Logs message orxFONTGEN_LOG(LOAD, "Invalid character code point '0x%X', skipping.", u32CharacterCodePoint); } } } } // Has remaining buffer? if((pc != acBuffer) && (pcNext > pc)) { // Updates offset u32Offset = (orxU32)(orxMIN(pcNext, acBuffer + u32Size) - pc); // Copies it at the beginning of the buffer orxMemory_Copy(acBuffer, pc, u32Offset); } else { // Clears offset u32Offset = 0; } } // Logs message orxFONTGEN_LOG(LOAD, "'%s': added %d characters.", _zFileName, u32Counter); // Updates result eResult = orxSTATUS_SUCCESS; } else { // Updates result eResult = orxSTATUS_FAILURE; } // Done! return eResult; }
/** Computes DT according to modifier * @param[in] _fDT Real DT * @param[in] _pstClockInfo Concerned clock info * @return Modified DT */ static orxINLINE orxFLOAT orxClock_ComputeDT(orxFLOAT _fDT, const orxCLOCK_INFO *_pstClockInfo) { register const orxCLOCK_MOD_TYPE *peModType; register const orxFLOAT *pfModValue; register orxFLOAT fResult; /* Using global one? */ if(_pstClockInfo == orxNULL) { peModType = &(sstClock.eModType); pfModValue = &(sstClock.fModValue); } /* Using clock one */ else { peModType = &(_pstClockInfo->eModType); pfModValue = &(_pstClockInfo->fModValue); } /* Depending on modifier type */ switch(*peModType) { case orxCLOCK_MOD_TYPE_FIXED: { /* Fixed DT value */ fResult = *pfModValue; break; } case orxCLOCK_MOD_TYPE_MULTIPLY: { /* Multiplied DT value */ fResult = *pfModValue * _fDT; break; } case orxCLOCK_MOD_TYPE_MAXED: { /* Updates DT value */ fResult = orxMIN(*pfModValue, _fDT); break; } default: { /* Logs message */ orxDEBUG_PRINT(orxDEBUG_LEVEL_CLOCK, "Invalid clock modifier type (%d).", *peModType); /* Falls through */ } case orxCLOCK_MOD_TYPE_NONE: { /* Gets base DT */ fResult = _fDT; break; } } /* Done! */ return fResult; }