📄 cleardiffbc.cpp
字号:
//========================================================================
// CONSOLE APPLICATION : ClearDiffBC
//========================================================================
//
//This application is a wrapper interface between ClearCase and Beyond Compare.
//
//It takes the ClearCase compare and merge command line requests, maps them to
//Beyond Compare requirements, and then runs Beyond Compare.
//
//If a ClearCase command-line option is not recognised, a popup message will be
//displayed.
//
//It has been built using Visual Studio 6 with Service pack 4 in release mode.
//
//The ClearDiffBC.exe is copied into the bin directory of the ClearCase installation
//This is normally C:\Atria\Bin
//
//Beyond Compare version 2 is expected to already be installed.
//
//Which file types the user wishes to use Beyond Compare with is controlled by the
//ClearCase type manager map file.
//An example map file is in the source directory, and this can be copied to the
//lib\mgrs directory of the ClearCase installation.
//(Or compare it and copy the required lines)
//
//========================================================================
//
// ClearDiffBC.cpp
//
// Written by Glyn Williams, UK. October 2006
//
//========================================================================
//
#include "stdafx.h"
#include "ClearDiffBC.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
///////DEBUG OUTPUT////////////////////////////////////////////
// Set this to True to get debug output
bool bDebugOutput = FALSE;
///////DEBUG END///////////////////////////////////////////////
CWinApp theApp;
using namespace std;
int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
int nRetCode = 0;
CString strCommand = _T("");
CString strCommandLine = _T("");
CString strTitle[2];
CString strArg;
bool bJustCompare = FALSE;
bool bIgnoreBase = FALSE;
bool bSkipNextArg = FALSE;
long nArg;
bool bReportAbortedAutoMerge = FALSE; // -abort option, tell user automerge failed, and doing manual merge
bool bDirectoryCompare = FALSE; // -directory option, currently ignored
bool bSerialCompare = FALSE; // -serial option, currently ignored
bool bUnrecognised = FALSE;
CString strUnrecognised = _T("");
bool bMerging = FALSE;
bool bSetMergeOutput = FALSE;
CString strMergeOutput = _T("");
bool bSetTitle = FALSE;
int nTitleNumber = 0;
CString strFirstFile = _T("");
// initialize MFC and print and error on failure
if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
{
// TODO: change error code to suit your needs
cerr << _T("Fatal Error: MFC initialization failed") << endl;
nRetCode = 1;
}
else
{
strTitle[0] = _T("");
strTitle[1] = _T("");
for (nArg = 1; nArg < argc; nArg++)
{
strArg = argv[nArg];
if (TRUE == strArg.IsEmpty())
{
continue;
}
strCommandLine += strArg;
strCommandLine += _T(" ");
if (0 == strArg.Find(_T('-')))
{
if (0 == strArg.CompareNoCase(_T("-status_only")))
{
bJustCompare = TRUE;
continue;
}
if (0 == strArg.CompareNoCase(_T("-directory")))
{
bDirectoryCompare = TRUE;
continue;
}
if (0 == strArg.CompareNoCase(_T("-serial")))
{
// Do not know what the serial option is for.
// It appears when doing a merge that failed.
bSerialCompare = TRUE;
continue;
}
if (0 == strArg.CompareNoCase(_T("-abort")))
{
// Looks like it is used when an auto-merge failed
// We will display a message to the user
bReportAbortedAutoMerge = TRUE;
continue;
}
if (0 == strArg.CompareNoCase(_T("-out")))
{
bSetMergeOutput = TRUE;
bMerging = TRUE;
continue;
}
if (0 == strArg.CompareNoCase(_T("-base")))
{
// In a dynamic view, this will be followed by the basepath
// In a snapshot view this may be followed by a -out "<filepath> and then -fname "<basepath>"
// We therefore will set a flag to ignore the next filename, but this will be tested
// for after any -out processing.
bIgnoreBase = TRUE;
continue;
}
if (0 == strArg.CompareNoCase(_T("-fname")))
{
bSetTitle = TRUE;
continue;
}
// An option given and not recognised if reach here
bUnrecognised = TRUE;
strUnrecognised += argv[nArg];
strUnrecognised += _T(" ");
continue;
}
else
{
strCommand += _T(" ");
}
// Not an option - deal with the filename as appropriate
if (TRUE == bSkipNextArg)
{
bSkipNextArg = FALSE;
continue;
}
if (TRUE == bSetMergeOutput)
{
bSetMergeOutput = FALSE;
strMergeOutput = strArg;
}
else if (TRUE == bIgnoreBase)
{
bIgnoreBase = FALSE;
bSetTitle = FALSE; // We also clear this as the basename may follow a -fname
continue;
}
else if (TRUE == bSetTitle)
{
bSetTitle = FALSE;
if (1 < nTitleNumber)
{
// an extra -fname. Probably due to an fname for -base
// Get rid of the first fname, make the 2nd. into the first, and this new one as the 2nd.
strTitle[0] = strTitle[1];
nTitleNumber = 1;
}
strTitle[nTitleNumber] = strArg;
nTitleNumber++;
if (strFirstFile.IsEmpty())
{
// Although we have setup the title, so should not need FirstFile
// we set it up in case we need to display an abort message.
long nPos;
nPos = strArg.Find(_T(".vbs\\"));
if (-1 == nPos)
{
nPos = strArg.Find(_T("@@"));
if (-1 == nPos)
{
nPos = strArg.GetLength();
}
strFirstFile = strArg.Left(nPos);
}
}
}
else
{
strCommand += _T("\"");
strCommand += strArg;
strCommand += _T("\"");
if (strFirstFile.IsEmpty())
{
long nPos;
nPos = strArg.Find(_T(".vbs\\"));
if (-1 == nPos)
{
nPos = strArg.Find(_T("@@"));
if (-1 == nPos)
{
nPos = strArg.GetLength();
}
strFirstFile = strArg.Left(nPos);
}
}
}
}
///////DEBUG OUTPUT////////////////////////////////////////////
if (TRUE == bDebugOutput)
{
CString strDebug;
strDebug.Format(_T("command line = '%s'"), strCommandLine);
long lReturn;
lReturn = AfxMessageBox(strDebug, MB_OK);
}
///////DEBUG END///////////////////////////////////////////////
if (TRUE == bUnrecognised)
{
CString strHello;
strHello.Format(_T("Command Line error.\nOption '%s' is not recognised\n(command line = '%s')"), strUnrecognised, strCommandLine);
if (TRUE == bJustCompare)
{
cout << (LPCTSTR)strHello << endl;
}
else
{
long lReturn;
lReturn = AfxMessageBox(strHello, MB_OK);
}
nRetCode = 1;
}
else
{
if (TRUE == bReportAbortedAutoMerge)
{
CString strAbortMessage;
CString strAbortOf = _T("");
if (FALSE == strFirstFile.IsEmpty())
{
strAbortOf.Format(_T(" of '%s'"), strFirstFile);
}
strAbortMessage.Format(_T("Automerge %s did not work\nBeyond Compare will now be run so that you can manually merge\n"), strAbortOf);
long lReturn;
lReturn = AfxMessageBox(strAbortMessage, MB_OK);
}
// Following was thought necessary,
// But now it looks as if BC will create the output file if a save is done.
// I was probably misled by giving the wrong parameters before
// Commented code deliberately left in, just in case...
/*if (FALSE == strMergeOutput.IsEmpty())
{
nRetCode = CopyMergeOutput(strMergeOutput);
}
*/
if (0 == nRetCode)
{
if ((0 == nTitleNumber) && (FALSE == strFirstFile.IsEmpty()))
{
strArg.Format(_T(" /title1=\"%s\" "), strFirstFile);
strCommand.Insert(0,strArg);
}
else if (0 < nTitleNumber)
{
if (FALSE == strTitle[0].IsEmpty())
{
strArg.Format(_T(" /title1=\"%s\""), strTitle[0]);
strCommand += strArg;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -