- Timestamp:
- Nov 30, 2010 10:57:21 PM (14 years ago)
- Location:
- trunk/src/VBox/Runtime
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/common/misc/getopt.cpp
r33540 r34542 207 207 { 208 208 /* 209 * A value is required with the argument. We're trying to be very209 * A value is required with the argument. We're trying to be 210 210 * understanding here and will permit any of the following: 211 211 * --long12:value, --long12=value, --long12 value, 212 212 * --long:value, --long=value, --long value, 213 * --long: value, --long= value214 213 * 215 214 * If the option is index, then all trailing chars must be … … 574 573 * Find the argument value. 575 574 * 576 * A value is required with the argument. We're trying to be very575 * A value is required with the argument. We're trying to be 577 576 * understanding here and will permit any of the following: 578 * -svalue, -s:value, -s=value, 579 * -s value, -s: value, -s= value 577 * -svalue, -s value, -s:value and -s=value 580 578 * (Ditto for long options.) 581 579 */ … … 583 581 if (fShort) 584 582 { 585 if ( pszArgThis[2] == '\0' 586 || ( pszArgThis[3] == '\0' 587 && ( pszArgThis[2] == ':' 588 || pszArgThis[2] == '=')) ) 583 if (pszArgThis[2] == '\0') 589 584 { 590 585 if (iThis + 1 >= pState->argc) … … 636 631 else 637 632 { 638 if ( pszArgThis[cchLong] == '\0' 639 || pszArgThis[cchLong + 1] == '\0') 633 if (pszArgThis[cchLong] == '\0') 640 634 { 641 635 if (iThis + 1 >= pState->argc) -
trunk/src/VBox/Runtime/testcase/tstRTGetOpt.cpp
r28800 r34542 5 5 6 6 /* 7 * Copyright (C) 2007-20 09Oracle Corporation7 * Copyright (C) 2007-2010 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 111 111 { 112 112 "-s", "string1", 113 "--optwithstring", "string2", 113 "-sstring2", 114 "-s:string3", 115 "-s=string4", 116 "-s:", 117 "-s=", 118 "--optwithstring", "string5", 119 "--optwithstring:string6", 120 "--optwithstring=string7", 121 "--optwithstring:", 122 "--optwithstring=", 114 123 115 124 "-i", "-42", 116 125 "-i:-42", 117 126 "-i=-42", 118 "-i:", "-42",119 "-i=", "-42",120 127 121 128 "--optwithint", "42", 122 129 "--optwithint:42", 123 130 "--optwithint=42", 124 "--optwithint:", "42",125 "--optwithint=", "42",126 131 127 132 "-v", … … 134 139 135 140 "nodash", 136 "nodashval", "string 3",141 "nodashval", "string9", 137 142 138 143 "filename1", … … 147 152 "--mac:1:::::c", 148 153 149 "--strindex786", "string4", 150 "--strindex786:string5", 151 "--strindex786=string6", 152 "strindex687", "string7", 153 "strindex687:string8", 154 "strindex687=string9", 154 "--strindex786", "string10", 155 "--strindex786:string11", 156 "--strindex786=string12", 157 "strindex687", "string13", 158 "strindex687:string14", 159 "strindex687=string15", 160 "strindex688:", 161 "strindex689=", 155 162 "--intindex137", "1000", 156 163 "--macindex138", "08:0:27:00:ab:f3", … … 191 198 CHECK(VALID_PTR(Val.psz) && !strcmp(Val.psz, "string1")); 192 199 CHECK(GetState.uIndex == UINT32_MAX); 200 CHECK_GETOPT(RTGetOpt(&GetState, &Val), 's', 1); 201 CHECK(VALID_PTR(Val.psz) && !strcmp(Val.psz, "string2")); 202 CHECK(GetState.uIndex == UINT32_MAX); 203 CHECK_GETOPT(RTGetOpt(&GetState, &Val), 's', 1); 204 CHECK(VALID_PTR(Val.psz) && !strcmp(Val.psz, "string3")); 205 CHECK(GetState.uIndex == UINT32_MAX); 206 CHECK_GETOPT(RTGetOpt(&GetState, &Val), 's', 1); 207 CHECK(VALID_PTR(Val.psz) && !strcmp(Val.psz, "string4")); 208 CHECK(GetState.uIndex == UINT32_MAX); 209 CHECK_GETOPT(RTGetOpt(&GetState, &Val), 's', 1); 210 CHECK(VALID_PTR(Val.psz) && !strcmp(Val.psz, "")); 211 CHECK(GetState.uIndex == UINT32_MAX); 212 CHECK_GETOPT(RTGetOpt(&GetState, &Val), 's', 1); 213 CHECK(VALID_PTR(Val.psz) && !strcmp(Val.psz, "")); 214 CHECK(GetState.uIndex == UINT32_MAX); 193 215 CHECK_GETOPT(RTGetOpt(&GetState, &Val), 's', 2); 194 CHECK(VALID_PTR(Val.psz) && !strcmp(Val.psz, "string2")); 216 CHECK(VALID_PTR(Val.psz) && !strcmp(Val.psz, "string5")); 217 CHECK(GetState.uIndex == UINT32_MAX); 218 CHECK_GETOPT(RTGetOpt(&GetState, &Val), 's', 1); 219 CHECK(VALID_PTR(Val.psz) && !strcmp(Val.psz, "string6")); 220 CHECK(GetState.uIndex == UINT32_MAX); 221 CHECK_GETOPT(RTGetOpt(&GetState, &Val), 's', 1); 222 CHECK(VALID_PTR(Val.psz) && !strcmp(Val.psz, "string7")); 223 CHECK(GetState.uIndex == UINT32_MAX); 224 CHECK_GETOPT(RTGetOpt(&GetState, &Val), 's', 1); 225 CHECK(VALID_PTR(Val.psz) && !strcmp(Val.psz, "")); 226 CHECK(GetState.uIndex == UINT32_MAX); 227 CHECK_GETOPT(RTGetOpt(&GetState, &Val), 's', 1); 228 CHECK(VALID_PTR(Val.psz) && !strcmp(Val.psz, "")); 195 229 CHECK(GetState.uIndex == UINT32_MAX); 196 230 … … 201 235 CHECK(Val.i32 == -42); 202 236 CHECK_GETOPT(RTGetOpt(&GetState, &Val), 'i', 1); 203 CHECK(Val.i32 == -42);204 CHECK_GETOPT(RTGetOpt(&GetState, &Val), 'i', 2);205 CHECK(Val.i32 == -42);206 CHECK_GETOPT(RTGetOpt(&GetState, &Val), 'i', 2);207 237 CHECK(Val.i32 == -42); 208 238 … … 213 243 CHECK(Val.i32 == 42); 214 244 CHECK_GETOPT(RTGetOpt(&GetState, &Val), 'i', 1); 215 CHECK(Val.i32 == 42);216 CHECK_GETOPT(RTGetOpt(&GetState, &Val), 'i', 2);217 CHECK(Val.i32 == 42);218 CHECK_GETOPT(RTGetOpt(&GetState, &Val), 'i', 2);219 245 CHECK(Val.i32 == 42); 220 246 … … 239 265 CHECK_pDef(s_aOpts2, 7); 240 266 CHECK_GETOPT(RTGetOpt(&GetState, &Val), 388, 2); 241 CHECK(VALID_PTR(Val.psz) && !strcmp(Val.psz, "string 3"));267 CHECK(VALID_PTR(Val.psz) && !strcmp(Val.psz, "string9")); 242 268 243 269 /* non-option, option, non-option */ … … 282 308 RTTestSub(hTest, "RTGetOpt - Option w/ Index"); 283 309 CHECK_GETOPT(RTGetOpt(&GetState, &Val), 400, 2); 284 CHECK(VALID_PTR(Val.psz) && !strcmp(Val.psz, "string 4"));310 CHECK(VALID_PTR(Val.psz) && !strcmp(Val.psz, "string10")); 285 311 CHECK(GetState.uIndex == 786); 286 312 287 313 CHECK_GETOPT(RTGetOpt(&GetState, &Val), 400, 1); 288 CHECK(VALID_PTR(Val.psz) && !strcmp(Val.psz, "string 5"));314 CHECK(VALID_PTR(Val.psz) && !strcmp(Val.psz, "string11")); 289 315 CHECK(GetState.uIndex == 786); 290 316 291 317 CHECK_GETOPT(RTGetOpt(&GetState, &Val), 400, 1); 292 CHECK(VALID_PTR(Val.psz) && !strcmp(Val.psz, "string 6"));318 CHECK(VALID_PTR(Val.psz) && !strcmp(Val.psz, "string12")); 293 319 CHECK(GetState.uIndex == 786); 294 320 295 321 CHECK_GETOPT(RTGetOpt(&GetState, &Val), 400, 2); 296 CHECK(VALID_PTR(Val.psz) && !strcmp(Val.psz, "string 7"));322 CHECK(VALID_PTR(Val.psz) && !strcmp(Val.psz, "string13")); 297 323 CHECK(GetState.uIndex == 687); 298 324 299 325 CHECK_GETOPT(RTGetOpt(&GetState, &Val), 400, 1); 300 CHECK(VALID_PTR(Val.psz) && !strcmp(Val.psz, "string 8"));326 CHECK(VALID_PTR(Val.psz) && !strcmp(Val.psz, "string14")); 301 327 CHECK(GetState.uIndex == 687); 302 328 303 329 CHECK_GETOPT(RTGetOpt(&GetState, &Val), 400, 1); 304 CHECK(VALID_PTR(Val.psz) && !strcmp(Val.psz, "string 9"));330 CHECK(VALID_PTR(Val.psz) && !strcmp(Val.psz, "string15")); 305 331 CHECK(GetState.uIndex == 687); 332 333 CHECK_GETOPT(RTGetOpt(&GetState, &Val), 400, 1); 334 CHECK(VALID_PTR(Val.psz) && !strcmp(Val.psz, "")); 335 CHECK(GetState.uIndex == 688); 336 337 CHECK_GETOPT(RTGetOpt(&GetState, &Val), 400, 1); 338 CHECK(VALID_PTR(Val.psz) && !strcmp(Val.psz, "")); 339 CHECK(GetState.uIndex == 689); 306 340 307 341 CHECK_GETOPT(RTGetOpt(&GetState, &Val), 401, 2); … … 416 450 "foo6", 417 451 "foo7", 418 "-i: ", "-42",419 "-i= ", "-42",452 "-i:-42", 453 "-i=-42", 420 454 "foo8", 421 455 "--twovalues", "firstvalue", "secondvalue", … … 449 483 CHECK_GETOPT(RTGetOpt(&GetState, &Val), 'i', 1); 450 484 CHECK(Val.i32 == -42); 451 CHECK_GETOPT(RTGetOpt(&GetState, &Val), 'i', 2);452 CHECK(Val.i32 == -42); 453 CHECK_GETOPT(RTGetOpt(&GetState, &Val), 'i', 2);485 CHECK_GETOPT(RTGetOpt(&GetState, &Val), 'i', 1); 486 CHECK(Val.i32 == -42); 487 CHECK_GETOPT(RTGetOpt(&GetState, &Val), 'i', 1); 454 488 CHECK(Val.i32 == -42); 455 489 … … 502 536 "foo6", 503 537 "foo7", 504 "-i: ", "-42",505 "-i= ", "-42",538 "-i:-42", 539 "-i=-42", 506 540 "foo8", 507 541 "--twovalues", "firstvalue", "secondvalue", … … 533 567 CHECK_GETOPT(RTGetOpt(&GetState, &Val), 'i', 1); 534 568 CHECK(Val.i32 == -42); 535 CHECK_GETOPT(RTGetOpt(&GetState, &Val), 'i', 2);536 CHECK(Val.i32 == -42); 537 CHECK_GETOPT(RTGetOpt(&GetState, &Val), 'i', 2);569 CHECK_GETOPT(RTGetOpt(&GetState, &Val), 'i', 1); 570 CHECK(Val.i32 == -42); 571 CHECK_GETOPT(RTGetOpt(&GetState, &Val), 'i', 1); 538 572 CHECK(Val.i32 == -42); 539 573
Note:
See TracChangeset
for help on using the changeset viewer.