* @brief Parse a conflict file to separate files. * This function parses a conflict file to two different files which can be * opened into WinMerge's file compare. * @param [in] conflictFileName Full path to conflict file. * @param [in] workingCopyFileName Full path for user's modified file in * working copy/working folder. * @param [in] newRevisionFileName Full path for revision control fi
| 80 | * @return true if conflict file was successfully parsed, false otherwise. |
| 81 | */ |
| 82 | bool ParseConflictFile(const String& conflictFileName, |
| 83 | const String& workingCopyFileName, const String& newRevisionFileName, const String& baseRevisionFileName, |
| 84 | int iGuessEncodingType, bool &bNestedConflicts, bool &b3way) |
| 85 | { |
| 86 | UniMemFile conflictFile; |
| 87 | UniStdioFile workingCopy; |
| 88 | UniStdioFile newRevision; |
| 89 | UniStdioFile baseRevision; |
| 90 | String line; |
| 91 | std::string::size_type pos; |
| 92 | int state; |
| 93 | int iNestingLevel = 0; |
| 94 | bool bResult = false; |
| 95 | String revision = _T("none"); |
| 96 | bNestedConflicts = false; |
| 97 | b3way = false; |
| 98 | |
| 99 | // open input file |
| 100 | bool success = conflictFile.OpenReadOnly(conflictFileName); |
| 101 | if (!success) |
| 102 | return false; |
| 103 | |
| 104 | // Create output files |
| 105 | bool success2 = workingCopy.Open(workingCopyFileName, _T("wb")); |
| 106 | if (!success2) |
| 107 | return false; |
| 108 | bool success3 = newRevision.Open(newRevisionFileName, _T("wb")); |
| 109 | if (!success3) |
| 110 | return false; |
| 111 | bool success4 = baseRevision.Open(baseRevisionFileName, _T("wb")); |
| 112 | if (!success4) |
| 113 | return false; |
| 114 | |
| 115 | // detect codepage of conflict file |
| 116 | FileTextEncoding encoding = codepage_detect::Guess(conflictFileName, iGuessEncodingType); |
| 117 | |
| 118 | conflictFile.SetUnicoding(encoding.m_unicoding); |
| 119 | conflictFile.SetBom(encoding.m_bom); |
| 120 | conflictFile.SetCodepage(encoding.m_codepage); |
| 121 | workingCopy.SetUnicoding(encoding.m_unicoding); |
| 122 | workingCopy.SetBom(encoding.m_bom); |
| 123 | workingCopy.SetCodepage(encoding.m_codepage); |
| 124 | newRevision.SetUnicoding(encoding.m_unicoding); |
| 125 | newRevision.SetBom(encoding.m_bom); |
| 126 | newRevision.SetCodepage(encoding.m_codepage); |
| 127 | baseRevision.SetUnicoding(encoding.m_unicoding); |
| 128 | baseRevision.SetBom(encoding.m_bom); |
| 129 | baseRevision.SetCodepage(encoding.m_codepage); |
| 130 | |
| 131 | state = 0; |
| 132 | bool linesToRead = true; |
| 133 | do |
| 134 | { |
| 135 | bool lossy; |
| 136 | String eol; |
| 137 | linesToRead = conflictFile.ReadString(line, eol, &lossy); |
| 138 | switch (state) |
| 139 | { |
no test coverage detected