File indexing completed on 2024-04-28 13:39:48
0001 /* 0002 SPDX-FileCopyrightText: 2002-2004 Otto Bruggeman <otto.bruggeman@home.nl> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #include "cvsdiffparser.h" 0008 0009 #include <QRegularExpression> 0010 0011 #include <komparediffdebug.h> 0012 #include "komparemodellist.h" 0013 0014 using namespace Diff2; 0015 0016 CVSDiffParser::CVSDiffParser(const KompareModelList* list, const QStringList& diff) : ParserBase(list, diff) 0017 { 0018 // The regexps needed for context cvs diff parsing, the rest is the same as in parserbase.cpp 0019 // third capture in header1 is non optional for cvs diff, it is the revision 0020 m_contextDiffHeader1.setPattern(QRegularExpression::anchoredPattern(QStringLiteral("\\*\\*\\* ([^\\t]+)\\t([^\\t]+)\\t(.*)\\n"))); 0021 m_contextDiffHeader2.setPattern(QRegularExpression::anchoredPattern(QStringLiteral("--- ([^\\t]+)\\t([^\\t]+)(|\\t(.*))\\n"))); 0022 0023 m_normalDiffHeader.setPattern(QRegularExpression::anchoredPattern(QStringLiteral("Index: (.*)\\n"))); 0024 } 0025 0026 CVSDiffParser::~CVSDiffParser() 0027 { 0028 } 0029 0030 enum Kompare::Format CVSDiffParser::determineFormat() 0031 { 0032 // qCDebug(LIBKOMPAREDIFF2) << "Determining the format of the CVSDiff"; 0033 0034 QRegularExpression normalRE(QStringLiteral("[0-9]+[0-9,]*[acd][0-9]+[0-9,]*")); 0035 QRegularExpression unifiedRE(QStringLiteral("^--- [^\\t]+\\t")); 0036 QRegularExpression contextRE(QStringLiteral("^\\*\\*\\* [^\\t]+\\t")); 0037 QRegularExpression rcsRE(QStringLiteral("^[acd][0-9]+ [0-9]+")); 0038 QRegularExpression edRE(QStringLiteral("^[0-9]+[0-9,]*[acd]")); 0039 0040 QStringList::ConstIterator it = m_diffLines.begin(); 0041 0042 while (it != m_diffLines.end()) 0043 { 0044 if ((*it).indexOf(normalRE, 0) == 0) 0045 { 0046 // qCDebug(LIBKOMPAREDIFF2) << "Difflines are from a Normal diff..."; 0047 return Kompare::Normal; 0048 } 0049 else if ((*it).indexOf(unifiedRE, 0) == 0) 0050 { 0051 // qCDebug(LIBKOMPAREDIFF2) << "Difflines are from a Unified diff..."; 0052 return Kompare::Unified; 0053 } 0054 else if ((*it).indexOf(contextRE, 0) == 0) 0055 { 0056 // qCDebug(LIBKOMPAREDIFF2) << "Difflines are from a Context diff..."; 0057 return Kompare::Context; 0058 } 0059 else if ((*it).indexOf(rcsRE, 0) == 0) 0060 { 0061 // qCDebug(LIBKOMPAREDIFF2) << "Difflines are from a RCS diff..."; 0062 return Kompare::RCS; 0063 } 0064 else if ((*it).indexOf(edRE, 0) == 0) 0065 { 0066 // qCDebug(LIBKOMPAREDIFF2) << "Difflines are from an ED diff..."; 0067 return Kompare::Ed; 0068 } 0069 ++it; 0070 } 0071 // qCDebug(LIBKOMPAREDIFF2) << "Difflines are from an unknown diff..."; 0072 return Kompare::UnknownFormat; 0073 } 0074 0075 bool CVSDiffParser::parseNormalDiffHeader() 0076 { 0077 qCDebug(LIBKOMPAREDIFF2) << "CVSDiffParser::parseNormalDiffHeader()"; 0078 bool result = false; 0079 0080 QStringList::ConstIterator diffEnd = m_diffLines.end(); 0081 0082 while (m_diffIterator != diffEnd) 0083 { 0084 const auto normalDiffHeaderMatch = m_normalDiffHeader.match(*m_diffIterator); 0085 if (normalDiffHeaderMatch.hasMatch()) 0086 { 0087 qCDebug(LIBKOMPAREDIFF2) << "Matched length Header = " << normalDiffHeaderMatch.capturedLength(); 0088 qCDebug(LIBKOMPAREDIFF2) << "Matched string Header = " << normalDiffHeaderMatch.captured(0); 0089 0090 m_currentModel = new DiffModel(); 0091 m_currentModel->setSourceFile(normalDiffHeaderMatch.captured(1)); 0092 m_currentModel->setDestinationFile(normalDiffHeaderMatch.captured(1)); 0093 0094 result = true; 0095 0096 ++m_diffIterator; 0097 break; 0098 } 0099 else 0100 { 0101 qCDebug(LIBKOMPAREDIFF2) << "No match for: " << (*m_diffIterator); 0102 } 0103 ++m_diffIterator; 0104 } 0105 0106 if (result == false) 0107 { 0108 // Set this to the first line again and hope it is a single file diff 0109 m_diffIterator = m_diffLines.begin(); 0110 m_currentModel = new DiffModel(); 0111 m_singleFileDiff = true; 0112 } 0113 0114 return result; 0115 } 0116 0117 0118 bool CVSDiffParser::parseEdDiffHeader() 0119 { 0120 return false; 0121 } 0122 0123 bool CVSDiffParser::parseRCSDiffHeader() 0124 { 0125 return false; 0126 } 0127 0128 bool CVSDiffParser::parseEdHunkHeader() 0129 { 0130 return false; 0131 } 0132 0133 bool CVSDiffParser::parseRCSHunkHeader() 0134 { 0135 return false; 0136 } 0137 0138 bool CVSDiffParser::parseEdHunkBody() 0139 { 0140 return false; 0141 } 0142 0143 bool CVSDiffParser::parseRCSHunkBody() 0144 { 0145 return false; 0146 }