Changeset 68936 in vbox for trunk/src/VBox/Runtime/common/misc/getopt.cpp
- Timestamp:
- Sep 29, 2017 4:11:06 PM (8 years ago)
- svn:sync-xref-src-repo-rev:
- 118203
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/common/misc/getopt.cpp
r64602 r68936 254 254 * generic ints as octals. 255 255 */ 256 switch (fFlags & ( RTGETOPT_REQ_MASK 257 | RTGETOPT_FLAG_HEX 258 | RTGETOPT_FLAG_DEC 259 | RTGETOPT_FLAG_OCT)) 256 uint32_t const fSwitchValue = fFlags & ( RTGETOPT_REQ_MASK 257 | RTGETOPT_FLAG_HEX 258 | RTGETOPT_FLAG_DEC 259 | RTGETOPT_FLAG_OCT); 260 switch (fSwitchValue) 260 261 { 261 262 case RTGETOPT_REQ_STRING: … … 407 408 } 408 409 410 #define MY_INT_PAIR_CASE(a_fReqValue, a_fReqValueOptional, a_Type, a_MemberPrefix, a_fnConv, a_ConvBase, a_DefaultValue) \ 411 case a_fReqValue: \ 412 case a_fReqValueOptional: \ 413 { \ 414 /* First value: */ \ 415 a_Type Value1; \ 416 char *pszNext = NULL; \ 417 unsigned uBase = pszValue[0] == '0' \ 418 && (pszValue[1] == 'x' || pszValue[1] == 'X') \ 419 && RT_C_IS_XDIGIT(pszValue[2]) \ 420 ? 16 : a_ConvBase; \ 421 int rc = a_fnConv(pszValue, &pszNext, uBase, &Value1); \ 422 if (rc == VINF_SUCCESS || rc == VWRN_TRAILING_CHARS || rc == VWRN_TRAILING_SPACES) \ 423 { \ 424 /* The second value, could be optional: */ \ 425 a_Type Value2 = a_DefaultValue; \ 426 pszValue = pszNext;\ 427 if (pszValue) \ 428 { \ 429 while (RT_C_IS_BLANK(*pszValue)) \ 430 pszValue++; \ 431 if (*pszValue == ':' || *pszValue == '/' || *pszValue == '|') \ 432 do pszValue++; \ 433 while (RT_C_IS_BLANK(*pszValue)); \ 434 if (pszValue != pszNext) \ 435 { \ 436 unsigned uBase = pszValue[0] == '0' \ 437 && (pszValue[1] == 'x' || pszValue[1] == 'X') \ 438 && RT_C_IS_XDIGIT(pszValue[2]) \ 439 ? 16 : a_ConvBase; \ 440 rc = a_fnConv(pszValue, &pszNext, uBase, &Value2); \ 441 if (rc == VINF_SUCCESS) \ 442 { /* likely */ } \ 443 else \ 444 { RTAssertMsg2("z rc=%Rrc: '%s' '%s' uBase=%d\n", rc, pszValue, pszNext, uBase); return VERR_GETOPT_INVALID_ARGUMENT_FORMAT; } \ 445 } \ 446 else if (fSwitchValue != (a_fReqValueOptional)) \ 447 { RTAssertMsg2("x\n"); return VERR_GETOPT_INVALID_ARGUMENT_FORMAT; } \ 448 } \ 449 else if (fSwitchValue != (a_fReqValueOptional)) \ 450 { RTAssertMsg2("y\n"); return VERR_GETOPT_INVALID_ARGUMENT_FORMAT; } \ 451 pValueUnion->a_MemberPrefix##Second = Value2; \ 452 pValueUnion->a_MemberPrefix##First = Value1; \ 453 break; \ 454 } \ 455 return VERR_GETOPT_INVALID_ARGUMENT_FORMAT; \ 456 } 457 458 MY_INT_PAIR_CASE(RTGETOPT_REQ_UINT32_PAIR, RTGETOPT_REQ_UINT32_OPTIONAL_PAIR, 459 uint32_t, PairU32.u, RTStrToUInt32Ex, 10, UINT32_MAX) 460 MY_INT_PAIR_CASE(RTGETOPT_REQ_UINT32_PAIR | RTGETOPT_FLAG_DEC, RTGETOPT_REQ_UINT32_OPTIONAL_PAIR | RTGETOPT_FLAG_DEC, 461 uint32_t, PairU32.u, RTStrToUInt32Ex, 10, UINT32_MAX) 462 MY_INT_PAIR_CASE(RTGETOPT_REQ_UINT32_PAIR | RTGETOPT_FLAG_HEX, RTGETOPT_REQ_UINT32_OPTIONAL_PAIR | RTGETOPT_FLAG_HEX, 463 uint32_t, PairU32.u, RTStrToUInt32Ex, 16, UINT32_MAX) 464 MY_INT_PAIR_CASE(RTGETOPT_REQ_UINT32_PAIR | RTGETOPT_FLAG_OCT, RTGETOPT_REQ_UINT32_OPTIONAL_PAIR | RTGETOPT_FLAG_OCT, 465 uint32_t, PairU32.u, RTStrToUInt32Ex, 8, UINT32_MAX) 466 467 MY_INT_PAIR_CASE(RTGETOPT_REQ_UINT64_PAIR, RTGETOPT_REQ_UINT64_OPTIONAL_PAIR, 468 uint64_t, PairU64.u, RTStrToUInt64Ex, 10, UINT64_MAX) 469 MY_INT_PAIR_CASE(RTGETOPT_REQ_UINT64_PAIR | RTGETOPT_FLAG_DEC, RTGETOPT_REQ_UINT64_OPTIONAL_PAIR | RTGETOPT_FLAG_DEC, 470 uint64_t, PairU64.u, RTStrToUInt64Ex, 10, UINT64_MAX) 471 MY_INT_PAIR_CASE(RTGETOPT_REQ_UINT64_PAIR | RTGETOPT_FLAG_HEX, RTGETOPT_REQ_UINT64_OPTIONAL_PAIR | RTGETOPT_FLAG_HEX, 472 uint64_t, PairU64.u, RTStrToUInt64Ex, 16, UINT64_MAX) 473 MY_INT_PAIR_CASE(RTGETOPT_REQ_UINT64_PAIR | RTGETOPT_FLAG_OCT, RTGETOPT_REQ_UINT64_OPTIONAL_PAIR | RTGETOPT_FLAG_OCT, 474 uint64_t, PairU64.u, RTStrToUInt64Ex, 8, UINT64_MAX) 475 409 476 default: 410 477 AssertMsgFailed(("f=%#x\n", fFlags));
Note:
See TracChangeset
for help on using the changeset viewer.