VirtualBox

Ignore:
Timestamp:
Apr 28, 2015 7:18:15 PM (10 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
99844
Message:

Tought RTGetOptArgvFromString about escapes and fixed some RTGetOptArgvToString quoting table bugs.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/common/misc/getoptargv.cpp

    r44529 r55494  
    4747 * require quoting of.
    4848 */
    49 static uint8_t const g_abmQuoteChars[RTGETOPTARGV_CNV_QUOTE_MASK + 1][128/8] =
    50 {
    51     { 0xfe, 0xff, 0x0f, 0x00, 0x65, 0x00, 0x00, 0x50 },
    52     { 0xfe, 0xff, 0x0f, 0x00, 0xd7, 0x07, 0x00, 0xd8 },
     49static uint8_t
     50#ifndef IPRT_REGENERATE_QUOTE_CHARS
     51const
     52#endif
     53g_abmQuoteChars[RTGETOPTARGV_CNV_QUOTE_MASK + 1][16] =
     54{
     55    { 0xfe, 0xff, 0xff, 0xff, 0x65, 0x00, 0x00, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10 },
     56    { 0xfe, 0xff, 0xff, 0xff, 0xd7, 0x07, 0x00, 0xd8, 0x00, 0x00, 0x00, 0x18, 0x01, 0x00, 0x00, 0x50 },
    5357};
    5458
    5559
    56 #if 0   /* To re-generate the bitmaps. */
    57 #include <stdio.h>
     60#ifdef IPRT_REGENERATE_QUOTE_CHARS   /* To re-generate the bitmaps. */
     61# include <stdio.h>
    5862int main()
    5963{
     
    6670        } while (0)
    6771# define SET(ConstSuffix, ch) \
    68         ASMBitSet(&g_abmQuoteChars[RTGETOPTARGV_CNV_QUOTE_##ConstSuffix], (ch));
     72        do { \
     73            ASMBitSet(&g_abmQuoteChars[RTGETOPTARGV_CNV_QUOTE_##ConstSuffix], (ch)); \
     74            printf(#ConstSuffix ": %#x %d %c\n", (ch), (ch), (ch)); \
     75        } while (0)
    6976
    7077    /* just flag all the control chars as in need of quoting. */
     
    7683
    7784    /* MS CRT / CMD.EXE: */
    78     SET(MS_CRT, '"')
    79     SET(MS_CRT, '&')
    80     SET(MS_CRT, '>')
    81     SET(MS_CRT, '<')
    82     SET(MS_CRT, '|')
    83     SET(MS_CRT, '%')
     85    SET(MS_CRT, '"');
     86    SET(MS_CRT, '&');
     87    SET(MS_CRT, '>');
     88    SET(MS_CRT, '<');
     89    SET(MS_CRT, '|');
     90    SET(MS_CRT, '%');
    8491
    8592    /* Bourne shell: */
     
    105112    {
    106113        printf("    {");
    107         for (size_t iByte = 0; iByte < 8; iByte++)
     114        for (size_t iByte = 0; iByte < 16; iByte++)
    108115            printf(iByte == 0 ? " 0x%02x" : ", 0x%02x", g_abmQuoteChars[iType][iByte]);
    109116        printf(" },\n");
     
    111118    return 0;
    112119}
    113 #endif /* To re-generate the bitmaps. */
    114 
     120
     121#else /* !IPRT_REGENERATE_QUOTE_CHARS */
    115122
    116123/**
     
    262269        papszArgs[iArg++] = pszDst;
    263270
    264         /* Parse and copy the string over. */
     271        /*
     272         * Parse and copy the string over.
     273         */
    265274        RTUNICP CpQuote = 0;
    266275        RTUNICP Cp;
     
    276285                else if (rtGetOptIsCpInSet(Cp, pszSeparators, cchSeparators))
    277286                    break;
     287                else if (Cp != '\\')
     288                    pszDst = RTStrPutCp(pszDst, Cp);
    278289                else
     290                {
     291                    /* escaped char */
     292                    rc = RTStrGetCpEx(&pszSrc, &Cp);
     293                    if (RT_FAILURE(rc) || !Cp)
     294                        break;
    279295                    pszDst = RTStrPutCp(pszDst, Cp);
     296                }
    280297            }
    281298            else if (CpQuote != Cp)
    282                 pszDst = RTStrPutCp(pszDst, 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            }
    283311            else
    284312                CpQuote = 0;
     
    511539}
    512540
     541#endif  /* !IPRT_REGENERATE_QUOTE_CHARS */
     542
Note: See TracChangeset for help on using the changeset viewer.

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