VirtualBox

Ignore:
Timestamp:
Feb 24, 2009 7:58:09 PM (16 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
43323
Message:

RTGetOpt interface changes.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/common/misc/getopt.cpp

    r17088 r17093  
    4040
    4141
    42 RTDECL(int) RTGetOpt(int argc, char **argv, PCRTOPTIONDEF paOptions, size_t cOptions, int *piThis, PRTOPTIONUNION pValueUnion)
     42RTDECL(int) RTGetOptInit(PRTGETOPTSTATE pState, int argc, char **argv,
     43                         PCRTGETOPTDEF paOptions, size_t cOptions,
     44                         int iFirst, uint32_t fFlags)
     45{
     46    AssertReturn(!fFlags, VERR_INVALID_PARAMETER);
     47
     48    pState->argv        = argv;
     49    pState->argc        = argc;
     50    pState->paOptions   = paOptions;
     51    pState->cOptions    = cOptions;
     52    pState->iNext       = iFirst;
     53
     54    return VINF_SUCCESS;
     55}
     56
     57
     58RTDECL(int) RTGetOpt(PRTGETOPTSTATE pState, PRTGETOPTUNION pValueUnion)
    4359{
    4460    pValueUnion->u64 = 0;
    4561    pValueUnion->pDef = NULL;
    4662
    47     if (    !piThis
    48          || *piThis >= argc
    49        )
     63    if (pState->iNext >= pState->argc)
    5064        return 0;
    5165
    52     int iThis = (*piThis)++;
    53     const char *pszArgThis = argv[iThis];
     66    int             iThis = pState->iNext++;
     67    const char     *pszArgThis = pState->argv[iThis];
     68    size_t const    cOptions  = pState->cOptions;
     69    PCRTGETOPTDEF   paOptions = pState->paOptions;
    5470
    5571    for (size_t i = 0; i < cOptions; i++)
     
    5773        Assert(!(paOptions[i].fFlags & ~RTGETOPT_VALID_MASK));
    5874        Assert(paOptions[i].iShort > 0);
     75        Assert(paOptions[i].iShort != VINF_GETOPT_NOT_OPTION);
    5976
    6077        bool fShort = *pszArgThis == '-'
    61                     && (uint32_t)pszArgThis[1] == paOptions[i].iShort;
     78                    && pszArgThis[1] == paOptions[i].iShort;
    6279
    6380        if ((paOptions[i].fFlags & RTGETOPT_REQ_MASK) != RTGETOPT_REQ_NOTHING)
     
    91108                    :   pszArgThis[cchLong] == '\0' || pszArgThis[cchLong + 1] == '\0')
    92109                {
    93                     if (iThis + 1 >= argc)
     110                    if (iThis + 1 >= pState->argc)
    94111                        return VERR_GETOPT_REQUIRED_ARGUMENT_MISSING;
    95                     pszValue = argv[iThis + 1];
    96                     (*piThis)++;
     112                    pszValue = pState->argv[iThis + 1];
     113                    pState->iNext++;
    97114                }
    98115                else /* same argument. */
     
    196213        return VERR_GETOPT_UNKNOWN_OPTION;
    197214
     215    /** @todo Handle '--' and possibly implement an RTGetOptInit that lets us
     216     *        optionally sort the stuff and set other policeis sorts the result.  */
     217
    198218    /*
    199219     * Not an option.
    200220     */
    201     (*piThis)--;
    202     /** @todo Sort options and arguments (i.e. stuff that doesn't start with '-'), stop when
    203      * encountering the first argument. */
    204 
    205     return 0;
     221    pValueUnion->psz = pszArgThis;
     222    return VINF_GETOPT_NOT_OPTION;
    206223}
    207224
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