Changeset 17141 in vbox for trunk/src/VBox/Runtime/common
- Timestamp:
- Feb 25, 2009 5:09:22 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/common/misc/getopt.cpp
r17101 r17141 46 46 AssertReturn(!fFlags, VERR_INVALID_PARAMETER); 47 47 48 pState->argv = argv; 49 pState->argc = argc; 50 pState->paOptions = paOptions; 51 pState->cOptions = cOptions; 52 pState->iNext = iFirst; 48 pState->argv = argv; 49 pState->argc = argc; 50 pState->paOptions = paOptions; 51 pState->cOptions = cOptions; 52 pState->iNext = iFirst; 53 pState->pszNextShort = NULL; 53 54 54 55 /* validate the options. */ … … 127 128 RTDECL(int) RTGetOpt(PRTGETOPTSTATE pState, PRTGETOPTUNION pValueUnion) 128 129 { 130 /* 131 * Make sure the union is completely cleared out, whatever happens below. 132 */ 129 133 pValueUnion->u64 = 0; 130 134 pValueUnion->pDef = NULL; 131 135 132 if (pState->iNext >= pState->argc) 133 return 0; 136 /* 137 * The next option. 138 */ 139 bool fShort; 140 int iThis; 141 const char *pszArgThis; 142 PCRTGETOPTDEF pOpt; 143 144 if (pState->pszNextShort) 145 { 146 /* 147 * We've got short options left over from the previous call. 148 */ 149 pOpt = rtGetOptSearchShort(*pState->pszNextShort, pState->paOptions, pState->cOptions); 150 if (!pOpt) 151 { 152 pValueUnion->psz = pState->pszNextShort; 153 return VERR_GETOPT_UNKNOWN_OPTION; 154 } 155 pState->pszNextShort++; 156 pszArgThis = pState->pszNextShort - 2; 157 iThis = pState->iNext; 158 fShort = true; 159 } 160 else 161 { 162 /* 163 * Pop off the next argument. 164 */ 165 if (pState->iNext >= pState->argc) 166 return 0; 167 iThis = pState->iNext++; 168 pszArgThis = pState->argv[iThis]; 169 170 /* 171 * Do a long option search first and the a short option one. 172 * This way we can make sure single dash long options doesn't 173 * get mixed up with short ones. 174 */ 175 pOpt = rtGetOptSearchLong(pszArgThis, pState->paOptions, pState->cOptions); 176 if ( !pOpt 177 && pszArgThis[0] == '-' 178 && pszArgThis[1] != '-' 179 && pszArgThis[1] != '\0') 180 { 181 pOpt = rtGetOptSearchShort(pszArgThis[1], pState->paOptions, pState->cOptions); 182 fShort = pOpt != NULL; 183 } 184 else 185 fShort = false; 186 } 187 134 188 135 189 /** @todo Handle '--' and possibly implement an RTGetOptInit that lets us … … 140 194 */ 141 195 142 /*143 * Pop off the next argument.144 */145 int iThis = pState->iNext++;146 const char *pszArgThis = pState->argv[iThis];147 148 /*149 * Do a long option search first and the a short option one.150 * This way we can make sure single dash long options doesn't151 * get mixed up with short ones.152 */153 bool fShort = false;154 PCRTGETOPTDEF pOpt = rtGetOptSearchLong(pszArgThis, pState->paOptions, pState->cOptions);155 if ( !pOpt156 && pszArgThis[0] == '-'157 && pszArgThis[1] != '-'158 && pszArgThis[1] != '\0')159 {160 pOpt = rtGetOptSearchShort(pszArgThis[1], pState->paOptions, pState->cOptions);161 fShort = pOpt != NULL;162 }163 196 if (pOpt) 164 197 { … … 191 224 else /* same argument. */ 192 225 pszValue = &pszArgThis[2 + (pszArgThis[2] == ':' || pszArgThis[2] == '=')]; 226 if (pState->pszNextShort) 227 { 228 pState->pszNextShort = NULL; 229 pState->iNext++; 230 } 193 231 } 194 232 else … … 285 323 } 286 324 } 325 else if (fShort) 326 { 327 /* 328 * Deal with "compressed" short option lists, correcting the next 329 * state variables for the start and end cases. 330 */ 331 if (pszArgThis[2]) 332 { 333 if (!pState->pszNextShort) 334 { 335 /* start */ 336 pState->pszNextShort = &pszArgThis[2]; 337 pState->iNext--; 338 } 339 } 340 else if (pState->pszNextShort) 341 { 342 /* end */ 343 pState->pszNextShort = NULL; 344 pState->iNext++; 345 } 346 } 347 287 348 return pOpt->iShort; 288 349 } … … 294 355 295 356 if (*pszArgThis == '-') 357 { 358 pValueUnion->psz = pszArgThis; 296 359 return VERR_GETOPT_UNKNOWN_OPTION; 360 } 297 361 298 362 pValueUnion->psz = pszArgThis;
Note:
See TracChangeset
for help on using the changeset viewer.