void C4MusicSystem::LoadMoreMusic() { StdStrBuf MoreMusicFile; // load MoreMusic.txt if (!MoreMusicFile.LoadFromFile(Config.AtUserDataPath(C4CFN_MoreMusic))) return; // read contents char *pPos = MoreMusicFile.getMData(); while (pPos && *pPos) { // get line char szLine[1024 + 1]; SCopyUntil(pPos, szLine, '\n', 1024); pPos = strchr(pPos, '\n'); if (pPos) pPos++; // remove leading whitespace char *pLine = szLine; while (*pLine == ' ' || *pLine == '\t' || *pLine == '\r') pLine++; // and whitespace at end char *p = pLine + strlen(pLine) - 1; while (*p == ' ' || *p == '\t' || *p == '\r') { *p = 0; --p; } // comment? if (*pLine == '#') { // might be a "directive" if (SEqual(pLine, "#clear")) ClearSongs(); continue; } // try to load file(s) LoadDir(pLine); } }
bool GetLogSection(size_t iStart, size_t iLength, StdStrBuf &rsOut) { if (!iLength) { rsOut.Clear(); return true; } // read section from log file StdStrBuf BufOrig; if (!BufOrig.LoadFromFile(sLogFileName.getData())) return false; char *szBuf = BufOrig.getMData(); size_t iSize = BufOrig.getSize(); // size excluding terminator // reduce to desired buffer section if (iStart > iSize) iStart = iSize; if (iStart + iLength > iSize) iLength = iSize - iStart; szBuf += iStart; szBuf[iLength] = '\0'; // strip timestamps; convert linebreaks to Clonk-linebreaks '|' char *szPosWrite=szBuf; const char *szPosRead=szBuf; while (*szPosRead) { // skip timestamp if (*szPosRead == '[') while (*szPosRead && *szPosRead != ']') { --iSize; ++szPosRead; } // skip whitespace behind timestamp if (!*szPosRead) break; szPosRead++; // copy data until linebreak size_t iLen=0; while (*szPosRead && *szPosRead != 0x0d && *szPosRead != 0x0a) { ++szPosRead; ++iLen; } if (iLen && szPosRead-iLen != szPosWrite) memmove(szPosWrite, szPosRead-iLen, iLen); szPosWrite += iLen; // skip additional linebreaks while (*szPosRead == 0x0d || *szPosRead == 0x0a) ++szPosRead; // write a Clonk-linebreak if (*szPosRead) *szPosWrite++ = '|'; } // done; create string buffer from data rsOut.Copy(szBuf, szPosWrite - szBuf); // done, success return true; }