Changeset 17093 in vbox for trunk/src/VBox/Runtime/common/misc
- Timestamp:
- Feb 24, 2009 7:58:09 PM (16 years ago)
- svn:sync-xref-src-repo-rev:
- 43323
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/common/misc/getopt.cpp
r17088 r17093 40 40 41 41 42 RTDECL(int) RTGetOpt(int argc, char **argv, PCRTOPTIONDEF paOptions, size_t cOptions, int *piThis, PRTOPTIONUNION pValueUnion) 42 RTDECL(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 58 RTDECL(int) RTGetOpt(PRTGETOPTSTATE pState, PRTGETOPTUNION pValueUnion) 43 59 { 44 60 pValueUnion->u64 = 0; 45 61 pValueUnion->pDef = NULL; 46 62 47 if ( !piThis 48 || *piThis >= argc 49 ) 63 if (pState->iNext >= pState->argc) 50 64 return 0; 51 65 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; 54 70 55 71 for (size_t i = 0; i < cOptions; i++) … … 57 73 Assert(!(paOptions[i].fFlags & ~RTGETOPT_VALID_MASK)); 58 74 Assert(paOptions[i].iShort > 0); 75 Assert(paOptions[i].iShort != VINF_GETOPT_NOT_OPTION); 59 76 60 77 bool fShort = *pszArgThis == '-' 61 && (uint32_t)pszArgThis[1] == paOptions[i].iShort;78 && pszArgThis[1] == paOptions[i].iShort; 62 79 63 80 if ((paOptions[i].fFlags & RTGETOPT_REQ_MASK) != RTGETOPT_REQ_NOTHING) … … 91 108 : pszArgThis[cchLong] == '\0' || pszArgThis[cchLong + 1] == '\0') 92 109 { 93 if (iThis + 1 >= argc)110 if (iThis + 1 >= pState->argc) 94 111 return VERR_GETOPT_REQUIRED_ARGUMENT_MISSING; 95 pszValue = argv[iThis + 1];96 (*piThis)++;112 pszValue = pState->argv[iThis + 1]; 113 pState->iNext++; 97 114 } 98 115 else /* same argument. */ … … 196 213 return VERR_GETOPT_UNKNOWN_OPTION; 197 214 215 /** @todo Handle '--' and possibly implement an RTGetOptInit that lets us 216 * optionally sort the stuff and set other policeis sorts the result. */ 217 198 218 /* 199 219 * Not an option. 200 220 */ 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; 206 223 } 207 224
Note:
See TracChangeset
for help on using the changeset viewer.