Debian Codegraph @

lib/HistorySearch.cpp

raw symbols SCIP
1 /*
2 Copyright 2013 Christian Surlykke
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17 02110-1301 USA.
18 */
19 #include <QApplication>
20 #include <QTextStream>
21 #include <QDebug>
22
23 #include "TerminalCharacterDecoder.h"cxx . . $ `<file>/lib/TerminalCharacterDecoder.h`/
24 #include "Emulation.h"cxx . . $ `<file>/lib/Emulation.h`/
25 #include "HistorySearch.h"cxx . . $ `<file>/lib/HistorySearch.h`/
26
27 HistorySearchcxx . . $ HistorySearch#::HistorySearchcxx . . $ HistorySearch#HistorySearch(faa5ea263d11b3c2).(EmulationPtrcxx . . $ EmulationPtr# emulation, const QRegExpcxx . . $ QRegExp#& regExp,
28 bool forwards, int startColumn, int startLine,
29 QObjectcxx . . $ QObject#* parent) :
30 QObjectcxx . . $ QObject#QObject(749de1b6ae65bddd).(parent),
31 m_emulationcxx . . $ HistorySearch#m_emulation.(emulation),
32 m_regExpcxx . . $ HistorySearch#m_regExp.(regExp),
33 m_forwardscxx . . $ HistorySearch#m_forwards.(forwards),
34 m_startColumncxx . . $ HistorySearch#m_startColumn.(startColumn),
35 m_startLinecxx . . $ HistorySearch#m_startLine.(startLine) {
36 }
37
38 HistorySearchcxx . . $ HistorySearch#::~cxx . . $ HistorySearch#`~HistorySearch`(ced63f7c635d850d).HistorySearchcxx . . $ HistorySearch#() {
39 }
40
41 void HistorySearchcxx . . $ HistorySearch#::searchcxx . . $ HistorySearch#search(49f6e7a06ebc5aa8).() {
42 bool found = false;
43
44 if (! m_regExpcxx . . $ HistorySearch#m_regExp..isEmptycxx . . $ QRegExp#isEmpty(50ce9a9e25b4a850).())
45 {
46 if (m_forwardscxx . . $ HistorySearch#m_forwards.) {
47 found = searchcxx . . $ HistorySearch#search(a1642a0ee405ca20).(m_startColumncxx . . $ HistorySearch#m_startColumn., m_startLinecxx . . $ HistorySearch#m_startLine., -1, m_emulationcxx . . $ HistorySearch#m_emulation.->cxx . . $ QPointer#`operator->`(5a2a78a048fb49a8).lineCountcxx . . $ Konsole/Emulation#lineCount(455f465bc33b4cdf).()) || searchcxx . . $ HistorySearch#search(a1642a0ee405ca20).(0, 0, m_startColumncxx . . $ HistorySearch#m_startColumn., m_startLinecxx . . $ HistorySearch#m_startLine.);
48 } else {
49 found = searchcxx . . $ HistorySearch#search(a1642a0ee405ca20).(0, 0, m_startColumncxx . . $ HistorySearch#m_startColumn., m_startLinecxx . . $ HistorySearch#m_startLine.) || searchcxx . . $ HistorySearch#search(a1642a0ee405ca20).(m_startColumncxx . . $ HistorySearch#m_startColumn., m_startLinecxx . . $ HistorySearch#m_startLine., -1, m_emulationcxx . . $ HistorySearch#m_emulation.->cxx . . $ QPointer#`operator->`(5a2a78a048fb49a8).lineCountcxx . . $ Konsole/Emulation#lineCount(455f465bc33b4cdf).());
50 }
51
52 if (found) {
53 emitcxx . . $ `<external>/1208926524888476972/qobjectdefs.h:97:10`! matchFoundcxx . . $ HistorySearch#matchFound(748afa4755bc9595).(m_foundStartColumncxx . . $ HistorySearch#m_foundStartColumn., m_foundStartLinecxx . . $ HistorySearch#m_foundStartLine., m_foundEndColumncxx . . $ HistorySearch#m_foundEndColumn., m_foundEndLinecxx . . $ HistorySearch#m_foundEndLine.);
54 }
55 else {
56 emitcxx . . $ `<external>/1208926524888476972/qobjectdefs.h:97:10`! noMatchFoundcxx . . $ HistorySearch#noMatchFound(49f6e7a06ebc5aa8).();
57 }
58 }
59
60 deleteLatercxx . . $ QObject#deleteLater(49f6e7a06ebc5aa8).();
61 }
62
63 bool HistorySearchcxx . . $ HistorySearch#::searchcxx . . $ HistorySearch#search(a1642a0ee405ca20).(int startColumn, int startLine, int endColumn, int endLine) {
64 qDebugcxx . . $ `<external>/10450329605257866924/qlogging.h:164:9`!() <<cxx . . $ QDebug#`operator<<`(d8a917b173851aad). "search from" <<cxx . . $ QDebug#`operator<<`(6e3b7ae53f380c3). startColumn <<cxx . . $ QDebug#`operator<<`(d8a917b173851aad). "," <<cxx . . $ QDebug#`operator<<`(6e3b7ae53f380c3). startLine
65 <<cxx . . $ QDebug#`operator<<`(d8a917b173851aad). "to" <<cxx . . $ QDebug#`operator<<`(6e3b7ae53f380c3). endColumn <<cxx . . $ QDebug#`operator<<`(d8a917b173851aad). "," <<cxx . . $ QDebug#`operator<<`(6e3b7ae53f380c3). endLine;
66
67 int linesRead = 0;
68 int linesToRead = endLine - startLine + 1;
69
70 qDebugcxx . . $ `<external>/10450329605257866924/qlogging.h:164:9`!() <<cxx . . $ QDebug#`operator<<`(d8a917b173851aad). "linesToRead:" <<cxx . . $ QDebug#`operator<<`(6e3b7ae53f380c3). linesToRead;
71
72 // We read process history from (and including) startLine to (and including) endLine in
73 // blocks of at most 10K lines so that we do not use unhealthy amounts of memory
74 int blockSize;
75 while ((blockSize = qMincxx . . $ qMin(2a338fce5842aa6a).(10000, linesToRead - linesRead)) > 0) {
76
77 QStringcxx . . $ QString# stringcxx . . $ QString#QString(ced63f7c635d850d).;
78 QTextStreamcxx . . $ QTextStream# searchStreamcxx . . $ QTextStream#QTextStream(16e3d097052a73db).(&string);
79 PlainTextDecodercxx . . $ Konsole/PlainTextDecoder# decodercxx . . $ Konsole/PlainTextDecoder#PlainTextDecoder(49f6e7a06ebc5aa8).;
80 decoder.begincxx . . $ Konsole/PlainTextDecoder#begin(aca783e314870a73).(&searchStream);
81 decoder.setRecordLinePositionscxx . . $ Konsole/PlainTextDecoder#setRecordLinePositions(b45ddcbc8423892c).(true);
82
83 // Calculate lines to read and read them
84 int blockStartLine = m_forwardscxx . . $ HistorySearch#m_forwards. ? startLine + linesRead : endLine - linesRead - blockSize + 1;
85 int chunkEndLine = blockStartLine + blockSize - 1;
86 m_emulationcxx . . $ HistorySearch#m_emulation.->cxx . . $ QPointer#`operator->`(5a2a78a048fb49a8).writeToStreamcxx . . $ Konsole/Emulation#writeToStream(af4856893d912e4e).(&decoder, blockStartLine, chunkEndLine);
87
88 // We search between startColumn in the first line of the string and endColumn in the last
89 // line of the string. First we calculate the position (in the string) of endColumn in the
90 // last line of the string
91 int endPosition;
92
93 // The String that Emulator.writeToStream produces has a newline at the end, and so ends with an
94 // empty line - we ignore that.
95 int numberOfLinesInString = decoder.linePositionscxx . . $ Konsole/PlainTextDecoder#linePositions(acfbda32237c20a3).().sizecxx . . $ QList#size(ea6fe5115c70a13f).() - 1;
96 if (numberOfLinesInString > 0 && endColumn > -1 )
97 {
98 endPosition = decoder.linePositionscxx . . $ Konsole/PlainTextDecoder#linePositions(acfbda32237c20a3).().atcxx . . $ QList#at(e2681f9bb6b2f357).(numberOfLinesInString - 1) + endColumn;
99 }
100 else
101 {
102 endPosition = string.sizecxx . . $ QString#size(455f465bc33b4cdf).();
103 }
104
105 // So now we can log for m_regExp in the string between startColumn and endPosition
106 int matchStart;
107 if (m_forwardscxx . . $ HistorySearch#m_forwards.)
108 {
109 matchStart = string.indexOfcxx . . $ QString#indexOf(ed75f67234c5535b).(m_regExpcxx . . $ HistorySearch#m_regExp., startColumn);
110 if (matchStart >= endPosition)
111 matchStart = -1;
112 }
113 else
114 {
115 matchStart = string.lastIndexOfcxx . . $ QString#lastIndexOf(ed75f67234c5535b).(m_regExpcxx . . $ HistorySearch#m_regExp., endPosition - 1);
116 if (matchStart < startColumn)
117 matchStart = -1;
118 }
119
120 if (matchStart > -1)
121 {
122 int matchEnd = matchStart + m_regExpcxx . . $ HistorySearch#m_regExp..matchedLengthcxx . . $ QRegExp#matchedLength(455f465bc33b4cdf).() - 1;
123 qDebugcxx . . $ `<external>/10450329605257866924/qlogging.h:164:9`!() <<cxx . . $ QDebug#`operator<<`(d8a917b173851aad). "Found in string from" <<cxx . . $ QDebug#`operator<<`(6e3b7ae53f380c3). matchStart <<cxx . . $ QDebug#`operator<<`(d8a917b173851aad). "to" <<cxx . . $ QDebug#`operator<<`(6e3b7ae53f380c3). matchEnd;
124
125 // Translate startPos and endPos to startColum, startLine, endColumn and endLine in history.
126 int startLineNumberInString = findLineNumberInStringcxx . . $ HistorySearch#findLineNumberInString(bae4cce454b0b3c).(decoder.linePositionscxx . . $ Konsole/PlainTextDecoder#linePositions(acfbda32237c20a3).(), matchStart);
127 m_foundStartColumncxx . . $ HistorySearch#m_foundStartColumn. = matchStart - decoder.linePositionscxx . . $ Konsole/PlainTextDecoder#linePositions(acfbda32237c20a3).().atcxx . . $ QList#at(e2681f9bb6b2f357).(startLineNumberInString);
128 m_foundStartLinecxx . . $ HistorySearch#m_foundStartLine. = startLineNumberInString + startLine + linesRead;
129
130 int endLineNumberInString = findLineNumberInStringcxx . . $ HistorySearch#findLineNumberInString(bae4cce454b0b3c).(decoder.linePositionscxx . . $ Konsole/PlainTextDecoder#linePositions(acfbda32237c20a3).(), matchEnd);
131 m_foundEndColumncxx . . $ HistorySearch#m_foundEndColumn. = matchEnd - decoder.linePositionscxx . . $ Konsole/PlainTextDecoder#linePositions(acfbda32237c20a3).().atcxx . . $ QList#at(e2681f9bb6b2f357).(endLineNumberInString);
132 m_foundEndLinecxx . . $ HistorySearch#m_foundEndLine. = endLineNumberInString + startLine + linesRead;
133
134 qDebugcxx . . $ `<external>/10450329605257866924/qlogging.h:164:9`!() <<cxx . . $ QDebug#`operator<<`(d8a917b173851aad). "m_foundStartColumn" <<cxx . . $ QDebug#`operator<<`(6e3b7ae53f380c3). m_foundStartColumncxx . . $ HistorySearch#m_foundStartColumn.
135 <<cxx . . $ QDebug#`operator<<`(d8a917b173851aad). "m_foundStartLine" <<cxx . . $ QDebug#`operator<<`(6e3b7ae53f380c3). m_foundEndLinecxx . . $ HistorySearch#m_foundEndLine.
136 <<cxx . . $ QDebug#`operator<<`(d8a917b173851aad). "m_foundEndColumn" <<cxx . . $ QDebug#`operator<<`(6e3b7ae53f380c3). m_foundEndColumncxx . . $ HistorySearch#m_foundEndColumn.
137 <<cxx . . $ QDebug#`operator<<`(d8a917b173851aad). "m_foundEndLine" <<cxx . . $ QDebug#`operator<<`(6e3b7ae53f380c3). m_foundEndLinecxx . . $ HistorySearch#m_foundEndLine.;
138
139 return true;
140 }
141
142
143 linesRead += blockSize;
144 }
145
146 qDebugcxx . . $ `<external>/10450329605257866924/qlogging.h:164:9`!() <<cxx . . $ QDebug#`operator<<`(d8a917b173851aad). "Not found";
147 return false;
148 }
149
150
151 int HistorySearchcxx . . $ HistorySearch#::findLineNumberInStringcxx . . $ HistorySearch#findLineNumberInString(bae4cce454b0b3c).(QListcxx . . $ QList#<int> linePositions, int position) {
152 int lineNum = 0;
153 while (lineNum + 1 < linePositions.sizecxx . . $ QList#size(ea6fe5115c70a13f).() && linePositions[cxx . . $ QList#`operator[]`(7a0ef1c7079e8533).lineNum + 1] <= position)
154 lineNum++;
155
156 return lineNum;
157 }