-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathDiffAndMerge.cpp
More file actions
245 lines (214 loc) · 7.31 KB
/
DiffAndMerge.cpp
File metadata and controls
245 lines (214 loc) · 7.31 KB
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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
/* DiffAndMerge.cpp : implementation file
Copyright (c) 1987-2019 Advanced Systems for Power Engineering, Inc. (ASPEN).
All rights reserved.
*/
#include "stdafx.h"
#include "TestBenchOlxAPI.h"
#include "DiffAndMerge.h"
#include "afxdialogex.h"
#include "OlxAPI.h"
// CDiffAndMerge dialog
IMPLEMENT_DYNAMIC(CDiffAndMerge, CDialogEx)
CDiffAndMerge::CDiffAndMerge(CWnd* pParent /*=NULL*/)
: CDialogEx(CDiffAndMerge::IDD, pParent)
{
m_strPathName[0] = "";
m_strPathName[1] = "";
m_strPathName[2] = "";
m_strPathName[3] = "";
m_bDoMerge = FALSE;
}
CDiffAndMerge::~CDiffAndMerge()
{
}
void CDiffAndMerge::DoDataExchange(CDataExchange* pDX)
{
CDialogEx::DoDataExchange(pDX);
}
BEGIN_MESSAGE_MAP(CDiffAndMerge, CDialogEx)
ON_BN_CLICKED( IDC_BUTTONA, &CDiffAndMerge::OnBnClickedButtonA )
ON_BN_CLICKED( IDC_BUTTONB, &CDiffAndMerge::OnBnClickedButtonB )
ON_BN_CLICKED( IDC_BUTTONBASE, &CDiffAndMerge::OnBnClickedButtonBase )
ON_BN_CLICKED( IDC_BUTTONDIFF, &CDiffAndMerge::OnBnClickedButtonDiffFile )
ON_BN_CLICKED( IDOK2, &CDiffAndMerge::OnBnClickedMerge )
ON_BN_CLICKED( IDOK, &CDiffAndMerge::OnBnClickedCompare )
END_MESSAGE_MAP()
// CDiffAndMerge message handlers
BOOL CDiffAndMerge::OnInitDialog() {
CDialogEx::OnInitDialog();
SetDlgItemText( IDC_EDITA, m_strPathName[0] );
SetDlgItemText( IDC_EDITB, m_strPathName[1] );
SetDlgItemText( IDC_EDITBASE, m_strPathName[2] );
CheckDlgButton( IDC_CHECK_1L, TRUE );
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CDiffAndMerge::OnBnClickedButtonA() {
CFileDialog cFD( TRUE, "*.OLR", NULL, NULL,
"OneLiner Data File (*.OLR)|*.OLR||" );
cFD.m_ofn.lpstrTitle = "File A";
if ( cFD.DoModal() != IDOK )
return;
SetDlgItemText( IDC_EDITA, cFD.GetPathName() );
}
void CDiffAndMerge::OnBnClickedButtonB() {
CFileDialog cFD( TRUE, "*.OLR", NULL, NULL,
"OneLiner Data File (*.OLR)|*.OLR||" );
cFD.m_ofn.lpstrTitle = "File B";
if ( cFD.DoModal() != IDOK )
return;
SetDlgItemText( IDC_EDITB, cFD.GetPathName() );
}
void CDiffAndMerge::OnBnClickedButtonBase() {
CFileDialog cFD( TRUE, "*.OLR", NULL, NULL,
"OneLiner Data File (*.OLR)|*.OLR||" );
cFD.m_ofn.lpstrTitle = "File A and B Common Base";
if ( cFD.DoModal() != IDOK )
return;
SetDlgItemText( IDC_EDITBASE, cFD.GetPathName() );
}
void CDiffAndMerge::OnBnClickedButtonDiffFile() {
CFileDialog cFD( FALSE, "*.XML", NULL, OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT,
"OneLiner Diff File (*.ADX,*.XML)|*.ADX;*.XML||" );
cFD.m_ofn.lpstrTitle = "Diff File";
if ( cFD.DoModal() != IDOK )
return;
SetDlgItemText( IDC_EDITDIFF, cFD.GetPathName() );
}
void CDiffAndMerge::OnBnClickedButtonmerge() {
CFileDialog cFD( FALSE, "*.OLR", NULL, OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT,
"OneLiner Data File (*.OLR)|*.OLR||" );
cFD.m_ofn.lpstrTitle = "Merged File";
if ( cFD.DoModal() != IDOK )
return;
SetDlgItemText( IDC_EDITMERGE, cFD.GetPathName() );
}
void CDiffAndMerge::OnBnClickedMerge() {
m_bDoMerge = TRUE;
OnOK();
}
void CDiffAndMerge::OnBnClickedCompare() {
m_bDoMerge = FALSE;
OnOK();
}
void CDiffAndMerge::OnOK() {
FILE *fFile;
GetDlgItemText( IDC_EDITA, m_strPathName[0] );
if ( m_strPathName[0] != "" && m_strPathName[0] != "N/A" ) {
fFile = fopen( m_strPathName[0], "r" );
if ( !fFile ) {
MessageBox( "File A path name is invalid." );
return;
}
fclose( fFile );
}
GetDlgItemText( IDC_EDITB, m_strPathName[1] );
if ( m_strPathName[1] == "" ) {
MessageBox( "File B path name is missing." );
return;
}
fFile = fopen( m_strPathName[1], "r" );
if ( !fFile ) {
MessageBox( "File B path name is invalid." );
return;
}
fclose( fFile );
if ( m_strPathName[0] == m_strPathName[1] ) {
MessageBox( "File A and B cannot be the same." );
return;
}
GetDlgItemText( IDC_EDITBASE, m_strPathName[2] );
if ( m_strPathName[0] == m_strPathName[2] ) {
MessageBox( "File A and Base cannot be the same." );
return;
}
if ( m_strPathName[1] == m_strPathName[2] ) {
MessageBox( "File B and Base cannot be the same." );
return;
}
if ( m_strPathName[2] != "" && m_strPathName[2] != "N/A" ) {
fFile = fopen( m_strPathName[2], "r" );
if ( !fFile ) {
MessageBox( "Base path name is invalid." );
return;
}
fclose( fFile );
}
GetDlgItemText( IDC_EDITDIFF, m_strPathName[3] );
if ( m_strPathName[3] != "" && m_strPathName[3] != "N/A" ) {
fFile = fopen( m_strPathName[3], "w" );
if ( !fFile ) {
MessageBox( "Diff path name is invalid." );
return;
}
fclose( fFile );
DeleteFile( m_strPathName[3] );
}
GetDlgItemText( IDC_EDITMERGE, m_strPathName[4] );
if ( m_strPathName[4] != "" && m_strPathName[4] != "N/A" ) {
fFile = fopen( m_strPathName[4], "w" );
if ( !fFile ) {
MessageBox( "Merged path name is invalid." );
return;
}
fclose( fFile );
DeleteFile( m_strPathName[3] );
}
m_bDo1L = IsDlgButtonChecked( IDC_CHECK_1L ) ? FALSE:TRUE;
CDialogEx::OnOK();
}
//
//
///////////////////////////////////////////////////////////////////////////////////////////////////
#include <fstream>
#include <string>
void TestDiffNMerge() {
CDiffAndMerge dlg;
if ( IDOK != dlg.DoModal() )
return;
CString sFileA = dlg.m_strPathName[0];
CString sFileB = dlg.m_strPathName[1];
CString sFileBase = dlg.m_strPathName[2];
CString sPath = sFileA;
sPath = sPath.Left( sPath.ReverseFind( '\\' ) + 1 );
// MergedAB must be the same as B
// Merge A to B
CString sFileDiff = sPath + CString( "Diff_A_B.xlm" );
CString sFileMerged = sPath + CString( "MergedAB.olr" );
CString sXML =
CString( "<DIFFANDMERGE " ) +
CString( "FILEPATHA =\"" ) + sFileA + CString( "\" " ) +
CString( "FILEPATHB =\"" ) + sFileB + CString( "\" " ) +
// CString( "FILEPATHBASE =\"" ) + sFileBase + CString( "\" " ) +
CString( "FILEPATHDIFF =\"" ) + sFileDiff + CString( "\" " ) +
CString( "FILEPATHMERGED =\"" ) + sFileMerged + CString( "\" " ) +
CString( " />" );
if ( OLXAPI_OK != OlxAPIRun1LPFCommand( sXML.GetBuffer() ) )
AfxMessageBox( OlxAPIErrorString() );
// MergedAB and B must be the same
sFileDiff = sPath + CString( "Diff_MergedAB_B.xlm" );
sXML =
CString( "<DIFFANDMERGE " ) +
CString( "FILEPATHA =\"" ) + sFileMerged + CString( "\" " ) +
CString( "FILEPATHB =\"" ) + sFileB + CString( "\" " ) +
// CString( "FILEPATHBASE =\"" ) + sFileBase + CString( "\" " ) +
CString( "FILEPATHDIFF =\"" ) + sFileDiff + CString( "\" " ) +
CString( " />" );
if ( OLXAPI_OK != OlxAPIRun1LPFCommand( sXML.GetBuffer() ) )
AfxMessageBox( OlxAPIErrorString() );
std::ifstream diffFile( sFileDiff );
std::string line;
int nChange = 0;
if ( diffFile.is_open() ) {
while ( std::getline( diffFile, line ) ) {
CString sT( line.c_str() );
if ( sT.Find( "CHANGEREC" ) > -1 ) {
++nChange;
}
}
}
if ( nChange )
AfxMessageBox( "Error: MergedAB != B" );
else
AfxMessageBox( "MergedAB == B" );
}