comparison kdiff3/src/diff.h @ 58:8af4bb9d9a5a

Version 0.9.83
author joachim99
date Sun, 07 Mar 2004 09:59:09 +0000
parents c59d5a3a8ff3
children efe33e938730
comparison
equal deleted inserted replaced
57:023fbd76c1e3 58:8af4bb9d9a5a
1 /*************************************************************************** 1 /***************************************************************************
2 diff.h - description 2 diff.h - description
3 ------------------- 3 -------------------
4 begin : Mon Mar 18 2002 4 begin : Mon Mar 18 2002
5 copyright : (C) 2002 by Joachim Eibl 5 copyright : (C) 2002-2004 by Joachim Eibl
6 email : joachim.eibl@gmx.de 6 email : joachim.eibl@gmx.de
7 ***************************************************************************/ 7 ***************************************************************************/
8 8
9 /*************************************************************************** 9 /***************************************************************************
10 * * 10 * *
26 #include <vector> 26 #include <vector>
27 #include <assert.h> 27 #include <assert.h>
28 #include "common.h" 28 #include "common.h"
29 #include "fileaccess.h" 29 #include "fileaccess.h"
30 30
31 31 class OptionDialog;
32 32
33 // Each range with matching elements is followed by a range with differences on either side. 33 // Each range with matching elements is followed by a range with differences on either side.
34 // Then again range of matching elements should follow. 34 // Then again range of matching elements should follow.
35 struct Diff 35 struct Diff
36 { 36 {
121 const char* pLine; 121 const char* pLine;
122 const char* pFirstNonWhiteChar; 122 const char* pFirstNonWhiteChar;
123 int size; 123 int size;
124 124
125 LineData(){ pLine=0; size=0; occurances=0; bContainsPureComment=false; } 125 LineData(){ pLine=0; size=0; occurances=0; bContainsPureComment=false; }
126 int width(); // Calcs width considering tabs. 126 int width() const; // Calcs width considering tabs.
127 int occurances; 127 int occurances;
128 bool whiteLine(){ return pFirstNonWhiteChar-pLine == size; } 128 bool whiteLine() const { return pFirstNonWhiteChar-pLine == size; }
129 bool bContainsPureComment; 129 bool bContainsPureComment;
130 }; 130 };
131 131
132 void prepareOccurances( LineData* p, int size );
133
134 132
135 class SourceData 133 class SourceData
136 { 134 {
137 public: 135 public:
138 SourceData(){ m_pBuf=0;m_size=0;m_vSize=0;m_bIsText=false;m_bPreserve=false; } 136 SourceData();
139 const char* m_pBuf; 137 ~SourceData();
140 int m_size; 138
141 int m_vSize; // Nr of lines in m_pBuf1 and size of m_v1, m_dv12 and m_dv13 139 void setOptionDialog( OptionDialog* pOptionDialog );
142 std::vector<LineData> m_v; 140
143 bool m_bIsText; 141 int getSizeLines() const;
144 bool m_bPreserve; 142 int getSizeBytes() const;
145 void reset(); 143 const char* getBuf() const;
146 void readPPFile( bool bPreserveCR, const QString& ppCmd, bool bUpCase ); 144 const LineData* getLineDataForDisplay() const;
147 void readLMPPFile( SourceData* pOrigSource, const QString& ppCmd, bool bUpCase, bool bRemoveComments ); 145 const LineData* getLineDataForDiff() const;
148 void readFile(const QString& filename, bool bFollowLinks, bool bUpCase ); 146
149 void preprocess(bool bPreserveCR );
150 void removeComments( LineData* pLD );
151 void setData( const QString& data, bool bUpCase );
152 void setFilename(const QString& filename); 147 void setFilename(const QString& filename);
153 void setFileAccess( const FileAccess& fa ); 148 void setFileAccess( const FileAccess& fa );
154 FileAccess& getFileAccess(); 149 FileAccess& getFileAccess();
155 QString getFilename(); 150 QString getFilename();
156 void setAliasName(const QString& a); 151 void setAliasName(const QString& a);
157 QString getAliasName(); 152 QString getAliasName();
158 bool isEmpty() { return getFilename().isEmpty(); } 153 bool isEmpty(); // File was set
159 private: 154 bool hasData(); // Data was readable
160 QString m_fileName; 155 bool isText(); // is it pure text (vs. binary data)
156 bool isFromBuffer(); // was it set via setData() (vs. setFileAccess() or setFilename())
157 void setData( const QString& data );
158
159 void readAndPreprocess();
160 bool saveNormalDataAs( const QString& fileName );
161
162 bool isBinaryEqualWith( const SourceData& other ) const;
163
164 void reset();
165
166 private:
161 QString m_aliasName; 167 QString m_aliasName;
162 FileAccess m_fileAccess; 168 FileAccess m_fileAccess;
163 }; 169 OptionDialog* m_pOptionDialog;
164 170 QString m_tempInputFileName;
165 void calcDiff3LineListTrim( Diff3LineList& d3ll, LineData* pldA, LineData* pldB, LineData* pldC ); 171
166 void calcWhiteDiff3Lines( Diff3LineList& d3ll, LineData* pldA, LineData* pldB, LineData* pldC ); 172 struct FileData
173 {
174 FileData(){ m_pBuf=0; m_size=0; }
175 ~FileData(){ reset(); }
176 const char* m_pBuf;
177 int m_size;
178 int m_vSize; // Nr of lines in m_pBuf1 and size of m_v1, m_dv12 and m_dv13
179 std::vector<LineData> m_v;
180 bool m_bIsText;
181 bool readFile( const QString& filename );
182 bool writeFile( const QString& filename );
183 void preprocess(bool bPreserveCR );
184 void reset();
185 void removeComments();
186 void copyBufFrom( const FileData& src );
187 };
188 FileData m_normalData;
189 FileData m_lmppData;
190 };
191
192 void calcDiff3LineListTrim( Diff3LineList& d3ll, const LineData* pldA, const LineData* pldB, const LineData* pldC );
193 void calcWhiteDiff3Lines( Diff3LineList& d3ll, const LineData* pldA, const LineData* pldB, const LineData* pldC );
167 194
168 void calcDiff3LineVector( const Diff3LineList& d3ll, Diff3LineVector& d3lv ); 195 void calcDiff3LineVector( const Diff3LineList& d3ll, Diff3LineVector& d3lv );
169 196
170 void debugLineCheck( Diff3LineList& d3ll, int size, int idx ); 197 void debugLineCheck( Diff3LineList& d3ll, int size, int idx );
171 198
212 }; 239 };
213 240
214 class OptionDialog; 241 class OptionDialog;
215 242
216 QString decodeString( const char*s , OptionDialog* ); 243 QString decodeString( const char*s , OptionDialog* );
244 QCString encodeString( const QString& s , OptionDialog* );
217 245
218 class DiffTextWindow : public QWidget 246 class DiffTextWindow : public QWidget
219 { 247 {
220 Q_OBJECT 248 Q_OBJECT
221 public: 249 public:
224 QStatusBar* pStatusBar, 252 QStatusBar* pStatusBar,
225 OptionDialog* pOptionDialog 253 OptionDialog* pOptionDialog
226 ); 254 );
227 void init( 255 void init(
228 const QString& fileName, 256 const QString& fileName,
229 LineData* pLineData, 257 const LineData* pLineData,
230 int size, 258 int size,
231 const Diff3LineVector* pDiff3LineVector, 259 const Diff3LineVector* pDiff3LineVector,
232 int winIdx, 260 int winIdx,
233 bool bTriple 261 bool bTriple
234 ); 262 );
269 void resetSelection(); 297 void resetSelection();
270 void setFastSelectorRange( int line1, int nofLines ); 298 void setFastSelectorRange( int line1, int nofLines );
271 299
272 private: 300 private:
273 bool m_bPaintingAllowed; 301 bool m_bPaintingAllowed;
274 LineData* m_pLineData; 302 const LineData* m_pLineData;
275 int m_size; 303 int m_size;
276 QString m_filename; 304 QString m_filename;
277 305
278 const Diff3LineVector* m_pDiff3LineVector; 306 const Diff3LineVector* m_pDiff3LineVector;
279 307
436 void slotGoPrevConflict(); 464 void slotGoPrevConflict();
437 void slotGoNextConflict(); 465 void slotGoNextConflict();
438 void slotAutoSolve(); 466 void slotAutoSolve();
439 void slotUnsolve(); 467 void slotUnsolve();
440 void slotSetFastSelectorLine(int); 468 void slotSetFastSelectorLine(int);
469 void setPaintingAllowed(bool);
441 470
442 signals: 471 signals:
443 void scroll( int deltaX, int deltaY ); 472 void scroll( int deltaX, int deltaY );
444 void modified(); 473 void modified();
445 void setFastSelectorRange( int line1, int nofLines ); 474 void setFastSelectorRange( int line1, int nofLines );
460 const LineData* m_pldB; 489 const LineData* m_pldB;
461 const LineData* m_pldC; 490 const LineData* m_pldC;
462 491
463 const Diff3LineList* m_pDiff3LineList; 492 const Diff3LineList* m_pDiff3LineList;
464 const TotalDiffStatus* m_pTotalDiffStatus; 493 const TotalDiffStatus* m_pTotalDiffStatus;
494
495 bool m_bPaintingAllowed;
465 496
466 private: 497 private:
467 class MergeEditLine 498 class MergeEditLine
468 { 499 {
469 public: 500 public:
494 class MergeEditLineList : private std::list<MergeEditLine> 525 class MergeEditLineList : private std::list<MergeEditLine>
495 { // I want to know the size immediately! 526 { // I want to know the size immediately!
496 private: 527 private:
497 typedef std::list<MergeEditLine> BASE; 528 typedef std::list<MergeEditLine> BASE;
498 int m_size; 529 int m_size;
530 int* m_pTotalSize;
499 public: 531 public:
500 typedef std::list<MergeEditLine>::iterator iterator; 532 typedef std::list<MergeEditLine>::iterator iterator;
501 typedef std::list<MergeEditLine>::const_iterator const_iterator; 533 typedef std::list<MergeEditLine>::const_iterator const_iterator;
502 MergeEditLineList(){m_size=0;} 534 MergeEditLineList(){m_size=0; m_pTotalSize=0; }
503 void clear() { m_size=0; BASE::clear(); } 535 void clear() { ds(-m_size); BASE::clear(); }
504 void push_back( const MergeEditLine& m) { ++m_size; BASE::push_back(m); } 536 void push_back( const MergeEditLine& m) { ds(+1); BASE::push_back(m); }
505 void push_front( const MergeEditLine& m) { ++m_size; BASE::push_front(m); } 537 void push_front( const MergeEditLine& m) { ds(+1); BASE::push_front(m); }
506 iterator erase( iterator i ) { --m_size; return BASE::erase(i); } 538 iterator erase( iterator i ) { ds(-1); return BASE::erase(i); }
507 iterator insert( iterator i, const MergeEditLine& m ) { ++m_size; return BASE::insert(i,m); } 539 iterator insert( iterator i, const MergeEditLine& m ) { ds(+1); return BASE::insert(i,m); }
508 int size(){ /*assert(int(BASE::size())==m_size);*/ return m_size;} 540 int size(){ /*assert(int(BASE::size())==m_size);*/ return m_size;}
509 iterator begin(){return BASE::begin();} 541 iterator begin(){return BASE::begin();}
510 iterator end(){return BASE::end();} 542 iterator end(){return BASE::end();}
511 bool empty() { return m_size==0; } 543 bool empty() { return m_size==0; }
544
545 void setTotalSizePtr(int* pTotalSize)
546 {
547 m_pTotalSize = pTotalSize;
548 *m_pTotalSize += m_size;
549 }
550
551 private:
552 void ds(int deltaSize)
553 {
554 m_size+=deltaSize;
555 if (m_pTotalSize!=0) *m_pTotalSize+=deltaSize;
556 }
512 }; 557 };
513 558
514 friend class MergeEditLine; 559 friend class MergeEditLine;
515 560
516 struct MergeLine 561 struct MergeLine
567 QPixmap m_pixmap; 612 QPixmap m_pixmap;
568 int m_firstLine; 613 int m_firstLine;
569 int m_firstColumn; 614 int m_firstColumn;
570 int m_nofColumns; 615 int m_nofColumns;
571 int m_nofLines; 616 int m_nofLines;
617 int m_totalSize; //Same as m_nofLines, but calculated differently
572 bool m_bMyUpdate; 618 bool m_bMyUpdate;
573 bool m_bInsertMode; 619 bool m_bInsertMode;
574 QString m_fileName; 620 QString m_fileName;
575 bool m_bModified; 621 bool m_bModified;
576 void setModified(); 622 void setModified();
595 }; 641 };
596 642
597 void fineDiff( 643 void fineDiff(
598 Diff3LineList& diff3LineList, 644 Diff3LineList& diff3LineList,
599 int selector, 645 int selector,
600 LineData* v1, 646 const LineData* v1,
601 LineData* v2, 647 const LineData* v2,
602 bool& bTextsTotalEqual 648 bool& bTextsTotalEqual
603 ); 649 );
604 650
605 651
606 bool equal( const LineData& l1, const LineData& l2, bool bStrict ); 652 bool equal( const LineData& l1, const LineData& l2, bool bStrict );