/** * @brief * Parse next parameter */ bool ParamsParser::Next() { // Parse next expression if (m_nParsePos > -1 && m_cRegEx.Match(m_sParameters, m_nParsePos)) { // Get expression and new parse position m_nParsePos = m_cRegEx.GetPosition(); String sExpression = m_cRegEx.GetResult(0); // Process the found expression if (sExpression[sExpression.GetLength()-1] == '\'') { static RegEx cRegEx("\\s*(\\w*)\\s*=\\s*'?\\s*([^\']*)\\s*'?"); if (cRegEx.Match(sExpression)) { // Get name and value m_sName = cRegEx.GetResult(0); m_sValue = cRegEx.GetResult(1); return true; } } else { static RegEx cRegEx("\\s*(\\w*)\\s*=\\s*\"?\\s*([^\"]*)\\s*\"?"); if (cRegEx.Match(sExpression)) { // Get name and value m_sName = cRegEx.GetResult(0); m_sValue = cRegEx.GetResult(1); return true; } } } // Error, could not parse next expression m_sName = ""; m_sValue = ""; m_nParsePos = -1; return false; }
/** * @brief * Reads memory information from the '/proc/meminfo'-file */ bool SystemLinux::GetMemoryInformation(MemoryInformation &sMemoryInformation) const { // Initialize memory information sMemoryInformation.nTotalPhysicalMemory = 0; sMemoryInformation.nFreePhysicalMemory = 0; sMemoryInformation.nTotalSwapMemory = 0; sMemoryInformation.nFreeSwapMemory = 0; // Parse kernel information file File cFile("/proc/meminfo"); if (cFile.Open(File::FileRead | File::FileText)) { static RegEx cRegEx("^\\s*(MemTotal|MemFree|SwapTotal|SwapFree):\\s*(\\d+).*$"); while (!cFile.IsEof()) { const String sLine = cFile.GetS(); if (cRegEx.Match(sLine)) { const String sName = cRegEx.GetResult(0); const String sResult = cRegEx.GetResult(1); if (sName == "MemTotal") sMemoryInformation.nTotalPhysicalMemory = sResult.GetInt() * 1024; if (sName == "MemFree") sMemoryInformation.nFreePhysicalMemory = sResult.GetInt() * 1024; if (sName == "SwapTotal") sMemoryInformation.nTotalSwapMemory = sResult.GetInt() * 1024; if (sName == "SwapFree") sMemoryInformation.nFreeSwapMemory = sResult.GetInt() * 1024; } } // Done return true; } // Error! return false; }
/** * @brief * Writes the flexible scene node variables */ void PLSceneNode::WriteVariables(XmlElement &cNodeElement) const { // Export variables? if (g_SEOptions.bUserPropVariables) { // Is there a 3ds Max node (No 3ds Max node, no properties) INode *pMaxNode = GetMaxNode(); if (pMaxNode) { // Check for variables TSTR s3dsMaxString; if (pMaxNode->GetUserPropString(_T("Vars"), s3dsMaxString)) { // Get all expressions static RegEx cExpressionRegEx("\\s*((\\w*\\s*=\\s*\"[^\"]*\")|(\\w*\\s*=\\s*[\\w|]*))"); const String sString = s3dsMaxString; uint32 nExpressionParsePos = 0; while (cExpressionRegEx.Match(sString, nExpressionParsePos)) { // Get expression nExpressionParsePos = cExpressionRegEx.GetPosition(); const String sExpression = cExpressionRegEx.GetResult(0); // Process the found expression static RegEx cRegEx("\\s*(\\w*)\\s*=\\s*\"?\\s*([^\"]*)\\s*\"?"); if (cRegEx.Match(sExpression)) { // Get name and value const String sName = cRegEx.GetResult(0); const String sValue = cRegEx.GetResult(1); // Flags variable? if (sName == "Flags") { // Update attribute String sFlags = cNodeElement.GetAttribute(sName); if (sFlags.GetLength()) sFlags += '|' + sValue; else sFlags = sValue; sFlags.Trim(); cNodeElement.SetAttribute(sName, sFlags); } else { // Set attribute cNodeElement.SetAttribute(sName, sValue); } } } } } } }
cell match_c(AMX *amx, cell *params, bool all) { int id = params[2] - 1; if (id >= (int)PEL.length() || id < 0 || PEL[id]->isFree()) { MF_LogError(amx, AMX_ERR_NATIVE, "Invalid regex handle %d", id); return 0; } int len; const char *str = MF_GetAmxString(amx, params[1], 0, &len); cell *errorCode = MF_GetAmxAddr(amx, params[3]); RegEx *x = PEL[id]; int e; if (all) e = x->MatchAll(str); else e = x->Match(str); if (e == -1) { /* there was a match error. move on. */ *errorCode = x->mErrorOffset; /* only clear the match results, since the regex object may still be referenced later */ x->ClearMatch(); return -2; } else if (e == 0) { *errorCode = 0; /* only clear the match results, since the regex object may still be referenced later */ x->ClearMatch(); return 0; } else { *errorCode = x->Count(); return x->Count(); } }
uint32 SystemLinux::GetCPUMhz() const { // Initialize uint32 nMhz = 0; // Parse kernel information file File cFile("/proc/cpuinfo"); if (cFile.Open(File::FileRead | File::FileText)) { static RegEx cRegEx("^\\s*cpu MHz\\s*:\\s*(\\d+(\\.\\d+)).*$"); while (!cFile.IsEof()) { const String sLine = cFile.GetS(); if (cRegEx.Match(sLine)) { const String sResult = cRegEx.GetResult(0); nMhz = sResult.GetInt(); } } } // Done return nMhz; }
/** * @brief * From string */ bool Vector2i::FromString(const String &sString) { if (sString.GetLength()) { // Parse components uint32 nParsePos = 0; uint32 nComponent = 0; static RegEx cRegEx("\\s*(\\S+)"); while (nComponent < 2 && cRegEx.Match(sString, nParsePos)) { nV[nComponent++] = cRegEx.GetResult(0).GetInt(); nParsePos = cRegEx.GetPosition(); } // Set unused components to 0 while (nComponent < 2) nV[nComponent++] = 0; // Done return true; } else { // Error! x = y = 0; return false; } }
/** * @brief * From string */ bool Color3::FromString(const String &sString) { if (sString.GetLength()) { // Parse components uint32 nParsePos = 0; uint32 nComponent = 0; static RegEx cRegEx("\\s*(\\S+)"); while (nComponent < 3 && cRegEx.Match(sString, nParsePos)) { fColor[nComponent++] = cRegEx.GetResult(0).GetFloat(); nParsePos = cRegEx.GetPosition(); } // Set unused components to 0 while (nComponent < 3) fColor[nComponent++] = 0.0f; // Done return true; } else { // Error! r = g = b = 0.0f; return false; } }
static cell_t MatchRegex(IPluginContext *pCtx, const cell_t *params) { Handle_t hndl = static_cast<Handle_t>(params[1]); HandleError err; HandleSecurity sec; sec.pOwner = NULL; sec.pIdentity = myself->GetIdentity(); unsigned int offset = 0; if (params[0] >= 4) { offset = (unsigned int)params[4]; } RegEx *x; if ((err=g_pHandleSys->ReadHandle(hndl, g_RegexHandle, &sec, (void **)&x)) != HandleError_None) { return pCtx->ThrowNativeError("Invalid regex handle %x (error %d)", hndl, err); } if (!x) { pCtx->ThrowNativeError("Regex data not found\n"); return 0; } char *str; pCtx->LocalToString(params[2], &str); if(offset >= strlen(str)) return pCtx->ThrowNativeError("Invalid string index\n"); int e = x->Match(str, offset); if (e == -1) { /* there was a match error. move on. */ cell_t *res; pCtx->LocalToPhysAddr(params[3], &res); *res = x->mErrorCode; /* only clear the match results, since the regex object may still be referenced later */ x->ClearMatch(); return -1; } else if (e == 0) { /* only clear the match results, since the regex object may still be referenced later */ x->ClearMatch(); return 0; } else { return x->mMatches[0].mSubStringCount; } }
void cpp_hl_tests(RegEx& e, bool recurse = true) { if(flags[4] & REG_MERGE) return; if(e.error_code()) { if(search_text != BOOST_RE_STR("!")) { begin_error(); cout << "Expression did not compile with class RegEx" << endl; } return; } if(recurse) { // copy and assign test: RegEx e2(e); cpp_hl_tests(e2, false); e2 = e; cpp_hl_tests(e2, false); } if(flags[4] & REG_GREP) { // try to do grep: hl_match_id = 0; GrepCallback cb = hl_grep_test_proc; e.Grep(cb, search_text.c_str(), flags[3]); } else { if(e.Search(search_text.c_str(), flags[3])) { unsigned int i = 0; unsigned int j = 0; while(matches[j] != -2) { if( (matches[j] != (int)e.Position(i)) || ((matches[j] != -1) && ((matches[j+1] - matches[j] != (int)e.Length(i)))) ) { begin_error(); cout << "RegEx::Search error in subexpression " << i << ": found [" << e.Position(i) << "," << (e.Position(i) + e.Length(i)) << "] expected [" << matches[j] << "," << matches[j+1] << "]" << endl; } ++i; j += 2; } } else { if(matches[0] != -1) { begin_error(); cout << "match expected but not found with RexEx::Search" << endl; } } // // test RegEx::Match only if we expect to match all of the input: // if((matches[0] == 0) && (matches[1] == search_text.size())) { if(e.Match(search_text.c_str(), flags[3])) { unsigned int i = 0; unsigned int j = 0; while(matches[j] != -2) { if( (matches[j] != (int)e.Position(i)) || ((matches[j] != -1) && ((matches[j+1] - matches[j] != (int)e.Length(i)))) ) { begin_error(); cout << "RegEx::Match error in subexpression " << i << ": found [" << e.Position(i) << "," << (e.Position(i) + e.Length(i)) << "] expected [" << matches[j] << "," << matches[j+1] << "]" << endl; } ++i; j += 2; } } else { begin_error(); cout << "Match expected but not found with RegEx::Match" << endl; } } } }
cell match(AMX *amx, cell *params, bool all) { int len; const char *str = MF_GetAmxString(amx, params[1], 0, &len); const char *regex = MF_GetAmxString(amx, params[2], 1, &len); int id = GetPEL(); RegEx *x = PEL[id]; char *flags = NULL; cell *errorCode; int result = 0; if (!all) { if (*params / sizeof(cell) >= 6) // compiled with 1.8's extra parameter { flags = MF_GetAmxString(amx, params[6], 2, &len); } result = x->Compile(regex, flags); errorCode = MF_GetAmxAddr(amx, params[3]); } else { result = x->Compile(regex, params[3]); errorCode = MF_GetAmxAddr(amx, params[6]); } if (!result) { const char *err = x->mError; *errorCode = x->mErrorOffset; MF_SetAmxString(amx, params[4], err ? err : "unknown", params[5]); return -1; } int e; if (all) e = x->MatchAll(str); else e = x->Match(str); if (e == -1) { /* there was a match error. destroy this and move on. */ *errorCode = x->mErrorOffset; x->Clear(); return -2; } else if (e == 0) { *errorCode = 0; x->Clear(); return 0; } else { *errorCode = x->Count(); if (all) return x->Count(); } return id + 1; }
void ListBinCommand::Execute() { SNZBListRequest ListRequest; if (!ReceiveRequest(&ListRequest, sizeof(ListRequest))) { return; } SNZBListResponse ListResponse; memset(&ListResponse, 0, sizeof(ListResponse)); ListResponse.m_MessageBase.m_iSignature = htonl(NZBMESSAGE_SIGNATURE); ListResponse.m_MessageBase.m_iStructSize = htonl(sizeof(ListResponse)); ListResponse.m_iEntrySize = htonl(sizeof(SNZBListResponseFileEntry)); ListResponse.m_bRegExValid = 0; char* buf = NULL; int bufsize = 0; if (ntohl(ListRequest.m_bFileList)) { eRemoteMatchMode eMatchMode = (eRemoteMatchMode)ntohl(ListRequest.m_iMatchMode); bool bMatchGroup = ntohl(ListRequest.m_bMatchGroup); const char* szPattern = ListRequest.m_szPattern; RegEx *pRegEx = NULL; if (eMatchMode == eRemoteMatchModeRegEx) { pRegEx = new RegEx(szPattern); ListResponse.m_bRegExValid = pRegEx->IsValid(); } // Make a data structure and copy all the elements of the list into it DownloadQueue* pDownloadQueue = g_pQueueCoordinator->LockQueue(); // calculate required buffer size for nzbs int iNrNZBEntries = pDownloadQueue->GetNZBInfoList()->size(); int iNrPPPEntries = 0; bufsize += iNrNZBEntries * sizeof(SNZBListResponseNZBEntry); for (NZBInfoList::iterator it = pDownloadQueue->GetNZBInfoList()->begin(); it != pDownloadQueue->GetNZBInfoList()->end(); it++) { NZBInfo* pNZBInfo = *it; bufsize += strlen(pNZBInfo->GetFilename()) + 1; bufsize += strlen(pNZBInfo->GetName()) + 1; bufsize += strlen(pNZBInfo->GetDestDir()) + 1; bufsize += strlen(pNZBInfo->GetCategory()) + 1; bufsize += strlen(pNZBInfo->GetQueuedFilename()) + 1; // align struct to 4-bytes, needed by ARM-processor (and may be others) bufsize += bufsize % 4 > 0 ? 4 - bufsize % 4 : 0; // calculate required buffer size for pp-parameters for (NZBParameterList::iterator it = pNZBInfo->GetParameters()->begin(); it != pNZBInfo->GetParameters()->end(); it++) { NZBParameter* pNZBParameter = *it; bufsize += sizeof(SNZBListResponsePPPEntry); bufsize += strlen(pNZBParameter->GetName()) + 1; bufsize += strlen(pNZBParameter->GetValue()) + 1; // align struct to 4-bytes, needed by ARM-processor (and may be others) bufsize += bufsize % 4 > 0 ? 4 - bufsize % 4 : 0; iNrPPPEntries++; } } // calculate required buffer size for files int iNrFileEntries = pDownloadQueue->GetFileQueue()->size(); bufsize += iNrFileEntries * sizeof(SNZBListResponseFileEntry); for (FileQueue::iterator it = pDownloadQueue->GetFileQueue()->begin(); it != pDownloadQueue->GetFileQueue()->end(); it++) { FileInfo* pFileInfo = *it; bufsize += strlen(pFileInfo->GetSubject()) + 1; bufsize += strlen(pFileInfo->GetFilename()) + 1; // align struct to 4-bytes, needed by ARM-processor (and may be others) bufsize += bufsize % 4 > 0 ? 4 - bufsize % 4 : 0; } buf = (char*) malloc(bufsize); char* bufptr = buf; // write nzb entries for (NZBInfoList::iterator it = pDownloadQueue->GetNZBInfoList()->begin(); it != pDownloadQueue->GetNZBInfoList()->end(); it++) { unsigned long iSizeHi, iSizeLo; NZBInfo* pNZBInfo = *it; SNZBListResponseNZBEntry* pListAnswer = (SNZBListResponseNZBEntry*) bufptr; Util::SplitInt64(pNZBInfo->GetSize(), &iSizeHi, &iSizeLo); pListAnswer->m_iSizeLo = htonl(iSizeLo); pListAnswer->m_iSizeHi = htonl(iSizeHi); pListAnswer->m_bMatch = htonl(bMatchGroup && (!pRegEx || pRegEx->Match(pNZBInfo->GetName()))); pListAnswer->m_iFilenameLen = htonl(strlen(pNZBInfo->GetFilename()) + 1); pListAnswer->m_iNameLen = htonl(strlen(pNZBInfo->GetName()) + 1); pListAnswer->m_iDestDirLen = htonl(strlen(pNZBInfo->GetDestDir()) + 1); pListAnswer->m_iCategoryLen = htonl(strlen(pNZBInfo->GetCategory()) + 1); pListAnswer->m_iQueuedFilenameLen = htonl(strlen(pNZBInfo->GetQueuedFilename()) + 1); bufptr += sizeof(SNZBListResponseNZBEntry); strcpy(bufptr, pNZBInfo->GetFilename()); bufptr += ntohl(pListAnswer->m_iFilenameLen); strcpy(bufptr, pNZBInfo->GetName()); bufptr += ntohl(pListAnswer->m_iNameLen); strcpy(bufptr, pNZBInfo->GetDestDir()); bufptr += ntohl(pListAnswer->m_iDestDirLen); strcpy(bufptr, pNZBInfo->GetCategory()); bufptr += ntohl(pListAnswer->m_iCategoryLen); strcpy(bufptr, pNZBInfo->GetQueuedFilename()); bufptr += ntohl(pListAnswer->m_iQueuedFilenameLen); // align struct to 4-bytes, needed by ARM-processor (and may be others) if ((size_t)bufptr % 4 > 0) { pListAnswer->m_iQueuedFilenameLen = htonl(ntohl(pListAnswer->m_iQueuedFilenameLen) + 4 - (size_t)bufptr % 4); memset(bufptr, 0, 4 - (size_t)bufptr % 4); //suppress valgrind warning "uninitialized data" bufptr += 4 - (size_t)bufptr % 4; } } // write ppp entries int iNZBIndex = 1; for (NZBInfoList::iterator it = pDownloadQueue->GetNZBInfoList()->begin(); it != pDownloadQueue->GetNZBInfoList()->end(); it++, iNZBIndex++) { NZBInfo* pNZBInfo = *it; for (NZBParameterList::iterator it = pNZBInfo->GetParameters()->begin(); it != pNZBInfo->GetParameters()->end(); it++) { NZBParameter* pNZBParameter = *it; SNZBListResponsePPPEntry* pListAnswer = (SNZBListResponsePPPEntry*) bufptr; pListAnswer->m_iNZBIndex = htonl(iNZBIndex); pListAnswer->m_iNameLen = htonl(strlen(pNZBParameter->GetName()) + 1); pListAnswer->m_iValueLen = htonl(strlen(pNZBParameter->GetValue()) + 1); bufptr += sizeof(SNZBListResponsePPPEntry); strcpy(bufptr, pNZBParameter->GetName()); bufptr += ntohl(pListAnswer->m_iNameLen); strcpy(bufptr, pNZBParameter->GetValue()); bufptr += ntohl(pListAnswer->m_iValueLen); // align struct to 4-bytes, needed by ARM-processor (and may be others) if ((size_t)bufptr % 4 > 0) { pListAnswer->m_iValueLen = htonl(ntohl(pListAnswer->m_iValueLen) + 4 - (size_t)bufptr % 4); memset(bufptr, 0, 4 - (size_t)bufptr % 4); //suppress valgrind warning "uninitialized data" bufptr += 4 - (size_t)bufptr % 4; } } } // write file entries for (FileQueue::iterator it = pDownloadQueue->GetFileQueue()->begin(); it != pDownloadQueue->GetFileQueue()->end(); it++) { unsigned long iSizeHi, iSizeLo; FileInfo* pFileInfo = *it; SNZBListResponseFileEntry* pListAnswer = (SNZBListResponseFileEntry*) bufptr; pListAnswer->m_iID = htonl(pFileInfo->GetID()); int iNZBIndex = 0; for (unsigned int i = 0; i < pDownloadQueue->GetNZBInfoList()->size(); i++) { iNZBIndex++; if (pDownloadQueue->GetNZBInfoList()->at(i) == pFileInfo->GetNZBInfo()) { break; } } pListAnswer->m_iNZBIndex = htonl(iNZBIndex); if (pRegEx && !bMatchGroup) { char szFilename[MAX_PATH]; snprintf(szFilename, sizeof(szFilename) - 1, "%s/%s", pFileInfo->GetNZBInfo()->GetName(), Util::BaseFileName(pFileInfo->GetFilename())); pListAnswer->m_bMatch = htonl(pRegEx->Match(szFilename)); } Util::SplitInt64(pFileInfo->GetSize(), &iSizeHi, &iSizeLo); pListAnswer->m_iFileSizeLo = htonl(iSizeLo); pListAnswer->m_iFileSizeHi = htonl(iSizeHi); Util::SplitInt64(pFileInfo->GetRemainingSize(), &iSizeHi, &iSizeLo); pListAnswer->m_iRemainingSizeLo = htonl(iSizeLo); pListAnswer->m_iRemainingSizeHi = htonl(iSizeHi); pListAnswer->m_bFilenameConfirmed = htonl(pFileInfo->GetFilenameConfirmed()); pListAnswer->m_bPaused = htonl(pFileInfo->GetPaused()); pListAnswer->m_iActiveDownloads = htonl(pFileInfo->GetActiveDownloads()); pListAnswer->m_iPriority = htonl(pFileInfo->GetPriority()); pListAnswer->m_iSubjectLen = htonl(strlen(pFileInfo->GetSubject()) + 1); pListAnswer->m_iFilenameLen = htonl(strlen(pFileInfo->GetFilename()) + 1); bufptr += sizeof(SNZBListResponseFileEntry); strcpy(bufptr, pFileInfo->GetSubject()); bufptr += ntohl(pListAnswer->m_iSubjectLen); strcpy(bufptr, pFileInfo->GetFilename()); bufptr += ntohl(pListAnswer->m_iFilenameLen); // align struct to 4-bytes, needed by ARM-processor (and may be others) if ((size_t)bufptr % 4 > 0) { pListAnswer->m_iFilenameLen = htonl(ntohl(pListAnswer->m_iFilenameLen) + 4 - (size_t)bufptr % 4); memset(bufptr, 0, 4 - (size_t)bufptr % 4); //suppress valgrind warning "uninitialized data" bufptr += 4 - (size_t)bufptr % 4; } } g_pQueueCoordinator->UnlockQueue(); if (pRegEx) { delete pRegEx; } ListResponse.m_iNrTrailingNZBEntries = htonl(iNrNZBEntries); ListResponse.m_iNrTrailingPPPEntries = htonl(iNrPPPEntries); ListResponse.m_iNrTrailingFileEntries = htonl(iNrFileEntries); ListResponse.m_iTrailingDataLength = htonl(bufsize); } if (htonl(ListRequest.m_bServerState)) { unsigned long iSizeHi, iSizeLo; ListResponse.m_iDownloadRate = htonl((int)(g_pQueueCoordinator->CalcCurrentDownloadSpeed() * 1024)); Util::SplitInt64(g_pQueueCoordinator->CalcRemainingSize(), &iSizeHi, &iSizeLo); ListResponse.m_iRemainingSizeHi = htonl(iSizeHi); ListResponse.m_iRemainingSizeLo = htonl(iSizeLo); ListResponse.m_iDownloadLimit = htonl((int)(g_pOptions->GetDownloadRate() * 1024)); ListResponse.m_bDownloadPaused = htonl(g_pOptions->GetPauseDownload()); ListResponse.m_bDownload2Paused = htonl(g_pOptions->GetPauseDownload2()); ListResponse.m_bPostPaused = htonl(g_pOptions->GetPausePostProcess()); ListResponse.m_bScanPaused = htonl(g_pOptions->GetPauseScan()); ListResponse.m_iThreadCount = htonl(Thread::GetThreadCount() - 1); // not counting itself PostQueue* pPostQueue = g_pQueueCoordinator->LockQueue()->GetPostQueue(); ListResponse.m_iPostJobCount = htonl(pPostQueue->size()); g_pQueueCoordinator->UnlockQueue(); int iUpTimeSec, iDnTimeSec; long long iAllBytes; bool bStandBy; g_pQueueCoordinator->CalcStat(&iUpTimeSec, &iDnTimeSec, &iAllBytes, &bStandBy); ListResponse.m_iUpTimeSec = htonl(iUpTimeSec); ListResponse.m_iDownloadTimeSec = htonl(iDnTimeSec); ListResponse.m_bDownloadStandBy = htonl(bStandBy); Util::SplitInt64(iAllBytes, &iSizeHi, &iSizeLo); ListResponse.m_iDownloadedBytesHi = htonl(iSizeHi); ListResponse.m_iDownloadedBytesLo = htonl(iSizeLo); } // Send the request answer send(m_iSocket, (char*) &ListResponse, sizeof(ListResponse), 0); // Send the data if (bufsize > 0) { send(m_iSocket, buf, bufsize, 0); } if (buf) { free(buf); } }
int main( int argc, char **argv ) { RegEx re; re.Compile("abcd"); assert ( true == re.Match("abcd")); assert ( true == re.Match("abcde")); assert ( true == re.Match("acde")); re.Compile("ab*"); assert ( true == re.Match("ac")); assert ( true == re.Match("abc")); assert ( true == re.Match("abbc")); assert ( true == re.Match("acbb")); assert ( false == re.Match("xcbb")); re.Compile("ab+"); assert ( true == re.Match("abc")); assert ( true == re.Match("abbc")); assert ( false == re.Match ("ac")); re.Compile("ab?"); assert ( true == re.Match("ac")); assert ( true == re.Match("abc")); assert ( true == re.Match ("abbc")); re.Compile("a|b*"); assert ( true == re.Match("a")); assert ( true == re.Match("b")); assert ( true == re.Match ("bbb")); assert ( true == re.Match ("bb")); re.Compile("(a|b)*"); assert ( true == re.Match("a")); assert ( true == re.Match("b")); assert ( true == re.Match ("aa")); assert ( true == re.Match ("ab")); assert ( true == re.Match ("ba")); assert ( true == re.Match ("bb")); assert ( true == re.Match ("aaa")); re.Compile("a*b"); assert ( false == re.Match("a")); assert ( true == re.Match("ab")); assert ( true == re.Match("aaaabbbcccb")); assert ( false == re.Match("a12344b")); assert ( false == re.Match("a@#$@#$b")); assert ( true == re.Match("b")); re.Compile("(a|b)*abb"); assert ( true == re.Match("abb")); assert ( true == re.Match("aabb")); assert ( true == re.Match("babb")); assert ( true == re.Match("aaabb")); assert ( true == re.Match("bbabb")); assert ( true == re.Match("ababb")); assert ( true == re.Match("aababb")); re.Compile("ab[0-9]"); assert ( true == re.Match("ab0")); assert ( true == re.Match("ab1")); assert ( true == re.Match("ab2")); assert ( true == re.Match("ab3")); assert ( true == re.Match("ab4")); assert ( true == re.Match("ab5")); assert ( true == re.Match("ab6")); assert ( true == re.Match("ab7")); assert ( true == re.Match("ab8")); assert ( true == re.Match("ab9")); assert ( true == re.Match("ab199")); re.Compile("XYZ[aeiou]"); assert ( true == re.Match("XYZa")); assert ( true == re.Match("XYZe")); assert ( true == re.Match("XYZi")); assert ( true == re.Match("XYZo")); assert ( true == re.Match("XYZu")); assert ( false == re.Match("XYZb")); return 0; }
/** * @brief * Writes the scene node modifiers */ void PLSceneNode::WriteModifiers(XmlElement &cSceneElement, const String &sApplicationDrive, const String &sApplicationDir) { // Is there a 3ds Max node? (no 3ds Max node, no properties) INode *pMaxNode = GetMaxNode(); if (pMaxNode) { // Has this 3ds Max node a target? if (pMaxNode->GetTarget()) { // Write down the scene node modifier WriteTargetRotationModifier(cSceneElement, *pMaxNode->GetTarget(), false); } // Are there any position, rotation, scale keyframes? bool bPositionKeyframes = false; bool bRotationKeyframes = false; bool bScaleKeyframes = false; // Check 3ds Max node controllers Control *pTMController = pMaxNode->GetTMController(); if (pTMController) { // Position controller Control *pController = pTMController->GetPositionController(); if (pController) { // Are there any position keyframes? bPositionKeyframes = PLTools::HasKeyControlInterface(*pController); if (!bPositionKeyframes) { // Is there a path controller? IPathPosition *pPathController = GetIPathConstInterface(pController); if (pPathController && pPathController->GetNumTargets() > 0) { INode *pTarget = pPathController->GetNode(0); if (pTarget) { // Get path filename const String sPathFilename = PLTools::GetResourceFilename(PLTools::ResourcePath, String(pTarget->GetName()) + ".path"); // Get the percentage along the path float fPercentageAlongPath = 0.0f; { IParamBlock2 *pIParamBlock2 = pPathController->GetParamBlock(path_params); int nRefNum = pIParamBlock2 ? pIParamBlock2->GetControllerRefNum(path_percent) : -1; RefTargetHandle cRefTargetHandle = (nRefNum >= 0) ? pIParamBlock2->GetReference(nRefNum) : nullptr; if (cRefTargetHandle) fPercentageAlongPath = pIParamBlock2->GetFloat(path_percent, 0); } { // Add scene node modifier XmlElement *pModifierElement = new XmlElement("Modifier"); pModifierElement->SetAttribute("Class", "PLScene::SNMPositionPath"); pModifierElement->SetAttribute("Filename", sPathFilename); pModifierElement->SetAttribute("Progress", String::Format("%f", fPercentageAlongPath)); // [TODO] Any change to setup speed inside 3ds Max? static const float fSpeed = 0.03f; // Automatic animation playback? if (g_SEOptions.bAnimationPlayback) pModifierElement->SetAttribute("Speed", String::Format("%f", (pPathController->GetFlip() ? -fSpeed : fSpeed))); else pModifierElement->SetAttribute("Speed", "0.0"); // Link modifier element cSceneElement.LinkEndChild(*pModifierElement); } // Follow? if (pPathController->GetFollow()) { // Add scene node modifier XmlElement *pModifierElement = new XmlElement("Modifier"); pModifierElement->SetAttribute("Class", "PLScene::SNMRotationMoveDirection"); // Link modifier element cSceneElement.LinkEndChild(*pModifierElement); } } } } } // Rotation controller pController = pTMController->GetRotationController(); if (pController) { // Are there any rotation keyframes? bRotationKeyframes = PLTools::HasKeyControlInterface(*pController); if (!bRotationKeyframes) { // Is there a look at controller? ILookAtConstRotation *pLookAtController = GetILookAtConstInterface(pController); if (pLookAtController && pLookAtController->GetNumTargets() > 0) { INode *pTarget = pLookAtController->GetNode(0); if (pTarget) { // Check look at controller bool bFlip = (pLookAtController->GetTargetAxisFlip() != 0); // Write down the scene node modifier WriteTargetRotationModifier(cSceneElement, *pTarget, bFlip); } } } } // Scale controller pController = pTMController->GetScaleController(); if (pController) { // Are there any scale keyframes? bScaleKeyframes = PLTools::HasKeyControlInterface(*pController); } } // Export keyframes? if (bPositionKeyframes || bRotationKeyframes || bScaleKeyframes) { // Get timing Interval cInterval = GetCOREInterface()->GetAnimRange(); int nTicksPerFrame = GetTicksPerFrame(); int nFrameCount = (cInterval.End() - cInterval.Start()) / nTicksPerFrame + 1; // Used to detect whether or not something is animated Point3 vFirstPos, vFirstScale; Quat qFirstRot; bool bUsePosition = false, bUseScale = false, bUseRotation = false; // Prepare the position chunk Chunk cPositionChunk; cPositionChunk.SetSemantic(Chunk::Position); cPositionChunk.Allocate(Chunk::Float, 3, nFrameCount); float *pfPositionData = reinterpret_cast<float*>(cPositionChunk.GetData()); // Prepare the rotation chunk Chunk cRotationChunk; cRotationChunk.SetSemantic(Chunk::Rotation); cRotationChunk.Allocate(Chunk::Float, 4, nFrameCount); float *pfRotationData = reinterpret_cast<float*>(cRotationChunk.GetData()); // Prepare the scale chunk Chunk cScaleChunk; cScaleChunk.SetSemantic(Chunk::Scale); cScaleChunk.Allocate(Chunk::Float, 3, nFrameCount); float *pfScaleData = reinterpret_cast<float*>(cScaleChunk.GetData()); // Loop through all frames int nTime = cInterval.Start(); for (int nFrame=0; nFrame<nFrameCount; nFrame++, nTime+=nTicksPerFrame) { // Get the position, rotation and scale Point3 vPos, vScale; Quat qRot; GetPosRotScale(vPos, qRot, vScale, nTime); // First frame? if (!nFrame) { vFirstPos = vPos; vFirstScale = vScale; qFirstRot = qRot; } else { if (!vFirstPos.Equals(vPos)) bUsePosition = true; if (!vFirstScale.Equals(vScale)) bUseScale = true; if (!qFirstRot.Equals(qRot)) bUseRotation = true; } // Position if (bPositionKeyframes && pfPositionData) { // Currently ONLY the center of the container the node is in use used to make it relative const Point3 vParentWorldSpaceCenter = GetContainer() ? GetContainer()->GetWorldSpaceCenter() : Point3(0.0f, 0.0f, 0.0f); // Get the position const Point3 vFinalPos = (GetType() != TypeScene && GetType() != TypeCell) ? vPos-vParentWorldSpaceCenter : static_cast<const PLSceneContainer*>(this)->GetWorldSpaceCenter(); // x *pfPositionData = vFinalPos.x; pfPositionData++; // y *pfPositionData = vFinalPos.y; pfPositionData++; // z *pfPositionData = vFinalPos.z; pfPositionData++; } // Rotation if (bRotationKeyframes && pfRotationData) { // [TODO] Check this (why do we need it?) qRot.Invert(); // w *pfRotationData = qRot.w; pfRotationData++; // x *pfRotationData = qRot.x; pfRotationData++; // y *pfRotationData = qRot.y; pfRotationData++; // z *pfRotationData = qRot.z; pfRotationData++; } // Scale if (bScaleKeyframes && pfScaleData) { // x *pfScaleData = vScale.x; pfScaleData++; // y *pfScaleData = vScale.y; pfScaleData++; // z *pfScaleData = vScale.z; pfScaleData++; } } // Create keyframe animation scene node modifiers if (bPositionKeyframes && bUsePosition) { // [TODO] Better (and safer) filename // Save chunk const String sPositionKeys = PLTools::GetResourceFilename(PLTools::ResourceKeyframes, String::Format("%s_PositionKeyframes.chunk", GetName().GetASCII()).GetASCII()); if (SaveChunk(cPositionChunk, sApplicationDrive + sApplicationDir + sPositionKeys)) { // Add the modifier XmlElement *pModifierElement = new XmlElement("Modifier"); // Set class attribute pModifierElement->SetAttribute("Class", "PLScene::SNMPositionKeyframeAnimation"); // [TODO] Currently the frame rate is by default always 24 // Set frames per second attribute // pModifierElement->SetAttribute("FramesPerSecond", GetFrameRate()); // Automatic animation playback? pModifierElement->SetAttribute("Speed", g_SEOptions.bAnimationPlayback ? "1.0" : "0.0"); // Set keys attribute pModifierElement->SetAttribute("Keys", sPositionKeys); // Link modifier elements cSceneElement.LinkEndChild(*pModifierElement); } } if (bRotationKeyframes && bUseRotation) { // [TODO] Better (and safer) filename // Save chunk const String sRotationKeys = PLTools::GetResourceFilename(PLTools::ResourceKeyframes, String::Format("%s_RotationKeyframes.chunk", GetName().GetASCII()).GetASCII()); if (SaveChunk(cRotationChunk, sApplicationDrive + sApplicationDir + sRotationKeys)) { // Add the modifier XmlElement *pModifierElement = new XmlElement("Modifier"); // Set class attribute pModifierElement->SetAttribute("Class", "PLScene::SNMRotationKeyframeAnimation"); // [TODO] Currently the frame rate is by default always 24 // Set frames per second attribute // pModifierElement->SetAttribute("FramesPerSecond", GetFrameRate()); // Automatic animation playback? pModifierElement->SetAttribute("Speed", g_SEOptions.bAnimationPlayback ? "1.0" : "0.0"); // Set keys attribute pModifierElement->SetAttribute("Keys", sRotationKeys); // Link modifier elements cSceneElement.LinkEndChild(*pModifierElement); } } if (bScaleKeyframes && bUseScale) { // [TODO] Better (and safer) filename // Save chunk const String sScaleKeys = PLTools::GetResourceFilename(PLTools::ResourceKeyframes, String::Format("%s_ScaleKeyframes.chunk", GetName().GetASCII()).GetASCII()); if (SaveChunk(cScaleChunk, sApplicationDrive + sApplicationDir + sScaleKeys)) { // Add the modifier XmlElement *pModifierElement = new XmlElement("Modifier"); // Set class attribute pModifierElement->SetAttribute("Class", "PLScene::SNMScaleKeyframeAnimation"); // [TODO] Currently the frame rate is by default always 24 // Set frames per second attribute // pModifierElement->SetAttribute("FramesPerSecond", GetFrameRate()); // Automatic animation playback? pModifierElement->SetAttribute("Speed", g_SEOptions.bAnimationPlayback ? "1.0" : "0.0"); // Set keys attribute pModifierElement->SetAttribute("Keys", sScaleKeys); // Link modifier elements cSceneElement.LinkEndChild(*pModifierElement); } } } // Use modifiers? if (g_SEOptions.bUserPropModifiers) { // Check for modifiers MSTR sModifier; int nIndex = 1; TSTR s3dsMaxString; sModifier = _T("Mod"); while (pMaxNode->GetUserPropString(sModifier, s3dsMaxString)) { // Add scene node modifier XmlElement *pModifierElement = new XmlElement("Modifier"); // We really NEED a 'Class' attribute! bool bClassFound = false; // Get all expressions static RegEx cExpressionRegEx("\\s*((\\w*\\s*=\\s*\"[^\"]*\")|(\\w*\\s*=\\s*[\\w|]*))"); const String sString = s3dsMaxString; uint32 nExpressionParsePos = 0; while (cExpressionRegEx.Match(sString, nExpressionParsePos)) { // Get expression nExpressionParsePos = cExpressionRegEx.GetPosition(); const String sExpression = cExpressionRegEx.GetResult(0); // Process the found expression static RegEx cRegEx("\\s*(\\w*)\\s*=\\s*\"?\\s*([^\"]*)\\s*\"?"); if (cRegEx.Match(sExpression)) { // Get name and value const String sName = cRegEx.GetResult(0); const String sValue = cRegEx.GetResult(1); // Set attribute pModifierElement->SetAttribute(sName, sValue); // Class variable already found? if (!bClassFound && sName == "Class") bClassFound = true; } } // Link modifier element? if (bClassFound) cSceneElement.LinkEndChild(*pModifierElement); else delete pModifierElement; // Get next modifier sModifier.printf(_T("Mod%d"), nIndex); nIndex++; } } } }
bool QueueEditor::BuildIDListFromNameList(DownloadQueue* pDownloadQueue, IDList* pIDList, NameList* pNameList, EMatchMode eMatchMode, EEditAction eAction) { #ifndef HAVE_REGEX_H if (eMatchMode == mmRegEx) { return false; } #endif std::set<int> uniqueIDs; for (NameList::iterator it = pNameList->begin(); it != pNameList->end(); it++) { const char* szName = *it; RegEx *pRegEx = NULL; if (eMatchMode == mmRegEx) { pRegEx = new RegEx(szName); if (!pRegEx->IsValid()) { delete pRegEx; return false; } } bool bFound = false; for (FileQueue::iterator it2 = pDownloadQueue->GetFileQueue()->begin(); it2 != pDownloadQueue->GetFileQueue()->end(); it2++) { FileInfo* pFileInfo = *it2; if (eAction < eaGroupMoveOffset) { // file action char szFilename[MAX_PATH]; snprintf(szFilename, sizeof(szFilename) - 1, "%s/%s", pFileInfo->GetNZBInfo()->GetName(), Util::BaseFileName(pFileInfo->GetFilename())); if (((!pRegEx && !strcmp(szFilename, szName)) || (pRegEx && pRegEx->Match(szFilename))) && (uniqueIDs.find(pFileInfo->GetID()) == uniqueIDs.end())) { uniqueIDs.insert(pFileInfo->GetID()); pIDList->push_back(pFileInfo->GetID()); bFound = true; } } else { // group action const char *szFilename = pFileInfo->GetNZBInfo()->GetName(); if (((!pRegEx && !strcmp(szFilename, szName)) || (pRegEx && pRegEx->Match(szFilename))) && (uniqueIDs.find(pFileInfo->GetNZBInfo()->GetID()) == uniqueIDs.end())) { uniqueIDs.insert(pFileInfo->GetNZBInfo()->GetID()); pIDList->push_back(pFileInfo->GetID()); bFound = true; } } } if (pRegEx) { delete pRegEx; } if (!bFound && (eMatchMode == mmName)) { return false; } } return true; }