scm.cpp revision 56689b5c06781615da91826b9f9df665826a0b92
/* $Id$ */
/** @file
* IPRT Testcase / Tool - Source Code Massager.
*/
/*
* Copyright (C) 2010 Sun Microsystems, Inc.
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*
* The contents of this file may alternatively be used under the terms
* of the Common Development and Distribution License Version 1.0
* (CDDL) only, as it comes in the "COPYING.CDDL" file of the
* VirtualBox OSE distribution, in which case the provisions of the
* CDDL are applicable instead of those of the GPL.
*
* You may elect to license modified versions of this file under the
* terms and conditions of either the GPL or the CDDL or both.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
* Clara, CA 95054 USA or visit http://www.sun.com if you need
* additional information or have any questions.
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
#include <iprt/initterm.h>
/*******************************************************************************
* Defined Constants And Macros *
*******************************************************************************/
/** The name of the settings files. */
#define SCM_SETTINGS_FILENAME ".scm-settings"
/*******************************************************************************
* Structures and Typedefs *
*******************************************************************************/
/** Pointer to const massager settings. */
typedef struct SCMSETTINGSBASE const *PCSCMSETTINGSBASE;
/** End of line marker type. */
typedef enum SCMEOL
{
SCMEOL_NONE = 0,
SCMEOL_LF = 1,
SCMEOL_CRLF = 2
} SCMEOL;
/** Pointer to an end of line marker type. */
/**
* Line record.
*/
typedef struct SCMSTREAMLINE
{
/** The offset of the line. */
/** The line length, excluding the LF character.
* @todo This could be derived from the offset of the next line if that wasn't
* so tedious. */
/** The end of line marker type. */
/** Pointer to a line record. */
typedef SCMSTREAMLINE *PSCMSTREAMLINE;
/**
* Source code massager stream.
*/
typedef struct SCMSTREAM
{
/** Pointer to the file memory. */
char *pch;
/** The current stream position. */
/** The current stream size. */
/** The size of the memory pb points to. */
/** Line records. */
/** The current line. */
/** The current stream size given in lines. */
/** The sizeof the the memory backing paLines. */
/** Set if write-only, clear if read-only. */
bool fWriteOrRead;
/** Set if the memory pb points to is from RTFileReadAll. */
bool fFileMemory;
/** Set if fully broken into lines. */
bool fFullyLineated;
/** Stream status code (IPRT). */
int rc;
} SCMSTREAM;
/** Pointer to a SCM stream. */
typedef SCMSTREAM *PSCMSTREAM;
/** Pointer to a const SCM stream. */
typedef SCMSTREAM const *PCSCMSTREAM;
/**
* Rewriter state.
*/
typedef struct SCMRWSTATE
{
/** The filename. */
const char *pszFilename;
/** Set after the printing the first verbose message about a file under
* rewrite. */
bool fFirst;
} SCMRWSTATE;
/** Pointer to the rewriter state. */
typedef SCMRWSTATE *PSCMRWSTATE;
/**
* A rewriter.
*
* This works like a stream editor, reading @a pIn, modifying it and writing it
* to @a pOut.
*
* @returns true if any changes were made, false if not.
* @param pIn The input stream.
* @param pOut The output stream.
* @param pSettings The settings.
*/
typedef bool (*PFNSCMREWRITER)(PSCMRWSTATE pState, PSCMSTREAM pIn, PSCMSTREAM pOut, PCSCMSETTINGSBASE pSettings);
/**
* Configuration entry.
*/
typedef struct SCMCFGENTRY
{
/** Number of rewriters. */
/** Pointer to an array of rewriters. */
PFNSCMREWRITER const *papfnRewriter;
/** File pattern (simple). */
const char *pszFilePattern;
} SCMCFGENTRY;
typedef SCMCFGENTRY *PSCMCFGENTRY;
typedef SCMCFGENTRY const *PCSCMCFGENTRY;
/**
* Diff state.
*/
typedef struct SCMDIFFSTATE
{
const char *pszFilename;
/** Whether to ignore end of line markers when diffing. */
bool fIgnoreEol;
/** Whether to ignore trailing whitespace. */
bool fIgnoreTrailingWhite;
/** Whether to ignore leading whitespace. */
bool fIgnoreLeadingWhite;
/** Whether to print special characters in human readable form or not. */
bool fSpecialChars;
/** The tab size. */
/** Where to push the diff. */
} SCMDIFFSTATE;
/** Pointer to a diff state. */
typedef SCMDIFFSTATE *PSCMDIFFSTATE;
/**
* Source Code Massager Settings.
*/
typedef struct SCMSETTINGSBASE
{
bool fConvertEol;
bool fConvertTabs;
bool fForceFinalEol;
bool fForceTrailingLine;
bool fStripTrailingBlanks;
bool fStripTrailingLines;
/** Only recurse into directories containing an .svn dir. */
bool fOnlySvnDirs;
/** */
unsigned cchTab;
/** Only consider files matcihng these patterns. This is only applied to the
* base names. */
char *pszFilterFiles;
/** Filter out files matching the following patterns. This is applied to base
* names as well as the aboslute paths. */
char *pszFilterOutFiles;
/** Filter out directories matching the following patterns. This is applied
* to base names as well as the aboslute paths. All absolute paths ends with a
* slash and dot ("/."). */
char *pszFilterOutDirs;
/** Pointer to massager settings. */
typedef SCMSETTINGSBASE *PSCMSETTINGSBASE;
/**
* Option identifiers.
*
* @note The first chunk, down to SCMOPT_TAB_SIZE, are alternately set &
* clear. So, the option setting a flag (boolean) will have an even
* number and the one clearing it will have an odd number.
* @note Down to SCMOPT_LAST_SETTINGS corresponds exactly to SCMSETTINGSBASE.
*/
typedef enum SCMOPT
{
SCMOPT_CONVERT_EOL = 10000,
//
} SCMOPT;
/**
*/
typedef struct SCMPATRNOPTPAIR
{
char *pszPattern;
char *pszOptions;
/** Pointer to a pattern + option pair. */
typedef SCMPATRNOPTPAIR *PSCMPATRNOPTPAIR;
/** Pointer to a settings set. */
typedef struct SCMSETTINGS *PSCMSETTINGS;
/**
* Settings set.
*
* This structure is constructed from the command line arguments or any
* .scm-settings file found in a directory we recurse into. When recusing in
* and out of a directory, we push and pop a settings set for it.
*
* The .scm-settings file has two kinds of setttings, first there are the
* unqualified base settings and then there are the settings which applies to a
* set of files or directories. The former are lines with command line options.
* For the latter, the options are preceeded by a string pattern and a colon.
* to.
*
* We parse the base options into the Base member and put the others into the
* paPairs array.
*/
typedef struct SCMSETTINGS
{
/** Pointer to the setting file below us in the stack. */
/** Pointer to the setting file above us in the stack. */
/** The number of entires in paPairs. */
/** The base settings that was read out of the file. */
} SCMSETTINGS;
/** Pointer to a const settings set. */
typedef SCMSETTINGS const *PCSCMSETTINGS;
/*******************************************************************************
* Internal Functions *
*******************************************************************************/
static bool rewrite_StripTrailingBlanks(PSCMRWSTATE pState, PSCMSTREAM pIn, PSCMSTREAM pOut, PCSCMSETTINGSBASE pSettings);
static bool rewrite_ExpandTabs(PSCMRWSTATE pState, PSCMSTREAM pIn, PSCMSTREAM pOut, PCSCMSETTINGSBASE pSettings);
static bool rewrite_ForceNativeEol(PSCMRWSTATE pState, PSCMSTREAM pIn, PSCMSTREAM pOut, PCSCMSETTINGSBASE pSettings);
static bool rewrite_ForceLF(PSCMRWSTATE pState, PSCMSTREAM pIn, PSCMSTREAM pOut, PCSCMSETTINGSBASE pSettings);
static bool rewrite_ForceCRLF(PSCMRWSTATE pState, PSCMSTREAM pIn, PSCMSTREAM pOut, PCSCMSETTINGSBASE pSettings);
static bool rewrite_AdjustTrailingLines(PSCMRWSTATE pState, PSCMSTREAM pIn, PSCMSTREAM pOut, PCSCMSETTINGSBASE pSettings);
static bool rewrite_Makefile_kup(PSCMRWSTATE pState, PSCMSTREAM pIn, PSCMSTREAM pOut, PCSCMSETTINGSBASE pSettings);
static bool rewrite_Makefile_kmk(PSCMRWSTATE pState, PSCMSTREAM pIn, PSCMSTREAM pOut, PCSCMSETTINGSBASE pSettings);
static bool rewrite_C_and_CPP(PSCMRWSTATE pState, PSCMSTREAM pIn, PSCMSTREAM pOut, PCSCMSETTINGSBASE pSettings);
/*******************************************************************************
* Global Variables *
*******************************************************************************/
static const char g_szProgName[] = "scm";
static const char *g_pszChangedSuff = "";
static bool g_fDryRun = true;
static bool g_fDiffSpecialChars = true;
static bool g_fDiffIgnoreEol = false;
static bool g_fDiffIgnoreLeadingWS = false;
static bool g_fDiffIgnoreTrailingWS = false;
/** The global settings. */
static SCMSETTINGSBASE const g_Defaults =
{
/* .fConvertEol = */ true,
/* .fConvertTabs = */ true,
/* .fForceFinalEol = */ true,
/* .fForceTrailingLine = */ false,
/* .fStripTrailingBlanks = */ true,
/* .fStripTrailingLines = */ true,
/* .fOnlySvnDirs = */ false,
/* .cchTab = */ 8,
/* .pszFilterFiles = */ (char *)"",
/* .pszFilterOutFiles = */ (char *)"*.exe|*.com|20*-*-*.log",
/* .pszFilterOutDirs = */ (char *)".svn|.hg|.git|CVS",
};
/** Option definitions for the base settings. */
static RTGETOPTDEF g_aScmOpts[] =
{
};
/** Consider files matching the following patterns (base names only). */
static const char *g_pszFileFilter = NULL;
static PFNSCMREWRITER const g_aRewritersFor_Makefile_kup[] =
{
};
static PFNSCMREWRITER const g_aRewritersFor_Makefile_kmk[] =
{
};
static PFNSCMREWRITER const g_aRewritersFor_C_and_CPP[] =
{
};
static PFNSCMREWRITER const g_aRewritersFor_RC[] =
{
};
static PFNSCMREWRITER const g_aRewritersFor_ShellScripts[] =
{
};
static PFNSCMREWRITER const g_aRewritersFor_BatchFiles[] =
{
};
static SCMCFGENTRY const g_aConfigs[] =
{
{ RT_ELEMENTS(g_aRewritersFor_C_and_CPP), &g_aRewritersFor_C_and_CPP[0], "*.c|*.h|*.cpp|*.hpp|*.C|*.CPP|*.cxx|*.cc" },
{ RT_ELEMENTS(g_aRewritersFor_BatchFiles), &g_aRewritersFor_BatchFiles[0], "*.bat|*.cmd|*.btm|*.vbs|*.ps1" },
};
/* -=-=-=-=-=- memory streams -=-=-=-=-=- */
/**
* Initializes the stream structure.
*
* @param pStream The stream structure.
* @param fWriteOrRead The value of the fWriteOrRead stream member.
*/
{
pStream->cbAllocated = 0;
pStream->cLinesAllocated = 0;
pStream->fFileMemory = false;
pStream->fFullyLineated = false;
}
/**
* Initialize an input stream.
*
* @returns IPRT status code.
* @param pStream The stream to initialize.
* @param pszFilename The file to take the stream content from.
*/
{
void *pvFile;
if (RT_SUCCESS(rc))
{
pStream->fFileMemory = true;
}
return rc;
}
/**
* Initialize an output stream.
*
* @returns IPRT status code
* @param pStream The stream to initialize.
* @param pRelatedStream Pointer to a related stream. NULL is fine.
*/
{
/* allocate stuff */
: _64K;
{
: cbEstimate / 24;
{
return VINF_SUCCESS;
}
}
}
/**
* Frees the resources associated with the stream.
*
* Nothing is happens to whatever the stream was initialized from or dumped to.
*
* @param pStream The stream to delete.
*/
{
{
if (pStream->fFileMemory)
else
}
pStream->cbAllocated = 0;
{
}
pStream->cLinesAllocated = 0;
}
/**
* Get the stream status code.
*
* @returns IPRT status code.
* @param pStream The stream.
*/
{
}
/**
* Grows the buffer of a write stream.
*
* @returns IPRT status code.
* @param pStream The stream. Must be in write mode.
* @param cbAppending The minimum number of bytes to grow the buffer
* with.
*/
{
void *pvNew;
if (!pStream->fFileMemory)
{
if (!pvNew)
}
else
{
if (!pvNew)
pStream->fFileMemory = false;
}
return VINF_SUCCESS;
}
/**
* Grows the line array of a stream.
*
* @returns IPRT status code.
* @param pStream The stream.
* @param iMinLine Minimum line number.
*/
{
if (!pvNew)
return VINF_SUCCESS;
}
/**
* Rewinds the stream and sets the mode to read.
*
* @param pStream The stream.
*/
{
pStream->fWriteOrRead = false;
}
/**
* Rewinds the stream and sets the mode to write.
*
* @param pStream The stream.
*/
{
pStream->fWriteOrRead = true;
pStream->fFullyLineated = true;
}
/**
* Checks if it's a text stream.
*
* Not 100% proof.
*
* @returns true if it probably is a text file, false if not.
* @param pStream The stream. Write or read, doesn't matter.
*/
{
return false;
return false;
return true;
}
/**
* Performs an integrity check of the stream.
*
* @returns IPRT status code.
* @param pStream The stream.
*/
{
/*
* Perform sanity checks.
*/
{
{
case SCMEOL_LF:
break;
case SCMEOL_CRLF:
break;
case SCMEOL_NONE:
break;
default:
}
}
return VINF_SUCCESS;
}
/**
* Writes the stream to a file.
*
* @returns IPRT status code
* @param pStream The stream.
* @param pszFilenameFmt The filename format string.
* @param ... Format arguments.
*/
{
int rc;
#ifdef RT_STRICT
/*
* Check that what we're going to write makes sense first.
*/
if (RT_FAILURE(rc))
return rc;
#endif
/*
* Do the actual writing.
*/
rc = RTFileOpenV(&hFile, RTFILE_O_WRITE | RTFILE_O_CREATE_REPLACE | RTFILE_O_DENY_WRITE, pszFilenameFmt, va);
if (RT_SUCCESS(rc))
{
}
return rc;
}
/**
* Worker for ScmStreamGetLine that builds the line number index while parsing
* the stream.
*
* @returns Same as SCMStreamGetLine.
* @param pStream The stream. Must be in read mode.
* @param pcchLine Where to return the line length.
* @param penmEol Where to return the kind of end of line marker.
*/
{
return NULL;
{
pStream->fFullyLineated = true;
return NULL;
}
{
if (RT_FAILURE(rc))
return NULL;
}
{
if ( cb < 1
else
{
cb--;
}
}
else
{
}
return pchRet;
}
/**
* Internal worker that lineates a stream.
*
* @returns IPRT status code.
* @param pStream The stream. Caller must check that it is in
* read mode.
*/
{
/* Save the stream position. */
/* Get each line. */
/* nothing */;
/* Restore the position */
}
/**
* Get the current stream position as a line number.
*
* @returns The current line (0-based).
* @param pStream The stream.
*/
{
}
/**
* Gets the number of lines in the stream.
*
* @returns The number of lines.
* @param pStream The stream.
*/
{
if (!pStream->fFullyLineated)
}
/**
* Seeks to a given line in the tream.
*
* @returns IPRT status code.
*
* @param pStream The stream. Must be in read mode.
* @param iLine The line to seek to. If this is beyond the end
* of the stream, the position is set to the end.
*/
{
/* Must be fully lineated of course. */
{
if (RT_FAILURE(rc))
return rc;
}
/* Ok, do the job. */
{
}
else
{
}
return VINF_SUCCESS;
}
/**
* Get a numbered line from the stream (changes the position).
*
* A line is always delimited by a LF character or the end of the stream. The
* delimiter is not included in returned line length, but instead returned via
* the @a penmEol indicator.
*
* @returns Pointer to the first character in the line, not NULL terminated.
* NULL if the end of the stream has been reached or some problem
* occured.
*
* @param pStream The stream. Must be in read mode.
* @param iLine The line to get (0-based).
* @param pcchLine The length.
* @param penmEol Where to return the end of line type indicator.
*/
static const char *ScmStreamGetLineByNo(PSCMSTREAM pStream, size_t iLine, size_t *pcchLine, PSCMEOL penmEol)
{
return NULL;
/* Make sure it's fully lineated so we can use the index. */
{
if (RT_FAILURE(rc))
return NULL;
}
/* End of stream? */
{
return NULL;
}
/* Get the data. */
/* update the stream position. */
return pchRet;
}
/**
* Get a line from the stream.
*
* A line is always delimited by a LF character or the end of the stream. The
* delimiter is not included in returned line length, but instead returned via
* the @a penmEol indicator.
*
* @returns Pointer to the first character in the line, not NULL terminated.
* NULL if the end of the stream has been reached or some problem
* occured.
*
* @param pStream The stream. Must be in read mode.
* @param pcchLine The length.
* @param penmEol Where to return the end of line type indicator.
*/
{
if (!pStream->fFullyLineated)
}
/**
* Checks if the given line is empty or full of white space.
*
* @returns true if white space only, false if not (or if non-existant).
* @param pStream The stream. Must be in read mode.
* @param iLine The line in question.
*/
{
if (!pchLine)
return false;
return cchLine == 0;
}
/**
* Try figure out the end of line style of the give stream.
*
* @returns Most likely end of line style.
* @param pStream The stream.
*/
{
else
{
else
}
if (enmEol == SCMEOL_NONE)
#if defined(RT_OS_WINDOWS) || defined(RT_OS_OS2)
#else
#endif
return enmEol;
}
/**
* Get the end of line indicator type for a line.
*
* @returns The EOL indicator. If the line isn't found, the default EOL
* indicator is return.
* @param pStream The stream.
* @param iLine The line (0-base).
*/
{
else
#if defined(RT_OS_WINDOWS) || defined(RT_OS_OS2)
#else
#endif
return enmEol;
}
/**
* Appends a line to the stream.
*
* @returns IPRT status code.
* @param pStream The stream. Must be in write mode.
* @param pchLine Pointer to the line.
* @param cchLine Line length.
* @param enmEol Which end of line indicator to use.
*/
{
/*
* Make sure the previous line has a new-line indicator.
*/
if (RT_UNLIKELY( iLine != 0
{
{
if (RT_FAILURE(rc))
return rc;
}
else
{
}
}
/*
* Ensure we've got sufficient buffer space.
*/
{
if (RT_FAILURE(rc))
return rc;
}
/*
* Add a line record.
*/
{
if (RT_FAILURE(rc))
return rc;
}
iLine++;
/*
* Copy the line
*/
else if (enmEol == SCMEOL_CRLF)
{
}
/*
* Start a new line.
*/
return VINF_SUCCESS;
}
/**
* Writes to the stream.
*
* @returns IPRT status code
* @param pStream The stream. Must be in write mode.
* @param pchBuf What to write.
* @param cchBuf How much to write.
*/
{
/*
* Ensure we've got sufficient buffer space.
*/
{
if (RT_FAILURE(rc))
return rc;
}
/*
* Deal with the odd case where we've already pushed a line with SCMEOL_NONE.
*/
if (RT_UNLIKELY( iLine > 0
{
iLine--;
}
/*
* Deal with lines.
*/
if (!pchLF)
else
{
for (;;)
{
{
if (RT_FAILURE(rc))
{
return rc;
}
}
if ( cchLine
else
{
cchLine--;
}
iLine++;
if (!pchLF)
{
break;
}
}
}
/*
* Copy the data and update position and size.
*/
return VINF_SUCCESS;
}
/**
* Write a character to the stream.
*
* @returns IPRT status code
* @param pStream The stream. Must be in write mode.
* @param pchBuf What to write.
* @param cchBuf How much to write.
*/
{
/*
* Only deal with the simple cases here, use ScmStreamWrite for the
* annyoing stuff.
*/
if ( ch == '\n'
/*
* Just append it.
*/
return VINF_SUCCESS;
}
/**
* Copies @a cLines from the @a pSrc stream onto the @a pDst stream.
*
* The stream positions will be used and changed in both streams.
*
* @returns IPRT status code.
* @param pDst The destionation stream. Must be in write mode.
* @param cLines The number of lines. (0 is accepted.)
* @param pSrc The source stream. Must be in read mode.
*/
{
while (cLines-- > 0)
{
if (!pchLine)
if (RT_FAILURE(rc))
return rc;
}
return VINF_SUCCESS;
}
/* -=-=-=-=-=- diff -=-=-=-=-=- */
/**
* Prints a range of lines with a prefix.
*
* @param pState The diff state.
* @param chPrefix The prefix.
* @param pStream The stream to get the lines from.
* @param iLine The first line.
* @param cLines The number of lines.
*/
static void scmDiffPrintLines(PSCMDIFFSTATE pState, char chPrefix, PSCMSTREAM pStream, size_t iLine, size_t cLines)
{
while (cLines-- > 0)
{
{
if (!pState->fSpecialChars)
else
{
while (pchTab)
{
switch (cchTab)
{
}
/* next */
}
if (cchLeft)
}
}
if (!pState->fSpecialChars)
else if (enmEol == SCMEOL_CRLF)
else
iLine++;
}
}
/**
* Reports a difference and propells the streams to the lines following the
* resync.
*
*
* @returns New pState->cDiff value (just to return something).
* @param pState The diff state. The cDiffs member will be
* incremented.
* @param cMatches The resync length.
* @param iLeft Where the difference starts on the left side.
* @param cLeft How long it is on this side. ~(size_t)0 is used
* to indicate that it goes all the way to the end.
* @param iRight Where the difference starts on the right side.
* @param cRight How long it is.
*/
{
/*
* Adjust the input.
*/
{
if (c >= iLeft)
else
{
iLeft = c;
cLeft = 0;
}
}
{
if (c >= iRight)
else
{
iRight = c;
cRight = 0;
}
}
/*
* Print header if it's the first difference
*/
/*
* Emit the change description.
*/
? 'a'
: cRight == 0
? 'd'
: 'c';
RTStrmPrintf(pState->pDiff, "%zu,%zu%c%zu,%zu\n", iLeft + 1, iLeft + cLeft, ch, iRight + 1, iRight + cRight);
else if (cLeft > 1)
else if (cRight > 1)
else
/*
* And the lines.
*/
if (cLeft)
if (cRight)
/*
* Reposition the streams (safely ignores return value).
*/
}
/**
* Helper for scmDiffCompare that takes care of trailing spaces and stuff
* like that.
*/
{
if (pState->fIgnoreTrailingWhite)
{
cchLeft--;
cchRight--;
}
if (pState->fIgnoreLeadingWhite)
{
}
return false;
return true;
}
/**
* Compare two lines.
*
* @returns true if the are equal, false if not.
*/
{
{
if ( pState->fIgnoreTrailingWhite
return scmDiffCompareSlow(pState,
return false;
}
return true;
}
/**
* Compares two sets of lines from the two files.
*
* @returns true if they matches, false if they don't.
* @param pState The diff state.
* @param iLeft Where to start in the left stream.
* @param iRight Where to start in the right stream.
* @param cLines How many lines to compare.
*/
{
{
const char *pchRight = ScmStreamGetLineByNo(pState->pRight, iRight + iLine, &cchRight, &enmEolRight);
return false;
}
return true;
}
/**
* Resynchronize the two streams and reports the difference.
*
* Upon return, the streams will be positioned after the block of @a cMatches
* lines where it resynchronized them.
*
* @returns pState->cDiffs (just so we can use it in a return statement).
* @param pState The state.
* @param cMatches The number of lines that needs to match for the
* stream to be considered synchronized again.
*/
{
/*
* Compare each new line from each of the streams will all the preceding
* ones, including iStartLeft/Right.
*/
{
/*
* Get the next line in the left stream and compare it against all the
* preceding lines on the right side.
*/
if (!pchLine)
{
&cchRight, &enmEolRight);
cMatches - 1)
)
}
/*
* Get the next line in the right stream and compare it against all the
* lines on the right side.
*/
if (!pchLine)
{
&cchLeft, &enmEolLeft);
cMatches - 1)
)
}
}
}
/**
* Creates a diff of the changes between the streams @a pLeft and @a pRight.
*
* This currently only implements the simplest diff format, so no contexts.
*
* Also, note that we won't detect differences in the final newline of the
* streams.
*
* @returns The number of differences.
* @param pszFilename The filename.
* @param pLeft The left side stream.
* @param pRight The right side stream.
* @param fIgnoreEol Whether to ignore end of line markers.
* @param fIgnoreLeadingWhite Set if leading white space should be ignored.
* @param fIgnoreTrailingWhite Set if trailing white space should be ignored.
* @param fSpecialChars Whether to print special chars in a human
* readable form or not.
* @param cchTab The tab size.
* @param pDiff Where to write the diff.
*/
size_t ScmDiffStreams(const char *pszFilename, PSCMSTREAM pLeft, PSCMSTREAM pRight, bool fIgnoreEol,
{
#ifdef RT_STRICT
#endif
/*
* Set up the diff state.
*/
/*
* Compare them line by line.
*/
const char *pchLeft;
const char *pchRight;
for (;;)
{
break;
}
/*
* Deal with any remaining differences.
*/
if (pchLeft)
else if (pchRight)
/*
* Report any errors.
*/
}
/* -=-=-=-=-=- settings -=-=-=-=-=- */
/**
* Init a settings structure with settings from @a pSrc.
*
* @returns IPRT status code
* @param pSettings The settings.
* @param pSrc The source settings.
*/
{
if (RT_SUCCESS(rc))
{
if (RT_SUCCESS(rc))
{
if (RT_SUCCESS(rc))
return VINF_SUCCESS;
}
}
return rc;
}
/**
* Init a settings structure.
*
* @returns IPRT status code
* @param pSettings The settings.
*/
{
}
/**
* Deletes the settings, i.e. free any dynamically allocated content.
*
* @param pSettings The settings.
*/
{
if (pSettings)
{
}
}
/**
* Processes a RTGetOpt result.
*
* @retval VINF_SUCCESS if handled.
* @retval VERR_OUT_OF_RANGE if the option value was out of range.
* @retval VERR_GETOPT_UNKNOWN_OPTION if the option was not recognized.
*
* @param pSettings The settings to change.
* @param rc The RTGetOpt return value.
* @param pValueUnion The RTGetOpt value union.
*/
{
switch (rc)
{
case SCMOPT_CONVERT_EOL:
pSettings->fConvertEol = true;
return VINF_SUCCESS;
case SCMOPT_NO_CONVERT_EOL:
pSettings->fConvertEol = false;
return VINF_SUCCESS;
case SCMOPT_CONVERT_TABS:
pSettings->fConvertTabs = true;
return VINF_SUCCESS;
case SCMOPT_NO_CONVERT_TABS:
pSettings->fConvertTabs = false;
return VINF_SUCCESS;
case SCMOPT_FORCE_FINAL_EOL:
pSettings->fForceFinalEol = true;
return VINF_SUCCESS;
pSettings->fForceFinalEol = false;
return VINF_SUCCESS;
pSettings->fForceTrailingLine = true;
return VINF_SUCCESS;
pSettings->fForceTrailingLine = false;
return VINF_SUCCESS;
pSettings->fStripTrailingBlanks = true;
return VINF_SUCCESS;
pSettings->fStripTrailingBlanks = false;
return VINF_SUCCESS;
pSettings->fStripTrailingLines = true;
return VINF_SUCCESS;
pSettings->fStripTrailingLines = false;
return VINF_SUCCESS;
case SCMOPT_ONLY_SVN_DIRS:
pSettings->fOnlySvnDirs = true;
return VINF_SUCCESS;
case SCMOPT_NOT_ONLY_SVN_DIRS:
pSettings->fOnlySvnDirs = false;
return VINF_SUCCESS;
case SCMOPT_TAB_SIZE:
{
RTMsgError("Invalid tab size: %u - must be in {1..%u}\n",
return VERR_OUT_OF_RANGE;
}
return VINF_SUCCESS;
case SCMOPT_FILTER_OUT_DIRS:
case SCMOPT_FILTER_FILES:
case SCMOPT_FILTER_OUT_FILES:
{
char **ppsz;
switch (rc)
{
}
/*
* An empty string zaps the current list.
*/
if (!*pValueUnion->psz)
return RTStrATruncate(ppsz, 0);
/*
* Non-empty strings are appended to the pattern list.
*
* Strip leading and trailing pattern separators before attempting
* to append it. If it's just separators, don't do anything.
*/
while (*pszSrc == '|')
pszSrc++;
cchSrc--;
if (!cchSrc)
return VINF_SUCCESS;
}
default:
return VERR_GETOPT_UNKNOWN_OPTION;
}
}
/**
* Parses an option string.
*
* @returns IPRT status code.
* @param pBase The base settings structure to apply the options
* to.
* @param pszOptions The options to parse.
*/
{
int cArgs;
char **papszArgs;
if (RT_SUCCESS(rc))
{
rc = RTGetOptInit(&GetOptState, cArgs, papszArgs, &g_aScmOpts[0], RT_ELEMENTS(g_aScmOpts), 0, 0 /*fFlags*/);
if (RT_SUCCESS(rc))
{
{
if (RT_FAILURE(rc))
break;
}
}
}
return rc;
}
/**
* Parses an unterminated option string.
*
* @returns IPRT status code.
* @param pBase The base settings structure to apply the options
* to.
* @param pchLine The line.
* @param cchLine The line length.
*/
{
if (!pszLine)
return VERR_NO_MEMORY;
return rc;
}
/**
* Verifies the options string.
*
* @returns IPRT status code.
* @param pszOptions The options to verify .
*/
static int scmSettingsBaseVerifyString(const char *pszOptions)
{
if (RT_SUCCESS(rc))
{
}
return rc;
}
/**
* Loads settings found in editor and SCM settings directives within the
* document (@a pStream).
*
* @returns IPRT status code.
* @param pBase The settings base to load settings into.
* @param pStream The stream to scan for settings directives.
*/
{
/** @todo Editor and SCM settings directives in documents. */
return VINF_SUCCESS;
}
/**
* Creates a new settings file struct, cloning @a pSettings.
*
* @returns IPRT status code.
* @param ppSettings Where to return the new struct.
* @param pSettingsBase The settings to inherit from.
*/
{
if (!pSettings)
return VERR_NO_MEMORY;
if (RT_SUCCESS(rc))
{
*ppSettings = pSettings;
return VINF_SUCCESS;
}
return rc;
}
/**
* Destroys a settings structure.
*
* @param pSettings The settgins structure to destroy. NULL is OK.
*/
{
if (pSettings)
{
{
}
}
}
/**
*
* @returns IPRT status code.
* @param pSettings The settings.
* @param pchLine The line containing the unparsed pair.
* @param cchLine The length of the line.
*/
{
/*
* Split the string.
*/
if (!pchOptions)
return VERR_INVALID_PARAMETER;
pchOptions++;
/* strip spaces everywhere */
cchPattern--;
cchPattern--, pchLine++;
cchOptions--;
cchOptions--, pchOptions++;
/* Quietly ignore empty patterns and empty options. */
if (!cchOptions || !cchPattern)
return VINF_SUCCESS;
/*
* Add the pair and verify the option string.
*/
if ((iPair % 32) == 0)
{
if (!pvNew)
return VERR_NO_MEMORY;
}
int rc;
else
rc = VERR_NO_MEMORY;
if (RT_SUCCESS(rc))
else
{
}
return rc;
}
/**
* Loads in the settings from @a pszFilename.
*
* @returns IPRT status code.
* @param pSettings Where to load the settings file.
* @param pszFilename The file to load.
*/
{
if (RT_FAILURE(rc))
{
return rc;
}
const char *pchLine;
{
/* Ignore leading spaces. */
/* Ignore empty lines and comment lines. */
continue;
/* What kind of line is it? */
if (pchColon)
else
if (RT_FAILURE(rc))
{
break;
}
}
if (RT_SUCCESS(rc))
{
if (RT_FAILURE(rc))
}
return rc;
}
/**
* Parse the specified settings file creating a new settings struct from it.
*
* @returns IPRT status code
* @param ppSettings Where to return the new settings.
* @param pszFilename The file to parse.
* @param pSettingsBase The base settings we inherit from.
*/
static int scmSettingsCreateFromFile(PSCMSETTINGS *ppSettings, const char *pszFilename, PCSCMSETTINGSBASE pSettingsBase)
{
if (RT_SUCCESS(rc))
{
if (RT_SUCCESS(rc))
{
*ppSettings = pSettings;
return VINF_SUCCESS;
}
}
*ppSettings = NULL;
return rc;
}
/**
* Create an initial settings structure when starting processing a new file or
* directory.
*
* This will look for .scm-settings files from the root and down to the
* specified directory, combining them into the returned settings structure.
*
* @returns IPRT status code.
* @param ppSettings Where to return the pointer to the top stack
* object.
* @param pBaseSettings The base settings we inherit from (globals
* typically).
* @param pszPath The absolute path to the new directory or file.
*/
static int scmSettingsCreateForPath(PSCMSETTINGS *ppSettings, PCSCMSETTINGSBASE pBaseSettings, const char *pszPath)
{
/*
* We'll be working with a stack copy of the path.
*/
char szFile[RTPATH_MAX];
return VERR_FILENAME_TOO_LONG;
/*
* Create the bottom-most settings.
*/
if (RT_FAILURE(rc))
return rc;
/*
* Enumerate the path components from the root and down. Load any setting
* files we find.
*/
{
if (RT_SUCCESS(rc))
if (RT_FAILURE(rc))
break;
if (RTFileExists(szFile))
{
if (RT_FAILURE(rc))
break;
}
}
if (RT_SUCCESS(rc))
*ppSettings = pSettings;
else
return rc;
}
/**
* Pushes a new settings set onto the stack.
*
* @param ppSettingsStack The pointer to the pointer to the top stack
* element. This will be used as input and output.
* @param pSettings The settings to push onto the stack.
*/
{
if (pOld)
}
/**
* Pushes the settings of the specified directory onto the stack.
*
* We will load any .scm-settings in the directory. A stack entry is added even
* if no settings file was found.
*
* @returns IPRT status code.
* @param ppSettingsStack The pointer to the pointer to the top stack
* element. This will be used as input and output.
* @param pszDir The directory to do this for.
*/
{
char szFile[RTPATH_MAX];
if (RT_SUCCESS(rc))
{
if (RT_SUCCESS(rc))
{
if (RTFileExists(szFile))
if (RT_SUCCESS(rc))
{
return VINF_SUCCESS;
}
}
}
return rc;
}
/**
* Pops a settings set off the stack.
*
* @returns The popped setttings.
* @param ppSettingsStack The pointer to the pointer to the top stack
* element. This will be used as input and output.
*/
{
*ppSettingsStack = pNew;
if (pNew)
if (pRet)
{
}
return pRet;
}
/**
* Pops and destroys the top entry of the stack.
*
* @param ppSettingsStack The pointer to the pointer to the top stack
* element. This will be used as input and output.
*/
{
}
/**
* Constructs the base settings for the specified file name.
*
* @returns IPRT status code.
* @param pSettingsStack The top element on the settings stack.
* @param pszFilename The file name.
* @param pszBasename The base name (pointer within @a pszFilename).
* @param cchBasename The length of the base name. (For passing to
* RTStrSimplePatternMultiMatch.)
* @param pBase Base settings to initialize.
*/
{
if (RT_SUCCESS(rc))
{
/* find the bottom entry in the stack. */
/* Work our way up thru the stack and look for matching pairs. */
while (pCur)
{
if (cPairs)
{
{
if (RT_FAILURE(rc))
break;
}
if (RT_FAILURE(rc))
break;
}
/* advance */
}
}
if (RT_FAILURE(rc))
return rc;
}
/* -=-=-=-=-=- misc -=-=-=-=-=- */
/**
* Prints a verbose message if the level is high enough.
*
* @param pState The rewrite state. Optional.
* @param iLevel The required verbosity level.
* @param pszFormat The message format string. Can be NULL if we
* only want to trigger the per file message.
* @param ... Format arguments.
*/
{
if (iLevel <= g_iVerbosity)
{
{
}
if (pszFormat)
{
}
}
}
/* -=-=-=-=-=- rewriters -=-=-=-=-=- */
/**
* Strip trailing blanks (space & tab).
*
* @returns True if modified, false if not.
* @param pIn The input stream.
* @param pOut The output stream.
* @param pSettings The settings.
*/
static bool rewrite_StripTrailingBlanks(PSCMRWSTATE pState, PSCMSTREAM pIn, PSCMSTREAM pOut, PCSCMSETTINGSBASE pSettings)
{
if (!pSettings->fStripTrailingBlanks)
return false;
bool fModified = false;
const char *pchLine;
{
int rc;
if ( cchLine == 0
else
{
cchLine--;
cchLine--;
fModified = true;
}
if (RT_FAILURE(rc))
return false;
}
if (fModified)
return fModified;
}
/**
* Expand tabs.
*
* @returns True if modified, false if not.
* @param pIn The input stream.
* @param pOut The output stream.
* @param pSettings The settings.
*/
static bool rewrite_ExpandTabs(PSCMRWSTATE pState, PSCMSTREAM pIn, PSCMSTREAM pOut, PCSCMSETTINGSBASE pSettings)
{
if (!pSettings->fConvertTabs)
return false;
bool fModified = false;
const char *pchLine;
{
int rc;
if (!pchTab)
else
{
for (;;)
{
if (!pchTab)
{
break;
}
}
fModified = true;
}
if (RT_FAILURE(rc))
return false;
}
if (fModified)
return fModified;
}
/**
* Worker for rewrite_ForceNativeEol, rewrite_ForceLF and rewrite_ForceCRLF.
*
* @returns true if modifications were made, false if not.
* @param pIn The input stream.
* @param pOut The output stream.
* @param pSettings The settings.
* @param enmDesiredEol The desired end of line indicator type.
*/
static bool rewrite_ForceEol(PSCMRWSTATE pState, PSCMSTREAM pIn, PSCMSTREAM pOut, PCSCMSETTINGSBASE pSettings, SCMEOL enmDesiredEol)
{
if (!pSettings->fConvertEol)
return false;
bool fModified = false;
const char *pchLine;
{
if ( enmEol != enmDesiredEol
&& enmEol != SCMEOL_NONE)
{
fModified = true;
}
if (RT_FAILURE(rc))
return false;
}
if (fModified)
/** @todo also check the subversion svn:eol-style state! */
return fModified;
}
/**
* Force native end of line indicator.
*
* @returns true if modifications were made, false if not.
* @param pIn The input stream.
* @param pOut The output stream.
* @param pSettings The settings.
*/
static bool rewrite_ForceNativeEol(PSCMRWSTATE pState, PSCMSTREAM pIn, PSCMSTREAM pOut, PCSCMSETTINGSBASE pSettings)
{
#if defined(RT_OS_WINDOWS) || defined(RT_OS_OS2)
#else
#endif
}
/**
* Force the stream to use LF as the end of line indicator.
*
* @returns true if modifications were made, false if not.
* @param pIn The input stream.
* @param pOut The output stream.
* @param pSettings The settings.
*/
static bool rewrite_ForceLF(PSCMRWSTATE pState, PSCMSTREAM pIn, PSCMSTREAM pOut, PCSCMSETTINGSBASE pSettings)
{
}
/**
* Force the stream to use CRLF as the end of line indicator.
*
* @returns true if modifications were made, false if not.
* @param pIn The input stream.
* @param pOut The output stream.
* @param pSettings The settings.
*/
static bool rewrite_ForceCRLF(PSCMRWSTATE pState, PSCMSTREAM pIn, PSCMSTREAM pOut, PCSCMSETTINGSBASE pSettings)
{
}
/**
* at the end of the file.
*
* @returns true if modifications were made, false if not.
* @param pIn The input stream.
* @param pOut The output stream.
* @param pSettings The settings.
*
* @remarks ASSUMES trailing white space has been removed already.
*/
static bool rewrite_AdjustTrailingLines(PSCMRWSTATE pState, PSCMSTREAM pIn, PSCMSTREAM pOut, PCSCMSETTINGSBASE pSettings)
{
if ( !pSettings->fStripTrailingLines
&& !pSettings->fForceFinalEol)
return false;
/* Empty files remains empty. */
if (cLines <= 1)
return false;
/* Figure out if we need to adjust the number of lines or not. */
if ( pSettings->fStripTrailingLines
{
while ( cLinesNew > 1
cLinesNew--;
}
if ( pSettings->fForceTrailingLine
cLinesNew++;
if ( !fFixMissingEol
return false;
/* Copy the number of lines we've arrived at. */
{
}
/* Fix missing EOL if required. */
else if (fFixMissingEol)
{
else
}
return true;
}
/**
* Makefile.kup are empty files, enforce this.
*
* @returns true if modifications were made, false if not.
* @param pIn The input stream.
* @param pOut The output stream.
* @param pSettings The settings.
*/
static bool rewrite_Makefile_kup(PSCMRWSTATE pState, PSCMSTREAM pIn, PSCMSTREAM pOut, PCSCMSETTINGSBASE pSettings)
{
/* These files should be zero bytes. */
return false;
return true;
}
/**
* Rewrite a kBuild makefile.
*
* @returns true if modifications were made, false if not.
* @param pIn The input stream.
* @param pOut The output stream.
* @param pSettings The settings.
*
* @todo
*
* Ideas for Makefile.kmk and Config.kmk:
* - line continuation slashes should only be preceeded by one space.
*/
static bool rewrite_Makefile_kmk(PSCMRWSTATE pState, PSCMSTREAM pIn, PSCMSTREAM pOut, PCSCMSETTINGSBASE pSettings)
{
return false;
}
/**
* Rewrite a C/C++ source or header file.
*
* @returns true if modifications were made, false if not.
* @param pIn The input stream.
* @param pOut The output stream.
* @param pSettings The settings.
*
* @todo
*
* Ideas for C/C++:
* - space after if, while, for, switch
* - spaces in for (i=0;i<x;i++)
* - complex conditional, bird style.
* - remove unnecessary parentheses.
* - sort defined RT_OS_*|| and RT_ARCH
* - sizeof without parenthesis.
* - defined without parenthesis.
* - trailing spaces.
* - parameter indentation.
* - space after comma.
* - while (x--); -> multi line + comment.
* - else statement;
* - space between function and left parenthesis.
* - TODO, XXX, @todo cleanup.
* - ensure new line at end of file.
* - Indentation of precompiler statements (#ifdef, #defines).
* - space between functions.
*/
static bool rewrite_C_and_CPP(PSCMRWSTATE pState, PSCMSTREAM pIn, PSCMSTREAM pOut, PCSCMSETTINGSBASE pSettings)
{
return false;
}
/* -=-=-=-=-=- file and directory processing -=-=-=-=-=- */
/**
* Processes a file.
*
* @returns IPRT status code.
* @param pszFilename The file name.
* @param pszBasename The base name (pointer within @a pszFilename).
* @param cchBasename The length of the base name. (For passing to
* RTStrSimplePatternMultiMatch.)
* @param pBaseSettings The base settings to use. It's OK to modify
* these.
*/
static int scmProcessFileInner(const char *pszFilename, const char *pszBasename, size_t cchBasename,
{
/*
* Init the rewriter state data.
*/
/*
* Do the file level filtering.
*/
if ( pBaseSettings->pszFilterFiles
&& !RTStrSimplePatternMultiMatch(pBaseSettings->pszFilterFiles, RTSTR_MAX, pszBasename, cchBasename, NULL))
{
return VINF_SUCCESS;
}
&& ( RTStrSimplePatternMultiMatch(pBaseSettings->pszFilterOutFiles, RTSTR_MAX, pszBasename, cchBasename, NULL)
|| RTStrSimplePatternMultiMatch(pBaseSettings->pszFilterOutFiles, RTSTR_MAX, pszFilename, RTSTR_MAX, NULL)) )
{
return VINF_SUCCESS;
}
/*
* Try find a matching rewrite config for this filename.
*/
if (RTStrSimplePatternMultiMatch(g_aConfigs[iCfg].pszFilePattern, RTSTR_MAX, pszBasename, cchBasename, NULL))
{
break;
}
if (!pCfg)
{
return VINF_SUCCESS;
}
/*
* Create an input stream from the file and check that it's text.
*/
if (RT_FAILURE(rc))
{
return rc;
}
if (ScmStreamIsText(&Stream1))
{
/*
* Gather SCM and editor settings from the stream.
*/
if (RT_SUCCESS(rc))
{
/*
* Create two more streams for output and push the text thru all the
* rewriters, switching the two streams around when something is
* actually rewritten. Stream1 remains unchanged.
*/
if (RT_SUCCESS(rc))
{
if (RT_SUCCESS(rc))
{
bool fModified = false;
{
if (fRc)
{
fModified = true;
}
}
/*
* If rewritten, write it back to disk.
*/
if (fModified)
{
if (!g_fDryRun)
{
if (RT_FAILURE(rc))
}
else
{
}
}
else
}
else
}
else
}
else
}
else
return rc;
}
/**
* Processes a file.
*
* This is just a wrapper for scmProcessFileInner for avoid wasting stack in the
* directory recursion method.
*
* @returns IPRT status code.
* @param pszFilename The file name.
* @param pszBasename The base name (pointer within @a pszFilename).
* @param cchBasename The length of the base name. (For passing to
* RTStrSimplePatternMultiMatch.)
* @param pSettingsStack The settings stack (pointer to the top element).
*/
{
int rc = scmSettingsStackMakeFileBase(pSettingsStack, pszFilename, pszBasename, cchBasename, &Base);
if (RT_SUCCESS(rc))
{
}
return rc;
}
/**
* Tries to correct RTDIRENTRY_UNKNOWN.
*
* @returns Corrected type.
* @param pszPath The path to the object in question.
*/
{
if (RT_FAILURE(rc))
return RTDIRENTRYTYPE_UNKNOWN;
return RTDIRENTRYTYPE_DIRECTORY;
return RTDIRENTRYTYPE_FILE;
return RTDIRENTRYTYPE_UNKNOWN;
}
/**
* Recurse into a sub-directory and process all the files and directories.
*
* @returns IPRT status code.
* @param pszBuf Path buffer containing the directory path on
* entry. This ends with a dot. This is passed
* along when recusing in order to save stack space
* and avoid needless copying.
* @param cchDir Length of our path in pszbuf.
* @param pEntry Directory entry buffer. This is also passed
* along when recursing to save stack space.
* @param pSettingsStack The settings stack (pointer to the top element).
* @param iRecursion The recursion depth. This is used to restrict
* the recursions.
*/
{
int rc;
/*
* Make sure we stop somewhere.
*/
if (iRecursion > 128)
{
return VINF_SUCCESS; /* ignore */
}
/*
* Check if it's excluded by --only-svn-dir.
*/
{
if (RT_FAILURE(rc))
{
return rc;
}
if (!RTDirExists(pszBuf))
return VINF_SUCCESS;
}
/*
* Try open and read the directory.
*/
if (RT_FAILURE(rc))
{
return rc;
}
for (;;)
{
/* Read the next entry. */
if (RT_FAILURE(rc))
break;
/* Skip '.' and '..'. */
continue;
/* Enter it into the buffer so we've got a full name to work
with when needed. */
{
continue;
}
/* Figure the type. */
if (enmType == RTDIRENTRYTYPE_UNKNOWN)
/* Process the file or directory, skip the rest. */
if (enmType == RTDIRENTRYTYPE_FILE)
else if (enmType == RTDIRENTRYTYPE_DIRECTORY)
{
/* Append the dot for the benefit of the pattern matching. */
{
continue;
}
)
)
{
if (RT_SUCCESS(rc))
{
}
}
}
if (RT_FAILURE(rc))
break;
}
}
/**
* Process a directory tree.
*
* @returns IPRT status code.
* @param pszDir The directory to start with. This is pointer to
* a RTPATH_MAX sized buffer.
*/
{
/*
* Setup the recursion.
*/
if (RT_SUCCESS(rc))
{
}
else
return rc;
}
/**
* Processes a file or directory specified as an command line argument.
*
* @returns IPRT status code
* @param pszSomething What we found in the commad line arguments.
* @param pSettingsStack The settings stack (pointer to the top element).
*/
{
char szBuf[RTPATH_MAX];
if (RT_SUCCESS(rc))
{
if (RT_SUCCESS(rc))
{
if (RTFileExists(szBuf))
{
if (pszBasename)
{
}
else
{
RTMsgError("RTPathFilename: NULL\n");
}
}
else
}
else
}
else
return rc;
}
{
if (RT_FAILURE(rc))
return 1;
/*
* Init the settings.
*/
if (RT_FAILURE(rc))
{
return 1;
}
/*
* Parse arguments and process input in order (because this is the only
* thing that works at the moment).
*/
{
};
memcpy(&s_aOpts[RT_ELEMENTS(s_aOpts) - RT_ELEMENTS(g_aScmOpts)], &g_aScmOpts[0], sizeof(g_aScmOpts));
rc = RTGetOptInit(&GetOptState, argc, argv, &s_aOpts[0], RT_ELEMENTS(s_aOpts), 1, RTGETOPTINIT_FLAGS_OPTS_FIRST);
size_t cProcessed = 0;
{
switch (rc)
{
case 'd':
g_fDryRun = true;
break;
case 'D':
g_fDryRun = false;
break;
case 'f':
break;
case 'h':
RTPrintf("VirtualBox Source Code Massager\n"
"\n"
"Usage: %s [options] <files & dirs>\n"
"\n"
"Options:\n", g_szProgName);
{
bool fAdvanceTwo = false;
{
if (fAdvanceTwo)
else
}
else
{
case SCMOPT_FORCE_TRAILING_LINE: RTPrintf(" Default: %RTbool\n", g_Defaults.fForceTrailingLine); break;
case SCMOPT_STRIP_TRAILING_BLANKS: RTPrintf(" Default: %RTbool\n", g_Defaults.fStripTrailingBlanks); break;
case SCMOPT_STRIP_TRAILING_LINES: RTPrintf(" Default: %RTbool\n", g_Defaults.fStripTrailingLines); break;
}
i += fAdvanceTwo;
}
return 1;
case 'q':
g_iVerbosity = 0;
break;
case 'v':
g_iVerbosity++;
break;
case 'V':
{
/* The following is assuming that svn does it's job here. */
static const char s_szRev[] = "$Revision$";
return 0;
}
case SCMOPT_DIFF_IGNORE_EOL:
g_fDiffIgnoreEol = true;
break;
g_fDiffIgnoreEol = false;
break;
case SCMOPT_DIFF_IGNORE_SPACE:
break;
g_fDiffIgnoreTrailingWS = g_fDiffIgnoreLeadingWS = false;
break;
g_fDiffIgnoreLeadingWS = true;
break;
g_fDiffIgnoreLeadingWS = false;
break;
g_fDiffIgnoreTrailingWS = true;
break;
g_fDiffIgnoreTrailingWS = false;
break;
g_fDiffSpecialChars = true;
break;
g_fDiffSpecialChars = false;
break;
case VINF_GETOPT_NOT_OPTION:
{
if (!g_fDryRun)
{
if (!cProcessed)
{
RTPrintf("%s: Warning! This program will make changes to your source files and\n"
"%s: there is a slight risk that bugs or a full disk may cause\n"
"%s: LOSS OF DATA. So, please make sure you have checked in\n"
"%s: all your changes already. If you didn't, then don't blame\n"
"%s: anyone for not warning you!\n"
"%s:\n"
"%s: Press any key to continue...\n",
}
cProcessed++;
}
if (RT_FAILURE(rc))
return rc;
break;
}
default:
{
if (RT_SUCCESS(rc2))
break;
if (rc2 != VERR_GETOPT_UNKNOWN_OPTION)
return 2;
}
}
}
return 0;
}