VirtualBox

Changeset 26488 in vbox


Ignore:
Timestamp:
Feb 14, 2010 7:08:38 AM (15 years ago)
Author:
vboxsync
Message:

scm: better help, correct defaults, verbose message cleanup.

File:
1 edited

Legend:

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

    r26483 r26488  
    125125typedef SCMSTREAM const *PCSCMSTREAM;
    126126
     127
     128/**
     129 * Rewriter state.
     130 */
     131typedef struct SCMRWSTATE
     132{
     133    /** The filename.  */
     134    const char     *pszFilename;
     135    /** Set after the printing the first verbose message about a file under
     136     *  rewrite. */
     137    bool            fFirst;
     138} SCMRWSTATE;
     139/** Pointer to the rewriter state. */
     140typedef SCMRWSTATE *PSCMRWSTATE;
     141
    127142/**
    128143 * A rewriter.
     
    136151 * @param   pSettings           The settings.
    137152 */
    138 typedef bool (*PFNSCMREWRITER)(PSCMSTREAM pIn, PSCMSTREAM pOut, PCSCMSETTINGSBASE pSettings);
     153typedef bool (*PFNSCMREWRITER)(PSCMRWSTATE pState, PSCMSTREAM pIn, PSCMSTREAM pOut, PCSCMSETTINGSBASE pSettings);
    139154
    140155
     
    298313
    299314
    300 
    301315/*******************************************************************************
    302316*   Internal Functions                                                         *
    303317*******************************************************************************/
    304 static bool rewrite_StripTrailingBlanks(PSCMSTREAM pIn, PSCMSTREAM pOut, PCSCMSETTINGSBASE pSettings);
    305 static bool rewrite_ExpandTabs(PSCMSTREAM pIn, PSCMSTREAM pOut, PCSCMSETTINGSBASE pSettings);
    306 static bool rewrite_ForceNativeEol(PSCMSTREAM pIn, PSCMSTREAM pOut, PCSCMSETTINGSBASE pSettings);
    307 static bool rewrite_ForceLF(PSCMSTREAM pIn, PSCMSTREAM pOut, PCSCMSETTINGSBASE pSettings);
    308 static bool rewrite_ForceCRLF(PSCMSTREAM pIn, PSCMSTREAM pOut, PCSCMSETTINGSBASE pSettings);
    309 static bool rewrite_AdjustTrailingLines(PSCMSTREAM pIn, PSCMSTREAM pOut, PCSCMSETTINGSBASE pSettings);
    310 static bool rewrite_Makefile_kup(PSCMSTREAM pIn, PSCMSTREAM pOut, PCSCMSETTINGSBASE pSettings);
    311 static bool rewrite_Makefile_kmk(PSCMSTREAM pIn, PSCMSTREAM pOut, PCSCMSETTINGSBASE pSettings);
    312 static bool rewrite_C_and_CPP(PSCMSTREAM pIn, PSCMSTREAM pOut, PCSCMSETTINGSBASE pSettings);
     318static bool rewrite_StripTrailingBlanks(PSCMRWSTATE pState, PSCMSTREAM pIn, PSCMSTREAM pOut, PCSCMSETTINGSBASE pSettings);
     319static bool rewrite_ExpandTabs(PSCMRWSTATE pState, PSCMSTREAM pIn, PSCMSTREAM pOut, PCSCMSETTINGSBASE pSettings);
     320static bool rewrite_ForceNativeEol(PSCMRWSTATE pState, PSCMSTREAM pIn, PSCMSTREAM pOut, PCSCMSETTINGSBASE pSettings);
     321static bool rewrite_ForceLF(PSCMRWSTATE pState, PSCMSTREAM pIn, PSCMSTREAM pOut, PCSCMSETTINGSBASE pSettings);
     322static bool rewrite_ForceCRLF(PSCMRWSTATE pState, PSCMSTREAM pIn, PSCMSTREAM pOut, PCSCMSETTINGSBASE pSettings);
     323static bool rewrite_AdjustTrailingLines(PSCMRWSTATE pState, PSCMSTREAM pIn, PSCMSTREAM pOut, PCSCMSETTINGSBASE pSettings);
     324static bool rewrite_Makefile_kup(PSCMRWSTATE pState, PSCMSTREAM pIn, PSCMSTREAM pOut, PCSCMSETTINGSBASE pSettings);
     325static bool rewrite_Makefile_kmk(PSCMRWSTATE pState, PSCMSTREAM pIn, PSCMSTREAM pOut, PCSCMSETTINGSBASE pSettings);
     326static bool rewrite_C_and_CPP(PSCMRWSTATE pState, PSCMSTREAM pIn, PSCMSTREAM pOut, PCSCMSETTINGSBASE pSettings);
    313327
    314328
     
    329343static SCMSETTINGSBASE const g_Defaults =
    330344{
     345    /* .fConvertEol = */            true,
     346    /* .fConvertTabs = */           true,
     347    /* .fForceFinalEol = */         true,
     348    /* .fForceTrailingLine = */     false,
    331349    /* .fStripTrailingBlanks = */   true,
    332350    /* .fStripTrailingLines = */    true,
    333     /* .fForceFinalEol = */         true,
    334     /* .fForceTrailingLine = */     false,
    335     /* .fConvertTabs = */           true,
    336351    /* .cchTab = */                 8,
    337     /* .fConvertEol = */            true,
    338352    /* .pszFilterFiles = */         (char *)"",
    339353    /* .pszFilterOutFiles = */      (char *)"*.exe|*.com|20*-*-*.log",
     
    21772191     */
    21782192    size_t cComponents = RTPathCountComponents(pszPath);
    2179     for (size_t i = 1; i < cComponents; i++)
     2193    for (size_t i = 1; i <= cComponents; i++)
    21802194    {
    21812195        rc = RTPathCopyComponents(szFile, sizeof(szFile), pszPath, i);
     
    23432357 * Prints a verbose message if the level is high enough.
    23442358 *
     2359 * @param   pState              The rewrite state.  Optional.
    23452360 * @param   iLevel              The required verbosity level.
    2346  * @param   pszFormat           The message format string.
     2361 * @param   pszFormat           The message format string.  Can be NULL if we
     2362 *                              only want to trigger the per file message.
    23472363 * @param   ...                 Format arguments.
    23482364 */
    2349 static void ScmVerbose(int iLevel, const char *pszFormat, ...)
     2365static void ScmVerbose(PSCMRWSTATE pState, int iLevel, const char *pszFormat, ...)
    23502366{
    23512367    if (iLevel <= g_iVerbosity)
    23522368    {
    2353         RTPrintf("%s: info: ", g_szProgName);
    2354         va_list va;
    2355         va_start(va, pszFormat);
    2356         RTPrintfV(pszFormat, va);
    2357         va_end(va);
     2369        if (pState && !pState->fFirst)
     2370        {
     2371            RTPrintf("%s: info: Rewriting '%s'...\n", g_szProgName, pState->pszFilename);
     2372            pState->fFirst = true;
     2373        }
     2374        if (pszFormat)
     2375        {
     2376            RTPrintf("%s: info: ", g_szProgName);
     2377            va_list va;
     2378            va_start(va, pszFormat);
     2379            RTPrintfV(pszFormat, va);
     2380            va_end(va);
     2381        }
    23582382    }
    23592383}
     
    23712395 * @param   pSettings           The settings.
    23722396 */
    2373 static bool rewrite_StripTrailingBlanks(PSCMSTREAM pIn, PSCMSTREAM pOut, PCSCMSETTINGSBASE pSettings)
     2397static bool rewrite_StripTrailingBlanks(PSCMRWSTATE pState, PSCMSTREAM pIn, PSCMSTREAM pOut, PCSCMSETTINGSBASE pSettings)
    23742398{
    23752399    if (!pSettings->fStripTrailingBlanks)
     
    23982422    }
    23992423    if (fModified)
    2400         ScmVerbose(2, " * Stripped trailing blanks\n");
     2424        ScmVerbose(pState, 2, " * Stripped trailing blanks\n");
    24012425    return fModified;
    24022426}
     
    24102434 * @param   pSettings           The settings.
    24112435 */
    2412 static bool rewrite_ExpandTabs(PSCMSTREAM pIn, PSCMSTREAM pOut, PCSCMSETTINGSBASE pSettings)
     2436static bool rewrite_ExpandTabs(PSCMRWSTATE pState, PSCMSTREAM pIn, PSCMSTREAM pOut, PCSCMSETTINGSBASE pSettings)
    24132437{
    24142438    if (!pSettings->fConvertTabs)
     
    24562480    }
    24572481    if (fModified)
    2458         ScmVerbose(2, " * Expanded tabs\n");
     2482        ScmVerbose(pState, 2, " * Expanded tabs\n");
    24592483    return fModified;
    24602484}
     
    24692493 * @param   enmDesiredEol       The desired end of line indicator type.
    24702494 */
    2471 static bool rewrite_ForceEol(PSCMSTREAM pIn, PSCMSTREAM pOut, PCSCMSETTINGSBASE pSettings, SCMEOL enmDesiredEol)
     2495static bool rewrite_ForceEol(PSCMRWSTATE pState, PSCMSTREAM pIn, PSCMSTREAM pOut, PCSCMSETTINGSBASE pSettings, SCMEOL enmDesiredEol)
    24722496{
    24732497    if (!pSettings->fConvertEol)
     
    24912515    }
    24922516    if (fModified)
    2493         ScmVerbose(2, " * Converted EOL markers\n");
     2517        ScmVerbose(pState, 2, " * Converted EOL markers\n");
    24942518    return fModified;
    24952519}
     
    25032527 * @param   pSettings           The settings.
    25042528 */
    2505 static bool rewrite_ForceNativeEol(PSCMSTREAM pIn, PSCMSTREAM pOut, PCSCMSETTINGSBASE pSettings)
     2529static bool rewrite_ForceNativeEol(PSCMRWSTATE pState, PSCMSTREAM pIn, PSCMSTREAM pOut, PCSCMSETTINGSBASE pSettings)
    25062530{
    25072531#if defined(RT_OS_WINDOWS) || defined(RT_OS_OS2)
    2508     return rewrite_ForceEol(pIn, pOut, pSettings, SCMEOL_CRLF);
     2532    return rewrite_ForceEol(pState, pIn, pOut, pSettings, SCMEOL_CRLF);
    25092533#else
    2510     return rewrite_ForceEol(pIn, pOut, pSettings, SCMEOL_LF);
     2534    return rewrite_ForceEol(pState, pIn, pOut, pSettings, SCMEOL_LF);
    25112535#endif
    25122536}
     
    25202544 * @param   pSettings           The settings.
    25212545 */
    2522 static bool rewrite_ForceLF(PSCMSTREAM pIn, PSCMSTREAM pOut, PCSCMSETTINGSBASE pSettings)
    2523 {
    2524     return rewrite_ForceEol(pIn, pOut, pSettings, SCMEOL_LF);
     2546static bool rewrite_ForceLF(PSCMRWSTATE pState, PSCMSTREAM pIn, PSCMSTREAM pOut, PCSCMSETTINGSBASE pSettings)
     2547{
     2548    return rewrite_ForceEol(pState, pIn, pOut, pSettings, SCMEOL_LF);
    25252549}
    25262550
     
    25332557 * @param   pSettings           The settings.
    25342558 */
    2535 static bool rewrite_ForceCRLF(PSCMSTREAM pIn, PSCMSTREAM pOut, PCSCMSETTINGSBASE pSettings)
    2536 {
    2537     return rewrite_ForceEol(pIn, pOut, pSettings, SCMEOL_CRLF);
     2559static bool rewrite_ForceCRLF(PSCMRWSTATE pState, PSCMSTREAM pIn, PSCMSTREAM pOut, PCSCMSETTINGSBASE pSettings)
     2560{
     2561    return rewrite_ForceEol(pState, pIn, pOut, pSettings, SCMEOL_CRLF);
    25382562}
    25392563
     
    25492573 * @remarks ASSUMES trailing white space has been removed already.
    25502574 */
    2551 static bool rewrite_AdjustTrailingLines(PSCMSTREAM pIn, PSCMSTREAM pOut, PCSCMSETTINGSBASE pSettings)
     2575static bool rewrite_AdjustTrailingLines(PSCMRWSTATE pState, PSCMSTREAM pIn, PSCMSTREAM pOut, PCSCMSETTINGSBASE pSettings)
    25522576{
    25532577    if (   !pSettings->fStripTrailingLines
     
    26042628    }
    26052629
    2606     ScmVerbose(2, " * Adjusted trailing blank lines\n");
     2630    ScmVerbose(pState, 2, " * Adjusted trailing blank lines\n");
    26072631    return true;
    26082632}
     
    26162640 * @param   pSettings           The settings.
    26172641 */
    2618 static bool rewrite_Makefile_kup(PSCMSTREAM pIn, PSCMSTREAM pOut, PCSCMSETTINGSBASE pSettings)
     2642static bool rewrite_Makefile_kup(PSCMRWSTATE pState, PSCMSTREAM pIn, PSCMSTREAM pOut, PCSCMSETTINGSBASE pSettings)
    26192643{
    26202644    /* These files should be zero bytes. */
    26212645    if (pIn->cb == 0)
    26222646        return false;
    2623     ScmVerbose(2, " * Truncated file to zero bytes\n");
     2647    ScmVerbose(pState, 2, " * Truncated file to zero bytes\n");
    26242648    return true;
    26252649}
     
    26392663 *      - line continuation slashes should only be preceeded by one space.
    26402664 */
    2641 static bool rewrite_Makefile_kmk(PSCMSTREAM pIn, PSCMSTREAM pOut, PCSCMSETTINGSBASE pSettings)
     2665static bool rewrite_Makefile_kmk(PSCMRWSTATE pState, PSCMSTREAM pIn, PSCMSTREAM pOut, PCSCMSETTINGSBASE pSettings)
    26422666{
    26432667    return false;
     
    26742698 *      - space between functions.
    26752699 */
    2676 static bool rewrite_C_and_CPP(PSCMSTREAM pIn, PSCMSTREAM pOut, PCSCMSETTINGSBASE pSettings)
     2700static bool rewrite_C_and_CPP(PSCMRWSTATE pState, PSCMSTREAM pIn, PSCMSTREAM pOut, PCSCMSETTINGSBASE pSettings)
    26772701{
    26782702
     
    26972721{
    26982722    /*
     2723     * Init the rewriter state data.
     2724     */
     2725    SCMRWSTATE State;
     2726    State.fFirst      = false;
     2727    State.pszFilename = pszFilename;
     2728
     2729    /*
    26992730     * Do the file level filtering.
    27002731     */
     
    27032734        && !RTStrSimplePatternMultiMatch(pBaseSettings->pszFilterFiles, RTSTR_MAX, pszBasename, cchBasename, NULL))
    27042735    {
    2705         ScmVerbose(4, "file filter mismatch: \"%s\"\n", pszFilename);
     2736        ScmVerbose(NULL, 5, "file filter mismatch: \"%s\"\n", pszFilename);
    27062737        return VINF_SUCCESS;
    27072738    }
     
    27112742            || RTStrSimplePatternMultiMatch(pBaseSettings->pszFilterOutFiles, RTSTR_MAX, pszFilename, RTSTR_MAX, NULL)) )
    27122743    {
    2713         ScmVerbose(4, "file filter out: \"%s\"\n", pszFilename);
     2744        ScmVerbose(NULL, 5, "file filter out: \"%s\"\n", pszFilename);
    27142745        return VINF_SUCCESS;
    27152746    }
     
    27272758    if (!pCfg)
    27282759    {
    2729         ScmVerbose(3, "No rewriters configured for \"%s\"\n", pszFilename);
     2760        ScmVerbose(NULL, 4, "No rewriters configured for \"%s\"\n", pszFilename);
    27302761        return VINF_SUCCESS;
    27312762    }
    2732     ScmVerbose(3, "\"%s\" matched \"%s\"\n", pszFilename, pCfg->pszFilePattern);
     2763    ScmVerbose(&State, 4, "matched \"%s\"\n", pCfg->pszFilePattern);
    27332764
    27342765    /*
     
    27442775    if (ScmStreamIsText(&Stream1))
    27452776    {
    2746         ScmVerbose(1, "Processing '%s'...\n", pszFilename);
     2777        ScmVerbose(&State, 3, NULL);
    27472778
    27482779        /*
     
    27722803                    for (size_t iRw = 0; iRw < pCfg->cRewriters; iRw++)
    27732804                    {
    2774                         bool fRc = pCfg->papfnRewriter[iRw](pIn, pOut, pBaseSettings);
     2805                        bool fRc = pCfg->papfnRewriter[iRw](&State, pIn, pOut, pBaseSettings);
    27752806                        if (fRc)
    27762807                        {
     
    27912822                        if (!g_fDryRun)
    27922823                        {
    2793                             ScmVerbose(1, "Writing modified file to \"%s%s\"\n", pszFilename, g_pszChangedSuff);
     2824                            ScmVerbose(&State, 1, "Writing modified file to \"%s%s\"\n", pszFilename, g_pszChangedSuff);
    27942825                            rc = ScmStreamWriteToFile(pIn, "%s%s", pszFilename, g_pszChangedSuff);
    27952826                            if (RT_FAILURE(rc))
     
    27982829                        else
    27992830                        {
    2800                             ScmVerbose(1, "Would have modified file \"%s\"\n", pszFilename);
     2831                            ScmVerbose(&State, 1, NULL);
    28012832                            ScmDiffStreams(pszFilename, &Stream1, pIn, g_fDiffIgnoreEol, g_fDiffIgnoreLeadingWS,
    28022833                                           g_fDiffIgnoreTrailingWS, g_fDiffSpecialChars, pBaseSettings->cchTab, g_pStdOut);
     2834                            ScmVerbose(&State, 3, "Would have modified the file \"%s%s\"\n", pszFilename, g_pszChangedSuff);
    28032835                        }
    28042836                    }
    28052837                    else
    2806                         ScmVerbose(2, "Unchanged \"%s\"\n", pszFilename);
     2838                        ScmVerbose(&State, 3, "No change\n", pszFilename);
    28072839
    28082840                    ScmStreamDelete(&Stream3);
     
    28192851    }
    28202852    else
    2821         ScmVerbose(3, "not text file: \"%s\"\n", pszFilename);
     2853        ScmVerbose(&State, 4, "not text file: \"%s\"\n", pszFilename);
    28222854    ScmStreamDelete(&Stream1);
    28232855
     
    30723104     * thing that works at the moment).
    30733105     */
    3074     static RTGETOPTDEF s_aOpts[16 + RT_ELEMENTS(g_aScmOpts)] =
     3106    static RTGETOPTDEF s_aOpts[14 + RT_ELEMENTS(g_aScmOpts)] =
    30753107    {
    30763108        { "--dry-run",                          'd',                                    RTGETOPT_REQ_NOTHING },
    30773109        { "--real-run",                         'D',                                    RTGETOPT_REQ_NOTHING },
    30783110        { "--file-filter",                      'f',                                    RTGETOPT_REQ_STRING  },
    3079         { "--help",                             'h',                                    RTGETOPT_REQ_NOTHING },
    30803111        { "--quiet",                            'q',                                    RTGETOPT_REQ_NOTHING },
    30813112        { "--verbose",                          'v',                                    RTGETOPT_REQ_NOTHING },
    3082         { "--version",                          'V',                                    RTGETOPT_REQ_NOTHING },
    30833113        { "--diff-ignore-eol",                  SCMOPT_DIFF_IGNORE_EOL,                 RTGETOPT_REQ_NOTHING },
    30843114        { "--diff-no-ignore-eol",               SCMOPT_DIFF_NO_IGNORE_EOL,              RTGETOPT_REQ_NOTHING },
     
    30963126    RTGETOPTUNION   ValueUnion;
    30973127    RTGETOPTSTATE   GetOptState;
    3098     rc = RTGetOptInit(&GetOptState, argc, argv, &s_aOpts[0], RT_ELEMENTS(s_aOpts), 1, 0 /*fFlags*/);
     3128    rc = RTGetOptInit(&GetOptState, argc, argv, &s_aOpts[0], RT_ELEMENTS(s_aOpts), 1, RTGETOPTINIT_FLAGS_OPTS_FIRST);
    30993129    AssertReleaseRCReturn(rc, 1);
    31003130    size_t          cProcessed = 0;
     
    31233153                         "Options:\n", g_szProgName);
    31243154                for (size_t i = 0; i < RT_ELEMENTS(s_aOpts); i++)
     3155                {
     3156                    bool fAdvanceTwo = false;
    31253157                    if ((s_aOpts[i].fFlags & RTGETOPT_REQ_MASK) == RTGETOPT_REQ_NOTHING)
    3126                         RTPrintf("  %s\n", s_aOpts[i].pszLong);
     3158                    {
     3159                        if ((fAdvanceTwo = i + 1 < RT_ELEMENTS(s_aOpts) && strstr(s_aOpts[i+1].pszLong, "-no-") != NULL))
     3160                            RTPrintf("  %s, %s\n", s_aOpts[i].pszLong, s_aOpts[i + 1].pszLong);
     3161                        else
     3162                            RTPrintf("  %s\n", s_aOpts[i].pszLong);
     3163                    }
    31273164                    else if ((s_aOpts[i].fFlags & RTGETOPT_REQ_MASK) == RTGETOPT_REQ_STRING)
    31283165                        RTPrintf("  %s string\n", s_aOpts[i].pszLong);
    31293166                    else
    31303167                        RTPrintf("  %s value\n", s_aOpts[i].pszLong);
     3168                    switch (s_aOpts[i].iShort)
     3169                    {
     3170                        case SCMOPT_CONVERT_EOL:            RTPrintf("      Default: %RTbool\n", g_Defaults.fConvertEol); break;
     3171                        case SCMOPT_CONVERT_TABS:           RTPrintf("      Default: %RTbool\n", g_Defaults.fConvertTabs); break;
     3172                        case SCMOPT_FORCE_FINAL_EOL:        RTPrintf("      Default: %RTbool\n", g_Defaults.fForceFinalEol); break;
     3173                        case SCMOPT_FORCE_TRAILING_LINE:    RTPrintf("      Default: %RTbool\n", g_Defaults.fForceTrailingLine); break;
     3174                        case SCMOPT_STRIP_TRAILING_BLANKS:  RTPrintf("      Default: %RTbool\n", g_Defaults.fStripTrailingBlanks); break;
     3175                        case SCMOPT_STRIP_TRAILING_LINES:   RTPrintf("      Default: %RTbool\n", g_Defaults.fStripTrailingLines); break;
     3176                        case SCMOPT_TAB_SIZE:               RTPrintf("      Default: %u\n", g_Defaults.cchTab); break;
     3177                        case SCMOPT_FILTER_OUT_DIRS:        RTPrintf("      Default: %s\n", g_Defaults.pszFilterOutDirs); break;
     3178                        case SCMOPT_FILTER_FILES:           RTPrintf("      Default: %s\n", g_Defaults.pszFilterFiles); break;
     3179                        case SCMOPT_FILTER_OUT_FILES:       RTPrintf("      Default: %s\n", g_Defaults.pszFilterOutFiles); break;
     3180                    }
     3181                    i += fAdvanceTwo;
     3182                }
    31313183                return 1;
    31323184
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