Changeset 67598 in vbox
- Timestamp:
- Jun 26, 2017 9:17:22 AM (8 years ago)
- svn:sync-xref-src-repo-rev:
- 116356
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/iprt/getopt.h
r64603 r67598 412 412 * 413 413 * @param ppapszArgv Where to return the argument vector. This must be 414 * freed by calling RTGetOptArgvFree. 414 * freed by calling RTGetOptArgvFreeEx or 415 * RTGetOptArgvFree. 415 416 * @param pcArgs Where to return the argument count. 416 417 * @param pszCmdLine The string to parse. … … 432 433 433 434 /** 435 * Frees and argument vector returned by RTGetOptStringToArgv, taking 436 * RTGETOPTARGV_CNV_MODIFY_INPUT into account. 437 * 438 * @param papszArgv Argument vector. NULL is fine. 439 * @param fFlags The flags passed to RTGetOptStringToArgv. 440 */ 441 RTDECL(void) RTGetOptArgvFreeEx(char **papszArgv, uint32_t fFlags); 442 443 /** 434 444 * Turns an argv array into a command line string. 435 445 * … … 448 458 RTDECL(int) RTGetOptArgvToString(char **ppszCmdLine, const char * const *papszArgv, uint32_t fFlags); 449 459 450 /** @name RTGetOptArgvToString and RTGetOptArgvToUtf16String flags 460 /** @name RTGetOptArgvToString, RTGetOptArgvToUtf16String and 461 * RTGetOptArgvFromString flags 451 462 * @{ */ 452 463 /** Quote strings according to the Microsoft CRT rules. */ 453 #define RTGETOPTARGV_CNV_QUOTE_MS_CRT UINT32_C(0 )464 #define RTGETOPTARGV_CNV_QUOTE_MS_CRT UINT32_C(0x00000000) 454 465 /** Quote strings according to the Unix Bourne Shell. */ 455 #define RTGETOPTARGV_CNV_QUOTE_BOURNE_SH UINT32_C( 1)466 #define RTGETOPTARGV_CNV_QUOTE_BOURNE_SH UINT32_C(0x00000001) 456 467 /** Don't quote any strings at all. */ 457 #define RTGETOPTARGV_CNV_UNQUOTED UINT32_C( 2)468 #define RTGETOPTARGV_CNV_UNQUOTED UINT32_C(0x00000002) 458 469 /** Mask for the quoting style. */ 459 #define RTGETOPTARGV_CNV_QUOTE_MASK UINT32_C(3) 470 #define RTGETOPTARGV_CNV_QUOTE_MASK UINT32_C(0x00000003) 471 /** Allow RTGetOptArgvFromString to modifying the command line input string. 472 * @note Must use RTGetOptArgvFreeEx to free. */ 473 #define RTGETOPTARGV_CNV_MODIFY_INPUT UINT32_C(0x00000004) 474 /** Valid bits. */ 475 #define RTGETOPTARGV_CNV_VALID_MASK UINT32_C(0x00000007) 460 476 /** @} */ 461 477 -
trunk/include/iprt/mangling.h
r67549 r67598 956 956 # define RTGetOpt RT_MANGLER(RTGetOpt) 957 957 # define RTGetOptArgvFree RT_MANGLER(RTGetOptArgvFree) 958 # define RTGetOptArgvFreeEx RT_MANGLER(RTGetOptArgvFreeEx) 958 959 # define RTGetOptArgvFromString RT_MANGLER(RTGetOptArgvFromString) 959 960 # define RTGetOptArgvToString RT_MANGLER(RTGetOptArgvToString) -
trunk/src/VBox/Runtime/common/misc/getoptargv.cpp
r66861 r67598 231 231 AssertPtr(pcArgs); 232 232 AssertPtr(ppapszArgv); 233 AssertReturn( fFlags == RTGETOPTARGV_CNV_QUOTE_BOURNE_SH 234 || fFlags == RTGETOPTARGV_CNV_QUOTE_MS_CRT, VERR_INVALID_FLAGS); 233 AssertReturn( (fFlags & RTGETOPTARGV_CNV_QUOTE_MASK) == RTGETOPTARGV_CNV_QUOTE_BOURNE_SH 234 || (fFlags & RTGETOPTARGV_CNV_QUOTE_MASK) == RTGETOPTARGV_CNV_QUOTE_MS_CRT, VERR_INVALID_FLAGS); 235 AssertReturn(~(fFlags & ~RTGETOPTARGV_CNV_VALID_MASK), VERR_INVALID_FLAGS); 236 235 237 if (!pszSeparators) 236 238 pszSeparators = " \t\n\r"; … … 243 245 * Parse the command line and chop off it into argv individual argv strings. 244 246 */ 247 const char *pszSrc = pszCmdLine; 248 char *pszDup = NULL; 249 char *pszDst; 250 if (fFlags & RTGETOPTARGV_CNV_MODIFY_INPUT) 251 pszDst = (char *)pszCmdLine; 252 else 253 { 254 pszDst = pszDup = (char *)RTMemAlloc(strlen(pszSrc) + 1); 255 if (!pszDup) 256 return VERR_NO_STR_MEMORY; 257 } 245 258 int rc = VINF_SUCCESS; 246 const char *pszSrc = pszCmdLine;247 char *pszDup = (char *)RTMemAlloc(strlen(pszSrc) + 1);248 char *pszDst = pszDup;249 if (!pszDup)250 return VERR_NO_STR_MEMORY;251 259 char **papszArgs = NULL; 252 260 unsigned iArg = 0; … … 425 433 RTDECL(void) RTGetOptArgvFree(char **papszArgv) 426 434 { 435 RTGetOptArgvFreeEx(papszArgv, 0); 436 } 437 438 439 RTDECL(void) RTGetOptArgvFreeEx(char **papszArgv, uint32_t fFlags) 440 { 441 Assert(~(fFlags & ~RTGETOPTARGV_CNV_VALID_MASK)); 427 442 if (papszArgv) 428 443 { … … 431 446 * RTGetOptArgvFromString for the particulars. 432 447 */ 433 RTMemFree(papszArgv[0]); 448 if (!(fFlags & RTGETOPTARGV_CNV_MODIFY_INPUT)) 449 RTMemFree(papszArgv[0]); 434 450 RTMemFree(papszArgv); 435 451 } … … 502 518 RTDECL(int) RTGetOptArgvToString(char **ppszCmdLine, const char * const *papszArgv, uint32_t fFlags) 503 519 { 504 AssertReturn(fFlags <= RTGETOPTARGV_CNV_UNQUOTED, VERR_INVALID_PARAMETER); 520 AssertReturn((fFlags & RTGETOPTARGV_CNV_QUOTE_MASK) <= RTGETOPTARGV_CNV_UNQUOTED, VERR_INVALID_FLAGS); 521 AssertReturn(!(fFlags & (~RTGETOPTARGV_CNV_VALID_MASK | RTGETOPTARGV_CNV_MODIFY_INPUT)), VERR_INVALID_FLAGS); 505 522 506 523 #define PUT_CH(ch) \
Note:
See TracChangeset
for help on using the changeset viewer.