strversion.cpp revision c7814cf6e1240a519cbec0441e033d0e2470ed00
/* $Id$ */
/** @file
* IPRT - Version String Parsing.
*/
/*
* Copyright (C) 2009-2010 Oracle Corporation
*
* 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.
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
/*******************************************************************************
* Defined Constants And Macros *
*******************************************************************************/
#define RTSTRVER_IS_PUNCTUACTION(ch) \
/**
* Parses a out the next block from a version string.
*
* @returns true if numeric, false if not.
* @param pi32Value Where to return the value if numeric.
* @param pcchBlock Where to return the block length.
*/
{
/*
* Check for end-of-string.
*/
if (!*psz)
{
*pi32Value = 0;
*pcchBlock = 0;
return false;
}
/*
* Try convert the block to a number the simple way.
*/
char ch;
if (fNumeric)
{
do
{
fNumeric = false;
*pi32Value = 0;
}
}
else
{
/*
* Find the end of the current string. Make a special case for SVN
* revision numbers that immediately follows a release tag string.
*/
do
while ( ch
&& !RT_C_IS_DIGIT(ch)
&& !RTSTRVER_IS_PUNCTUACTION(ch));
if ( cchBlock > 1
&& RT_C_IS_DIGIT(*psz))
{
psz--;
cchBlock--;
}
/*
* Translate standard pre release terms to negative values.
*/
static const struct
{
const char *psz;
} s_aTerms[] =
{
{ 2, "RC", -100000 },
{ 3, "PRE", -200000 },
{ 5, "GAMMA", -300000 },
{ 4, "BETA", -400000 },
{ 5, "ALPHA", -500000 }
};
for (unsigned i = 0; i < RT_ELEMENTS(s_aTerms); i++)
{
break;
}
if (iVal1 != 0)
{
/*
* Does the prelease term have a trailing number?
* Add it assuming BETA == BETA1.
*/
if (RT_C_IS_DIGIT(*psz))
{
do
while ( ch
&& RT_C_IS_DIGIT(ch)
&& !RTSTRVER_IS_PUNCTUACTION(ch));
else
{
}
}
fNumeric = true;
}
}
/*
* Skip trailing punctuation.
*/
if (RTSTRVER_IS_PUNCTUACTION(*psz))
psz++;
return fNumeric;
}
{
/*
* Do a parallel parse of the strings.
*/
{
{
}
&& ( fNumeric1
)
{
/*else: 1.0 == 1.0.0.0.0. */;
}
{
/* Pre-release indicators are smaller than all other strings. */
}
else
{
if (iDiff)
}
}
return 0;
}