VirtualBox

Changeset 69493 in vbox for trunk/src/bldprogs


Ignore:
Timestamp:
Oct 28, 2017 2:47:09 PM (7 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
118832
Message:

scm: Added --del-action option.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bldprogs/scm.cpp

    r69486 r69493  
    108108    SCMOPT_TREAT_AS,
    109109    SCMOPT_ADD_ACTION,
    110     SCMOPT_LAST_SETTINGS = SCMOPT_ADD_ACTION,
     110    SCMOPT_DEL_ACTION,
     111    SCMOPT_LAST_SETTINGS = SCMOPT_DEL_ACTION,
    111112    //
    112113    SCMOPT_DIFF_IGNORE_EOL,
     
    243244    { "--treat-as",                         SCMOPT_TREAT_AS,                        RTGETOPT_REQ_STRING  },
    244245    { "--add-action",                       SCMOPT_ADD_ACTION,                      RTGETOPT_REQ_STRING  },
     246    { "--del-action",                       SCMOPT_DEL_ACTION,                      RTGETOPT_REQ_STRING  },
    245247
    246248    /* Additional help */
     
    665667    SCM_CFG_ENTRY("iasl",       g_apRewritersFor_DSL,              false, "*.dsl" ),
    666668    SCM_CFG_ENTRY("shell",      g_apRewritersFor_ShellScripts,     false, "*.sh|configure" ),
    667     SCM_CFG_ENTRY("bat",        g_apRewritersFor_BatchFiles,       false, "*.bat|*.cmd|*.btm" ),
     669    SCM_CFG_ENTRY("batch",      g_apRewritersFor_BatchFiles,       false, "*.bat|*.cmd|*.btm" ),
    668670    SCM_CFG_ENTRY("vbs",        g_apRewritersFor_BasicScripts,     false, "*.vbs|*.vb" ),
    669671    SCM_CFG_ENTRY("sed",        g_apRewritersFor_SedScripts,       false, "*.sed" ),
     
    697699/* -=-=-=-=-=- settings -=-=-=-=-=- */
    698700
     701/**
     702 * Delete the given config entry.
     703 *
     704 * @param   pEntry              The configuration entry to delete.
     705 */
    699706static void scmCfgEntryDelete(PSCMCFGENTRY pEntry)
    700707{
     
    704711}
    705712
    706 static PSCMCFGENTRY scmCfgEntryDup(PCSCMCFGENTRY pEntry)
    707 {
    708     PSCMCFGENTRY pDup = (PSCMCFGENTRY)RTMemDup(pEntry, sizeof(*pEntry));
    709     if (pDup)
    710     {
    711         size_t    cbRewriters = sizeof(pEntry->paRewriters[0]) * RT_ALIGN_Z(pEntry->cRewriters, 8);
    712         pDup->paRewriters = (PCSCMREWRITERCFG const *)RTMemDup(pEntry->paRewriters, cbRewriters);
    713         if (pDup->paRewriters)
    714             return pDup;
    715 
    716         RTMemFree(pDup);
    717     }
    718     return NULL;
    719 }
    720 
    721 #if 0
     713/**
     714 * Create a new configuration entry.
     715 *
     716 * @returns The new entry. NULL if out of memory.
     717 * @param   pEntry              The configuration entry to duplicate.
     718 */
    722719static PSCMCFGENTRY scmCfgEntryNew(void)
    723720{
     
    733730    return pNew;
    734731}
    735 #endif
    736 
    737 static int scmCfgEntryAddAction(PSCMCFGENTRY pEntry, PCSCMREWRITERCFG pActions)
     732
     733/**
     734 * Duplicate the given config entry.
     735 *
     736 * @returns The duplicate. NULL if out of memory.
     737 * @param   pEntry              The configuration entry to duplicate.
     738 */
     739static PSCMCFGENTRY scmCfgEntryDup(PCSCMCFGENTRY pEntry)
     740{
     741    if (pEntry)
     742    {
     743        PSCMCFGENTRY pDup = (PSCMCFGENTRY)RTMemDup(pEntry, sizeof(*pEntry));
     744        if (pDup)
     745        {
     746            size_t    cbRewriters = sizeof(pEntry->paRewriters[0]) * RT_ALIGN_Z(pEntry->cRewriters, 8);
     747            pDup->paRewriters = (PCSCMREWRITERCFG const *)RTMemDup(pEntry->paRewriters, cbRewriters);
     748            if (pDup->paRewriters)
     749                return pDup;
     750
     751            RTMemFree(pDup);
     752        }
     753        return NULL;
     754    }
     755    return scmCfgEntryNew();
     756}
     757
     758/**
     759 * Adds a rewriter action to the given config entry (--add-action).
     760 *
     761 * @returns VINF_SUCCESS.
     762 * @param   pEntry              The configuration entry.
     763 * @param   pAction             The rewriter action to add.
     764 */
     765static int scmCfgEntryAddAction(PSCMCFGENTRY pEntry, PCSCMREWRITERCFG pAction)
    738766{
    739767    PCSCMREWRITERCFG *paRewriters = (PCSCMREWRITERCFG *)pEntry->paRewriters;
    740     if ((pEntry->cRewriters + 1) % 8 == 0)
     768    if (pEntry->cRewriters % 8 == 0)
    741769    {
    742770        size_t cbRewriters = sizeof(pEntry->paRewriters[0]) * RT_ALIGN_Z((pEntry->cRewriters + 1), 8);
     
    748776    }
    749777
    750     paRewriters[pEntry->cRewriters++] = pActions;
     778    paRewriters[pEntry->cRewriters++] = pAction;
    751779    return VINF_SUCCESS;
     780}
     781
     782/**
     783 * Delets an rewriter action from the given config entry (--del-action).
     784 *
     785 * @param   pEntry              The configuration entry.
     786 * @param   pAction             The rewriter action to remove.
     787 */
     788static void scmCfgEntryDelAction(PSCMCFGENTRY pEntry, PCSCMREWRITERCFG pAction)
     789{
     790    PCSCMREWRITERCFG *paRewriters = (PCSCMREWRITERCFG *)pEntry->paRewriters;
     791    size_t const cEntries = pEntry->cRewriters;
     792    size_t       iDst = 0;
     793    for (size_t iSrc = 0; iSrc < cEntries; iSrc++)
     794    {
     795        PCSCMREWRITERCFG pCurAction = paRewriters[iSrc];
     796        if (pCurAction == pAction)
     797            paRewriters[iDst++] = pAction;
     798    }
     799    pEntry->cRewriters = iDst;
    752800}
    753801
     
    11261174            RTMsgError("Unknown --add-action value '%s'.  Try --help-actions for a list.", pValueUnion->psz);
    11271175            return VERR_NOT_FOUND;
     1176
     1177        case SCMOPT_DEL_ACTION:
     1178        {
     1179            uint32_t cActions = 0;
     1180            for (uint32_t iAction = 0; iAction < RT_ELEMENTS(g_papRewriterActions); iAction++)
     1181                if (RTStrSimplePatternMatch(pValueUnion->psz, g_papRewriterActions[iAction]->pszName))
     1182                {
     1183                    cActions++;
     1184                    PSCMCFGENTRY pEntry = (PSCMCFGENTRY)pSettings->pTreatAs;
     1185                    if (!pSettings->fFreeTreatAs)
     1186                    {
     1187                        pEntry = scmCfgEntryDup(pEntry);
     1188                        if (!pEntry)
     1189                            return VERR_NO_MEMORY;
     1190                        pSettings->pTreatAs = pEntry;
     1191                        pSettings->fFreeTreatAs = true;
     1192                    }
     1193                    scmCfgEntryDelAction(pEntry, g_papRewriterActions[iAction]);
     1194                    if (!strchr(pValueUnion->psz, '*'))
     1195                        return VINF_SUCCESS;
     1196                }
     1197            if (cActions > 0)
     1198                return VINF_SUCCESS;
     1199            RTMsgError("Unknown --del-action value '%s'.  Try --help-actions for a list.", pValueUnion->psz);
     1200            return VERR_NOT_FOUND;
     1201        }
    11281202
    11291203        default:
     
    24932567        }
    24942568        else if ((paOpts[i].fFlags & RTGETOPT_REQ_MASK) == RTGETOPT_REQ_STRING)
    2495             RTPrintf("  %s string\n", paOpts[i].pszLong);
     2569            switch (paOpts[i].iShort)
     2570            {
     2571                case SCMOPT_DEL_ACTION:
     2572                    RTPrintf("  %s pattern\n", paOpts[i].pszLong);
     2573                    break;
     2574                case SCMOPT_FILTER_OUT_DIRS:
     2575                case SCMOPT_FILTER_FILES:
     2576                case SCMOPT_FILTER_OUT_FILES:
     2577                    RTPrintf("  %s multi-pattern\n", paOpts[i].pszLong);
     2578                    break;
     2579                default:
     2580                    RTPrintf("  %s string\n", paOpts[i].pszLong);
     2581            }
    24962582        else
    24972583            RTPrintf("  %s value\n", paOpts[i].pszLong);
     
    25612647                         "      the action list selected by the --treat-as.  The actuion list will be\n"
    25622648                         "      flushed by --treat-as.\n");
     2649                break;
     2650
     2651            case SCMOPT_DEL_ACTION:
     2652                RTPrintf("      Deletes one or more rewriter action (pattern). Best used after\n"
     2653                         "      a --treat-as.\n");
    25632654                break;
    25642655
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