static void GoToLine (text_file_data_t *tptr, uint index) { uint ix; debug_message("go to line %u", index); if (tptr->m_line_offset_tail != NULL) { debug_message("tail index %u", index); } if (tptr->m_line_offset_tail != NULL && tptr->m_line_offset_tail->index >= index) { debug_message("Looking for tail"); text_line_offset_t *tlptr; for (ix = 0, tlptr = tptr->m_line_offset_head; ix < index; ix++) { tlptr = tlptr->next_line; } if (tlptr->index != index) { error_message("Seek not right %u %u", tlptr->index, index); } GoToLine(tptr, tlptr); return; } uint start_index = 0; if (tptr->m_line_offset_tail) { start_index = tptr->m_line_offset_tail->index; GoToLine(tptr, tptr->m_line_offset_tail); } for (ix = start_index; ix < index; ix++) { if (ReadNextLine(tptr) == false) return; } }
void HostVector<ValueType>::ReadFile(const std::string filename) { DEBUGLOG(this, "HostVector::ReadFile()", "filename = " << filename, 2); std::ifstream mFile(filename); std::string line; std::getline(mFile, line); if ( !std::regex_match (line, std::regex("^[0-9]+"))) { std::cerr << "Bad syntax line 1" << std::endl; } int size = std::stoi(line); this->Allocate(size); std::getline(mFile, line); int index = 0; if (!regex_match (line, std::regex("^(-?[0-9.]+e(?:\\+|\\-)[0-9]+)"))) { std::cerr << "Bad syntax in line: " << index+2 << std::endl; } GoToLine(mFile, 2); while (std::getline(mFile, line)) { mData[index] = std::stod(line); index++; } DEBUGEND(); }
void CEdit::ReplaceAllInBuffer() { CHourGlass wait( this ); CDelayRepaint delay( this ); if ( m_Buffer.GetLineCount() && g_FindReplaceData.m_pszFindText && *g_FindReplaceData.m_pszFindText ) { m_Selection.MakeEmpty(); int nStartRow = m_Selection.GetStartRow(); int nStartCol = m_Selection.GetStartCol(); m_Buffer.BeginEdit( nStartRow, nStartCol ); BOOL bFoundText = FALSE; int nFirstRow = 0, nFirstCol = 0; int nCol = 0; int nRow = 0; int cbFindText = _tcslen( g_FindReplaceData.m_pszFindText ); int cbReplaceText = _tcslen( g_FindReplaceData.m_pszReplaceText ); for ( ;; ) { BOOL bWrapped; int cbMatched; if ( m_Buffer.FindText( g_FindReplaceData.m_pszFindText, cbFindText, TRUE, g_FindReplaceData.m_bCaseSensitiveSearch, g_FindReplaceData.m_bWholeWordOnly, g_FindReplaceData.m_bRegExp, nRow, nCol, bWrapped, cbMatched ) ) { if ( !bFoundText ) { bFoundText = TRUE; nFirstRow = nRow; nFirstCol = nCol; } else if ( bWrapped && ( nRow >= nFirstRow ) && ( nCol >= nFirstCol ) ) { // have completely wrapped around and came back to the first occurrence. break; } m_Selection.SetExtendedSelection( nCol, nRow, nCol + cbMatched, nRow ); if ( g_FindReplaceData.m_pszReplaceText ) { FindReplaceSelection(); nCol += cbReplaceText; } else { DeleteSelection( FALSE, FALSE ); nCol += cbMatched; } } else { break; } } if ( bFoundText && !m_pActiveView->LineIsVisible( nFirstRow ) ) { // found occurrences of the find text. Go to the location of the first bookmark GoToLine( nFirstRow, TRUE ); } Repaint( FALSE ); m_Buffer.EndEdit( nStartRow, nStartCol ); } }
//--------------------------------------------------------------------------- void __fastcall TEditorForm::EditorActionsExecute(TBasicAction *Action, bool &Handled) { Handled = true; if (Action == SaveAction) { assert(!FFileName.IsEmpty()); SaveToFile(); if (FOnFileChanged) { FOnFileChanged(this); } EditorMemo->Modified = false; UpdateControls(); } else if (Action == PreferencesAction) { DoPreferencesDialog(pmEditor); } else if (Action == ReloadAction) { Reload(); } else if (Action == FindAction || Action == ReplaceAction) { StartFind(Action == FindAction); } else if (Action == FindNextAction) { if (!FLastFindDialog) { FLastFindDialog = FFindDialog; } Find(); } else if (Action == GoToLineAction) { GoToLine(); } else if (Action == EditRedo) { EditorMemo->Redo(); } else if (Action == HelpAction) { FormHelp(this); } else if (Action == DefaultEncodingAction) { ChangeEncoding(TEncoding::Default); } else if (Action == UTF8EncodingAction) { ChangeEncoding(TEncoding::UTF8); } else { Handled = false; } }
void CEdit::FindText( BOOL bForward ) { if ( g_FindReplaceData.m_pszFindText ) { int nRow = bForward ? m_Selection.GetEndRow() : m_Selection.GetStartRow(); int nRowSave = nRow; int nCol = bForward ? m_Selection.GetEndCol() : m_Selection.GetStartCol(); int cbWord = _tcslen( g_FindReplaceData.m_pszFindText ); BOOL bWrapped; int cbMatched; if ( m_Buffer.FindText( g_FindReplaceData.m_pszFindText, cbWord, bForward, g_FindReplaceData.m_bCaseSensitiveSearch, g_FindReplaceData.m_bWholeWordOnly, g_FindReplaceData.m_bRegExp, nRow, nCol, bWrapped, cbMatched ) ) { if ( nRow != nRowSave && !m_pActiveView->LineIsVisible( nRow ) ) { GoToLine( nRow, TRUE ); } m_Selection.SetExtendedSelection( nCol, nRow, nCol + cbMatched, nRow, FALSE ); m_Selection.EnsureVisible( TRUE, TRUE ); // center the selection } else { NotifyParentOfCmdFailure( CMDERR_NOTFOUND ); m_Selection.MakeEmpty( TRUE, bForward ); if ( IsPlayingMacro() ) { m_bAbortMacro = TRUE; } } } else { m_Selection.EnsureVisible( TRUE, TRUE ); // center the selection } }
void CEdit::FindMarkAll() { CHourGlass wait( this ); m_Selection.MakeEmpty(); if ( m_Buffer.GetLineCount() ) { if ( g_FindReplaceData.m_pszFindText && *g_FindReplaceData.m_pszFindText ) { BOOL bFirstBookmark = TRUE; int nFirstRow = 0, nFirstCol = 0; int nCol = 0; int nRow = 0; int cbFindText = _tcslen( g_FindReplaceData.m_pszFindText ); for ( ;; ) { BOOL bWrapped; int cbMatched; if ( m_Buffer.FindText( g_FindReplaceData.m_pszFindText, cbFindText, TRUE, g_FindReplaceData.m_bCaseSensitiveSearch, g_FindReplaceData.m_bWholeWordOnly, g_FindReplaceData.m_bRegExp, nRow, nCol, bWrapped, cbMatched ) ) { if ( bFirstBookmark ) { bFirstBookmark = FALSE; nFirstRow = nRow; nFirstCol = nCol; } else if ( bWrapped && ( nRow >= nFirstRow ) && ( nCol >= nFirstCol ) ) { // have completely wrapped around and came back to the first occurrence. break; } m_Buffer.SetBookmark( nRow ); nCol += cbMatched; } else { NotifyParentOfCmdFailure( CMDERR_NOTFOUND ); break; } } if ( !bFirstBookmark && !m_pActiveView->LineIsVisible( nFirstRow ) ) { // found occurrences of the find text. Go to the location of the first bookmark GoToLine( nFirstRow, TRUE ); } Repaint( FALSE ); } else { NotifyParentOfCmdFailure( CMDERR_INPUT ); } } else { NotifyParentOfCmdFailure( CMDERR_EMPTYBUF ); } }
static void on_StartButton_clicked (GtkButton *button, gpointer user_data) { debug_message("start clicked"); text_file_data_t *tptr = GetTextFileDataFromUserData(user_data); GoToLine(tptr, 0); DisplayLineInBuffer(user_data, tptr); }
void CEdit::BookmarkJumpToFirst() { if ( m_Buffer.GetLineCount() ) { int nLine = GetAdjacentBookmark( -1, FALSE ); if ( nLine != -1 ) { GoToLine( nLine, !m_pActiveView->LineIsVisible( nLine ) ); } } }
void CEdit::BookmarkNext() { if ( m_Buffer.GetLineCount() ) { int nLine = GetAdjacentBookmark( m_Selection.GetEndRow(), FALSE ); if ( nLine != -1 ) { GoToLine( nLine, !m_pActiveView->LineIsVisible( nLine ) ); } } }
void CEdit::BreakpointPrev() { if ( m_Buffer.GetLineCount() ) { int nLine = GetAdjacentBreakpoint( m_Selection.GetEndRow(), TRUE ); if ( nLine != -1 ) { GoToLine( nLine, !m_pActiveView->LineIsVisible( nLine ) ); } } }
void CEdit::BookmarkJumpToLast() { int nLineCount = m_Buffer.GetLineCount(); if ( nLineCount ) { int nLine = GetAdjacentBookmark( nLineCount, TRUE ); if ( nLine != -1 ) { GoToLine( nLine, !m_pActiveView->LineIsVisible( nLine ) ); } } }
static void on_PrevButton_clicked (GtkButton *button, gpointer user_data) { debug_message("prev clicked"); text_file_data_t *tptr = GetTextFileDataFromUserData(user_data); uint index = tptr->m_index; if (tptr->m_index > 2) index = tptr->m_index - 2; else index = 0; GoToLine(tptr, index); DisplayLineInBuffer(user_data, tptr); }
void HostCOOMatrix<ValueType>::ReadFile(const std::string filename) { DEBUGLOG(this, "HostCOOMatrix::ReadFile()", "filename = " << filename, 2); BaseMatrix<ValueType>::ReadFile(filename); //Allocate matrix after reading the size from the file this->Allocate(this->mNRows, this->mNCols, this->mNnz); // Re open file std::ifstream mFile; mFile.exceptions ( std::ifstream::failbit | std::ifstream::badbit ); mFile.open(filename); // Go to line 3 where the data begins GoToLine(mFile, 3); std::string line; std::getline(mFile, line); // Only check syntax on first line for performance issues // Checking regex in each iteration very slow if (!regex_match (line, std::regex("^((?:(?:[0-9][0-9]*\\s+?){2})" "-?[0-9\\.]+e(?:\\+|\\-)[0-9]+)"))) { std::cerr << "Bad syntax in line: 3" << std::endl; } GoToLine(mFile, 3); std::istringstream linestream; for (int index=0; index<this->mNnz; index++) { std::getline(mFile, line); linestream.str(line); int rowInd, colInd; linestream >> rowInd >> colInd >> mData[index]; mRowInd[index] = rowInd - 1; mColInd[index] = colInd - 1; linestream.clear(); } mFile.close(); DEBUGEND(); }
bool wxExTextFile::Parse() { if (m_Tool.GetId() == ID_TOOL_REPORT_REPLACE && m_FileName.GetStat().IsReadOnly()) { return false; } if (m_Tool.IsFindType()) { if (wxExFindReplaceData::Get()->GetFindString().empty()) { wxFAIL; return false; } m_FindString = wxExFindReplaceData::Get()->GetFindString(); if (!wxExFindReplaceData::Get()->MatchCase()) { std::transform( m_FindString.begin(), m_FindString.end(), m_FindString.begin(), toupper); } } for (size_t i = 0; i < GetLineCount(); i++) { wxString& line = GetLine(i); if (m_Tool.IsFindType()) { if (MatchLine(line)) { Report(i); } } else { GoToLine(i); if (!ParseLine(line)) { return false; } } } return true; }
static void on_EndButton_clicked (GtkButton *button, gpointer user_data) { text_file_data_t *tptr = GetTextFileDataFromUserData(user_data); if (tptr->m_line_offset_tail != NULL) { if (tptr->m_index < tptr->m_line_offset_tail->index) { GoToLine(tptr, tptr->m_line_offset_tail); } } while (ReadNextLine(tptr)); DisplayLineInBuffer(user_data, tptr); }
void CEdit::ReplaceAllInSelection() { CHourGlass wait( this ); CDelayRepaint delay( this ); if ( m_Buffer.GetLineCount() && g_FindReplaceData.m_pszFindText && *g_FindReplaceData.m_pszFindText ) { int nStartCol, nStartRow, nEndCol, nEndRow; m_Selection.GetNormalizedBufferSelection( nStartCol, nStartRow, nEndCol, nEndRow ); m_Buffer.BeginEdit( nStartRow, nStartCol ); BOOL bFoundText = FALSE; int nFirstRow = 0, nFirstCol = 0; int nCol = nStartCol; int nRow = nStartRow; int cbFindText = _tcslen( g_FindReplaceData.m_pszFindText ); int cbReplaceText = _tcslen( g_FindReplaceData.m_pszReplaceText ); for ( ;; ) { BOOL bWrapped; int cbMatched; if ( m_Buffer.FindText( g_FindReplaceData.m_pszFindText, cbFindText, TRUE, g_FindReplaceData.m_bCaseSensitiveSearch, g_FindReplaceData.m_bWholeWordOnly, g_FindReplaceData.m_bRegExp, nRow, nCol, bWrapped, cbMatched ) ) { if ( !bFoundText ) { bFoundText = TRUE; nFirstRow = nRow; nFirstCol = nCol; } else { BOOL bOutsideSel = ( nRow < nStartRow ) || ( nRow == nStartRow && nCol < nStartCol ) || ( nRow > nEndRow ) || ( nRow == nEndRow && nCol >= nEndCol ); if ( bOutsideSel || ( bWrapped && ( nRow >= nFirstRow ) && ( nCol >= nFirstCol ) ) ) { // no longer in selection, or wrapped around to the start -- done! break; } } m_Selection.SetExtendedSelection( nCol, nRow, nCol + cbMatched, nRow ); if ( g_FindReplaceData.m_pszReplaceText ) { FindReplaceSelection(); nCol += cbReplaceText; } else { DeleteSelection( FALSE, FALSE ); nCol += cbMatched; } } else { break; } } if ( bFoundText && !m_pActiveView->LineIsVisible( nFirstRow ) ) { // found occurrences of the find text. Go to the location of the first bookmark GoToLine( nFirstRow, TRUE ); } Repaint( FALSE ); m_Buffer.EndEdit( nStartRow, nStartCol ); } }
static void GoToLine (text_file_data_t *tptr, int index) { return GoToLine(tptr, (uint)index); }