getoptargv.cpp revision 3bc27bc2604e7013a71c8a93bb64bc6d9e5f234b
/* $Id$ */
/** @file
* IPRT - Command Line Parsing, Argument Vector.
*/
/*
* Copyright (C) 2010 Sun Microsystems, Inc.
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*
* The contents of this file may alternatively be used under the terms
* of the Common Development and Distribution License Version 1.0
* (CDDL) only, as it comes in the "COPYING.CDDL" file of the
* VirtualBox OSE distribution, in which case the provisions of the
* CDDL are applicable instead of those of the GPL.
*
* You may elect to license modified versions of this file under the
* terms and conditions of either the GPL or the CDDL or both.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
* Clara, CA 95054 USA or visit http://www.sun.com if you need
* additional information or have any questions.
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
/**
* Look for an unicode code point in the separator string.
*
* @returns true if it's a separator, false if it isn't.
* @param Cp The code point.
* @param pszSeparators The separators.
*/
{
/* This could be done in a more optimal fashion. Probably worth a
separate RTStr function at some point. */
for (;;)
{
AssertRCReturn(rc, false);
return true;
if (!CpSep)
return false;
}
}
/**
* Look for an 7-bit ASCII character in the separator string.
*
* @returns true if it's a separator, false if it isn't.
* @param ch The character.
* @param pszSeparators The separators.
* @param cchSeparators The number of separators chars.
*/
{
switch (cchSeparators)
{
return false;
default:
}
}
/**
* Checks if the character is in the set of separators
*
* @returns true if it is, false if it isn't.
*
* @param Cp The code point.
* @param pszSeparators The separators.
* @param cchSeparators The length of @a pszSeparators.
*/
DECL_FORCE_INLINE(bool) rtGetOptIsCpInSet(RTUNICP Cp, const char *pszSeparators, size_t cchSeparators)
{
}
/**
* Skips any delimiters at the start of the string that is pointed to.
*
* @returns VINF_SUCCESS or RTStrGetCpEx status code.
* @param ppszSrc Where to get and return the string pointer.
* @param pszSeparators The separators.
* @param cchSeparators The length of @a pszSeparators.
*/
static int rtGetOptSkipDelimiters(const char **ppszSrc, const char *pszSeparators, size_t cchSeparators)
{
const char *pszRet;
for (;;)
{
if (RT_FAILURE(rc))
{
return rc;
}
if ( !Cp
break;
}
return VINF_SUCCESS;
}
RTDECL(int) RTGetOptArgvFromString(char ***ppapszArgv, int *pcArgs, const char *pszCmdLine, const char *pszSeparators)
{
/*
* Some input validation.
*/
if (!pszSeparators)
pszSeparators = " \t\n\r";
else
/*
* Parse the command line and chop off it into argv individual argv strings.
*/
int rc = VINF_SUCCESS;
const char *pszSrc = pszCmdLine;
if (!pszDup)
return VERR_NO_STR_MEMORY;
unsigned iArg = 0;
while (*pszSrc)
{
/* Skip stuff */
if (RT_FAILURE(rc))
break;
if (!*pszSrc)
break;
/* Start a new entry. */
if ((iArg % 32) == 0)
{
if (!pvNew)
{
rc = VERR_NO_MEMORY;
break;
}
}
/* Parse and copy the string over. */
for (;;)
{
break;
if (!CpQuote)
{
break;
else
}
else
CpQuote = 0;
}
*pszDst++ = '\0';
break;
}
if (RT_FAILURE(rc))
{
return rc;
}
/*
* Terminate the array.
* Check for empty string to make sure we've got an array.
*/
if (iArg == 0)
{
if (!papszArgs)
return VERR_NO_MEMORY;
}
*ppapszArgv = papszArgs;
return VINF_SUCCESS;
}
{
if (papszArgv)
{
}
}
/** @todo RTGetOptArgvToString (for windows)?
* RTGetOptArgvSort for RTGetOptInit()? */