Changeset 24140 in vbox
- Timestamp:
- Oct 28, 2009 2:29:34 PM (15 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/iprt/getopt.h
r23868 r24140 84 84 /** The value must be a valid UUID. */ 85 85 #define RTGETOPT_REQ_UUID 15 86 /** The value must be a string with value as "on" or "off". */ 87 #define RTGETOPT_REQ_BOOL_ONOFF 16 86 88 /** The mask of the valid required types. */ 87 #define RTGETOPT_REQ_MASK 1589 #define RTGETOPT_REQ_MASK 31 88 90 /** Treat the value as hexadecimal - only applicable with the RTGETOPT_REQ_*INT*. */ 89 91 #define RTGETOPT_FLAG_HEX RT_BIT(16) … … 172 174 /** An unsigned integer value. */ 173 175 uint64_t u; 176 /** A boolean flag. */ 177 bool f; 174 178 } RTGETOPTUNION; 175 179 /** Pointer to an option argument union. */ -
trunk/src/VBox/Runtime/common/misc/getopt.cpp
r23868 r24140 280 280 case RTGETOPT_REQ_STRING: 281 281 pValueUnion->psz = pszValue; 282 break; 283 284 case RTGETOPT_REQ_BOOL_ONOFF: 285 if (!RTStrICmp(pszValue, "on")) 286 pValueUnion->f = true; 287 else if (!RTStrICmp(pszValue, "off")) 288 pValueUnion->f = false; 289 else 290 { 291 pValueUnion->psz = pszValue; 292 return VERR_GETOPT_UNKNOWN_OPTION; 293 } 282 294 break; 283 295 -
trunk/src/VBox/Runtime/testcase/tstGetOpt.cpp
r23868 r24140 97 97 { "--twovaluesindex", 406, RTGETOPT_REQ_UINT32 | RTGETOPT_FLAG_INDEX }, 98 98 { "--threevalues", 407, RTGETOPT_REQ_UINT32 }, 99 { "--boolean", 408, RTGETOPT_REQ_BOOL_ONOFF }, 100 { "--booleanindex", 409, RTGETOPT_REQ_BOOL_ONOFF | RTGETOPT_FLAG_INDEX }, 99 101 }; 100 102 … … 154 156 "--twovaluesindex5=2", "0xB", 155 157 "--threevalues", "1", "0xC", "thirdvalue", 158 159 "--boolean", "on", 160 "--boolean", "off", 161 "--boolean", "invalid", 162 "--booleanindex2", "on", 163 "--booleanindex7", "off", 164 "--booleanindex9", "invalid", 156 165 157 166 NULL … … 333 342 CHECK(GetState.uIndex == UINT64_MAX); 334 343 344 /* bool on/off tests */ 345 CHECK_GETOPT(RTGetOpt(&GetState, &Val), 408, 2); 346 CHECK(Val.f); 347 CHECK_GETOPT(RTGetOpt(&GetState, &Val), 408, 2); 348 CHECK(!Val.f); 349 CHECK_GETOPT(RTGetOpt(&GetState, &Val), VERR_GETOPT_UNKNOWN_OPTION, 2); 350 CHECK(VALID_PTR(Val.psz) && !strcmp(Val.psz, "invalid")); 351 352 /* bool on/off with indexed argument */ 353 CHECK_GETOPT(RTGetOpt(&GetState, &Val), 409, 2); 354 CHECK(Val.f); 355 CHECK(GetState.uIndex == 2); 356 CHECK_GETOPT(RTGetOpt(&GetState, &Val), 409, 2); 357 CHECK(!Val.f); 358 CHECK(GetState.uIndex == 7); 359 CHECK_GETOPT(RTGetOpt(&GetState, &Val), VERR_GETOPT_UNKNOWN_OPTION, 2); 360 CHECK(VALID_PTR(Val.psz) && !strcmp(Val.psz, "invalid")); 361 335 362 /* the end */ 336 363 CHECK_GETOPT(RTGetOpt(&GetState, &Val), 0, 0);
Note:
See TracChangeset
for help on using the changeset viewer.