Revision: 3812
http://svn.sourceforge.net/winmerge/?rev=3812&view=rev
Author: galh
Date: 2006-11-17 06:27:57 -0800 (Fri, 17 Nov 2006)
Log Message:
-----------
PATCH: [ 1598194 ] New command line parser
Modified Paths:
--------------
trunk/Src/Changes.txt
trunk/Src/MainFrm.cpp
trunk/Src/Merge.cpp
trunk/Src/Merge.dsp
trunk/Src/Merge.h
Added Paths:
-----------
trunk/Src/ClearCaseCmdLineParser.cpp
trunk/Src/ClearCaseCmdLineParser.h
trunk/Src/CmdLineParser.h
trunk/Src/MergeCmdLineInfo.cpp
trunk/Src/MergeCmdLineInfo.h
trunk/Src/WinMergeCmdLineParser.cpp
trunk/Src/WinMergeCmdLineParser.h
Removed Paths:
-------------
trunk/Src/Common/CmdArgs.cpp
trunk/Src/Common/CmdArgs.h
trunk/Src/MergeArgs.cpp
Modified: trunk/Src/Changes.txt
===================================================================
--- trunk/Src/Changes.txt 2006-11-17 14:23:07 UTC (rev 3811)
+++ trunk/Src/Changes.txt 2006-11-17 14:27:57 UTC (rev 3812)
@@ -3,6 +3,14 @@
(This summarizes all changes to all files under Src, including Src\Languages.)
2006-11-17 Gal
+ PATCH: [ 1598194 ] New command line parser
+ Src: MainFrm.cpp Merge.cpp Merge.dsp Merge.h
+ Src added files: ClearCaseCmdLineParser.cpp ClearCaseCmdLineParser.h
+ CmdLineParser.h MergeCmdLineInfo.cpp MergeCmdLineInfo.h
+ WinMergeCmdLineParser.cpp WinMergeCmdLineParser.h
+ Src removed files: CmdArgs.cpp CmdArgs.h MergeArgs.cpp
+
+2006-11-17 Gal
PATCH: Moved white-space trimming to FileFilterHelper class
Src: FileFilterHelper.cpp
Added: trunk/Src/ClearCaseCmdLineParser.cpp
===================================================================
--- trunk/Src/ClearCaseCmdLineParser.cpp (rev 0)
+++ trunk/Src/ClearCaseCmdLineParser.cpp 2006-11-17 14:27:57 UTC (rev 3812)
@@ -0,0 +1,122 @@
+/////////////////////////////////////////////////////////////////////////////
+//
+// WinMerge: An interactive diff/merge utility
+// Copyright (C) 1997 Dean P. Grimm
+//
+// 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.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+//
+/////////////////////////////////////////////////////////////////////////////
+
+/**
+ * @file ClearCaseCmdLineParser.cpp
+ *
+ * @brief ClearCaseCmdLineParser class implemantation.
+ *
+ */
+
+// RCS ID line follows -- this is updated by CVS
+// $Id: CmdLineParser.cpp $
+
+#include "StdAfx.h"
+
+#include "ClearCaseCmdLineParser.h"
+#include "MainFrm.h"
+#include "MergeCmdLineInfo.h"
+#include "Paths.h"
+
+ClearCaseCmdLineParser::ClearCaseCmdLineParser(MergeCmdLineInfo& CmdLineInfo, const TCHAR *szFileName) :
+ CmdLineParser(CmdLineInfo),
+ m_bDesc(false),
+ m_bBaseFile(false),
+ m_bOutFile(false)
+{
+ m_CmdLineInfo.m_bEscShutdown = true;
+
+ m_CmdLineInfo.m_dwLeftFlags |= FFILEOPEN_READONLY | FFILEOPEN_NOMRU;
+ m_CmdLineInfo.m_dwRightFlags |= FFILEOPEN_NOMRU;
+
+ // szFileName is either "xmerge" or "xcompare".
+ if (lstrcmpi(szFileName, _T("xmerge")))
+ {
+ m_CmdLineInfo.m_dwRightFlags |= FFILEOPEN_READONLY;
+
+ // Compare tool doesn't have a common ancestor file description. We
+ // put a phony description so the command line parser will skip it.
+ m_sBaseDesc = _T("<No Base>");
+ }
+}
+
+void ClearCaseCmdLineParser::ParseParam(const TCHAR* pszParam, BOOL bFlag, BOOL bLast)
+{
+ if (TRUE == bFlag)
+ {
+ if (!lstrcmpi(pszParam, _T("base")))
+ {
+ // -base is followed by common ancestor file description.
+ m_bBaseFile = true;
+ }
+ else if (!lstrcmpi(pszParam, _T("out")))
+ {
+ // -out is followed by merge's output file name.
+ m_bOutFile = true;
+ }
+ else if (!lstrcmpi(pszParam, _T("fname")))
+ {
+ // -fname is followed by file description.
+ m_bDesc = true;
+ }
+ }
+ else
+ {
+ if ((m_bBaseFile == true) && m_sBaseFile.IsEmpty())
+ {
+ m_sBaseFile = pszParam;
+ }
+ else if ((m_bOutFile == true) && m_sOutFile.IsEmpty())
+ {
+ m_sOutFile = pszParam;
+ }
+ else if ((m_bDesc == true) && m_sBaseDesc.IsEmpty())
+ {
+ m_sBaseDesc = pszParam;
+ m_bDesc = false;
+ }
+ else if ((m_bDesc == true) && m_CmdLineInfo.m_sLeftDesc.IsEmpty())
+ {
+ m_CmdLineInfo.m_sLeftDesc = pszParam;
+ m_bDesc = false;
+ }
+ else if ((m_bDesc == true) && m_CmdLineInfo.m_sRightDesc.IsEmpty())
+ {
+ m_CmdLineInfo.m_sRightDesc = pszParam;
+ }
+ else
+ {
+ CString sFile = paths_GetLongPath(pszParam);
+ m_CmdLineInfo.m_Files.SetAtGrow(m_CmdLineInfo.m_nFiles, sFile);
+ m_CmdLineInfo.m_nFiles += 1;
+ }
+ }
+
+ if (TRUE == bLast)
+ {
+ if (FALSE == m_sOutFile.IsEmpty())
+ {
+ CString sFile = paths_GetLongPath(m_sOutFile);
+ m_CmdLineInfo.m_Files.SetAtGrow(m_CmdLineInfo.m_nFiles, sFile);
+ m_CmdLineInfo.m_nFiles += 1;
+ }
+ }
+}
Added: trunk/Src/ClearCaseCmdLineParser.h
===================================================================
--- trunk/Src/ClearCaseCmdLineParser.h (rev 0)
+++ trunk/Src/ClearCaseCmdLineParser.h 2006-11-17 14:27:57 UTC (rev 3812)
@@ -0,0 +1,71 @@
+/////////////////////////////////////////////////////////////////////////////
+//
+// WinMerge: An interactive diff/merge utility
+// Copyright (C) 1997 Dean P. Grimm
+//
+// 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.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+//
+/////////////////////////////////////////////////////////////////////////////
+
+#ifndef _CLEAR_CASE_CMD_LINE_PARSER_INCLUDED_
+#define _CLEAR_CASE_CMD_LINE_PARSER_INCLUDED_
+
+/**
+ * @file ClearCaseCmdLineParser.h
+ *
+ * @brief ClearCaseCmdLineParser class decleration.
+ *
+ */
+
+// RCS ID line follows -- this is updated by CVS
+// $Id: CmdLineParser.h $
+
+#include "CmdLineParser.h"
+
+/**
+ * @brief Rational ClearCase's command line parser.
+ *
+ * This parser is able to parse ClearCase external tools' command line, both
+ * compare and merge.
+ *
+ */
+class ClearCaseCmdLineParser : public CmdLineParser
+{
+public:
+
+ /** @brief ClearCaseCmdLineParser's constructor.
+ *
+ * @param [in] szFileName Executable file name. Required in order to
+ * know which external tool was executed.
+ *
+ */
+ ClearCaseCmdLineParser(MergeCmdLineInfo& CmdLineInfo, const TCHAR *szFileName);
+
+ virtual ~ClearCaseCmdLineParser() { }
+
+ virtual void ParseParam(const TCHAR* pszParam, BOOL bFlag, BOOL bLast);
+
+private:
+
+ bool m_bDesc;
+ bool m_bBaseFile; /**< Files' common ancestor. Used till we'll have a 3-ways merge. */
+ bool m_bOutFile;
+
+ CString m_sBaseFile;
+ CString m_sBaseDesc;
+ CString m_sOutFile;
+};
+
+#endif // _CLEAR_CASE_CMD_LINE_PARSER_INCLUDED_
Added: trunk/Src/CmdLineParser.h
===================================================================
--- trunk/Src/CmdLineParser.h (rev 0)
+++ trunk/Src/CmdLineParser.h 2006-11-17 14:27:57 UTC (rev 3812)
@@ -0,0 +1,84 @@
+/////////////////////////////////////////////////////////////////////////////
+//
+// WinMerge: An interactive diff/merge utility
+// Copyright (C) 1997 Dean P. Grimm
+//
+// 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.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+//
+/////////////////////////////////////////////////////////////////////////////
+
+#ifndef _CMD_LINE_PARSER_INCLUDED_
+#define _CMD_LINE_PARSER_INCLUDED_
+
+/**
+ * @file CmdLineParser.h
+ *
+ * @brief CmdLineParser class declaration.
+ *
+ */
+
+// RCS ID line follows -- this is updated by CVS
+// $Id: CmdLineParser.h $
+
+class MergeCmdLineInfo;
+
+/**
+ * @brief Base command line parser interface.
+ *
+ * WinMerge is able to parse command line arguments other than its own. In
+ * order to add this capability, a developer should inherit this class and
+ * implement the ParseParam method.
+ *
+ */
+class CmdLineParser
+{
+public:
+
+ /** @brief CmdLineParser's constructor.
+ *
+ * @param [in] CmdLineInfo A class which hold the information obtained
+ * from the command line arguments.
+ *
+ */
+ CmdLineParser(MergeCmdLineInfo& CmdLineInfo) :
+ m_CmdLineInfo(CmdLineInfo)
+ {
+
+ }
+
+ /** @brief CmdLineParser's destructor. */
+ virtual ~CmdLineParser() { }
+
+
+ /** @brief The command line argument parser.
+ *
+ * This method should be implemented by the derived class and do the
+ * actual parsing.
+ *
+ * @param [in] pszParam The parameter or flag.
+ * @bFlag [in] bFlag Indicates whether pszParam is a parameter or a
+ * flag.
+ * @bLast [in] bLast Indicates if this is the last parameter or flag
+ * on the command line.
+ *
+ */
+ virtual void ParseParam(const TCHAR* pszParam, BOOL bFlag, BOOL bLast) = 0;
+
+protected:
+
+ MergeCmdLineInfo& m_CmdLineInfo;
+};
+
+#endif // _CMD_LINE_PARSER_INCLUDED_
Deleted: trunk/Src/Common/CmdArgs.cpp
===================================================================
--- trunk/Src/Common/CmdArgs.cpp 2006-11-17 14:23:07 UTC (rev 3811)
+++ trunk/Src/Common/CmdArgs.cpp 2006-11-17 14:27:57 UTC (rev 3812)
@@ -1,148 +0,0 @@
-/* The X License
-Copyright (c) 2005 Perry Rapp
-Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
-The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-*/
-
-/**
- * @file CmdArgs.cpp
- *
- * @brief Implementation of CmdArgs class
- *
- */
-// RCS ID line follows -- this is updated by CVS
-// $Id$
-
-#include "stdafx.h"
-#include "CmdArgs.h"
-
-#ifndef __AFXTEMPL_H__
-#include <afxtempl.h>
-#endif
-
-#ifdef _DEBUG
-#define new DEBUG_NEW
-#undef THIS_FILE
-static char THIS_FILE[] = __FILE__;
-#endif
-
-/////////////////////////////////////////////////////////////////////////////
-// helper class StringMap
-
-class StringMap : public CMap<CString, LPCTSTR, CString, CString>
-{
-};
-
-/////////////////////////////////////////////////////////////////////////////
-// main class CmdArgs
-
-CmdArgs::CmdArgs(int argc, TCHAR *argv[])
-{
- m_switches = new StringMap;
- m_switchesCapitalized = new StringMap;
- m_params = new CStringArray;
-
- Parse(argc, argv);
-}
-CmdArgs::~CmdArgs()
-{
- delete m_switches; m_switches=0;
- delete m_switchesCapitalized; m_switchesCapitalized=0;
- delete m_params; m_params=0;
-}
-
-void CmdArgs::Clear()
-{
- m_switches->RemoveAll();
- m_switchesCapitalized->RemoveAll();
- m_params->RemoveAll();
-}
-
-void CmdArgs::Parse(int argc, TCHAR *argv[])
-{
- Clear();
-
- for (int i = 1; i < argc; i++)
- {
- CString arg = argv[i];
- if (arg.GetLength()>0 && (arg[0] == '-' || arg[0] == '/'))
- {
- CString value;
- // advance over flag specifier
- arg = arg.Mid(1);
- int index = arg.Find(':');
- if (index >= 0)
- { // switch has value
- value = arg.Mid(index+1);
- arg = arg.Left(index);
- }
- m_switches->SetAt(arg, value);
- arg.MakeUpper();
- m_switchesCapitalized->SetAt(arg, value);
- }
- else
- {
- m_params->Add(arg);
- }
- }
-}
-
-int
-CmdArgs::GetParamsCount() const
-{
- return m_params->GetSize();
-}
-
-CString
-CmdArgs::GetParam(int i) const
-{
- return m_params->GetAt(i);
-}
-
-/**
- * @brief Lookup a switch (encapsulating case-insensitive logic)
- */
-BOOL
-CmdArgs::Lookup(LPCTSTR key, CString & value, bool CaseSensitive) const
-{
- CString lookup = key;
- if (!CaseSensitive)
- lookup.MakeUpper();
- StringMap * map = (CaseSensitive ? m_switches : m_switchesCapitalized);
- return map->Lookup(lookup, value);
-}
-
-/**
- * @brief returns true if specified switch was present with no value (no colon)
- */
-bool
-CmdArgs::HasEmptySwitch(LPCTSTR name, bool CaseSensitive) const
-{
- CString value;
- if (!Lookup(name, value, CaseSensitive))
- return false;
- return value.IsEmpty()!=FALSE;
-}
-
-/**
- * @brief returns true if specified switch was present
- */
-bool
-CmdArgs::HasSwitch(LPCTSTR name, bool CaseSensitive) const
-{
- CString value;
- return GetSwitch(name, value, CaseSensitive);
-}
-
-/**
- * @brief Gets value of requested switch if found
- */
-bool
-CmdArgs::GetSwitch(LPCTSTR name, CString & value, bool CaseSensitive) const
-{
- if (!Lookup(name, value, CaseSensitive))
- return false;
- return true;
-}
-
Deleted: trunk/Src/Common/CmdArgs.h
===================================================================
--- trunk/Src/Common/CmdArgs.h 2006-11-17 14:23:07 UTC (rev 3811)
+++ trunk/Src/Common/CmdArgs.h 2006-11-17 14:27:57 UTC (rev 3812)
@@ -1,52 +0,0 @@
-/**
- * @file CmdArgs.h
- *
- * @brief Defines the CmdArgs class, which parses & stores commandline arguments for querying
- *
- */
-// RCS ID line follows -- this is updated by CVS
-// $Id$
-
-#ifndef CmdArgs_h_included
-#define CmdArgs_h_included
-
-#ifndef __AFXTEMPL_H__
-#include <afxtempl.h>
-#endif
-
-class StringMap;
-
-class CmdArgs
-{
-public:
- CmdArgs(int argc, TCHAR *argv[]);
- ~CmdArgs();
-
-// Settings
- void SetCaseSensitive(bool CaseSensitive=true) { m_CaseSensitive = CaseSensitive; }
-
-// Implementation but available for reparsing
- void Parse(int argc, TCHAR *argv[]);
- void Clear();
-
-// Querying parsed results
- bool HasEmptySwitch(LPCTSTR name, bool CaseSensitive=true) const;
- bool HasSwitch(LPCTSTR name, bool CaseSensitive=true) const;
- bool GetSwitch(LPCTSTR name, CString & value, bool CaseSensitive=true) const;
-
- int GetParamsCount() const;
- CString GetParam(int i) const;
-
-// Implementation methods
-private:
- BOOL Lookup(LPCTSTR key, CString & value, bool CaseSensitive) const;
-
-// Implementation data
-private:
- StringMap * m_switches;
- StringMap * m_switchesCapitalized;
- CStringArray * m_params;
- bool m_CaseSensitive;
-};
-
-#endif // CmdArgs_h_included
Modified: trunk/Src/MainFrm.cpp
===================================================================
--- trunk/Src/MainFrm.cpp 2006-11-17 14:23:07 UTC (rev 3811)
+++ trunk/Src/MainFrm.cpp 2006-11-17 14:27:57 UTC (rev 3812)
@@ -69,6 +69,7 @@
#include "PreferencesDlg.h"
#include "AppSerialize.h"
#include "ProjectFilePathsDlg.h"
+#include "MergeCmdLineInfo.h"
/*
One source file must compile the stubs for multimonitor
@@ -384,7 +385,7 @@
// Finds debug menu by looking for a submenu which
// starts with item ID_DEBUG_LOADCONFIG
- for (int i=0; i< menu->GetMenuItemCount(); ++i)
+ for (UINT i = 0; i < menu->GetMenuItemCount(); ++i)
{
if (menu->GetSubMenu(i)->GetMenuItemID(0) == ID_DEBUG_LOADCONFIG)
{
@@ -2697,10 +2698,10 @@
}
/**
- * @brief Receive commandline from another instance.
+ * @brief Receive command line from another instance.
*
- * This function receives commandline when only single-instance
- * is allowed. New instance tried to start sends its commandline
+ * This function receives command line when only single-instance
+ * is allowed. New instance tried to start sends its command line
* to here so we can open paths it was meant to.
*/
LRESULT CMainFrame::OnCopyData(WPARAM wParam, LPARAM lParam)
@@ -2710,7 +2711,7 @@
int argc = pCopyData->dwData;
TCHAR **argv = new (TCHAR *[argc]);
USES_CONVERSION;
-
+
for (int i = 0; i < argc; i++)
{
argv[i] = new TCHAR[lstrlenW(p) * (sizeof(WCHAR)/sizeof(TCHAR)) + 1];
@@ -2726,15 +2727,31 @@
LRESULT CMainFrame::OnUser(WPARAM wParam, LPARAM lParam)
{
- int argc = (int)wParam;
- TCHAR **argv = (TCHAR **)lParam;
+ // MFC's ParseCommandLine method is working with __argc and __targv
+ // variables. We need to send MergeCmdLineInfo object rather than
+ // passing the command line as string. Until we do, we temporary
+ // change these variable values and restore then after parsing.
- theApp.ParseArgsAndDoOpen(argc, argv, this);
-
- for (int i = 0; i < argc; i++)
- delete[] argv[i];
- delete [] argv;
+ int argc = __argc;
+ TCHAR **argv = __targv;
+ __argc = wParam;
+ __targv = reinterpret_cast<TCHAR **>(lParam);
+
+ MergeCmdLineInfo cmdInfo(*__targv);
+ theApp.ParseCommandLine(cmdInfo);
+ theApp.ParseArgsAndDoOpen(cmdInfo, this);
+
+ // Delete memrory allocated in OnCopyData method.
+ for (int i = 0; i < argc; ++i)
+ {
+ delete[] __targv[i];
+ }
+ delete __targv;
+
+ __argc = argc;
+ __targv = argv;
+
return TRUE;
}
Modified: trunk/Src/Merge.cpp
===================================================================
--- trunk/Src/Merge.cpp 2006-11-17 14:23:07 UTC (rev 3811)
+++ trunk/Src/Merge.cpp 2006-11-17 14:27:57 UTC (rev 3812)
@@ -48,6 +48,8 @@
#include "ProjectFile.h"
#include "MergeEditView.h"
#include "LanguageSelect.h"
+#include "OptionsDef.h"
+#include "MergeCmdLineInfo.h"
#ifdef _DEBUG
#define new DEBUG_NEW
@@ -90,41 +92,22 @@
static void AddEnglishResourceHook();
-class CMergeCmdLineInfo : public CCommandLineInfo
+/**
+* @brief Mapping from command line argument name (eg, ignorews) to WinMerge
+* option name (eg, Settings/IgnoreSpace).
+*
+* These arguments take an optional colon and number, like so:
+*
+* "/ignoreblanklines" (makes WinMerge ignore blank lines)
+* "/ignoreblanklines:1" (makes WinMerge ignore blank lines)
+* "/ignoreblanklines:0" (makes WinMerge not ignore blank lines)
+*/
+struct ArgSetting
{
- public:
-
- CMergeCmdLineInfo();
-
- ~CMergeCmdLineInfo() { }
-
- virtual void ParseParam(const TCHAR* pszParam, BOOL bFlag, BOOL bLast);
-
- public:
-
- BOOL m_bSingleInstance; /**< Allow only one instance of WinMerge executable. */
+ LPCTSTR CmdArgName;
+ LPCTSTR WinMergeOptionName;
};
-CMergeCmdLineInfo::CMergeCmdLineInfo() : CCommandLineInfo(),
- m_bSingleInstance(FALSE)
-{
-
-}
-
-void CMergeCmdLineInfo::ParseParam(const TCHAR* pszParam, BOOL bFlag, BOOL bLast)
-{
- // Give our base class a chance to figure out what is the parameter.
- CCommandLineInfo::ParseParam(pszParam, bFlag, bLast);
-
- if (TRUE == bFlag)
- {
- if (pszParam[0] == _T('s'))
- {
- m_bSingleInstance = TRUE;
- }
- }
-}
-
/////////////////////////////////////////////////////////////////////////////
// CMergeApp construction
@@ -132,11 +115,9 @@
m_bNeedIdleTimer(FALSE)
, m_pDiffTemplate(0)
, m_pDirTemplate(0)
-// FileFilterHelper m_globalFileFilter
, m_mainThreadScripts(NULL)
, m_nLastCompareResult(0)
-, m_bNoninteractive(false)
-, m_bShowUsage(false)
+, m_bNonInteractive(false)
{
// add construction code here,
// Place all significant initialization in InitInstance
@@ -195,7 +176,7 @@
#endif
// Parse command-line arguments.
- CMergeCmdLineInfo cmdInfo;
+ MergeCmdLineInfo cmdInfo(*__targv);
ParseCommandLine(cmdInfo);
// Set default codepage
@@ -206,7 +187,7 @@
SetRegistryKey(_T("Thingamahoochie"));
BOOL bSingleInstance = GetProfileInt(_T("Settings"), _T("SingleInstance"), FALSE) ||
- (TRUE == cmdInfo.m_bSingleInstance);
+ (true == cmdInfo.m_bSingleInstance);
HANDLE hMutex = NULL;
if (bSingleInstance)
@@ -309,41 +290,30 @@
CMenu * pNewMenu = CMenu::FromHandle(pMainFrame->m_hMenuDefault);
pMainFrame->MDISetMenu(pNewMenu, NULL);
- // Command line parsing is handled not by MFC wizard's CComandLineInfo
- // but rather by ParseArgsAndDoOpen below
-
//Track it so any other instances can find it.
instanceChecker.TrackFirstInstanceRunning();
- // The main window has been initialized, so show and update it.
- //pMainFrame->ShowWindow(m_nCmdShow);
- pMainFrame->ActivateFrame(m_nCmdShow);
+ // The main window has been initialized, so activate and update it.
+ pMainFrame->ActivateFrame(cmdInfo.m_nCmdShow);
pMainFrame->UpdateWindow();
// Since this function actually opens paths for compare it must be
// called after initializing CMainFrame!
- ParseArgsAndDoOpen(__argc, __targv, pMainFrame);
+ ParseArgsAndDoOpen(cmdInfo, pMainFrame);
- if (m_bShowUsage)
- {
- CString s = GetUsageDescription();
- AfxMessageBox(s, MB_ICONINFORMATION);
- m_bNoninteractive = false;
- }
-
if (hMutex)
{
ReleaseMutex(hMutex);
CloseHandle(hMutex);
}
- if (m_bNoninteractive)
+ if (m_bNonInteractive)
{
DirViewList DirViews;
pMainFrame->GetDirViews(&DirViews);
if (DirViews.GetCount() == 1)
{
- CDirView * pDirView = DirViews.RemoveHead();
+ CDirView *pDirView = DirViews.RemoveHead();
CDirFrame *pf = pDirView->GetParentFrame();
}
pMainFrame->PostMessage(WM_CLOSE, 0, 0);
@@ -595,7 +565,7 @@
// do not show again checkbox, and implements it on subsequent calls
// (if caller set the style)
- if (m_bNoninteractive)
+ if (m_bNonInteractive)
return IDCANCEL;
// Create the message box dialog.
@@ -646,6 +616,109 @@
m_globalFileFilter.LoadAllFileFilters();
}
+/** @brief Read command line arguments and open files for comparison.
+ *
+ * The name of the function is a legacy code from the time that this function
+ * actually parsed the command line. Today the parsing is done using the
+ * MergeCmdLineInfo class.
+ *
+ */
+void CMergeApp::ParseArgsAndDoOpen(MergeCmdLineInfo& cmdInfo, CMainFrame* pMainFrame)
+{
+ m_bNonInteractive = cmdInfo.m_bNonInteractive;
+
+ SetOptionsFromCmdLine(cmdInfo);
+
+ // Do not load or remember options (preferences).
+ if (cmdInfo.m_bNoPrefs)
+ {
+ // Turn off serializing to registry.
+ GetOptionsMgr()->SetSerializing(false);
+ // Load all default settings.
+ pMainFrame->ResetOptions();
+ }
+
+ // Set the global file filter.
+ if (!cmdInfo.m_sFileFilter.IsEmpty())
+ {
+ m_globalFileFilter.SetFilter(cmdInfo.m_sFileFilter);
+ }
+
+ // Unless the user has requested to see WinMerge's usage open files for
+ // comparison.
+ if (cmdInfo.m_bShowUsage)
+ {
+ CString s = GetUsageDescription();
+ AfxMessageBox(s, MB_ICONINFORMATION);
+ }
+ else
+ {
+ // Set the required information we need from the command line:
+
+ pMainFrame->m_bClearCaseTool = cmdInfo.m_bClearCaseTool;
+ pMainFrame->m_bExitIfNoDiff = cmdInfo.m_bExitIfNoDiff;
+ pMainFrame->m_bEscShutdown = cmdInfo.m_bEscShutdown;
+
+ pMainFrame->m_strSaveAsPath = _T("");
+
+ pMainFrame->m_strLeftDesc = cmdInfo.m_sLeftDesc;
+ pMainFrame->m_strRightDesc = cmdInfo.m_sRightDesc;
+
+ if (cmdInfo.m_nFiles > 2)
+ {
+ pMainFrame->m_strSaveAsPath = cmdInfo.m_Files[2];
+ pMainFrame->DoFileOpen(cmdInfo.m_Files[0], cmdInfo.m_Files[1],
+ cmdInfo.m_dwLeftFlags, cmdInfo.m_dwRightFlags, cmdInfo.m_bRecurse, NULL, cmdInfo.m_sPreDiffer);
+ }
+ else if (cmdInfo.m_nFiles > 1)
+ {
+ cmdInfo.m_dwLeftFlags |= FFILEOPEN_CMDLINE;
+ cmdInfo.m_dwRightFlags |= FFILEOPEN_CMDLINE;
+ pMainFrame->DoFileOpen(cmdInfo.m_Files[0], cmdInfo.m_Files[1],
+ cmdInfo.m_dwLeftFlags, cmdInfo.m_dwRightFlags, cmdInfo.m_bRecurse, NULL, cmdInfo.m_sPreDiffer);
+ }
+ else if (cmdInfo.m_nFiles == 1)
+ {
+ CString sFilepath = cmdInfo.m_Files[0];
+ if (IsProjectFile(sFilepath))
+ {
+ LoadAndOpenProjectFile(sFilepath);
+ }
+ else
+ {
+ cmdInfo.m_dwRightFlags = FFILEOPEN_NONE;
+ pMainFrame->DoFileOpen(sFilepath, _T(""),
+ cmdInfo.m_dwLeftFlags, cmdInfo.m_dwRightFlags, cmdInfo.m_bRecurse, NULL, cmdInfo.m_sPreDiffer);
+ }
+ }
+ }
+}
+
+/** @brief Handle all command line arguments which are mapped to WinMerge options. */
+void CMergeApp::SetOptionsFromCmdLine(const MergeCmdLineInfo& cmdInfo)
+{
+ static const ArgSetting f_ArgSettings[] =
+ {
+ { _T("ignorews"), OPT_CMP_IGNORE_WHITESPACE },
+ { _T("ignoreblanklines"), OPT_CMP_IGNORE_BLANKLINES },
+ { _T("ignorecase"), OPT_CMP_IGNORE_CASE },
+ { _T("ignoreeol"), OPT_CMP_IGNORE_EOL }
+ };
+
+ for (int i = 0; i < countof(f_ArgSettings); ++i)
+ {
+ const ArgSetting& argSetting = f_ArgSettings[i];
+ LPCTSTR szCmdArgName = argSetting.CmdArgName;
+ LPCTSTR szOptionName = argSetting.WinMergeOptionName;
+ CString sValue;
+
+ if (cmdInfo.m_Settings.Lookup(szCmdArgName, sValue))
+ {
+ GetOptionsMgr()->CoerceAndSaveOption(szOptionName, sValue);
+ }
+ }
+}
+
/** @brief Open help from mainframe when user presses F1*/
void CMergeApp::OnHelp()
{
@@ -741,3 +814,32 @@
{
m_pLangDlg->ReloadMenu();
}
+
+/** @brief Wrap one line of cmdline help in appropriate whitespace */
+static CString CmdlineOption(int idres)
+{
+ CString str = LoadResString(idres) + _T(" \n");
+ return str;
+}
+
+/** @brief Put together string of all cmdline arguments */
+CString CMergeApp::GetUsageDescription()
+{
+ CString str;
+ str += LoadResString(IDS_CMDLINE_SYNTAX);
+ str += _T(" [/f ") + LoadResString(IDS_CMDLINE_SYNTAX_ARG_FILTER) + _T("]");
+ str += _T(" ");
+ str += LoadResString(IDS_CMDLINE_SYNTAX_ARGS);
+ str += _T("\n\n") + LoadResString(IDS_CMDLINE_WHERE) + _T(" \n");
+ str += CmdlineOption(IDS_CMDLINE_HELP);
+ str += CmdlineOption(IDS_CMDLINE_RECURSIVE);
+ str += CmdlineOption(IDS_CMDLINE_ESCKEY);
+ str += CmdlineOption(IDS_CMDLINE_FILEMASK);
+ str += CmdlineOption(IDS_CMDLINE_FASTCLOSE);
+ str += CmdlineOption(IDS_CMDLINE_SINGLE_INST);
+ str += CmdlineOption(IDS_CMDLINE_LEFTPATH);
+ str += CmdlineOption(IDS_CMDLINE_RIGHTPATH);
+ str += CmdlineOption(IDS_CMDLINE_OUTPUTPATH);
+ str += _T("\n\n") + LoadResString(IDS_CMDLINE_SEEMANUAL);
+ return str;
+}
Modified: trunk/Src/Merge.dsp
===================================================================
--- trunk/Src/Merge.dsp 2006-11-17 14:23:07 UTC (rev 3811)
+++ trunk/Src/Merge.dsp 2006-11-17 14:27:57 UTC (rev 3812)
@@ -205,7 +205,7 @@
# End Source File
# Begin Source File
-SOURCE=.\Common\CmdArgs.cpp
+SOURCE=.\ClearCaseCmdLineParser.cpp
# End Source File
# Begin Source File
@@ -537,7 +537,7 @@
# End Source File
# Begin Source File
-SOURCE=.\MergeArgs.cpp
+SOURCE=.\MergeCmdLineInfo.cpp
# End Source File
# Begin Source File
@@ -933,6 +933,10 @@
# End Source File
# Begin Source File
+SOURCE=.\WinMergeCmdLineParser.cpp
+# End Source File
+# Begin Source File
+
SOURCE=.\WMGotoDlg.cpp
# End Source File
# End Group
@@ -973,10 +977,14 @@
# End Source File
# Begin Source File
-SOURCE=.\Common\CmdArgs.h
+SOURCE=.\ClearCaseCmdLineParser.h
# End Source File
# Begin Source File
+SOURCE=.\CmdLineParser.h
+# End Source File
+# Begin Source File
+
SOURCE=.\Common\CMoveConstraint.h
# End Source File
# Begin Source File
@@ -1237,6 +1245,10 @@
# End Source File
# Begin Source File
+SOURCE=.\MergeCmdLineInfo.h
+# End Source File
+# Begin Source File
+
SOURCE=.\MergeDiffDetailView.h
# End Source File
# Begin Source File
@@ -1513,6 +1525,10 @@
# End Source File
# Begin Source File
+SOURCE=.\WinMergeCmdLineParser.h
+# End Source File
+# Begin Source File
+
SOURCE=.\WMGotoDlg.h
# End Source File
# End Group
Modified: trunk/Src/Merge.h
===================================================================
--- trunk/Src/Merge.h 2006-11-17 14:23:07 UTC (rev 3811)
+++ trunk/Src/Merge.h 2006-11-17 14:27:57 UTC (rev 3812)
@@ -42,6 +42,7 @@
class CAssureScriptsForThread;
class CMainFrame;
class CLanguageSelect;
+class MergeCmdLineInfo;
/////////////////////////////////////////////////////////////////////////////
// CMergeApp:
@@ -86,13 +87,8 @@
virtual BOOL PreTranslateMessage(MSG* pMsg);
void InitializeFileFilters();
-
- // In MergeArgs.cpp
- void ParseArgs(int argc, TCHAR *argv[], CMainFrame* pMainFrame, CStringArray & files, UINT & nFiles, BOOL & recurse,
- DWORD & dwLeftFlags, DWORD & dwRightFlags, CString & prediffer);
- void ParseCCaseArgs(int argc, TCHAR *argv[], CMainFrame* pMainFrame, CStringArray & files, UINT & nFiles,
- DWORD & dwLeftFlags, DWORD & dwRightFlags);
- void ParseArgsAndDoOpen(int argc, TCHAR *argv[], CMainFrame* pMainFrame);
+ void ParseArgsAndDoOpen(MergeCmdLineInfo& cmdInfo, CMainFrame* pMainFrame);
+ void SetOptionsFromCmdLine(const MergeCmdLineInfo& cmdInfo);
CString GetUsageDescription();
// End MergeArgs.cpp
@@ -111,8 +107,7 @@
private:
CAssureScriptsForThread * m_mainThreadScripts;
int m_nLastCompareResult;
- bool m_bNoninteractive;
- bool m_bShowUsage;
+ bool m_bNonInteractive;
};
extern CMergeApp theApp;
Deleted: trunk/Src/MergeArgs.cpp
===================================================================
--- trunk/Src/MergeArgs.cpp 2006-11-17 14:23:07 UTC (rev 3811)
+++ trunk/Src/MergeArgs.cpp 2006-11-17 14:27:57 UTC (rev 3812)
@@ -1,420 +0,0 @@
-/////////////////////////////////////////////////////////////////////////////
-// WinMerge: an interactive diff/merge utility
-// Copyright (C) 1997-2000 Thingamahoochie Software
-// Author: Dean Grimm
-//
-// 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.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this program; if not, write to the Free Software
-// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-//
-/////////////////////////////////////////////////////////////////////////////
-/**
- * @file MergeArgs.cpp
- *
- * @brief Command line argument handling for WinMerge application
- *
- */
-// RCS ID line follows -- this is updated by CVS
-// $Id$
-
-#include "stdafx.h"
-#include "Merge.h"
-
-#include "MainFrm.h"
-#include "CmdArgs.h"
-#include "paths.h"
-#include "OptionsDef.h"
-
-
-#ifdef _DEBUG
-#define new DEBUG_NEW
-#undef THIS_FILE
-static char THIS_FILE[] = __FILE__;
-#endif
-
-
-/**
- * @brief Mapping from commandline argument name (eg, ignorews) to WinMerge option name (eg, Settings/IgnoreSpace)
- *
- * These arguments take an optional colon and number, like so:
- * "/ignoreblanklines" (makes WinMerge ignore blank lines)
- * "/ignoreblanklines:1" (makes WinMerge ignore blank lines)
- * "/ignoreblanklines:0" (makes WinMerge not ignore blank lines)
- */
-struct ArgSetting
-{
- LPCTSTR CmdArgName;
- LPCTSTR WinMergeOptionName;
-};
-static ArgSetting f_ArgSettings[] =
-{
- { _T("ignorews"), OPT_CMP_IGNORE_WHITESPACE }
- , { _T("ignoreblanklines"), OPT_CMP_IGNORE_BLANKLINES }
- , { _T("ignorecase"), OPT_CMP_IGNORE_CASE }
- , { _T("ignoreeol"), OPT_CMP_IGNORE_EOL }
-};
-
-
-/**
- * @brief Process command line arguments and open requested files/dirs if appropriate
- */
-void
-CMergeApp::ParseArgsAndDoOpen(int argc, TCHAR *argv[], CMainFrame* pMainFrame)
-{
- UINT nFiles=0;
- DWORD dwLeftFlags = FFILEOPEN_CMDLINE;
- DWORD dwRightFlags = FFILEOPEN_CMDLINE;
- BOOL recurse=FALSE;
- CString prediffer;
- CStringArray files;
- files.SetSize(2);
-
- // Split commandline arguments into files & flags & recursive flag
-
- // Rational ClearCase has a weird way of executing external
- // tools which replace the build-in ones. It also doesn't allow
- // you to define which parameters to send to the executable.
- // So, in order to run as an external tool, WinMerge should do:
- // if argv[0] is "xcompare" then it "knows" that it was
- // executed from ClearCase. In this case, it should read and
- // parse ClearCase's command line parameters and not the
- // "regular" parameters. More information can be found in
- // C:\Program Files\Rational\ClearCase\lib\mgrs\mgr_info.h file.
-
- if (lstrcmpi(argv[0], _T("xcompare")) && lstrcmpi(argv[0], _T("xmerge")))
- {
- ParseArgs(argc, argv, pMainFrame, files, nFiles, recurse, dwLeftFlags, dwRightFlags, prediffer);
- if (m_bShowUsage)
- return;
- }
- else
- {
- ParseCCaseArgs(argc, argv, pMainFrame, files, nFiles, dwLeftFlags, dwRightFlags);
- }
-
- pMainFrame->m_strSaveAsPath = _T("");
-
- if (nFiles > 2)
- {
- pMainFrame->m_strSaveAsPath = files[2];
- pMainFrame->DoFileOpen(files[0], files[1],
- dwLeftFlags, dwRightFlags, recurse, NULL, prediffer);
- }
- else if (nFiles > 1)
- {
- dwLeftFlags |= FFILEOPEN_CMDLINE;
- dwRightFlags |= FFILEOPEN_CMDLINE;
- pMainFrame->DoFileOpen(files[0], files[1],
- dwLeftFlags, dwRightFlags, recurse, NULL, prediffer);
- }
- else if (nFiles == 1)
- {
- CString sFilepath = files[0];
- if (IsProjectFile(sFilepath))
- {
- LoadAndOpenProjectFile(sFilepath);
- }
- else
- {
- dwRightFlags = FFILEOPEN_NONE;
- pMainFrame->DoFileOpen(sFilepath, _T(""),
- dwLeftFlags, dwRightFlags, recurse, NULL, prediffer);
- }
- }
-}
-
-/**
- * @brief Process all command line arguments
- */
-void
-CMergeApp::ParseArgs(int argc, TCHAR *argv[], CMainFrame* pMainFrame, CStringArray & files, UINT & nFiles, BOOL & recurse,
- DWORD & dwLeftFlags, DWORD & dwRightFlags, CString & prediffer)
-{
- CmdArgs cmdArgs(argc, argv);
-
- // -? for help
- if (cmdArgs.HasEmptySwitch(_T("?")))
- {
- m_bShowUsage = true;
- }
-
- cmdArgs.SetCaseSensitive(false);
-
- // -r to compare recursively
- if (cmdArgs.HasEmptySwitch(_T("r")))
- recurse = TRUE;
-
- // -e to allow closing with single esc press
- if (cmdArgs.HasEmptySwitch(_T("e")))
- pMainFrame->m_bEscShutdown = TRUE;
-
- // -x to close application if files are identical.
- if (cmdArgs.HasEmptySwitch(_T("x")))
- pMainFrame->m_bExitIfNoDiff = TRUE;
-
- // -wl to open left path as read-only
- if (cmdArgs.HasEmptySwitch(_T("wl")))
- dwLeftFlags |= FFILEOPEN_READONLY;
-
- // -wr to open right path as read-only
- if (cmdArgs.HasEmptySwitch(_T("wr")))
- dwRightFlags |= FFILEOPEN_READONLY;
-
- // -ul to not add left path to MRU
- if (cmdArgs.HasEmptySwitch(_T("ul")))
- dwLeftFlags |= FFILEOPEN_NOMRU;
-
- // -ur to not add right path to MRU
- if (cmdArgs.HasEmptySwitch(_T("ur")))
- dwRightFlags |= FFILEOPEN_NOMRU;
-
- // -ub to add neither right nor left path to MRU
- if (cmdArgs.HasEmptySwitch(_T("ub")))
- {
- dwLeftFlags |= FFILEOPEN_NOMRU;
- dwRightFlags |= FFILEOPEN_NOMRU;
- }
-
- // -noninteractive to suppress message boxes & close with result code
- if (cmdArgs.HasEmptySwitch(_T("noninteractive")))
- {
- m_bNoninteractive = true;
- }
-
- // Get prediffer if specified (otherwise prediffer will be blank, which is default)
- cmdArgs.GetSwitch(_T("prediffer"), prediffer);
-
- if (cmdArgs.HasSwitch(_T("noprefs")))
- {
- // /noprefs means do not load or remember options (preferences)
-
- // turn off serializing to registry
- GetOptionsMgr()->SetSerializing(false);
- // load all default settings
- GetMainFrame()->ResetOptions();
- }
-
- if (cmdArgs.HasSwitch(_T("minimize")))
- {
- // /minimize means minimize the main window
- m_nCmdShow = SW_MINIMIZE;
- }
-
- // Handle all switches in the f_ArgSettings table
- // this are arguments mapped to WinMerge options
- int i;
- for (i = 0; i < countof(f_ArgSettings); ++i)
- {
- const ArgSetting & argSetting = f_ArgSettings[i];
- LPCTSTR cmdargName = argSetting.CmdArgName;
- LPCTSTR optName = argSetting.WinMergeOptionName;
- CString value;
- if (cmdArgs.GetSwitch(cmdargName, value))
- {
- // eg, treat "/ignorews" as "/ignorews:1"
- if (value.IsEmpty())
- value = _T("1");
- GetOptionsMgr()->CoerceAndSaveOption(optName, value);
- }
- }
-
- // Can't get switches with arguments from cmdArgs
- // because cmdArgs recognizes arguments using colons not spaces
-
- for (i = 1; i < argc; i++)
- {
- LPCTSTR pszParam = argv[i];
- if (pszParam[0] == '-' || pszParam[0] == '/')
- {
- // remove flag specifier
- ++pszParam;
-
-
- // -dl "desc" - description for left file
- // Shown instead of filename
- if (!_tcsicmp(pszParam, _T("dl")))
- {
- if (i < (argc - 1))
- {
- LPCTSTR pszDesc = argv[i+1];
- pMainFrame->m_strLeftDesc = pszDesc;
- i++; // Just read next parameter
- }
- }
-
- // -dr "desc" - description for left file
- // Shown instead of filename
- if (!_tcsicmp(pszParam, _T("dr")))
- {
- if (i < (argc - 1))
- {
- LPCTSTR pszDesc = argv[i+1];
- pMainFrame->m_strRightDesc = pszDesc;
- i++; // Just read next parameter
- }
- }
-
- // -f "mask" - file filter mask ("*.h *.cpp")
- if (!_tcsicmp(pszParam, _T("f")))
- {
- if (i < (argc - 1))
- {
- CString sFilter = argv[i+1];
- sFilter.TrimLeft();
- sFilter.TrimRight();
- m_globalFileFilter.SetFilter(sFilter);
- i++; // Just read next parameter
- }
- }
- }
- else
- {
- CString sParam = pszParam;
- CString sFile = paths_GetLongPath(sParam);
- files.SetAtGrow(nFiles, sFile);
- nFiles++;
- }
- }
-
- // if "compare file dir" make it "compare file dir\file"
- if (nFiles >= 2)
- {
- PATH_EXISTENCE p1 = paths_DoesPathExist(files[0]);
- PATH_EXISTENCE p2 = paths_DoesPathExist(files[1]);
- if (p1 == IS_EXISTING_FILE && p2 == IS_EXISTING_DIR)
- {
- TCHAR fname[_MAX_PATH], fext[_MAX_PATH];
- _tsplitpath(files[0], NULL, NULL, fname, fext);
- if (files[1].Right(1) != _T('\\'))
- files[1] += _T('\\');
- files[1] = files[1] + fname + fext;
- }
- }
-
- // Reload menus in case a satellite language dll was loaded above
- ReloadMenu();
-}
-
-/// Process Rational ClearCase command line arguments
-void
-CMergeApp::ParseCCaseArgs(int argc, TCHAR *argv[], CMainFrame* pMainFrame, CStringArray & files, UINT & nFiles,
- DWORD & dwLeftFlags, DWORD & dwRightFlags)
-{
- CString *pDesc = NULL;
- CString sOutFile;
-
- pMainFrame->m_bClearCaseTool = TRUE;
- pMainFrame->m_bEscShutdown = TRUE;
-
- dwLeftFlags |= FFILEOPEN_READONLY | FFILEOPEN_NOMRU;
- dwRightFlags |= FFILEOPEN_NOMRU;
-
- if (lstrcmpi(argv[0], _T("xmerge")))
- {
- dwRightFlags |= FFILEOPEN_READONLY;
-
- // First description belong to the left file.
- pDesc = &(pMainFrame->m_strLeftDesc);
- }
-
- for (int i = 1; i < argc; i++)
- {
- LPCTSTR pszParam = argv[i];
- if (pszParam[0] == '-')
- {
- // remove flag specifier
- ++pszParam;
-
- if (!_tcsicmp(pszParam, _T("base")))
- {
- i++; // a 2-way merge doesn't need the common ancestor.
- }
-
- if (!_tcsicmp(pszParam, _T("out")))
- {
- if (i < (argc - 1))
- {
- sOutFile = argv[i+1];
- i++;
- }
- }
-
- // -fname "desc" - description for a file
- // Shown instead of filename
- if (!_tcsicmp(pszParam, _T("fname")))
- {
- if (i < (argc - 1))
- {
- if (NULL == pDesc)
- {
- // First description belong to the left file.
- pDesc = &(pMainFrame->m_strLeftDesc);
-
- i++; // Skip the common ancestor description.
- }
- else
- {
- LPCTSTR pszDesc = argv[i+1];
- *pDesc = pszDesc;
- i++; // Just read next parameter
-
- // Next description belong to the right file.
- pDesc = &(pMainFrame->m_strRightDesc);
- }
-
- }
- }
- }
- else
- {
- CString sFile = paths_GetLongPath(pszParam);
- files.SetAtGrow(nFiles, sFile);
- nFiles++;
- }
- }
-
- if (FALSE == sOutFile.IsEmpty())
- {
- files.SetAtGrow(nFiles, sOutFile);
- nFiles++;
- }
-}
-
-/** @brief Wrap one line of cmdline help in appropriate whitespace */
-static CString CmdlineOption(int idres)
-{
- CString str = LoadResString(idres) + _T(" \n");
- return str;
-}
-
-/** @brief Put together string of all cmdline arguments */
-CString CMergeApp::GetUsageDescription()
-{
- CString str;
- str += LoadResString(IDS_CMDLINE_SYNTAX);
- str += _T(" [/f ") + LoadResString(IDS_CMDLINE_SYNTAX_ARG_FILTER) + _T("]");
- str += _T(" ");
- str += LoadResString(IDS_CMDLINE_SYNTAX_ARGS);
- str += _T("\n\n") + LoadResString(IDS_CMDLINE_WHERE) + _T(" \n");
- str += CmdlineOption(IDS_CMDLINE_HELP);
- str += CmdlineOption(IDS_CMDLINE_RECURSIVE);
- str += CmdlineOption(IDS_CMDLINE_ESCKEY);
- str += CmdlineOption(IDS_CMDLINE_FILEMASK);
- str += CmdlineOption(IDS_CMDLINE_FASTCLOSE);
- str += CmdlineOption(IDS_CMDLINE_SINGLE_INST);
- str += CmdlineOption(IDS_CMDLINE_LEFTPATH);
- str += CmdlineOption(IDS_CMDLINE_RIGHTPATH);
- str += CmdlineOption(IDS_CMDLINE_OUTPUTPATH);
- str += _T("\n\n") + LoadResString(IDS_CMDLINE_SEEMANUAL);
- return str;
-}
Added: trunk/Src/MergeCmdLineInfo.cpp
===================================================================
--- trunk/Src/MergeCmdLineInfo.cpp (rev 0)
+++ trunk/Src/MergeCmdLineInfo.cpp 2006-11-17 14:27:57 UTC (rev 3812)
@@ -0,0 +1,93 @@
+/////////////////////////////////////////////////////////////////////////////
+//
+// WinMerge: An interactive diff/merge utility
+// Copyright (C) 1997 Dean P. Grimm
+//
+// 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.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+//
+/////////////////////////////////////////////////////////////////////////////
+
+/**
+ * @file CmdLineParser.h
+ *
+ * @brief CmdLineParser class implementation.
+ *
+ */
+
+// RCS ID line follows -- this is updated by CVS
+// $Id: CmdLineParser.h $
+
+#include "StdAfx.h"
+
+#include <shlwapi.h> // Required for PathFindFileName
+
+#include "MainFrm.h"
+#include "MergeCmdLineInfo.h"
+#include "ClearCaseCmdLineParser.h"
+#include "WinMergeCmdLineParser.h"
+
+// MergeCmdLineInfo
+
+MergeCmdLineInfo::MergeCmdLineInfo(const TCHAR *szExeName) : CCommandLineInfo(),
+ m_nCmdShow(SW_SHOWNORMAL),
+ m_bClearCaseTool(false),
+ m_bEscShutdown(false),
+ m_bExitIfNoDiff(false),
+ m_bRecurse(false),
+ m_bNonInteractive(false),
+ m_bNoPrefs(false),
+ m_bSingleInstance(false),
+ m_bShowUsage(false),
+ m_dwLeftFlags(FFILEOPEN_CMDLINE),
+ m_dwRightFlags(FFILEOPEN_CMDLINE),
+ m_nFiles(0)
+{
+ m_Files.SetSize(2);
+
+ // Rational ClearCase has a weird way of executing external
+ // tools which replace the build-in ones. It also doesn't allow
+ // you to define which parameters to send to the executable.
+ // So, in order to run as an external tool, WinMerge should do:
+ // if argv[0] is "xcompare" then it "knows" that it was
+ // executed from ClearCase. In this case, it should read and
+ // parse ClearCase's command line parameters and not the
+ // "regular" parameters. More information can be found in
+ // C:\Program Files\Rational\ClearCase\lib\mgrs\mgr_info.h file.
+
+ LPTSTR szFileName = ::PathFindFileName(szExeName);
+
+ if (lstrcmpi(szFileName, _T("xcompare")) && lstrcmpi(szFileName, _T("xmerge")))
+ {
+ m_pCmdLineParser = new WinMergeCmdLineParser(*this);
+ }
+ else
+ {
+ m_bClearCaseTool = true;
+ m_pCmdLineParser = new ClearCaseCmdLineParser(*this, szFileName);
+ }
+}
+
+MergeCmdLineInfo::~MergeCmdLineInfo()
+{
+ delete m_pCmdLineParser;
+}
+
+void MergeCmdLineInfo::ParseParam(const TCHAR* pszParam, BOOL bFlag, BOOL bLast)
+{
+ // Give our base class a chance to figure out what is the parameter.
+ CCommandLineInfo::ParseParam(pszParam, bFlag, bLast);
+
+ m_pCmdLineParser->ParseParam(pszParam, bFlag, bLast);
+}
Added: trunk/Src/MergeCmdLineInfo.h
===================================================================
--- trunk/Src/MergeCmdLineInfo.h (rev 0)
+++ trunk/Src/MergeCmdLineInfo.h 2006-11-17 14:27:57 UTC (rev 3812)
@@ -0,0 +1,95 @@
+/////////////////////////////////////////////////////////////////////////////
+//
+// WinMerge: An interactive diff/merge utility
+// Copyright (C) 1997 Dean P. Grimm
+//
+// 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.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+//
+/////////////////////////////////////////////////////////////////////////////
+
+#ifndef _MERGE_CMD_LINE_INFO_INCLUDED_
+#define _MERGE_CMD_LINE_INFO_INCLUDED_
+
+/**
+ * @file MergeCmdLineInfo.h
+ *
+ * @brief MergeCmdLineInfo class declaration.
+ *
+ */
+
+// RCS ID line follows -- this is updated by CVS
+// $Id: MergeCmdLineInfo.h $
+
+class CmdLineParser;
+
+/**
+ * @brief WinMerge's command line handler.
+ *
+ */
+class MergeCmdLineInfo : public CCommandLineInfo
+{
+public:
+
+ /** @brief ClearCaseCmdLineParser's constructor.
+ *
+ * @param [in] szFileName Executable file name. Required in order to
+ * know which command line parser to create and use.
+ *
+ */
+ MergeCmdLineInfo(const TCHAR *szExeName);
+
+ ~MergeCmdLineInfo();
+
+ /** @brief Override CCommandLineInfo's method. */
+ virtual void ParseParam(const TCHAR* pszParam, BOOL bFlag, BOOL bLast);
+
+public:
+
+ int m_nCmdShow; /**< Initial state of the application's window. */
+
+ bool m_bClearCaseTool; /**< Running as Rational ClearCase external tool. */
+ bool m_bEscShutdown; /**< Pressing ESC will close the application */
+ bool m_bExitIfNoDiff; /**< Exit after telling the user that files are identical. */
+ bool m_bRecurse; /**< Include sub folder in directories compare. */
+ bool m_bNonInteractive; /**< Suppress user's notifications. */
+ bool m_bNoPrefs; /**< Do not load or remember preferences. */
+ bool m_bSingleInstance; /**< Allow only one instance of WinMerge executable. */
+ bool m_bShowUsage; /**< Show a brief reminder to command line arguments. */
+
+ DWORD m_dwLeftFlags; /**< Left side file's behavior options. */
+ DWORD m_dwRightFlags; /**< Right side file's behavior options. */
+
+ CString m_sLeftDesc; /**< Left side file's description. */
+ CString m_sRightDesc; /**< Right side file's description. */
+
+ CString m_sFileFilter; /**< File filter mask. */
+ CString m_sPreDiffer;
+
+ /**< Command line arguments which are mapped to WinMerge's preferences. */
+ CMapStringToString m_Settings;
+
+ CStringArray m_Files; /**< Files (or directories) to compare. */
+
+ int m_nFiles; /**< Number of files (or directories) in m_Files. */
+
+private:
+
+ /**< operator= is not implemented. */
+ MergeCmdLineInfo& operator=(const MergeCmdLineInfo& rhs);
+
+ CmdLineParser *m_pCmdLineParser; /**< The command line parser instance. */
+};
+
+#endif // _MERGE_CMD_LINE_INFO_INCLUDED_
Added: trunk/Src/WinMergeCmdLineParser.cpp
===================================================================
--- trunk/Src/WinMergeCmdLineParser.cpp (rev 0)
+++ trunk/Src/WinMergeCmdLineParser.cpp 2006-11-17 14:27:57 UTC (rev 3812)
@@ -0,0 +1,219 @@
+/////////////////////////////////////////////////////////////////////////////
+//
+// WinMerge: An interactive diff/merge utility
+// Copyright (C) 1997 Dean P. Grimm
+//
+// 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.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+//
+/////////////////////////////////////////////////////////////////////////////
+
+/**
+* @file WinMergeCmdLineParser.h
+*
+* @brief WinMergeCmdLineParser class implementation.
+*
+*/
+
+// RCS ID line follows -- this is updated by CVS
+// $Id: WinMergeCmdLineParser.cpp $
+
+#include "StdAfx.h"
+
+#include "MainFrm.h"
+#include "MergeCmdLineInfo.h"
+#include "WinMergeCmdLineParser.h"
+#include "Paths.h"
+
+WinMergeCmdLineParser::WinMergeCmdLineParser(MergeCmdLineInfo& CmdLineInfo) :
+ CmdLineParser(CmdLineInfo),
+ m_bPreDiff(false),
+ m_bFileFilter(false),
+ m_bLeftDesc(false),
+ m_bRightDesc(false)
+{
+
+}
+
+void WinMergeCmdLineParser::ParseParam(const TCHAR* pszParam, BOOL bFlag, BOOL bLast)
+{
+ if (TRUE == bFlag)
+ {
+ if (!lstrcmp(pszParam, _T("?")))
+ {
+ // -? to show common command line arguments.
+ m_CmdLineInfo.m_bShowUsage = true;
+ }
+ else if (!lstrcmpi(pszParam, _T("dl")))
+ {
+ // -dl "desc" - description for left file
+ m_bLeftDesc = true;
+ }
+ else if (!lstrcmpi(pszParam, _T("dr")))
+ {
+ // -dr "desc" - description for right file
+ m_bRightDesc = true;
+ }
+ else if (!lstrcmpi(pszParam, _T("e")))
+ {
+ // -e to allow closing with single esc press
+ m_CmdLineInfo.m_bEscShutdown = true;
+ }
+ else if (!lstrcmpi(pszParam, _T("f")))
+ {
+ // -f "mask" - file filter mask ("*.h *.cpp")
+ m_bFileFilter = true;
+ }
+ else if (!lstrcmpi(pszParam, _T("r")))
+ {
+ // -r to compare recursively
+ m_CmdLineInfo.m_bRecurse = true;
+ }
+ else if (!lstrcmpi(pszParam, _T("s")))
+ {
+ // -s to allow only one instance
+ m_CmdLineInfo.m_bSingleInstance = true;
+ }
+ else if (!lstrcmpi(pszParam, _T("noninteractive")))
+ {
+ // -noninteractive to suppress message boxes & close with result code
+ m_CmdLineInfo.m_bNonInteractive = true;
+ }
+ else if (!lstrcmpi(pszParam, _T("noprefs")))
+ {
+ // -noprefs means do not load or remember options (preferences)
+ m_CmdLineInfo.m_bNoPrefs = true;
+ }
+ else if (!lstrcmpi(pszParam, _T("minimize")))
+ {
+ // -minimize means minimize the main window.
+ m_CmdLineInfo.m_nCmdShow = SW_MINIMIZE;
+ }
+ else if (!lstrcmpi(pszParam, _T("maximize")))
+ {
+ // -maximize means maximize the main window.
+ m_CmdLineInfo.m_nCmdShow = SW_MAXIMIZE;
+ }
+ else if (!lstrcmpi(pszParam, _T("prediffer")))
+ {
+ // Get prediffer if specified (otherwise prediffer will be blank, which is default)
+ m_bPreDiff = true;
+ }
+ else if (!lstrcmpi(pszParam, _T("wl")))
+ {
+ // -wl to open left path as read-only
+ m_CmdLineInfo.m_dwLeftFlags |= FFILEOPEN_READONLY;
+ }
+ else if (!lstrcmpi(pszParam, _T("wr")))
+ {
+ // -wr to open right path as read-only
+ m_CmdLineInfo.m_dwRightFlags |= FFILEOPEN_READONLY;
+ }
+ else if (!lstrcmpi(pszParam, _T("ul")))
+ {
+ // -ul to not add left path to MRU
+ m_CmdLineInfo.m_dwLeftFlags |= FFILEOPEN_NOMRU;
+ }
+ else if (!lstrcmpi(pszParam, _T("ur")))
+ {
+ // -ur to not add right path to MRU
+ m_CmdLineInfo.m_dwRightFlags |= FFILEOPEN_NOMRU;
+ }
+ else if (!lstrcmpi(pszParam, _T("ub")))
+ {
+ // -ub to add neither right nor left path to MRU
+ m_CmdLineInfo.m_dwLeftFlags |= FFILEOPEN_NOMRU;
+ m_CmdLineInfo.m_dwRightFlags |= FFILEOPEN_NOMRU;
+ }
+ else if (!lstrcmpi(pszParam, _T("x")))
+ {
+ // -x to close application if files are identical.
+ m_CmdLineInfo.m_bExitIfNoDiff = true;
+ }
+ else
+ {
+ CString sParam = pszParam;
+ CString sValue;
+
+ int nPos = sParam.ReverseFind(_T(':'));
+ if (nPos >= 0)
+ {
+ sParam = sParam.Left(nPos);
+ sValue = sParam.Mid(nPos + 1);
+ }
+ else
+ {
+ // Treat "/ignorews" as "/ignorews:1".
+ sValue = _T("1");
+ }
+
+ m_CmdLineInfo.m_Settings[sParam] = sValue;
+ }
+ }
+ else
+ {
+ if ((m_bPreDiff == true) && m_CmdLineInfo.m_sPreDiffer.IsEmpty())
+ {
+ m_CmdLineInfo.m_sPreDiffer = pszParam;
+ }
+ else if ((m_bFileFilter == true) && m_CmdLineInfo.m_sFileFilter.IsEmpty())
+ {
+ m_CmdLineInfo.m_sFileFilter = pszParam;
+ }
+ else if ((m_bRightDesc == true) && m_CmdLineInfo.m_sRightDesc.IsEmpty())
+ {
+ m_CmdLineInfo.m_sRightDesc = pszParam;
+ }
+ else if ((m_bLeftDesc == true) && m_CmdLineInfo.m_sLeftDesc.IsEmpty())
+ {
+ m_CmdLineInfo.m_sLeftDesc = pszParam;
+ }
+ else
+ {
+ CString sFile = paths_GetLongPath(pszParam);
+ m_CmdLineInfo.m_Files.SetAtGrow(m_CmdLineInfo.m_nFiles, sFile);
+ m_CmdLineInfo.m_nFiles += 1;
+ }
+ }
+
+ if (TRUE == bLast)
+ {
+ // If "compare file dir" make it "compare file dir\file".
+ if (m_CmdLineInfo.m_nFiles >= 2)
+ {
+ PATH_EXISTENCE p1 = paths_DoesPathExist(m_CmdLineInfo.m_Files[0]);
+ PATH_EXISTENCE p2 = paths_DoesPathExist(m_CmdLineInfo.m_Files[1]);
+
+ if ((p1 == IS_EXISTING_FILE) && (p2 == IS_EXISTING_DIR))
+ {
+ TCHAR fname[_MAX_PATH];
+ TCHAR fext[_MAX_PATH];
+
+ _tsplitpath(m_CmdLineInfo.m_Files[0], NULL, NULL, fname, fext);
+
+ if (m_CmdLineInfo.m_Files[1].Right(1) != _T('\\'))
+ {
+ m_CmdLineInfo.m_Files[1] += _T('\\');
+ }
+
+ m_CmdLineInfo.m_Files[1] = m_CmdLineInfo.m_Files[1] + fname + fext;
+ }
+ }
+
+ if (m_CmdLineInfo.m_bShowUsage)
+ {
+ m_CmdLineInfo.m_bNonInteractive = false;
+ }
+ }
+}
Added: trunk/Src/WinMergeCmdLineParser.h
===================================================================
--- trunk/Src/WinMergeCmdLineParser.h (rev 0)
+++ trunk/Src/WinMergeCmdLineParser.h 2006-11-17 14:27:57 UTC (rev 3812)
@@ -0,0 +1,56 @@
+/////////////////////////////////////////////////////////////////////////////
+//
+// WinMerge: An interactive diff/merge utility
+// Copyright (C) 1997 Dean P. Grimm
+//
+// 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.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+//
+/////////////////////////////////////////////////////////////////////////////
+
+/**
+* @file WinMergeCmdLineParser.h
+*
+* @brief WinMergeCmdLineParser class decleration.
+*
+*/
+
+// RCS ID line follows -- this is updated by CVS
+// $Id: WinMergeCmdLineParser.h $
+
+#pragma once
+
+#include "CmdLineParser.h"
+
+/**
+* @brief WinMerge's default command line parser.
+*
+*/
+class WinMergeCmdLineParser : public CmdLineParser
+{
+ public:
+
+ WinMergeCmdLineParser(MergeCmdLineInfo& CmdLineInfo);
+
+ virtual ~WinMergeCmdLineParser() { }
+
+ virtual void ParseParam(const TCHAR* pszParam, BOOL bFlag, BOOL bLast);
+
+ private:
+
+ bool m_bPreDiff;
+ bool m_bFileFilter;
+ bool m_bLeftDesc;
+ bool m_bRightDesc;
+};
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|