/*****************************************************************************/
/* SOURCE FILE */
/*****************************************************************************/
/*
$Archive: $
$Revision: $
$Date: $
$Author: $
Description: Implementation of a command line wrapper class
TOOL And XML FORMS License
==========================
Except where otherwise noted, all of the documentation
and software included in the TOOL package is
copyrighted by Michael Swartzendruber.
Copyright (C) 2005 Michael John Swartzendruber.
All rights reserved.
Access to this code, whether intentional or accidental,
does NOT IMPLY any transfer of rights.
This software is provided "as-is," without any express
or implied warranty. In no event shall the author be held
liable for any damages arising from the use of this software.
Permission is granted to anyone to use this software for
any purpose, including commercial applications, and to
alter and redistribute it, provided that the following
conditions are met:
1. All redistributions of source code files must retain
all copyright notices that are currently in place,
and this list of conditions without modification.
2. The origin of this software must not be misrepresented;
you must not claim that you wrote the original software.
3. If you use this software in another product, an acknowledgment
in the product documentation would be appreciated but is
not required.
4. Modified versions in source or binary form must be plainly
marked as such, and must not be misrepresented as being
the original software.
*/
static char OBJECT_ID[] = "$Revision: $ : $Date: $";
/*****************************************************************************/
#pragma warning( disable : 4786 ) // name too long warning from stl
#include "../../stdafx.h"
#include <assert.h>
#include <vector>
#include <string>
#include <string.h>
#include "VMCoreCmdLine.h"
/*****************************************************************************/
/*
FUNCTION NAME: VMCmdLine::VMCmdLine
DESCRIPTION: ctor. inits this
INPUT: psczCmdLine - pointer to a command line to be tokenized
OUTPUT: none
RETURNS: -
*/
VMCmdLine::VMCmdLine( const char** pchCmdLine, int iCount )
{
m_oTokens.clear();
m_iTokenCount = 0;
for( int iLoop = 0; iLoop < iCount; iLoop++ )
{
m_oCmdLine += pchCmdLine[iLoop];
if ( iLoop < iCount - 1 )
m_oCmdLine += ' ';
}
Tokenize( m_oCmdLine );
}
/* End of function "VMCmdLine::VMCmdLine"
/*****************************************************************************/
/*****************************************************************************/
/*
FUNCTION NAME: VMCmdLine::~VMCmdLine
DESCRIPTION: dtor.
INPUT: none
OUTPUT: none
RETURNS: none
*/
VMCmdLine::~VMCmdLine()
{
}
/* End of function "VMCmdLine::~VMCmdLine"
/*****************************************************************************/
/*****************************************************************************/
/*
FUNCTION NAME: VMCmdLine::Tokenize
DESCRIPTION: process the command line into its components
INPUT: roCmdLine - the entire command line to parse
OUTPUT: none
RETURNS: void -
*/
void VMCmdLine::Tokenize( std::string& roCmdLine )
{
char achDelimiters[] = { ' ', '\r', '\n', '\t', '=' };
std::string oTokens = roCmdLine;
std::string oTemp;
int iOffset = oTokens.find_first_of( achDelimiters, 0, sizeof( achDelimiters ) );
if ( -1 != iOffset )
oTemp = oTokens.substr( 0, iOffset );
while ( 0 < iOffset )
{
// strip quotes if any are there
//
if ( oTemp[0] == '\'' || oTemp[0] == '"' )
oTemp = oTemp.substr( 1, oTemp.length() );
if ( oTemp[ oTemp.length() ] == '\'' || oTemp[ oTemp.length() ] == '"' )
oTemp = oTemp.substr( 0, oTemp.length() - 1 );
m_oTokens.insert( m_oTokens.end(), oTemp );
m_iTokenCount++;
oTokens = oTokens.substr( iOffset + 1, oTokens.length() );
iOffset = oTokens.find_first_of( achDelimiters, 0, sizeof( achDelimiters ) );
if ( -1 != iOffset )
oTemp = oTokens.substr( 0, iOffset );
else
m_oTokens.insert( m_oTokens.end(), oTokens );
}
// A sentinel
oTemp = "|";
m_oTokens.insert( m_oTokens.end(), oTemp );
}
/* End of function "VMCmdLine::Tokenize"
/*****************************************************************************/
/*****************************************************************************/
/*
FUNCTION NAME: VMCmdLine::GetNumArgs
DESCRIPTION: Retrieve the number of command line arguments found
INPUT: none
OUTPUT: none
RETURNS: the number of arguments
*/
int VMCmdLine::GetNumArgs( void ) const
{
return m_iTokenCount;
}
/* End of function "VMCmdLine::GetNumArgs"
/*****************************************************************************/
/*****************************************************************************/
/*
FUNCTION NAME: operator[]
DESCRIPTION: fetch a specific item from the list
INPUT: iElementAt - the index of the element to fetch
OUTPUT: none
RETURNS: the string stored at that location
*/
std::string VMCmdLine::operator[] ( const int iElementAt ) const
{
assert( ( iElementAt >= 0 ) && ( iElementAt <= m_iTokenCount ) );
return m_oTokens[ iElementAt ];
}
/* End of function ""
/*****************************************************************************/
/*****************************************************************************/
/* Check-in history */
/*
*$Log: $
*/
/*****************************************************************************/