|
// ==========================================================================
// Class Implementation : COXCommandLine
// ==========================================================================
// Source file : OXCmdLne.cpp
// This software along with its related components, documentation and files ("The Libraries")
// is � 1994-2007 The Code Project (1612916 Ontario Limited) and use of The Libraries is
// governed by a software license agreement ("Agreement"). Copies of the Agreement are
// available at The Code Project (www.codeproject.com), as part of the package you downloaded
// to obtain this file, or directly from our office. For a copy of the license governing
// this software, you may contact us at legalaffairs@codeproject.com, or by calling 416-849-8900.
// //////////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include <string.h>
#include "OXCmdLne.h"
#ifdef _DEBUG
#undef THIS_FILE
static char BASED_CODE THIS_FILE[] = __FILE__;
#endif
IMPLEMENT_DYNAMIC(COXCommandLine, CObject)
#define new DEBUG_NEW
void COXCommandLine::Tokenize(LPTSTR pszCmdLine)
{
LPTSTR delimiters = _T(" =\r\n");
CString token;
LPCTSTR curTok = _tcstok(pszCmdLine, delimiters);
while (curTok != NULL)
{
if (*curTok == _T('\'') || *curTok == _T('"'))
{
TCHAR quote[2];
*quote = *curTok;
quote[1] = 0;
LPTSTR pLastToken = _tcsrchr(curTok, quote[0]);
if (pLastToken != curTok)
{
*pLastToken = '\0';
token = (curTok + 1);
curTok = token;
}
else
{
token = (curTok + 1);
token += _T(" ");
curTok = _tcstok(NULL, quote);
token += curTok;
curTok = token;
}
}
m_Tokens.Add(curTok);
m_NumTokens++;
curTok = _tcstok(NULL, delimiters);
}
// A sentinel
m_Tokens.Add(_T("|"));
}
COXCommandLine::COXCommandLine(LPCSTR psczCmdLine)
{
CString sCmdLine(psczCmdLine);
m_Tokens.RemoveAll();
m_NumTokens = 0;
Tokenize(sCmdLine.GetBuffer(0));
sCmdLine.ReleaseBuffer();
}
#ifdef WIN32
COXCommandLine::COXCommandLine(LPCWSTR psczCmdLine)
{
CString sCmdLine(psczCmdLine);
m_Tokens.RemoveAll();
m_NumTokens = 0;
Tokenize(sCmdLine.GetBuffer(0));
sCmdLine.ReleaseBuffer();
}
#endif
COXCommandLine::COXCommandLine(CStdioFile* pInfile)
{
m_Tokens.RemoveAll();
m_NumTokens = 0;
TCHAR ReadLine[256];
while (pInfile->ReadString(ReadLine, 256) != NULL)
Tokenize(ReadLine);
}
COXCommandLine::~COXCommandLine()
{
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
In January 2005, David Cunningham and Chris Maunder created TheUltimateToolbox.com, a new group dedicated to the continued development, support and growth of Dundas Software’s award winning line of MFC, C++ and ActiveX control products.
Ultimate Grid for MFC, Ultimate Toolbox for MFC, and Ultimate TCP/IP have been stalwarts of C++/MFC development for a decade. Thousands of developers have used these products to speed their time to market, improve the quality of their finished products, and enhance the reliability and flexibility of their software.