1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
|
/**************************************************************************
** cvsdiffparser.cpp
** -----------------
** begin : Sun Aug 4 15:05:35 2002
** copyright : (C) 2002-2004 Otto Bruggeman
** email : otto.bruggeman@home.nl
**
***************************************************************************/
/***************************************************************************
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** ( at your option ) any later version.
**
***************************************************************************/
#include <qregexp.h>
#include <kdebug.h>
#include "cvsdiffparser.h"
#include "komparemodellist.h"
using namespace Diff2;
CVSDiffParser::CVSDiffParser( const KompareModelList* list, const QStringList& diff ) : ParserBase( list, diff )
{
// The regexps needed for context cvs diff parsing, the rest is the same as in parserbase.cpp
// third capture in header1 is non optional for cvs diff, it is the revision
m_contextDiffHeader1.setPattern( "\\*\\*\\* ([^\\t]+)\\t([^\\t]+)\\t(.*)\\n" );
m_contextDiffHeader2.setPattern( "--- ([^\\t]+)\\t([^\\t]+)(|\\t(.*))\\n" );
m_normalDiffHeader.setPattern( "Index: (.*)\\n" );
}
CVSDiffParser::~CVSDiffParser()
{
}
enum Kompare::Format CVSDiffParser::determineFormat()
{
// kdDebug(8101) << "Determining the format of the CVSDiff" << endl;
QRegExp normalRE ( "[0-9]+[0-9,]*[acd][0-9]+[0-9,]*" );
QRegExp unifiedRE( "^--- [^\\t]+\\t" );
QRegExp contextRE( "^\\*\\*\\* [^\\t]+\\t" );
QRegExp rcsRE ( "^[acd][0-9]+ [0-9]+" );
QRegExp edRE ( "^[0-9]+[0-9,]*[acd]" );
QStringList::ConstIterator it = m_diffLines.begin();
while( it != m_diffLines.end() )
{
if( (*it).find( normalRE, 0 ) == 0 )
{
// kdDebug(8101) << "Difflines are from a Normal diff..." << endl;
return Kompare::Normal;
}
else if( (*it).find( unifiedRE, 0 ) == 0 )
{
// kdDebug(8101) << "Difflines are from a Unified diff..." << endl;
return Kompare::Unified;
}
else if( (*it).find( contextRE, 0 ) == 0 )
{
// kdDebug(8101) << "Difflines are from a Context diff..." << endl;
return Kompare::Context;
}
else if( (*it).find( rcsRE, 0 ) == 0 )
{
// kdDebug(8101) << "Difflines are from a RCS diff..." << endl;
return Kompare::RCS;
}
else if( (*it).find( edRE, 0 ) == 0 )
{
// kdDebug(8101) << "Difflines are from an ED diff..." << endl;
return Kompare::Ed;
}
++it;
}
// kdDebug(8101) << "Difflines are from an unknown diff..." << endl;
return Kompare::UnknownFormat;
}
bool CVSDiffParser::parseNormalDiffHeader()
{
kdDebug(8101) << "CVSDiffParser::parseNormalDiffHeader()" << endl;
bool result = false;
QStringList::ConstIterator diffEnd = m_diffLines.end();
while ( m_diffIterator != diffEnd )
{
if ( m_normalDiffHeader.exactMatch( *m_diffIterator ) )
{
kdDebug(8101) << "Matched length Header = " << m_normalDiffHeader.matchedLength() << endl;
kdDebug(8101) << "Matched string Header = " << m_normalDiffHeader.cap( 0 ) << endl;
m_currentModel = new DiffModel();
QObject::connect( m_currentModel, SIGNAL( setModified( bool ) ), m_list, SLOT( slotSetModified( bool ) ) );
m_currentModel->setSourceFile ( m_normalDiffHeader.cap( 1 ) );
m_currentModel->setDestinationFile ( m_normalDiffHeader.cap( 1 ) );
result = true;
++m_diffIterator;
break;
}
else
{
kdDebug(8101) << "No match for: " << ( *m_diffIterator ) << endl;
}
++m_diffIterator;
}
if ( result == false )
{
// Set this to the first line again and hope it is a single file diff
m_diffIterator = m_diffLines.begin();
m_currentModel = new DiffModel();
QObject::connect( m_currentModel, SIGNAL( setModified( bool ) ), m_list, SLOT( slotSetModified( bool ) ) );
m_singleFileDiff = true;
}
return result;
}
bool CVSDiffParser::parseEdDiffHeader()
{
return false;
}
bool CVSDiffParser::parseRCSDiffHeader()
{
return false;
}
bool CVSDiffParser::parseEdHunkHeader()
{
return false;
}
bool CVSDiffParser::parseRCSHunkHeader()
{
return false;
}
bool CVSDiffParser::parseEdHunkBody()
{
return false;
}
bool CVSDiffParser::parseRCSHunkBody()
{
return false;
}
|