VirtualBox

Changeset 55671 in vbox for trunk/src


Ignore:
Timestamp:
May 5, 2015 4:27:52 PM (10 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
100060
Message:

RTGetOptArgvFromString: Added fFlags parameter for selecting the quoting style.

Location:
trunk/src
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Additions/common/VBoxService/VBoxServiceControlProcess.cpp

    r55535 r55671  
    14931493    uint32_t uNumArgs = 0; /* Initialize in case of RTGetOptArgvFromString() is failing ... */
    14941494    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);
    14961497    /* Did we get the same result? */
    14971498    Assert(pProcess->StartupInfo.uNumArgs == uNumArgs);
  • trunk/src/VBox/Main/src-helper-apps/VBoxExtPackHelperApp.cpp

    r51978 r55671  
    19381938    int    cArgs;
    19391939    char **papszArgs;
    1940     rc = RTGetOptArgvFromString(&papszArgs, &cArgs, pszCmdLine, NULL);
     1940    rc = RTGetOptArgvFromString(&papszArgs, &cArgs, pszCmdLine, RTGETOPTARGV_CNV_QUOTE_MS_CRT, NULL);
    19411941    if (RT_SUCCESS(rc))
    19421942    {
  • trunk/src/VBox/Runtime/common/misc/getoptargv.cpp

    r55529 r55671  
    221221
    222222
    223 RTDECL(int) RTGetOptArgvFromString(char ***ppapszArgv, int *pcArgs, const char *pszCmdLine, const char *pszSeparators)
     223RTDECL(int) RTGetOptArgvFromString(char ***ppapszArgv, int *pcArgs, const char *pszCmdLine,
     224                                   uint32_t fFlags, const char *pszSeparators)
    224225{
    225226    /*
     
    229230    AssertPtr(pcArgs);
    230231    AssertPtr(ppapszArgv);
     232    AssertReturn(   fFlags == RTGETOPTARGV_CNV_QUOTE_BOURNE_SH
     233                 || fFlags == RTGETOPTARGV_CNV_QUOTE_MS_CRT, VERR_INVALID_FLAGS);
    231234    if (!pszSeparators)
    232235        pszSeparators = " \t\n\r";
     
    272275         * Parse and copy the string over.
    273276         */
    274         RTUNICP CpQuote = 0;
    275277        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 (;;)
    282285            {
    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))
    286338                    break;
    287339                else if (Cp != '\\')
     
    289341                else
    290342                {
    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                    }
    296370                }
    297371            }
    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
    314374        *pszDst++ = '\0';
    315375        if (RT_FAILURE(rc) || !Cp)
  • trunk/src/VBox/Runtime/testcase/tstRTGetOptArgv.cpp

    r55499 r55671  
    4343static const struct
    4444{
    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;
    4749    /** Separators, NULL if default. */
    4850    const char *pszSeparators;
     
    5355    /** Expected quoted string, bourne shell. */
    5456    const char *pszOutBourneSh;
    55     /** Expected quoted string, MSC CRT. */
     57    /** Expected quoted string, MS CRT. */
    5658    const char *pszOutMsCrt;
    57 } g_aBourneTests[] =
     59} g_aTests[] =
    5860{
    5961    {
    6062        "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",
    6164        NULL,
    6265        12,
     
    8184    {
    8285        "\t\" asdf \"  '\"'xyz  \"\t\"  '\n'  '\"'  \"'\"\n\r ",
     86        "\t\" asdf \"  \\\"xyz  \"\t\"  \"\n\"  \"\\\"\"  '\n\r ",
    8387        NULL,
    8488        6,
     
    98102    {
    99103        ":0::1::::2:3:4:5:",
     104        ":0::1::::2:3:4:5:",
    100105        ":",
    101106        6,
     
    115120    {
    116121        "0:1;2:3;4:5",
     122        "0:1;2:3;4:5",
    117123        ";;;;;;;;;;;;;;;;;;;;;;:",
    118124        6,
     
    132138    {
    133139        "abcd 'a ' ' b' ' c '",
     140        "abcd \"a \" \" b\" \" c \"",
    134141        NULL,
    135142        4,
     
    147154    {
    148155        "'a\n\\b' 'de'\"'\"'fg' h ''\"'\"''",
     156        "\"a\n\\b\" de'fg h     \"'\"    ",
    149157        NULL,
    150158        4,
     
    162170    {
    163171        "arg1 \"arg2=\\\"zyx\\\"\"  'arg3=\\\\\\'",
     172        "arg1 arg2=\\\"zyx\\\"  arg3=\\\\\\",
    164173        NULL,
    165174        3,
     
    176185    {
    177186        " a\\\\\\\\b  d\"e f\"g h ij\t",
     187        " a\\\\b  d\"e f\"g h ij\t",
    178188        NULL,
    179189        4,
     
    253263
    254264
    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++)
     265static 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++)
    263272    {
    264273        /* First */
    265274        char **papszArgs1 = NULL;
    266275        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);
    268278        if (rc == VINF_SUCCESS)
    269279        {
    270             if (cArgs1 != g_aBourneTests[i].cArgs)
    271                 RTTestIFailed("g_aBourneTests[%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);
    272282            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
     347static 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);
    277369            RTTESTI_CHECK_RETV(papszArgs1[cArgs1] == NULL);
    278370
     
    282374            if (rc == VINF_SUCCESS)
    283375            {
    284                 if (strcmp(pszArgs2, g_aBourneTests[i].pszOutBourneSh))
    285                     RTTestIFailed("g_aBourneTests[%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);
    286378
    287379                /*
     
    290382                char **papszArgs3 = NULL;
    291383                int    cArgs3     = -1;
    292                 rc = RTGetOptArgvFromString(&papszArgs3, &cArgs3, pszArgs2, NULL);
     384                rc = RTGetOptArgvFromString(&papszArgs3, &cArgs3, pszArgs2, RTGETOPTARGV_CNV_QUOTE_BOURNE_SH, NULL);
    293385                if (rc == VINF_SUCCESS)
    294386                {
    295                     if (cArgs3 != g_aBourneTests[i].cArgs)
    296                         RTTestIFailed("g_aBourneTests[%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);
    297389                    for (int iArg = 0; iArg < cArgs3; iArg++)
    298                         if (strcmp(papszArgs3[iArg], g_aBourneTests[i].apszArgs[iArg]) != 0)
    299                             RTTestIFailed("g_aBourneTests[%i]/3: argv[%i] differs: got '%s', expected '%s' (RTGetOptArgvFromString(,,'%s',))",
    300                                           i, iArg, papszArgs3[iArg], g_aBourneTests[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);
    301393                    RTTESTI_CHECK_RETV(papszArgs3[cArgs3] == NULL);
    302394
     
    309401                    {
    310402                        if (strcmp(pszArgs4, pszArgs2))
    311                             RTTestIFailed("g_aBourneTests[%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);
    312404                        RTStrFree(pszArgs4);
    313405                    }
    314406                    else
    315                         RTTestIFailed("g_aBourneTests[%i]/4: RTGetOptArgvToString() -> %Rrc", i, rc);
     407                        RTTestIFailed("g_aTests[%i]/4: RTGetOptArgvToString() -> %Rrc", i, rc);
    316408                    RTGetOptArgvFree(papszArgs3);
    317409                }
    318410                else
    319                     RTTestIFailed("g_aBourneTests[%i]/3: RTGetOptArgvFromString() -> %Rrc", i, rc);
     411                    RTTestIFailed("g_aTests[%i]/3: RTGetOptArgvFromString() -> %Rrc", i, rc);
    320412                RTStrFree(pszArgs2);
    321413            }
    322414            else
    323                 RTTestIFailed("g_aBourneTests[%i]/2: RTGetOptArgvToString() -> %Rrc", i, rc);
     415                RTTestIFailed("g_aTests[%i]/2: RTGetOptArgvToString() -> %Rrc", i, rc);
    324416            RTGetOptArgvFree(papszArgs1);
    325417        }
    326418        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    }
    331422}
    332423
     
    375466    }
    376467
    377     for (size_t i = 0; i < RT_ELEMENTS(g_aBourneTests); i++)
     468    for (size_t i = 0; i < RT_ELEMENTS(g_aTests); i++)
    378469    {
    379470        char *pszCmdLine = NULL;
    380         int rc = RTGetOptArgvToString(&pszCmdLine, g_aBourneTests[i].apszArgs, RTGETOPTARGV_CNV_QUOTE_MS_CRT);
     471        int rc = RTGetOptArgvToString(&pszCmdLine, g_aTests[i].apszArgs, RTGETOPTARGV_CNV_QUOTE_MS_CRT);
    381472        RTTESTI_CHECK_RC_RETV(rc, VINF_SUCCESS);
    382         if (!strcmp(g_aBourneTests[i].pszOutMsCrt, pszCmdLine))
    383             tstCheckNativeMsCrtToArgv(pszCmdLine, g_aBourneTests[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);
    384475        else
    385             RTTestIFailed("g_aBourneTests[%i] failed:\n"
     476            RTTestIFailed("g_aTests[%i] failed:\n"
    386477                          " got      |%s|\n"
    387478                          " expected |%s|\n",
    388                           i, pszCmdLine, g_aBourneTests[i].pszOutMsCrt);
     479                          i, pszCmdLine, g_aTests[i].pszOutMsCrt);
    389480        RTStrFree(pszCmdLine);
    390481    }
     
    394485    RTTestISub("RTGetOptArgvToString / BOURNE_SH");
    395486
    396     for (size_t i = 0; i < RT_ELEMENTS(g_aBourneTests); i++)
     487    for (size_t i = 0; i < RT_ELEMENTS(g_aTests); i++)
    397488    {
    398489        char *pszCmdLine = NULL;
    399         int rc = RTGetOptArgvToString(&pszCmdLine, g_aBourneTests[i].apszArgs, RTGETOPTARGV_CNV_QUOTE_BOURNE_SH);
     490        int rc = RTGetOptArgvToString(&pszCmdLine, g_aTests[i].apszArgs, RTGETOPTARGV_CNV_QUOTE_BOURNE_SH);
    400491        RTTESTI_CHECK_RC_RETV(rc, VINF_SUCCESS);
    401         if (strcmp(g_aBourneTests[i].pszOutBourneSh, pszCmdLine))
    402             RTTestIFailed("g_aBourneTests[%i] failed:\n"
     492        if (strcmp(g_aTests[i].pszOutBourneSh, pszCmdLine))
     493            RTTestIFailed("g_aTests[%i] failed:\n"
    403494                          " got      |%s|\n"
    404495                          " expected |%s|\n",
    405                           i, pszCmdLine, g_aBourneTests[i].pszOutBourneSh);
     496                          i, pszCmdLine, g_aTests[i].pszOutBourneSh);
    406497        RTStrFree(pszCmdLine);
    407498    }
     
    413504    char **papszArgs = NULL;
    414505    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);
    416507    RTTESTI_CHECK_RETV(cArgs == 0);
    417508    RTTESTI_CHECK_RETV(papszArgs);
     
    419510    RTGetOptArgvFree(papszArgs);
    420511
    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);
    422514    RTTESTI_CHECK_RETV(cArgs == 12);
    423515    RTTESTI_CHECK_RETV(!strcmp(papszArgs[0], "0"));
     
    436528    RTGetOptArgvFree(papszArgs);
    437529
    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);
    439532    RTTESTI_CHECK_RETV(cArgs == 6);
    440533    RTTESTI_CHECK_RETV(!strcmp(papszArgs[0], " asdf "));
     
    447540    RTGetOptArgvFree(papszArgs);
    448541
    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);
    450544    RTTESTI_CHECK_RETV(cArgs == 6);
    451545    RTTESTI_CHECK_RETV(!strcmp(papszArgs[0], "0"));
     
    458552    RTGetOptArgvFree(papszArgs);
    459553
    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);
    461556    RTTESTI_CHECK_RETV(cArgs == 6);
    462557    RTTESTI_CHECK_RETV(!strcmp(papszArgs[0], "0"));
     
    472567     * Tests from the list.
    473568     */
    474     for (unsigned i = 0; i < RT_ELEMENTS(g_aBourneTests); i++)
     569    for (unsigned i = 0; i < RT_ELEMENTS(g_aTests); i++)
    475570    {
    476571        papszArgs = NULL;
    477572        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);
    479575        if (rc == VINF_SUCCESS)
    480576        {
    481             if (cArgs == g_aBourneTests[i].cArgs)
     577            if (cArgs == g_aTests[i].cArgs)
    482578            {
    483579                for (int iArg = 0; iArg < cArgs; iArg++)
    484                     if (strcmp(papszArgs[iArg], g_aBourneTests[i].apszArgs[iArg]) != 0)
    485                         RTTestIFailed("g_aBourneTests[%i]: argv[%i] differs: got '%s', expected '%s' (RTGetOptArgvFromString(,,'%s', '%s'))",
    486                                       i, iArg, papszArgs[iArg], g_aBourneTests[i].apszArgs[iArg],
    487                                       g_aBourneTests[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);
    488584                RTTESTI_CHECK_RETV(papszArgs[cArgs] == NULL);
    489585            }
    490586            else
    491                 RTTestIFailed("g_aBourneTests[%i]: cArgs=%u, expected %u for RTGetOptArgvFromString(,,'%s', '%s')",
    492                               i, cArgs, g_aBourneTests[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);
    493589            RTGetOptArgvFree(papszArgs);
    494590        }
    495591        else
    496             RTTestIFailed("g_aBourneTests[%i]: RTGetOptArgvFromString(,,'%s', '%s') -> %Rrc",
    497                           i, g_aBourneTests[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);
    498594    }
    499595}
     
    516612    tst1();
    517613    tst2();
     614    tst4();
    518615    tst3();
    519616
  • trunk/src/bldprogs/scm.cpp

    r48958 r55671  
    482482    int    cArgs;
    483483    char **papszArgs;
    484     int rc = RTGetOptArgvFromString(&papszArgs, &cArgs, pszLine, NULL);
     484    int rc = RTGetOptArgvFromString(&papszArgs, &cArgs, pszLine, RTGETOPTARGV_CNV_QUOTE_BOURNE_SH, NULL);
    485485    if (RT_SUCCESS(rc))
    486486    {
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette