VirtualBox

Changeset 2747 in kBuild for trunk/src


Ignore:
Timestamp:
Jan 23, 2015 12:52:55 AM (10 years ago)
Author:
bird
Message:

redirect.c: Work around non-standard quoting rules for a bunch of (open) watcom tools.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/kmk/kmkbuiltin/redirect.c

    r2728 r2747  
    6060 * Arguments": http://msdn.microsoft.com/en-us/library/a1y7w461.aspx
    6161 *
    62  * @param   argc        The argument count.
    63  * @param   argv        The argument vector.
     62 * @param   argc                The argument count.
     63 * @param   argv                The argument vector.
     64 * @param   fWatcomBrainDamage  Set if we're catering for wcc, wcc386 or similar
     65 *                              OpenWatcom tools.  They seem to follow some
     66 *                              ancient or home made quoting convention.
    6467 */
    65 static void quoteArguments(int argc, char **argv)
     68static void quoteArguments(int argc, char **argv, int fWatcomBrainDamage)
    6669{
    6770    int i;
     
    7174        size_t      cchOrg    = strlen(pszOrg);
    7275        const char *pszQuotes = (const char *)memchr(pszOrg, '"', cchOrg);
     76        const char *pszProblem = NULL;
    7377        if (   pszQuotes
    7478            || cchOrg == 0
    75             || memchr(pszOrg, ' ', cchOrg)
    76             || memchr(pszOrg, '\t', cchOrg)
    77             || memchr(pszOrg, '\n', cchOrg)
    78             || memchr(pszOrg, '\r', cchOrg)
    79             || memchr(pszOrg, '&', cchOrg)
    80             || memchr(pszOrg, '>', cchOrg)
    81             || memchr(pszOrg, '<', cchOrg)
    82             || memchr(pszOrg, '|', cchOrg)
    83             || memchr(pszOrg, '%', cchOrg)
    84             || memchr(pszOrg, '\'', cchOrg)
    85             || memchr(pszOrg, '=', cchOrg)
     79            || (pszProblem = (const char *)memchr(pszOrg, ' ',  cchOrg)) != NULL
     80            || (pszProblem = (const char *)memchr(pszOrg, '\t', cchOrg)) != NULL
     81            || (pszProblem = (const char *)memchr(pszOrg, '\n', cchOrg)) != NULL
     82            || (pszProblem = (const char *)memchr(pszOrg, '\r', cchOrg)) != NULL
     83            || (pszProblem = (const char *)memchr(pszOrg, '&',  cchOrg)) != NULL
     84            || (pszProblem = (const char *)memchr(pszOrg, '>',  cchOrg)) != NULL
     85            || (pszProblem = (const char *)memchr(pszOrg, '<',  cchOrg)) != NULL
     86            || (pszProblem = (const char *)memchr(pszOrg, '|',  cchOrg)) != NULL
     87            || (pszProblem = (const char *)memchr(pszOrg, '%',  cchOrg)) != NULL
     88            || (pszProblem = (const char *)memchr(pszOrg, '\'', cchOrg)) != NULL
     89            || (pszProblem = (const char *)memchr(pszOrg, '=',  cchOrg)) != NULL
    8690            )
    8791        {
     
    9296
    9397            argv[i] = pszNew;
     98
     99            /* Watcom does not grok "-i=c:\program files\watcom\h", it thing
     100               it's a source specification. The quote must follow the equal. */
     101            if (fWatcomBrainDamage)
     102            {
     103                size_t cchUnquoted  = 0;
     104                if (pszOrg[0] == '@') /* Response file quoting: @"file name.rsp" */
     105                    cchUnquoted = 1;
     106                else if (pszOrg[0] == '-' || pszOrg[0] == '/') /* Switch quoting. */
     107                {
     108                    const char *pszNeedQuoting = (const char *)memchr(pszOrg, '=', cchOrg);
     109                    if (   pszNeedQuoting == NULL
     110                        || (uintptr_t)pszNeedQuoting > (uintptr_t)(pszProblem ? pszProblem : pszQuotes))
     111                        pszNeedQuoting = pszProblem ? pszProblem : pszQuotes;
     112                    else
     113                        pszNeedQuoting++;
     114                    cchUnquoted = pszNeedQuoting - pszOrg;
     115                }
     116                if (cchUnquoted)
     117                {
     118                    memcpy(pszNew, pszOrg, cchUnquoted);
     119                    pszNew += cchUnquoted;
     120                    pszOrg += cchUnquoted;
     121                    cchOrg -= cchUnquoted;
     122                }
     123            }
    94124
    95125            *pszNew++ = '"';
     
    188218{
    189219    fprintf(pOut,
    190             "usage: %s [-[rwa+tb]<fd> <file>] [-c<fd>] [-Z] [-E <var=val>] [-C <dir>] -- <program> [args]\n"
     220            "usage: %s [-[rwa+tb]<fd> <file>] [-c<fd>] [-Z] [-E <var=val>] [-C <dir>] [--wcc-brain-damage] -- <program> [args]\n"
    191221            "   or: %s --help\n"
    192222            "   or: %s --version\n"
     
    208238            "effect, so be careful where you put it.\n"
    209239            "\n"
     240            "The --wcc-brain-damage switch is to work around wcc and wcc386 (Open Watcom)\n"
     241            "not following normal quoting conventions on Windows, OS/2, and DOS.\n"
     242            "\n"
    210243            "This command was originally just a quick hack to avoid invoking the shell\n"
    211244            "on Windows (cygwin) where forking is very expensive and has exhibited\n"
     
    226259    FILE *pStdErr = stderr;
    227260    FILE *pStdOut = stdout;
     261    int fWatcomBrainDamage = 0;
    228262
    229263    /*
     
    262296                else if (!strcmp(psz, "-close"))
    263297                    psz = "c";
     298                else if (!strcmp(psz, "-wcc-brain-damage"))
     299                {
     300                    fWatcomBrainDamage = 1;
     301                    continue;
     302                }
    264303            }
    265304
     
    710749
    711750    /* MSC is a PITA since it refuses to quote the arguments... */
    712     quoteArguments(argc - i, &argv[i]);
     751    quoteArguments(argc - i, &argv[i], fWatcomBrainDamage);
    713752    rc = _spawnvp(_P_WAIT, argv[i], &argv[i]);
    714753    if (rc == -1 && pStdErr)
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