VirtualBox

Changeset 51655 in vbox


Ignore:
Timestamp:
Jun 18, 2014 8:36:51 PM (11 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
94419
Message:

crOpenGL: move parse int tooling to util

Location:
trunk/src/VBox
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/GuestHost/OpenGL/include/cr_string.h

    r48348 r51655  
    99
    1010#include <iprt/cdefs.h>
     11#include <iprt/types.h>
    1112
    1213RT_C_DECLS_BEGIN
     
    6162
    6263DECLEXPORT(int) crStrParseGlVersion(const char * ver);
     64DECLEXPORT(int32_t) crStrParseI32(const char *pszStr, const int32_t defaultVal);
    6365RT_C_DECLS_END
    6466
  • trunk/src/VBox/GuestHost/OpenGL/util/string.c

    r48348 r51655  
    532532    return iVer;
    533533}
     534
     535int32_t crStrParseI32(const char *pszStr, const int32_t defaultVal)
     536{
     537    int32_t result = 0;
     538    bool neg = false;
     539    unsigned char iDigit = 0;
     540    if (!pszStr || pszStr[0] == '\0')
     541        return defaultVal;
     542
     543    for (;;)
     544    {
     545        if (pszStr[0] == '\0')
     546            return defaultVal;
     547
     548        if (pszStr[0] == ' ' || pszStr[0] == '\t' || pszStr[0] == '\n')
     549        {
     550            ++pszStr;
     551            continue;
     552        }
     553
     554        if (pszStr[0] == '-')
     555        {
     556            if (neg)
     557                return defaultVal;
     558
     559            neg = true;
     560            ++pszStr;
     561            continue;
     562        }
     563
     564        break;
     565    }
     566
     567    for (;;)
     568    {
     569        unsigned char digit;
     570        if (pszStr[0] == '\0')
     571        {
     572            if (!iDigit)
     573                return defaultVal;
     574            break;
     575        }
     576
     577        digit = pszStr[0] - '0';
     578        if (digit > 9)
     579            return defaultVal;
     580
     581        result *= 10;
     582        result += digit;
     583        ++iDigit;
     584
     585        ++pszStr;
     586    }
     587
     588    return !neg ? result : -result;
     589}
  • trunk/src/VBox/HostServices/SharedOpenGL/crserverlib/server.h

    r51356 r51655  
    371371
    372372void crServerInitTmpCtxDispatch();
    373 
    374 int crServerVBoxParseNumerics(const char *pszStr, const int defaultVal);
    375373
    376374typedef struct CR_FBMAP
  • trunk/src/VBox/HostServices/SharedOpenGL/crserverlib/server_config.c

    r51201 r51655  
    5656
    5757    cr_server.pfnNotifyEventCB = NULL;
    58 }
    59 
    60 int crServerVBoxParseNumerics(const char *pszStr, const int defaultVal)
    61 {
    62     int result = 0;
    63     bool neg = false;
    64     unsigned char iDigit = 0;
    65     if (!pszStr || pszStr[0] == '\0')
    66         return defaultVal;
    67 
    68     for (;;)
    69     {
    70         if (pszStr[0] == '\0')
    71             return defaultVal;
    72 
    73         if (pszStr[0] == ' ' || pszStr[0] == '\t' || pszStr[0] == '\n')
    74         {
    75             ++pszStr;
    76             continue;
    77         }
    78 
    79         if (pszStr[0] == '-')
    80         {
    81             if (neg)
    82                 return defaultVal;
    83 
    84             neg = true;
    85             ++pszStr;
    86             continue;
    87         }
    88 
    89         break;
    90     }
    91 
    92     for (;;)
    93     {
    94         unsigned char digit;
    95         if (pszStr[0] == '\0')
    96         {
    97             if (!iDigit)
    98                 return defaultVal;
    99             break;
    100         }
    101 
    102         digit = pszStr[0] - '0';
    103         if (digit > 9)
    104             return defaultVal;
    105 
    106         result *= 10;
    107         result += digit;
    108         ++iDigit;
    109 
    110         ++pszStr;
    111     }
    112 
    113     return !neg ? result : -result;
    11458}
    11559
     
    213157    if (env != NULL && env[0] != '\0')
    214158    {
    215         unsigned int bits = (unsigned int)crServerVBoxParseNumerics(env, 0);
     159        unsigned int bits = (unsigned int)crStrParseI32(env, 0);
    216160        if (bits <= CR_ALL_BITS)
    217161            cr_server.fVisualBitsDefault = bits;
     
    225169    if (env && env[0] != '\0')
    226170    {
    227         cr_server.u32Caps = crServerVBoxParseNumerics(env, 0);
     171        cr_server.u32Caps = crStrParseI32(env, 0);
    228172        cr_server.u32Caps &= CR_VBOX_CAPS_ALL;
    229173    }
     
    363307    if (env != NULL && env[0] != '\0')
    364308    {
    365         unsigned int bits = (unsigned int)crServerVBoxParseNumerics(env, 0);
     309        unsigned int bits = (unsigned int)crStrParseI32(env, 0);
    366310        if (bits <= CR_ALL_BITS)
    367311            cr_server.fVisualBitsDefault = bits;
     
    375319    if (env && env[0] != '\0')
    376320    {
    377         cr_server.u32Caps = crServerVBoxParseNumerics(env, 0);
     321        cr_server.u32Caps = crStrParseI32(env, 0);
    378322        cr_server.u32Caps &= CR_VBOX_CAPS_ALL;
    379323    }
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette