- Timestamp:
- May 5, 2015 4:27:52 PM (10 years ago)
- svn:sync-xref-src-repo-rev:
- 100060
- Location:
- trunk/src
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Additions/common/VBoxService/VBoxServiceControlProcess.cpp
r55535 r55671 1493 1493 uint32_t uNumArgs = 0; /* Initialize in case of RTGetOptArgvFromString() is failing ... */ 1494 1494 rc = RTGetOptArgvFromString(&papszArgs, (int*)&uNumArgs, 1495 (pProcess->StartupInfo.uNumArgs > 0) ? pProcess->StartupInfo.szArgs : "", NULL); 1495 (pProcess->StartupInfo.uNumArgs > 0) ? pProcess->StartupInfo.szArgs : "", 1496 RTGETOPTARGV_CNV_QUOTE_BOURNE_SH, NULL); 1496 1497 /* Did we get the same result? */ 1497 1498 Assert(pProcess->StartupInfo.uNumArgs == uNumArgs); -
trunk/src/VBox/Main/src-helper-apps/VBoxExtPackHelperApp.cpp
r51978 r55671 1938 1938 int cArgs; 1939 1939 char **papszArgs; 1940 rc = RTGetOptArgvFromString(&papszArgs, &cArgs, pszCmdLine, NULL);1940 rc = RTGetOptArgvFromString(&papszArgs, &cArgs, pszCmdLine, RTGETOPTARGV_CNV_QUOTE_MS_CRT, NULL); 1941 1941 if (RT_SUCCESS(rc)) 1942 1942 { -
trunk/src/VBox/Runtime/common/misc/getoptargv.cpp
r55529 r55671 221 221 222 222 223 RTDECL(int) RTGetOptArgvFromString(char ***ppapszArgv, int *pcArgs, const char *pszCmdLine, const char *pszSeparators) 223 RTDECL(int) RTGetOptArgvFromString(char ***ppapszArgv, int *pcArgs, const char *pszCmdLine, 224 uint32_t fFlags, const char *pszSeparators) 224 225 { 225 226 /* … … 229 230 AssertPtr(pcArgs); 230 231 AssertPtr(ppapszArgv); 232 AssertReturn( fFlags == RTGETOPTARGV_CNV_QUOTE_BOURNE_SH 233 || fFlags == RTGETOPTARGV_CNV_QUOTE_MS_CRT, VERR_INVALID_FLAGS); 231 234 if (!pszSeparators) 232 235 pszSeparators = " \t\n\r"; … … 272 275 * Parse and copy the string over. 273 276 */ 274 RTUNICP CpQuote = 0;275 277 RTUNICP Cp; 276 for (;;) 277 { 278 rc = RTStrGetCpEx(&pszSrc, &Cp); 279 if (RT_FAILURE(rc) || !Cp) 280 break; 281 if (!CpQuote) 278 if ((fFlags & RTGETOPTARGV_CNV_QUOTE_MASK) == RTGETOPTARGV_CNV_QUOTE_BOURNE_SH) 279 { 280 /* 281 * Bourne shell style. 282 */ 283 RTUNICP CpQuote = 0; 284 for (;;) 282 285 { 283 if (Cp == '"' || Cp == '\'') 284 CpQuote = Cp; 285 else if (rtGetOptIsCpInSet(Cp, pszSeparators, cchSeparators)) 286 rc = RTStrGetCpEx(&pszSrc, &Cp); 287 if (RT_FAILURE(rc) || !Cp) 288 break; 289 if (!CpQuote) 290 { 291 if (Cp == '"' || Cp == '\'') 292 CpQuote = Cp; 293 else if (rtGetOptIsCpInSet(Cp, pszSeparators, cchSeparators)) 294 break; 295 else if (Cp != '\\') 296 pszDst = RTStrPutCp(pszDst, Cp); 297 else 298 { 299 /* escaped char */ 300 rc = RTStrGetCpEx(&pszSrc, &Cp); 301 if (RT_FAILURE(rc) || !Cp) 302 break; 303 pszDst = RTStrPutCp(pszDst, Cp); 304 } 305 } 306 else if (CpQuote != Cp) 307 { 308 if (Cp != '\\' || CpQuote == '\'') 309 pszDst = RTStrPutCp(pszDst, Cp); 310 else 311 { 312 /* escaped char */ 313 rc = RTStrGetCpEx(&pszSrc, &Cp); 314 if (RT_FAILURE(rc) || !Cp) 315 break; 316 pszDst = RTStrPutCp(pszDst, Cp); 317 } 318 } 319 else 320 CpQuote = 0; 321 } 322 } 323 else 324 { 325 /* 326 * Microsoft CRT style. 327 */ 328 Assert((fFlags & RTGETOPTARGV_CNV_QUOTE_MASK) == RTGETOPTARGV_CNV_QUOTE_MS_CRT); 329 bool fInQuote; 330 for (;;) 331 { 332 rc = RTStrGetCpEx(&pszSrc, &Cp); 333 if (RT_FAILURE(rc) || !Cp) 334 break; 335 if (Cp == '"') 336 fInQuote = !fInQuote; 337 else if (!fInQuote && rtGetOptIsCpInSet(Cp, pszSeparators, cchSeparators)) 286 338 break; 287 339 else if (Cp != '\\') … … 289 341 else 290 342 { 291 /* escaped char */ 292 rc = RTStrGetCpEx(&pszSrc, &Cp); 293 if (RT_FAILURE(rc) || !Cp) 294 break; 295 pszDst = RTStrPutCp(pszDst, Cp); 343 /* A backslash sequence is only relevant if followed by 344 a double quote, then it will work like an escape char. */ 345 size_t cQuotes = 1; 346 while (*pszSrc == '\\') 347 { 348 cQuotes++; 349 pszSrc++; 350 } 351 if (*pszSrc != '"') 352 /* Not an escape sequence. */ 353 while (cQuotes-- > 0) 354 pszDst = RTStrPutCp(pszDst, '\\'); 355 else 356 { 357 /* Escape sequence. Output half of the slashes. If odd 358 number, output the escaped double quote . */ 359 while (cQuotes >= 2) 360 { 361 pszDst = RTStrPutCp(pszDst, '\\'); 362 cQuotes -= 2; 363 } 364 if (!cQuotes) 365 fInQuote = !fInQuote; 366 else 367 pszDst = RTStrPutCp(pszDst, '"'); 368 pszSrc++; 369 } 296 370 } 297 371 } 298 else if (CpQuote != Cp) 299 { 300 if (Cp != '\\' || CpQuote == '\'') 301 pszDst = RTStrPutCp(pszDst, Cp); 302 else 303 { 304 /* escaped char */ 305 rc = RTStrGetCpEx(&pszSrc, &Cp); 306 if (RT_FAILURE(rc) || !Cp) 307 break; 308 pszDst = RTStrPutCp(pszDst, Cp); 309 } 310 } 311 else 312 CpQuote = 0; 313 } 372 } 373 314 374 *pszDst++ = '\0'; 315 375 if (RT_FAILURE(rc) || !Cp) -
trunk/src/VBox/Runtime/testcase/tstRTGetOptArgv.cpp
r55499 r55671 43 43 static const struct 44 44 { 45 /** The input string. */ 46 const char *pszInput; 45 /** The input string, bourne shell. */ 46 const char *pszInBourne; 47 /** The input string, MS CRT. */ 48 const char *pszInMsCrt; 47 49 /** Separators, NULL if default. */ 48 50 const char *pszSeparators; … … 53 55 /** Expected quoted string, bourne shell. */ 54 56 const char *pszOutBourneSh; 55 /** Expected quoted string, MS CCRT. */57 /** Expected quoted string, MS CRT. */ 56 58 const char *pszOutMsCrt; 57 } g_a BourneTests[] =59 } g_aTests[] = 58 60 { 59 61 { 60 62 "0 1 \"\"2'' '3' 4 5 '''''6' 7 8 9 10 11", 63 "0 1 \"\"2 3 4 5 \"6\" 7 8 \"\"\"\"\"\"9\"\"\"\" 10 11", 61 64 NULL, 62 65 12, … … 81 84 { 82 85 "\t\" asdf \" '\"'xyz \"\t\" '\n' '\"' \"'\"\n\r ", 86 "\t\" asdf \" \\\"xyz \"\t\" \"\n\" \"\\\"\" '\n\r ", 83 87 NULL, 84 88 6, … … 98 102 { 99 103 ":0::1::::2:3:4:5:", 104 ":0::1::::2:3:4:5:", 100 105 ":", 101 106 6, … … 115 120 { 116 121 "0:1;2:3;4:5", 122 "0:1;2:3;4:5", 117 123 ";;;;;;;;;;;;;;;;;;;;;;:", 118 124 6, … … 132 138 { 133 139 "abcd 'a ' ' b' ' c '", 140 "abcd \"a \" \" b\" \" c \"", 134 141 NULL, 135 142 4, … … 147 154 { 148 155 "'a\n\\b' 'de'\"'\"'fg' h ''\"'\"''", 156 "\"a\n\\b\" de'fg h \"'\" ", 149 157 NULL, 150 158 4, … … 162 170 { 163 171 "arg1 \"arg2=\\\"zyx\\\"\" 'arg3=\\\\\\'", 172 "arg1 arg2=\\\"zyx\\\" arg3=\\\\\\", 164 173 NULL, 165 174 3, … … 176 185 { 177 186 " a\\\\\\\\b d\"e f\"g h ij\t", 187 " a\\\\b d\"e f\"g h ij\t", 178 188 NULL, 179 189 4, … … 253 263 254 264 255 256 static void tst3(void) 257 { 258 /* 259 * Bourne shell round-tripping. 260 */ 261 RTTestISub("Round-trips / BOURNE_SH"); 262 for (unsigned i = 0; i < RT_ELEMENTS(g_aBourneTests); i++) 265 static void tst4(void) 266 { 267 /* 268 * Microsoft CRT round-tripping. 269 */ 270 RTTestISub("Round-trips / MS_CRT"); 271 for (unsigned i = 0; i < RT_ELEMENTS(g_aTests); i++) 263 272 { 264 273 /* First */ 265 274 char **papszArgs1 = NULL; 266 275 int cArgs1 = -1; 267 int rc = RTGetOptArgvFromString(&papszArgs1, &cArgs1, g_aBourneTests[i].pszInput, g_aBourneTests[i].pszSeparators); 276 int rc = RTGetOptArgvFromString(&papszArgs1, &cArgs1, g_aTests[i].pszInMsCrt, 277 RTGETOPTARGV_CNV_QUOTE_MS_CRT, g_aTests[i].pszSeparators); 268 278 if (rc == VINF_SUCCESS) 269 279 { 270 if (cArgs1 != g_a BourneTests[i].cArgs)271 RTTestIFailed("g_a BourneTests[%i]: #1=%d, expected %d", i, cArgs1, g_aBourneTests[i].cArgs);280 if (cArgs1 != g_aTests[i].cArgs) 281 RTTestIFailed("g_aTests[%i]: #1=%d, expected %d", i, cArgs1, g_aTests[i].cArgs); 272 282 for (int iArg = 0; iArg < cArgs1; iArg++) 273 if (strcmp(papszArgs1[iArg], g_aBourneTests[i].apszArgs[iArg]) != 0) 274 RTTestIFailed("g_aBourneTests[%i]/1: argv[%i] differs: got '%s', expected '%s' (RTGetOptArgvFromString(,,'%s', '%s'))", 275 i, iArg, papszArgs1[iArg], g_aBourneTests[i].apszArgs[iArg], 276 g_aBourneTests[i].pszInput, g_aBourneTests[i].pszSeparators); 283 if (strcmp(papszArgs1[iArg], g_aTests[i].apszArgs[iArg]) != 0) 284 RTTestIFailed("g_aTests[%i]/1: argv[%i] differs: got '%s', expected '%s' (RTGetOptArgvFromString(,,'%s', '%s'))", 285 i, iArg, papszArgs1[iArg], g_aTests[i].apszArgs[iArg], 286 g_aTests[i].pszInMsCrt, g_aTests[i].pszSeparators); 287 RTTESTI_CHECK_RETV(papszArgs1[cArgs1] == NULL); 288 tstCheckNativeMsCrtToArgv(g_aTests[i].pszInMsCrt, g_aTests[i].cArgs, g_aTests[i].apszArgs); 289 290 /* Second */ 291 char *pszArgs2 = NULL; 292 rc = RTGetOptArgvToString(&pszArgs2, papszArgs1, RTGETOPTARGV_CNV_QUOTE_MS_CRT); 293 if (rc == VINF_SUCCESS) 294 { 295 if (strcmp(pszArgs2, g_aTests[i].pszOutMsCrt)) 296 RTTestIFailed("g_aTests[%i]/2: '%s', expected '%s'", i, pszArgs2, g_aTests[i].pszOutMsCrt); 297 298 /* 299 * Third 300 */ 301 char **papszArgs3 = NULL; 302 int cArgs3 = -1; 303 rc = RTGetOptArgvFromString(&papszArgs3, &cArgs3, pszArgs2, RTGETOPTARGV_CNV_QUOTE_MS_CRT, NULL); 304 if (rc == VINF_SUCCESS) 305 { 306 if (cArgs3 != g_aTests[i].cArgs) 307 RTTestIFailed("g_aTests[%i]/3: %d, expected %d", i, cArgs3, g_aTests[i].cArgs); 308 for (int iArg = 0; iArg < cArgs3; iArg++) 309 if (strcmp(papszArgs3[iArg], g_aTests[i].apszArgs[iArg]) != 0) 310 RTTestIFailed("g_aTests[%i]/3: argv[%i] differs: got '%s', expected '%s' (RTGetOptArgvFromString(,,'%s',))", 311 i, iArg, papszArgs3[iArg], g_aTests[i].apszArgs[iArg], pszArgs2); 312 RTTESTI_CHECK_RETV(papszArgs3[cArgs3] == NULL); 313 tstCheckNativeMsCrtToArgv(pszArgs2, g_aTests[i].cArgs, g_aTests[i].apszArgs); 314 315 /* 316 * Fourth 317 */ 318 char *pszArgs4 = NULL; 319 rc = RTGetOptArgvToString(&pszArgs4, papszArgs3, RTGETOPTARGV_CNV_QUOTE_MS_CRT); 320 if (rc == VINF_SUCCESS) 321 { 322 if (strcmp(pszArgs4, pszArgs2)) 323 RTTestIFailed("g_aTests[%i]/4: '%s' does not match #4='%s'", i, pszArgs2, pszArgs4); 324 RTStrFree(pszArgs4); 325 } 326 else 327 RTTestIFailed("g_aTests[%i]/4: RTGetOptArgvToString() -> %Rrc", i, rc); 328 RTGetOptArgvFree(papszArgs3); 329 } 330 else 331 RTTestIFailed("g_aTests[%i]/3: RTGetOptArgvFromString() -> %Rrc", i, rc); 332 RTStrFree(pszArgs2); 333 } 334 else 335 RTTestIFailed("g_aTests[%i]/2: RTGetOptArgvToString() -> %Rrc", i, rc); 336 RTGetOptArgvFree(papszArgs1); 337 } 338 else 339 RTTestIFailed("g_aTests[%i]/1: RTGetOptArgvFromString(,,'%s', '%s') -> %Rrc", 340 i, g_aTests[i].pszInMsCrt, g_aTests[i].pszSeparators, rc); 341 } 342 343 } 344 345 346 347 static void tst3(void) 348 { 349 /* 350 * Bourne shell round-tripping. 351 */ 352 RTTestISub("Round-trips / BOURNE_SH"); 353 for (unsigned i = 0; i < RT_ELEMENTS(g_aTests); i++) 354 { 355 /* First */ 356 char **papszArgs1 = NULL; 357 int cArgs1 = -1; 358 int rc = RTGetOptArgvFromString(&papszArgs1, &cArgs1, g_aTests[i].pszInBourne, 359 RTGETOPTARGV_CNV_QUOTE_BOURNE_SH, g_aTests[i].pszSeparators); 360 if (rc == VINF_SUCCESS) 361 { 362 if (cArgs1 != g_aTests[i].cArgs) 363 RTTestIFailed("g_aTests[%i]: #1=%d, expected %d", i, cArgs1, g_aTests[i].cArgs); 364 for (int iArg = 0; iArg < cArgs1; iArg++) 365 if (strcmp(papszArgs1[iArg], g_aTests[i].apszArgs[iArg]) != 0) 366 RTTestIFailed("g_aTests[%i]/1: argv[%i] differs: got '%s', expected '%s' (RTGetOptArgvFromString(,,'%s', '%s'))", 367 i, iArg, papszArgs1[iArg], g_aTests[i].apszArgs[iArg], 368 g_aTests[i].pszInBourne, g_aTests[i].pszSeparators); 277 369 RTTESTI_CHECK_RETV(papszArgs1[cArgs1] == NULL); 278 370 … … 282 374 if (rc == VINF_SUCCESS) 283 375 { 284 if (strcmp(pszArgs2, g_a BourneTests[i].pszOutBourneSh))285 RTTestIFailed("g_a BourneTests[%i]/2: '%s', expected '%s'", i, pszArgs2, g_aBourneTests[i].pszOutBourneSh);376 if (strcmp(pszArgs2, g_aTests[i].pszOutBourneSh)) 377 RTTestIFailed("g_aTests[%i]/2: '%s', expected '%s'", i, pszArgs2, g_aTests[i].pszOutBourneSh); 286 378 287 379 /* … … 290 382 char **papszArgs3 = NULL; 291 383 int cArgs3 = -1; 292 rc = RTGetOptArgvFromString(&papszArgs3, &cArgs3, pszArgs2, NULL);384 rc = RTGetOptArgvFromString(&papszArgs3, &cArgs3, pszArgs2, RTGETOPTARGV_CNV_QUOTE_BOURNE_SH, NULL); 293 385 if (rc == VINF_SUCCESS) 294 386 { 295 if (cArgs3 != g_a BourneTests[i].cArgs)296 RTTestIFailed("g_a BourneTests[%i]/3: %d, expected %d", i, cArgs3, g_aBourneTests[i].cArgs);387 if (cArgs3 != g_aTests[i].cArgs) 388 RTTestIFailed("g_aTests[%i]/3: %d, expected %d", i, cArgs3, g_aTests[i].cArgs); 297 389 for (int iArg = 0; iArg < cArgs3; iArg++) 298 if (strcmp(papszArgs3[iArg], g_a BourneTests[i].apszArgs[iArg]) != 0)299 RTTestIFailed("g_a BourneTests[%i]/3: argv[%i] differs: got '%s', expected '%s' (RTGetOptArgvFromString(,,'%s',))",300 i, iArg, papszArgs3[iArg], g_a BourneTests[i].apszArgs[iArg], pszArgs2);390 if (strcmp(papszArgs3[iArg], g_aTests[i].apszArgs[iArg]) != 0) 391 RTTestIFailed("g_aTests[%i]/3: argv[%i] differs: got '%s', expected '%s' (RTGetOptArgvFromString(,,'%s',))", 392 i, iArg, papszArgs3[iArg], g_aTests[i].apszArgs[iArg], pszArgs2); 301 393 RTTESTI_CHECK_RETV(papszArgs3[cArgs3] == NULL); 302 394 … … 309 401 { 310 402 if (strcmp(pszArgs4, pszArgs2)) 311 RTTestIFailed("g_a BourneTests[%i]/4: '%s' does not match #4='%s'", i, pszArgs2, pszArgs4);403 RTTestIFailed("g_aTests[%i]/4: '%s' does not match #4='%s'", i, pszArgs2, pszArgs4); 312 404 RTStrFree(pszArgs4); 313 405 } 314 406 else 315 RTTestIFailed("g_a BourneTests[%i]/4: RTGetOptArgvToString() -> %Rrc", i, rc);407 RTTestIFailed("g_aTests[%i]/4: RTGetOptArgvToString() -> %Rrc", i, rc); 316 408 RTGetOptArgvFree(papszArgs3); 317 409 } 318 410 else 319 RTTestIFailed("g_a BourneTests[%i]/3: RTGetOptArgvFromString() -> %Rrc", i, rc);411 RTTestIFailed("g_aTests[%i]/3: RTGetOptArgvFromString() -> %Rrc", i, rc); 320 412 RTStrFree(pszArgs2); 321 413 } 322 414 else 323 RTTestIFailed("g_a BourneTests[%i]/2: RTGetOptArgvToString() -> %Rrc", i, rc);415 RTTestIFailed("g_aTests[%i]/2: RTGetOptArgvToString() -> %Rrc", i, rc); 324 416 RTGetOptArgvFree(papszArgs1); 325 417 } 326 418 else 327 RTTestIFailed("g_aBourneTests[%i]/1: RTGetOptArgvFromString(,,'%s', '%s') -> %Rrc", 328 i, g_aBourneTests[i].pszInput, g_aBourneTests[i].pszSeparators, rc); 329 } 330 419 RTTestIFailed("g_aTests[%i]/1: RTGetOptArgvFromString(,,'%s', '%s') -> %Rrc", 420 i, g_aTests[i].pszInBourne, g_aTests[i].pszSeparators, rc); 421 } 331 422 } 332 423 … … 375 466 } 376 467 377 for (size_t i = 0; i < RT_ELEMENTS(g_a BourneTests); i++)468 for (size_t i = 0; i < RT_ELEMENTS(g_aTests); i++) 378 469 { 379 470 char *pszCmdLine = NULL; 380 int rc = RTGetOptArgvToString(&pszCmdLine, g_a BourneTests[i].apszArgs, RTGETOPTARGV_CNV_QUOTE_MS_CRT);471 int rc = RTGetOptArgvToString(&pszCmdLine, g_aTests[i].apszArgs, RTGETOPTARGV_CNV_QUOTE_MS_CRT); 381 472 RTTESTI_CHECK_RC_RETV(rc, VINF_SUCCESS); 382 if (!strcmp(g_a BourneTests[i].pszOutMsCrt, pszCmdLine))383 tstCheckNativeMsCrtToArgv(pszCmdLine, g_a BourneTests[i].cArgs, g_aBourneTests[i].apszArgs);473 if (!strcmp(g_aTests[i].pszOutMsCrt, pszCmdLine)) 474 tstCheckNativeMsCrtToArgv(pszCmdLine, g_aTests[i].cArgs, g_aTests[i].apszArgs); 384 475 else 385 RTTestIFailed("g_a BourneTests[%i] failed:\n"476 RTTestIFailed("g_aTests[%i] failed:\n" 386 477 " got |%s|\n" 387 478 " expected |%s|\n", 388 i, pszCmdLine, g_a BourneTests[i].pszOutMsCrt);479 i, pszCmdLine, g_aTests[i].pszOutMsCrt); 389 480 RTStrFree(pszCmdLine); 390 481 } … … 394 485 RTTestISub("RTGetOptArgvToString / BOURNE_SH"); 395 486 396 for (size_t i = 0; i < RT_ELEMENTS(g_a BourneTests); i++)487 for (size_t i = 0; i < RT_ELEMENTS(g_aTests); i++) 397 488 { 398 489 char *pszCmdLine = NULL; 399 int rc = RTGetOptArgvToString(&pszCmdLine, g_a BourneTests[i].apszArgs, RTGETOPTARGV_CNV_QUOTE_BOURNE_SH);490 int rc = RTGetOptArgvToString(&pszCmdLine, g_aTests[i].apszArgs, RTGETOPTARGV_CNV_QUOTE_BOURNE_SH); 400 491 RTTESTI_CHECK_RC_RETV(rc, VINF_SUCCESS); 401 if (strcmp(g_a BourneTests[i].pszOutBourneSh, pszCmdLine))402 RTTestIFailed("g_a BourneTests[%i] failed:\n"492 if (strcmp(g_aTests[i].pszOutBourneSh, pszCmdLine)) 493 RTTestIFailed("g_aTests[%i] failed:\n" 403 494 " got |%s|\n" 404 495 " expected |%s|\n", 405 i, pszCmdLine, g_a BourneTests[i].pszOutBourneSh);496 i, pszCmdLine, g_aTests[i].pszOutBourneSh); 406 497 RTStrFree(pszCmdLine); 407 498 } … … 413 504 char **papszArgs = NULL; 414 505 int cArgs = -1; 415 RTTESTI_CHECK_RC_RETV(RTGetOptArgvFromString(&papszArgs, &cArgs, "", NULL), VINF_SUCCESS);506 RTTESTI_CHECK_RC_RETV(RTGetOptArgvFromString(&papszArgs, &cArgs, "", RTGETOPTARGV_CNV_QUOTE_BOURNE_SH, NULL), VINF_SUCCESS); 416 507 RTTESTI_CHECK_RETV(cArgs == 0); 417 508 RTTESTI_CHECK_RETV(papszArgs); … … 419 510 RTGetOptArgvFree(papszArgs); 420 511 421 RTTESTI_CHECK_RC_RETV(RTGetOptArgvFromString(&papszArgs, &cArgs, "0 1 \"\"2'' '3' 4 5 '''''6' 7 8 9 10 11", NULL), VINF_SUCCESS); 512 RTTESTI_CHECK_RC_RETV(RTGetOptArgvFromString(&papszArgs, &cArgs, "0 1 \"\"2'' '3' 4 5 '''''6' 7 8 9 10 11", 513 RTGETOPTARGV_CNV_QUOTE_BOURNE_SH, NULL), VINF_SUCCESS); 422 514 RTTESTI_CHECK_RETV(cArgs == 12); 423 515 RTTESTI_CHECK_RETV(!strcmp(papszArgs[0], "0")); … … 436 528 RTGetOptArgvFree(papszArgs); 437 529 438 RTTESTI_CHECK_RC_RETV(RTGetOptArgvFromString(&papszArgs, &cArgs, "\t\" asdf \" '\"'xyz \"\t\" '\n' '\"' \"'\"\n\r ", NULL), VINF_SUCCESS); 530 RTTESTI_CHECK_RC_RETV(RTGetOptArgvFromString(&papszArgs, &cArgs, "\t\" asdf \" '\"'xyz \"\t\" '\n' '\"' \"'\"\n\r ", 531 RTGETOPTARGV_CNV_QUOTE_BOURNE_SH, NULL), VINF_SUCCESS); 439 532 RTTESTI_CHECK_RETV(cArgs == 6); 440 533 RTTESTI_CHECK_RETV(!strcmp(papszArgs[0], " asdf ")); … … 447 540 RTGetOptArgvFree(papszArgs); 448 541 449 RTTESTI_CHECK_RC_RETV(RTGetOptArgvFromString(&papszArgs, &cArgs, ":0::1::::2:3:4:5:", ":"), VINF_SUCCESS); 542 RTTESTI_CHECK_RC_RETV(RTGetOptArgvFromString(&papszArgs, &cArgs, ":0::1::::2:3:4:5:", 543 RTGETOPTARGV_CNV_QUOTE_BOURNE_SH, ":"), VINF_SUCCESS); 450 544 RTTESTI_CHECK_RETV(cArgs == 6); 451 545 RTTESTI_CHECK_RETV(!strcmp(papszArgs[0], "0")); … … 458 552 RTGetOptArgvFree(papszArgs); 459 553 460 RTTESTI_CHECK_RC_RETV(RTGetOptArgvFromString(&papszArgs, &cArgs, "0:1;2:3;4:5", ";;;;;;;;;;;;;;;;;;;;;;:"), VINF_SUCCESS); 554 RTTESTI_CHECK_RC_RETV(RTGetOptArgvFromString(&papszArgs, &cArgs, "0:1;2:3;4:5", RTGETOPTARGV_CNV_QUOTE_BOURNE_SH, 555 ";;;;;;;;;;;;;;;;;;;;;;:"), VINF_SUCCESS); 461 556 RTTESTI_CHECK_RETV(cArgs == 6); 462 557 RTTESTI_CHECK_RETV(!strcmp(papszArgs[0], "0")); … … 472 567 * Tests from the list. 473 568 */ 474 for (unsigned i = 0; i < RT_ELEMENTS(g_a BourneTests); i++)569 for (unsigned i = 0; i < RT_ELEMENTS(g_aTests); i++) 475 570 { 476 571 papszArgs = NULL; 477 572 cArgs = -1; 478 int rc = RTGetOptArgvFromString(&papszArgs, &cArgs, g_aBourneTests[i].pszInput, g_aBourneTests[i].pszSeparators); 573 int rc = RTGetOptArgvFromString(&papszArgs, &cArgs, g_aTests[i].pszInBourne, RTGETOPTARGV_CNV_QUOTE_BOURNE_SH, 574 g_aTests[i].pszSeparators); 479 575 if (rc == VINF_SUCCESS) 480 576 { 481 if (cArgs == g_a BourneTests[i].cArgs)577 if (cArgs == g_aTests[i].cArgs) 482 578 { 483 579 for (int iArg = 0; iArg < cArgs; iArg++) 484 if (strcmp(papszArgs[iArg], g_a BourneTests[i].apszArgs[iArg]) != 0)485 RTTestIFailed("g_a BourneTests[%i]: argv[%i] differs: got '%s', expected '%s' (RTGetOptArgvFromString(,,'%s', '%s'))",486 i, iArg, papszArgs[iArg], g_a BourneTests[i].apszArgs[iArg],487 g_a BourneTests[i].pszInput, g_aBourneTests[i].pszSeparators);580 if (strcmp(papszArgs[iArg], g_aTests[i].apszArgs[iArg]) != 0) 581 RTTestIFailed("g_aTests[%i]: argv[%i] differs: got '%s', expected '%s' (RTGetOptArgvFromString(,,'%s', '%s'))", 582 i, iArg, papszArgs[iArg], g_aTests[i].apszArgs[iArg], 583 g_aTests[i].pszInBourne, g_aTests[i].pszSeparators); 488 584 RTTESTI_CHECK_RETV(papszArgs[cArgs] == NULL); 489 585 } 490 586 else 491 RTTestIFailed("g_a BourneTests[%i]: cArgs=%u, expected %u for RTGetOptArgvFromString(,,'%s', '%s')",492 i, cArgs, g_a BourneTests[i].cArgs, g_aBourneTests[i].pszInput, g_aBourneTests[i].pszSeparators);587 RTTestIFailed("g_aTests[%i]: cArgs=%u, expected %u for RTGetOptArgvFromString(,,'%s', '%s')", 588 i, cArgs, g_aTests[i].cArgs, g_aTests[i].pszInBourne, g_aTests[i].pszSeparators); 493 589 RTGetOptArgvFree(papszArgs); 494 590 } 495 591 else 496 RTTestIFailed("g_a BourneTests[%i]: RTGetOptArgvFromString(,,'%s', '%s') -> %Rrc",497 i, g_a BourneTests[i].pszInput, g_aBourneTests[i].pszSeparators, rc);592 RTTestIFailed("g_aTests[%i]: RTGetOptArgvFromString(,,'%s', '%s') -> %Rrc", 593 i, g_aTests[i].pszInBourne, g_aTests[i].pszSeparators, rc); 498 594 } 499 595 } … … 516 612 tst1(); 517 613 tst2(); 614 tst4(); 518 615 tst3(); 519 616 -
trunk/src/bldprogs/scm.cpp
r48958 r55671 482 482 int cArgs; 483 483 char **papszArgs; 484 int rc = RTGetOptArgvFromString(&papszArgs, &cArgs, pszLine, NULL);484 int rc = RTGetOptArgvFromString(&papszArgs, &cArgs, pszLine, RTGETOPTARGV_CNV_QUOTE_BOURNE_SH, NULL); 485 485 if (RT_SUCCESS(rc)) 486 486 {
Note:
See TracChangeset
for help on using the changeset viewer.