void CUploadsWnd::OnUploadsLaunch() { CSingleLock pLock( &Transfers.m_pSection, TRUE ); CList<CUploadFile*> pList; for ( POSITION pos = UploadFiles.GetIterator() ; pos ; ) { CUploadFile* pFile = UploadFiles.GetNext( pos ); if ( IsSelected( pFile ) ) pList.AddTail( pFile ); } while ( ! pList.IsEmpty() ) { CUploadFile* pFile = pList.RemoveHead(); if ( UploadFiles.Check( pFile ) ) { CString strPath = pFile->m_sPath; pLock.Unlock(); if ( ! CFileExecutor::Execute( strPath ) ) break; pLock.Lock(); } } }
void CUploadsWnd::OnSecurityBan() { CSingleLock pLock( &Transfers.m_pSection, TRUE ); CList<CUploadFile*> pList; for ( POSITION pos = UploadFiles.GetIterator() ; pos ; ) { CUploadFile* pFile = UploadFiles.GetNext( pos ); if ( IsSelected( pFile ) ) pList.AddTail( pFile ); } while ( ! pList.IsEmpty() ) { CUploadFile* pFile = pList.RemoveHead(); if ( UploadFiles.Check( pFile ) && pFile->GetActive() != NULL ) { CUploadTransfer* pUpload = pFile->GetActive(); IN_ADDR pAddress = pUpload->m_pHost.sin_addr; pUpload->Remove( FALSE ); pLock.Unlock(); Security.Ban( &pAddress, banSession ); pLock.Lock(); } } }
void CUploadsWnd::OnBrowseLaunch() { CSingleLock pLock( &Transfers.m_pSection, TRUE ); CList<CUploadFile*> pList; for ( POSITION pos = UploadFiles.GetIterator() ; pos ; ) { CUploadFile* pFile = UploadFiles.GetNext( pos ); if ( IsSelected( pFile ) ) pList.AddTail( pFile ); } while ( ! pList.IsEmpty() ) { CUploadFile* pFile = pList.RemoveHead(); if ( UploadFiles.Check( pFile ) && pFile->GetActive() != NULL ) { CUploadTransfer* pTransfer = pFile->GetActive(); PROTOCOLID nProtocol = pTransfer->m_nProtocol; SOCKADDR_IN pAddress = pTransfer->m_pHost; pLock.Unlock(); new CBrowseHostWnd( nProtocol, &pAddress ); pLock.Lock(); } } }
void CUploadsWnd::OnUploadsClear() { CSingleLock pLock( &Transfers.m_pSection, TRUE ); CList<CUploadFile*> pList; for ( POSITION pos = UploadFiles.GetIterator() ; pos ; ) { CUploadFile* pFile = UploadFiles.GetNext( pos ); if ( IsSelected( pFile ) ) pList.AddTail( pFile ); } while ( ! pList.IsEmpty() ) { CUploadFile* pFile = pList.RemoveHead(); if ( UploadFiles.Check( pFile ) ) { CUploadTransfer* pUpload = pFile->GetActive(); if ( pUpload != NULL && pUpload->m_nProtocol == PROTOCOL_ED2K && pUpload->m_nState != upsNull ) { CString strFormat, strMessage; LoadString( strFormat, IDS_UPLOAD_CANCEL_ED2K ); strMessage.Format( strFormat, (LPCTSTR)pUpload->m_sFileName ); pLock.Unlock(); UINT nResp = AfxMessageBox( strMessage, MB_ICONQUESTION|MB_YESNOCANCEL|MB_DEFBUTTON2 ); pLock.Lock(); if ( nResp == IDCANCEL ) break; if ( nResp != IDYES || ! UploadFiles.Check( pFile ) ) continue; } pFile->Remove(); } } }
bool Algorithm::IsFinished(void) { if (m_finished) return true; while(!m_WaitForCheckList_Row.IsEmpty()) { int row = m_WaitForCheckList_Row.RemoveHead(); int column = m_WaitForCheckList_Column.RemoveHead(); if (!m_NeverCheck[row][column]) { int originalcount = 0; for (int i = 0; i < 8; ++i) { int newrow = row + RowOffset[i]; int newcolumn = column + ColumnOffset[i]; if (newrow >= 0 && newrow < m_rows && newcolumn >=0 && newcolumn < m_columns) switch (m_MineMatrix[newrow][newcolumn]) { case ORIGINAL: ++originalcount; break; } } if (originalcount) { trow.AddTail(row); tcolumn.AddTail(column); } else m_NeverCheck[row][column] = true; } } while (!trow.IsEmpty()) { int row = trow.RemoveHead(); int column = tcolumn.RemoveHead(); if (!m_NeverCheck[row][column]) { m_WaitForCheckList_Row.AddTail(row); m_WaitForCheckList_Column.AddTail(column); } } if (m_started && m_WaitForCheckList_Row.IsEmpty()) { int originalcount2 = 0, minecount2 = 0; for (int i = 0; i < m_rows; ++i) for (int j = 0; j < m_columns; ++j) switch (m_MineMatrix[i][j]) { case ORIGINAL: ++originalcount2; break; case MINE: ++minecount2; break; } return originalcount2 == 0 && minecount2 == m_RemainderMines; } else return false; }
/** * @brief 响应鼠标单击按钮;Add * @note 该函数总是向列表框的后面追加记录。 * @param CBCGPGridCtrl* pGridCtrlEdit 输入行 * @param CBCGPGridCtrl* pGridCtrlList 列表 * @param CList<int, int>* ListNb Nb号队列指针 * @return void */ void CGridCtrlOperation::OnBnClickedButtonAddA(CBCGPGridCtrl* pGridCtrlEdit, CBCGPGridCtrl* pGridCtrlList) { int i; int iNb; COleVariant oEditVariant; CBCGPGridRow* pRowEdit = NULL; // 输入行 CBCGPGridRow* pRowNew = NULL; // 新行 int iRowID = 0; CList<int, int> ListNb; // 得到索引队列,增加操作 if(false == GetIndexListForAdd(pGridCtrlEdit, &ListNb)) { return; } pRowEdit = pGridCtrlEdit->GetRow(0); while(FALSE == ListNb.IsEmpty()) { // 得到索引号 iNb = ListNb.RemoveHead(); // 索引号在列表中已经存在 if(NULL != pGridCtrlList->FindRowByData(iNb)) { continue; } pRowNew = pGridCtrlList->CreateRow(pGridCtrlList->GetColumnCount()); pRowNew->SetData(iNb); oEditVariant.vt = VT_UI4; oEditVariant.ulVal = iNb; oEditVariant.ChangeType(VT_BSTR); pRowNew->GetItem(0)->SetValue(oEditVariant); for(i = 1; i < pGridCtrlList->GetColumnCount(); i++) { oEditVariant= pRowEdit->GetItem(i)->GetValue(); pRowNew->GetItem(i)->SetValue(oEditVariant); } pGridCtrlList->AddRow(pRowNew, FALSE); /* if(iSelectRowIndex == -1) // 无选中行 { pGridCtrlList->AddRow(pRowNew, FALSE); } else { pGridCtrlList->InsertRowAfter(iSelectRowIndex + iRowID, pRowNew, FALSE); iRowID++; }*/ } pGridCtrlList->AdjustLayout(); }
void CUploadsWnd::OnUploadsLaunch() { CSingleLock pTransfersLock( &Transfers.m_pSection ); if ( ! pTransfersLock.Lock( 500 ) ) return; const BOOL bShift = ( GetAsyncKeyState( VK_SHIFT ) & 0x8000 ); CList<CUploadFile*> pList; for ( POSITION pos = UploadFiles.GetIterator() ; pos ; ) { CUploadFile* pFile = UploadFiles.GetNext( pos ); if ( IsSelected( pFile ) ) pList.AddTail( pFile ); } pTransfersLock.Unlock(); while ( ! pList.IsEmpty() ) { pTransfersLock.Lock(); CUploadFile* pFile = pList.RemoveHead(); if ( pFile->m_sPath.IsEmpty() ) // Multifile torrent always opens folder? (ToDo: Update this path assumption when fixed elsewhere) { const CString strPath = Settings.Downloads.TorrentPath + _T("\\") + pFile->m_sName; // Try default multifile torrent folder (Need better detection) pTransfersLock.Unlock(); if ( PathIsDirectory( strPath ) ) ShellExecute( GetSafeHwnd(), _T("open"), strPath, NULL, NULL, SW_SHOWNORMAL ); } else if ( ! bShift ) // Show in Library by default { CPeerProjectFile oFile = *pFile; pTransfersLock.Unlock(); CSingleLock pLibraryLock( &Library.m_pSection, TRUE ); if ( CLibraryFile* pLibFile = LibraryMaps.LookupFileByHash( &oFile ) ) { if ( CLibraryWnd* pLibrary = CLibraryWnd::GetLibraryWindow() ) // (CLibraryWnd*)( pMainWnd->m_pWindows.Open( RUNTIME_CLASS(CLibraryWnd) ) ) ) { pLibrary->Display( pLibFile ); } } } else if ( UploadFiles.Check( pFile ) ) // Launch directly with Shift key { pTransfersLock.Unlock(); CFileExecutor::Execute( pFile->m_sPath ); } } }
/** * 响应鼠标单击按钮;Delete * @param CBCGPGridCtrl* pGridCtrlEdit 输入行 * @param CBCGPGridCtrl* pGridCtrlList 列表 * @return void */ void CGridCtrlOperation::OnBnClickedButtonDeleteA(CBCGPGridCtrl* pGridCtrlEdit, CBCGPGridCtrl* pGridCtrlList) { CList<int, int> ListNb; // 得到索引队列,修改操作、删除操作、颠倒操作 if(false == GetIndexListForChangeOrDeleteOrReverse(pGridCtrlEdit, pGridCtrlList, &ListNb)) { return; } while(FALSE == ListNb.IsEmpty()) { // 得到行索引号 int iRowIndex = ListNb.RemoveTail(); pGridCtrlList->RemoveRow(iRowIndex); } pGridCtrlList->AdjustLayout(); }
/** * 响应鼠标单击按钮;Change * @param CBCGPGridCtrl* pGridCtrlEdit 输入行 * @param CBCGPGridCtrl* pGridCtrlList 列表 * @return void */ void CGridCtrlOperation::OnBnClickedButtonChangeA(CBCGPGridCtrl* pGridCtrlEdit, CBCGPGridCtrl* pGridCtrlList) { int i,iRowIndex; COleVariant oEditVariant ; //COleVariant oListVariant ; CString strData; CBCGPGridRow* pRowEdit = NULL; // 输入行 CBCGPGridRow* pRowChange = NULL; // 修改行 CList<int, int> ListNb; // 得到索引队列,修改操作、删除操作、颠倒操作 if(false == GetIndexListForChangeOrDeleteOrReverse(pGridCtrlEdit, pGridCtrlList, &ListNb)) { return; } // 得到输入行 pRowEdit = pGridCtrlEdit->GetRow(0); while(FALSE == ListNb.IsEmpty()) { // 得到行索引号 iRowIndex = ListNb.RemoveHead(); pRowChange = pGridCtrlList->GetRow(iRowIndex); for(i = 1; i < pGridCtrlList->GetColumnCount(); i++) { oEditVariant= pRowEdit->GetItem(i)->GetValue(); if(oEditVariant.vt == VT_BSTR) { strData = oEditVariant; if(strData != _T("/")) { pRowChange->GetItem(i)->SetValue(oEditVariant); } } else { pRowChange->GetItem(i)->SetValue(oEditVariant); } } } pGridCtrlList->AdjustLayout(); }
/** * @brief 响应鼠标单击按钮;Change * @note 与 OnBnClickedButtonChangeA函数不同,该函数对每一列调用GetValueForTextField进行解析。 * 支持V/i的格式输入。 * @param CBCGPGridCtrl* pGridCtrlEdit 输入行 * @param CBCGPGridCtrl* pGridCtrlList 列表 * @return void */ void CGridCtrlOperation::OnBnClickedButtonChangeB(CBCGPGridCtrl* pGridCtrlEdit, CBCGPGridCtrl* pGridCtrlList) { int nIndex; // 计数器,计算当前更新的行数 int i,iRowIndex; COleVariant oEditVariant ; COleVariant oListVariant ; CString strData; CBCGPGridRow* pRowEdit = NULL; // 输入行 CBCGPGridRow* pRowChange = NULL; // 修改行 CList<int, int> ListNb; // 得到索引队列,修改操作、删除操作、颠倒操作 if(false == GetIndexListForChangeOrDeleteOrReverse(pGridCtrlEdit, pGridCtrlList, &ListNb)) { return; } // 得到输入行 pRowEdit = pGridCtrlEdit->GetRow(0); nIndex = 0; while(FALSE == ListNb.IsEmpty()) { // 得到行索引号 iRowIndex = ListNb.RemoveHead(); pRowChange = pGridCtrlList->GetRow(iRowIndex); for(i = 1; i < pGridCtrlList->GetColumnCount(); i++) { oEditVariant= pRowEdit->GetItem(i)->GetValue(); oListVariant= pRowChange->GetItem(i)->GetValue(); oListVariant = GetValueForTextField(&oEditVariant,&oListVariant,nIndex); if (oEditVariant.vt == VT_BSTR) { oListVariant.ChangeType(VT_BSTR); } pRowChange->GetItem(i)->SetValue(oListVariant); } nIndex++; } pGridCtrlList->AdjustLayout(); }
CSize CToolPalette::CalcButtonLocations(int nColumns, bool bCalcOnly) { if (nColumns < 1) { nColumns = 1; } bool bHorizontal = (GetCurrentAlignment () & CBRS_ORIENT_HORZ) != 0; // Toolbar layout mode CRect rectClient; GetClientRect (rectClient); EDisplayOptions edo = GetToolbarDisplayOptions (); if ((edo & eDisplayTitle) != 0) { if (!bHorizontal) { rectClient.top += m_nCaptionHeight + 4; } } int xBorders = 0; int yBorders = 0; if ((edo & eDisplayBorder) != 0) { const CRect& rectCorners = m_imgCaption.GetParams ().m_rectCorners; rectClient.left += rectCorners.left + 3; rectClient.top += rectCorners.top; xBorders = rectCorners.left + rectCorners.right; yBorders = rectCorners.top + rectCorners.bottom; } else { rectClient.left += 1; } if ((edo & eDisplaySizeControl) != 0 && bHorizontal) { const int sizeControlHeight = m_imgCaption.GetParams ().m_rectImage.Height (); yBorders += sizeControlHeight; rectClient.top += sizeControlHeight; } // Consider border area CPoint xyPos = rectClient.TopLeft (); // Current position bool bPrevSeparator = true; // Indicates that previous button was a separator. // Initial 'true' value prevents separator to appear first. CClientDC dc (this); CSize szButtonDefault (GetColumnWidth (), GetRowHeight ()); // Default button size to pass to button's OnCalculateSize method int nMaxSize = nColumns * (bHorizontal ? szButtonDefault.cy : szButtonDefault.cx) * 11 / 10; // (11/10) adds +10% space here // The toolbar height (for horizontal layout) or width (for vertical) of toolbar. CList<ButtonStripe, const ButtonStripe&> listStripes; ButtonStripe stripe; // Current stripe CBCGPToolbarButton* pButton = NULL; // Current button for (POSITION pos = m_Buttons.GetHeadPosition (); pos != NULL;) { pButton = (CBCGPToolbarButton*)m_Buttons.GetNext (pos); if (pButton == NULL) { break; } if (!pButton->IsVisible ()) { continue; } bool bSep = (pButton->m_nStyle & TBBS_SEPARATOR) != 0; if (bSep && bPrevSeparator) { continue; } // Layout algorithm: // ------------------- // if (separator) AddPreviousStripe, AddSeparatorStripe, BeginNewStripe // else { // AddButton // if (stripe.breadth > default_stripe_breadth) // AddPreviousStripe, BeginNewStripe, AddButton // } CSize szButton = pButton->OnCalculateSize (&dc, szButtonDefault, bHorizontal); if (bHorizontal) { } else // vertical layout { if (bSep) { if (stripe.buttonCount > 0) { listStripes.AddTail (stripe); } stripe.buttonCount = 1; stripe.breadth = 0; // separator length is set automatically stripe.size = szButton.cy; // cx for horz. listStripes.AddTail (stripe); stripe = ButtonStripe (); } else if (szButton.cx > nMaxSize) // this button is larger than current toolbar width { if (stripe.buttonCount > 0) { listStripes.AddTail (stripe); } stripe.buttonCount = 1; stripe.breadth = szButton.cx; // cy for horz. stripe.size = szButton.cy; // cx for horz. listStripes.AddTail (stripe); // stripe with a single large button stripe = ButtonStripe (); } else // usual button { if (stripe.breadth + szButton.cx <= nMaxSize) { stripe.breadth += szButton.cx; stripe.buttonCount ++; if (szButton.cy > stripe.size) stripe.size = szButton.cy; } else { if (stripe.buttonCount > 0) { listStripes.AddTail (stripe); } stripe.buttonCount = 1; stripe.breadth = szButton.cx; // cy for horz. stripe.size = szButton.cy; // cx for horz. } } } bPrevSeparator = bSep; } if (stripe.buttonCount > 0) { listStripes.AddTail (stripe); } if (listStripes.IsEmpty ()) { return CSize (0, 0); } if (listStripes.GetTail ().breadth == 0) // last item is separator { listStripes.RemoveTail (); } // Now calculate total size int totalLength = m_nCaptionHeight + 4; int maxBreadth = nMaxSize; POSITION posStripes = listStripes.GetHeadPosition (); while (posStripes != NULL) { stripe = listStripes.GetNext (posStripes); ASSERT (stripe.buttonCount > 0); totalLength += stripe.size; if (stripe.breadth > maxBreadth) { maxBreadth = stripe.breadth; } } if (!bCalcOnly) { CPoint ptButtonPos = rectClient.TopLeft (); posStripes = listStripes.GetHeadPosition (); stripe = ButtonStripe(); for (POSITION pos = m_Buttons.GetHeadPosition (); pos != NULL;) { pButton = (CBCGPToolbarButton*)m_Buttons.GetNext (pos); if (pButton == NULL) { break; } if (!pButton->IsVisible ()) { continue; } bool bSep = (pButton->m_nStyle & TBBS_SEPARATOR) != 0; if (bSep && bPrevSeparator) { continue; } CSize szButton = pButton->OnCalculateSize (&dc, szButtonDefault, bHorizontal); CRect rcButton (0, 0, 0, 0); if (stripe.buttonCount == 0) // this member is decremented below { ptButtonPos.y += stripe.size; if (posStripes == NULL) { break; } stripe = listStripes.GetNext (posStripes); ptButtonPos.x = rectClient.left + (maxBreadth - stripe.breadth) / 2; // center-alignment } if (bSep) { ASSERT (stripe.breadth == 0); ASSERT (stripe.buttonCount == 1); rcButton.left = rectClient.left; rcButton.top = ptButtonPos.y; rcButton.right = rcButton.left + maxBreadth; rcButton.bottom = rcButton.top + szButton.cy; } else { rcButton.left = ptButtonPos.x; rcButton.top = ptButtonPos.y + (stripe.size - szButton.cy) / 2; // center-alignment rcButton.right = rcButton.left + szButton.cx; rcButton.bottom = rcButton.top + szButton.cy; ptButtonPos.x += szButton.cx; } pButton->SetRect (rcButton); stripe.buttonCount --; } } if (m_bAdditionalPixel) { ++maxBreadth; } return bHorizontal ? CSize (totalLength + xBorders, maxBreadth + yBorders) : CSize (maxBreadth + xBorders, totalLength + yBorders); }
//************************************************************************************ void CBCGPOutlineParser::DoParse (const CString& strBuffer, const int nStartOffset, const int nEndOffset, CObList& lstResults) { ASSERT (nStartOffset >= 0); ASSERT (nEndOffset < strBuffer.GetLength ()); ASSERT (nStartOffset <= nEndOffset); m_strOut.Empty (); CList <Lexeme, Lexeme&> lstStack; Lexeme lexemStackTop (0, LT_Eps, 0, 0); lstStack.AddTail (lexemStackTop); int nOffset = nStartOffset; while (nOffset <= nEndOffset) { // Get next lexem: Lexeme lexemNext = GetNext (strBuffer, nOffset, nEndOffset); Lexeme lexemTop = lstStack.GetTail (); if (lexemNext.m_nType == LT_EndOfText) { break; } // Parser logic: switch (lexemNext.m_nType) { case LT_BlockStart: lstStack.AddTail (lexemNext); break; case LT_BlockEnd: if (lexemTop.m_nType == LT_BlockStart && lexemTop.m_nBlockType == lexemNext.m_nBlockType) { // Push Block: lstStack.RemoveTail (); Lexeme lexemRes (lexemTop.m_nBlockType, LT_CompleteBlock, lexemTop.m_nStart, lexemNext.m_nEnd); PushResult (lexemRes, lstResults); } else { lstStack.AddTail (lexemNext); } break; case LT_CompleteBlock: { // Push Comment: PushResult (lexemNext, lstResults); } break; case LT_CustomBlock: break; } } // Finish parsing: while (!lstStack.IsEmpty ()) { Lexeme lexem = lstStack.RemoveTail (); PushResult (lexem, lstResults); } }
bool Template::ParseHelper() { // Build our master string. m_helper->m_buffer.SetCount(0, 1024); m_helper->m_outBolPos = 0; // Start copying the string in. m_helper->m_codePtr = (LPCTSTR)m_code; m_helper->m_codeBolPtr = m_helper->m_codePtr; LPCTSTR& codePtr = m_helper->m_codePtr; CharArray& buffer = m_helper->m_buffer; // Conditional stack. CList<CondInfo, CondInfo&> conditionalStack; int nestedFalseConditionals = 0; // Go 'til the end. while (*codePtr != 0) { LPCTSTR outBolPtr = buffer.GetData() + m_helper->m_outBolPos; TokenHelper helper; helper.m_tabSize = m_helper->m_tabSize; helper.m_outBolPtr = outBolPtr; helper.m_file = this; helper.m_helper = m_helper; // See if it is a command. Commands can only occur at the beginning // of a line. if (*codePtr == '!' && *(codePtr + 1) == '!' && codePtr == m_helper->m_codeBolPtr) { // Move past the exclamation points. codePtr += 2; // Is it a command comment? // !!// This is a comment. if (*codePtr == '/' && *(codePtr + 1) == '/') { // Move past the double slash. codePtr += 2; SkipToEol(codePtr); continue; } /////////////////////////////////////////////////////////////////// // Lex the command token. char command[256]; char *comPtr = command; while (*codePtr != 0) { // Is it a space? if (*codePtr == ' ') { // Break at a space. codePtr++; break; } else if (*codePtr == '\n' || *codePtr == '\r') { break; } else { // Copy the command or flag. *comPtr++ = *codePtr++; } } *comPtr = 0; /////////////////////////////////////////////////////////////////// // "Conditional" commands /////////////////////////////////////////////////////////////////// // If the last conditional was false, then we ignore until the next // endif. if (conditionalStack.GetCount() > 0 && conditionalStack.GetTail().m_curState == false) { CondInfo condInfo = conditionalStack.GetTail(); if (stricmp(command, "if") == 0) { SkipToEol(codePtr); nestedFalseConditionals++; continue; } else if (stricmp(command, "elif") == 0 || stricmp(command, "else") == 0) { // If we're in nested false conditionals, then ignore. if (nestedFalseConditionals > 0) { SkipToEol(codePtr); continue; } } else if (stricmp(command, "endif") == 0) { // If we're in nested false conditionals, then ignore. if (nestedFalseConditionals > 0) { SkipToEol(codePtr); nestedFalseConditionals--; continue; } } } if (stricmp(command, "if") == 0 || stricmp(command, "elif") == 0) { // Our CondInfo structure. CondInfo condInfo; // If the command is an elif, then pop the old state. if (tolower(command[0]) == 'e') { // The conditional stack can't be empty on an elif. if (conditionalStack.IsEmpty()) { CString err; err.Format("!!elif used with no preceding !!if."); throw TException(TException::CONDSTACK_EMPTY, err); } // Get the current conditionalStack state. We are most // interested in retaining the m_thisLevelTrue variable. condInfo = conditionalStack.GetTail(); // Remove the old state, because it was false. conditionalStack.RemoveTail(); } // if and elif are setup in this format: // !!if var [cond] [condCheck] // condCheck is only optional if cond doesn't exist. // var is required. // Get the requested dictionary entry name. CString var = ParseToken(codePtr, &helper); /* if (var.IsEmpty()) { CString err; err.Format("The variable is missing."); throw TException(TException::IF_VAR_MISSING, err); } */ CString cond = ParseToken(codePtr, &helper); CString condCheck = ParseToken(codePtr, &helper); /* if (!cond.IsEmpty() && condCheck.IsEmpty()) { CString err; err.Format("The conditional is missing."); throw TException(TException::IF_COND_CHECKVAR_MISSING, err); } */ // Check for a ! symbol. bool isNot = false; if (!var.IsEmpty() && var[0] == '!') { isNot = true; var = var.Mid(1); } // Lookup the value. CString value = var; SkipToEol(codePtr); bool result; if (cond.IsEmpty()) { if (value != "0") result = true; else result = false; } else { // There is a conditional expression. Do it. result = CheckCondition(value, cond, condCheck); } if (isNot) result ^= 1; if (tolower(command[0]) == 'e' && result) result ^= condInfo.m_thisLevelTrue; condInfo.m_curState = result; condInfo.m_thisLevelTrue |= result; // Retain the old state. conditionalStack.AddTail(condInfo); continue; } /////////////////////////////////////////////////////////////////// else if (stricmp(command, "else") == 0) { SkipToEol(codePtr); if (conditionalStack.IsEmpty()) { CString err; err.Format("!!else used with no preceding !!if."); throw TException(TException::CONDSTACK_EMPTY, err); } // Get the current conditionalStack state. We are most // interested in retaining the m_thisLevelTrue variable. CondInfo condInfo = conditionalStack.GetTail(); conditionalStack.RemoveTail(); condInfo.m_curState = condInfo.m_thisLevelTrue ^ 1; conditionalStack.AddTail(condInfo); continue; } else if (stricmp(command, "endif") == 0) { SkipToEol(codePtr); if (conditionalStack.IsEmpty()) { CString err; err.Format("!!endif used with no preceding !!if."); throw TException(TException::CONDSTACK_EMPTY, err); } conditionalStack.RemoveTail(); continue; } if (conditionalStack.GetCount() > 0 && conditionalStack.GetTail().m_curState == false) { continue; } /////////////////////////////////////////////////////////////////// // Look up the command in the map. /////////////////////////////////////////////////////////////////// WWhizTemplateCommand* commandObject = m_helper->GetCommand(command); if (commandObject) { TemplateCommandArgs args; // Found a command. Build the arg list. while (true) { CString arg = ParseToken(codePtr, &helper); if (arg.IsEmpty()) break; args.m_argList.Add(arg); } // Skip anything else. SkipToEol(codePtr); // Run the command. commandObject->Run(this, args); RefreshFileInfo(); // Parse the next part. continue; } else { CString err; err.Format("Unable to find the command [%s].", command); if (AfxMessageBox(err + "\n\nKeep executing?", MB_YESNO) == IDNO) { throw TException(TException::MISSING_COMMAND, err); } } } /////////////////////////////////////////////////////////////////////// else if (*codePtr == '@' && *(codePtr + 1) == '@') { // If we're ignoring text, then skip. if (conditionalStack.GetCount() > 0 && conditionalStack.GetTail().m_curState == false) { codePtr += 2; continue; } // Is it a line continuation? // @@backslash if (*(codePtr + 2) == '\\') { SkipToEol(codePtr); continue; } CString out; // Ugly, but we need that \0 in there. buffer.Add(0); buffer.RemoveAt(buffer.GetCount() - 1); if (ParseTag(codePtr, out, &helper)) { // Move the output string into the buffer. for (int i = 0; i < out.GetLength(); i++) buffer.Add(out[i]); } } else { // See if it is an EOL. if (*codePtr == '\n') { m_helper->m_outBolPos = buffer.GetCount() + 1; m_helper->m_codeBolPtr = codePtr + 1; } // If we're ignoring text, then skip. if (conditionalStack.GetCount() > 0 && conditionalStack.GetTail().m_curState == false) { codePtr++; continue; } // Copy it straight. buffer.Add(*codePtr++); } } // Flush what's left. FlushText(); buffer.RemoveAll(); return true; }
BOOL CFileSharingPage::OnInitDialog() { CFilePropertiesPage::OnInitDialog(); m_wndTags.AddString( L"" ); { CQuickLock oLock( UploadQueues.m_pSection ); CList< CString > pAdded; for ( POSITION pos = UploadQueues.GetIterator(); pos; ) { CUploadQueue* pQueue = UploadQueues.GetNext( pos ); if ( ! pQueue->m_sShareTag.IsEmpty() ) { if ( pAdded.Find( pQueue->m_sShareTag ) == NULL ) { pAdded.AddTail( pQueue->m_sShareTag ); m_wndTags.AddString( pQueue->m_sShareTag ); } } } if ( pAdded.IsEmpty() ) { m_wndTags.AddString( L"Release" ); m_wndTags.AddString( L"Popular" ); } } { CQuickLock oLock( Library.m_pSection ); if ( CLibraryFile* pSingleFile = GetFile() ) { m_bOverride = pSingleFile->IsSharedOverride(); m_bShare = pSingleFile->IsShared(); m_sTags = pSingleFile->m_sShareTags; } else { CLibraryListPtr pList( GetList() ); if ( pList ) { for ( POSITION pos = pList->GetHeadPosition(); pos; ) { if ( CLibraryFile* pFile = pList->GetNextFile( pos ) ) { m_bOverride = pFile->IsSharedOverride(); m_bShare = pFile->IsShared(); m_sTags = pFile->m_sShareTags; } } } } } UpdateData( FALSE ); m_wndShare.EnableWindow( m_bOverride ); return TRUE; }
void CRemote::Output(LPCTSTR pszName) { if ( _tcsstr( pszName, L".." ) || _tcschr( pszName, L'/' ) ) return; CString strValue = Settings.General.Path + L"\\Remote\\" + pszName + L".html"; CFile hFile; if ( ! hFile.Open( strValue, CFile::modeRead ) ) return; int nBytes = (int)hFile.GetLength(); CAutoVectorPtr< BYTE > pBytes( new BYTE[ nBytes ] ); hFile.Read( pBytes, nBytes ); hFile.Close(); LPCSTR pBody = (LPCSTR)(BYTE*)pBytes; if ( nBytes > 3 && pBytes[0] == 0xEF && pBytes[1] == 0xBB && pBytes[2] == 0xBF ) { // Skip BOM pBody += 3; nBytes -= 3; } CString strBody = UTF8Decode( pBody, nBytes ); CList<BOOL> pDisplayStack; for ( BOOL bDisplay = TRUE; ; ) { int nStart = strBody.Find( L"<%" ); if ( nStart < 0 ) { if ( bDisplay ) m_sResponse += strBody; break; } else if ( nStart >= 0 ) { if ( bDisplay && nStart > 0 ) m_sResponse += strBody.Left( nStart ); strBody = strBody.Mid( nStart + 2 ); } int nEnd = strBody.Find( L"%>" ); if ( nEnd < 0 ) break; CString strKey = strBody.Left( nEnd ); strBody = strBody.Mid( nEnd + 2 ); strKey.Trim(); ToLower( strKey ); if ( strKey.IsEmpty() ) { // Nothing } else if ( strKey.GetAt( 0 ) == L'=' && bDisplay ) { strKey = strKey.Mid( 1 ); strKey.Trim(); if ( m_pKeys.Lookup( strKey, strValue ) ) m_sResponse += strValue; } else if ( strKey.GetAt( 0 ) == L'?' ) { strKey = strKey.Mid( 1 ); strKey.Trim(); if ( strKey.IsEmpty() ) { if ( ! pDisplayStack.IsEmpty() ) bDisplay = pDisplayStack.RemoveTail(); } else { if ( strKey.GetAt( 0 ) == L'!' ) { strKey = strKey.Mid( 1 ); strKey.Trim(); if ( ! m_pKeys.Lookup( strKey, strValue ) ) strValue.Empty(); pDisplayStack.AddTail( bDisplay ); bDisplay = bDisplay && strValue.IsEmpty(); } else { if ( ! m_pKeys.Lookup( strKey, strValue ) ) strValue.Empty(); pDisplayStack.AddTail( bDisplay ); bDisplay = bDisplay && ! strValue.IsEmpty(); } } } } }
void Algorithm::GetNotCertainOperations(void) { if (!m_WaitForCheckList_Row.IsEmpty()) { int SelectRow = -1, SelectColumn = -1; double ExplodeProbility = 1; while (!m_WaitForCheckList_Row.IsEmpty()) { int row = m_WaitForCheckList_Row.RemoveHead(); int column = m_WaitForCheckList_Column.RemoveHead(); trow.AddTail(row), tcolumn.AddTail(column); if (!m_NeverCheck[row][column]) { int minecount = 0, originalcount = 0; for (int i = 0; i < 8; ++i) { int newrow = row + RowOffset[i]; int newcolumn = column + ColumnOffset[i]; if (newrow >= 0 && newrow < m_rows && newcolumn >=0 && newcolumn < m_columns) switch (m_MineMatrix[newrow][newcolumn]) { case MINE: ++minecount; break; case ORIGINAL: ++originalcount; break; } } if ((double) (m_MineMatrix[row][column] - minecount) / originalcount < ExplodeProbility) { SelectRow = row; SelectColumn = column; ExplodeProbility = (double) (m_MineMatrix[row][column] - minecount) / originalcount; } } } while (!trow.IsEmpty()) { int row = trow.RemoveHead(); int column = tcolumn.RemoveHead(); if (!m_NeverCheck[row][column]) { m_WaitForCheckList_Row.AddTail(row); m_WaitForCheckList_Column.AddTail(column); } } if (SelectRow != -1) for (int i = 0; i < 8; ++i) { int newrow = SelectRow + RowOffset[i]; int newcolumn = SelectColumn + ColumnOffset[i]; if (newrow >= 0 && newrow < m_rows && newcolumn >=0 && newcolumn < m_columns) if (m_MineMatrix[newrow][newcolumn] == ORIGINAL) { AddOperation(Operation(Operation::OPEN, newrow, newcolumn)); NewWaitForIdentify(newrow, newcolumn); break; } } } else { bool flag = false; for (int i = 0; i < m_rows; ++i) { for (int j = 0; j < m_columns; ++j) { switch (m_MineMatrix[i][j]) { case ORIGINAL: AddOperation(Operation(Operation::OPEN, i, j)); NewWaitForIdentify(i, j); flag = true; break; } if (flag) break; } if (flag) break; } } }
void Algorithm::GetCertainOperations(void) { while(!m_WaitForCheckList_Row.IsEmpty()) { int row = m_WaitForCheckList_Row.RemoveHead(); int column = m_WaitForCheckList_Column.RemoveHead(); if (!m_NeverCheck[row][column]) { int minecount = 0, originalcount = 0; for (int i = 0; i < 8; ++i) { int newrow = row + RowOffset[i]; int newcolumn = column + ColumnOffset[i]; if (newrow >= 0 && newrow < m_rows && newcolumn >=0 && newcolumn < m_columns) switch (m_MineMatrix[newrow][newcolumn]) { case MINE: ++minecount; break; case ORIGINAL: ++originalcount; break; } } if (minecount == m_MineMatrix[row][column]) { m_NeverCheck[row][column] = true; if (originalcount) { AddOperation(Operation(Operation::QUICKOPEN, row, column)); for (int i = 0; i < 8; ++i) { int newrow = row + RowOffset[i]; int newcolumn = column + ColumnOffset[i]; if (newrow >= 0 && newrow < m_rows && newcolumn >=0 && newcolumn < m_columns) if (m_MineMatrix[newrow][newcolumn] == ORIGINAL) { m_MineMatrix[newrow][newcolumn] = ALREADYOPEN; NewWaitForIdentify(newrow, newcolumn); } } } } else if (minecount + originalcount == m_MineMatrix[row][column]) { m_NeverCheck[row][column] = true; for (int i = 0; i < 8; ++i) { int newrow = row + RowOffset[i]; int newcolumn = column + ColumnOffset[i]; if (newrow >= 0 && newrow < m_rows && newcolumn >=0 && newcolumn < m_columns) if (m_MineMatrix[newrow][newcolumn] == ORIGINAL) { m_MineMatrix[newrow][newcolumn] = MINE; AddOperation(Operation(Operation::MARKMINE, newrow, newcolumn)); } } } else { trow.AddTail(row); tcolumn.AddTail(column); } } } while (!trow.IsEmpty()) { int row = trow.RemoveHead(); int column = tcolumn.RemoveHead(); if (!m_NeverCheck[row][column]) { m_WaitForCheckList_Row.AddTail(row); m_WaitForCheckList_Column.AddTail(column); } } if (m_OperationList.IsEmpty()) { TRACE(_T("Searching...\n")); while(!m_WaitForCheckList_Row.IsEmpty()) { int row = m_WaitForCheckList_Row.RemoveHead(); int column = m_WaitForCheckList_Column.RemoveHead(); trow.AddTail(row); tcolumn.AddTail(column); if (!m_NeverCheck[row][column]) { Search_Clear(); Search(1, row, column); if (Search_Check()) break; //Search_Check(); } } while (!trow.IsEmpty()) { int row = trow.RemoveHead(); int column = tcolumn.RemoveHead(); if (!m_NeverCheck[row][column]) { m_WaitForCheckList_Row.AddTail(row); m_WaitForCheckList_Column.AddTail(column); } } } if (m_OperationList.IsEmpty()) { int originalcount2 = 0, minecount2 = 0; for (int i = 0; i < m_rows; ++i) for (int j = 0; j < m_columns; ++j) switch (m_MineMatrix[i][j]) { case ORIGINAL: ++originalcount2; break; case MINE: ++minecount2; break; } if (originalcount2 && originalcount2 + minecount2 == m_RemainderMines) for (int i = 0; i < m_rows; ++i) for (int j = 0; j < m_columns; ++j) switch (m_MineMatrix[i][j]) { case ORIGINAL: AddOperation(Operation(Operation::OPEN, i, j)); NewWaitForIdentify(i, j); break; } } }
void CPopulation::AssignRankAndCrowdingDistance() { ASSERT(individuals != NULL); ASSERT(pProblem != NULL); int front_size = 0; int rank = 1; int orig_index, cur_index; POSITION pos1, pos2, tmp_pos; CList<int, int> orig; CList<int, int> cur; for (int i=0; i<pProblem->popsize; i++) orig.AddTail(i); while (!orig.IsEmpty()) { pos1 = orig.GetHeadPosition(); orig_index = orig.GetNext(pos1); if (pos1 == NULL) { individuals[orig_index].rank = rank; individuals[orig_index].crowd_dist = INF; break; } cur.AddHead(orig_index); front_size = 1; orig.RemoveHead(); pos1 = orig.GetHeadPosition(); while (pos1 != NULL) { int flag = -1; orig_index = orig.GetAt(pos1); pos2 = cur.GetHeadPosition(); while (pos2 != NULL) { cur_index = cur.GetAt(pos2); flag = individuals[orig_index].CheckDominance(individuals[cur_index]); if (flag == 1) { orig.AddHead(cur_index); front_size--; tmp_pos = pos2; cur.GetNext(pos2); cur.RemoveAt(tmp_pos); } else if (flag == 0) { cur.GetNext(pos2); } else if (flag == -1) { break; } } if (flag != -1) { cur.AddHead(orig_index); front_size++; tmp_pos = pos1; orig.GetNext(pos1); orig.RemoveAt(tmp_pos); } else { orig.GetNext(pos1); } } pos2 = cur.GetHeadPosition(); while (pos2 != NULL) { cur_index = cur.GetNext(pos2); individuals[cur_index].rank = rank; } AssignCrowdingDistanceList((void*) &cur, front_size); cur.RemoveAll(); rank++; } }
void CSecureRule::SetContentWords(const CString& strContent) { if ( m_nType == srContentRegExp || m_nType == srExternal ) { delete [] m_pContent; m_nContentLength = strContent.GetLength() + 2; LPTSTR pszContent = new TCHAR[ m_nContentLength ]; _tcscpy_s( pszContent, m_nContentLength, strContent ); m_pContent = pszContent; pszContent += strContent.GetLength(); *pszContent++ = 0; *pszContent++ = 0; return; } LPTSTR pszContent = (LPTSTR)(LPCTSTR)strContent; int nTotalLength = 3; CList< CString > pWords; int nStart = 0, nPos = 0; for ( ; *pszContent; nPos++, pszContent++ ) { if ( *pszContent == ' ' || *pszContent == '\t' ) { if ( nStart < nPos ) { pWords.AddTail( strContent.Mid( nStart, nPos - nStart ) ); nTotalLength += nPos - nStart + 1; } nStart = nPos + 1; } } if ( nStart < nPos ) { pWords.AddTail( strContent.Mid( nStart, nPos - nStart ) ); nTotalLength += nPos - nStart + 1; } if ( m_pContent ) { delete [] m_pContent; m_pContent = NULL; m_nContentLength = 0; } if ( pWords.IsEmpty() ) return; m_pContent = new TCHAR[ m_nContentLength = nTotalLength ]; pszContent = m_pContent; for ( POSITION pos = pWords.GetHeadPosition(); pos; ) { CString strWord = pWords.GetNext( pos ); CopyMemory( pszContent, (LPCTSTR)strWord, ( strWord.GetLength() + 1 ) * sizeof( TCHAR ) ); pszContent += strWord.GetLength() + 1; } *pszContent++ = 0; *pszContent++ = 0; }