scm.cpp revision e99772f9bf09219c532812c859fbeea513c67e65
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * IPRT Testcase / Tool - Source Code Massager.
e99772f9bf09219c532812c859fbeea513c67e65vboxsync * Copyright (C) 2010-2012 Oracle Corporation
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * available from http://www.virtualbox.org. This file is free software;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * you can redistribute it and/or modify it under the terms of the GNU
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * General Public License (GPL) as published by the Free Software
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
a299266cddc1ae14d76d725a660bb278816bc151vboxsync/*******************************************************************************
a299266cddc1ae14d76d725a660bb278816bc151vboxsync* Header Files *
a299266cddc1ae14d76d725a660bb278816bc151vboxsync*******************************************************************************/
a299266cddc1ae14d76d725a660bb278816bc151vboxsync/*******************************************************************************
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync* Defined Constants And Macros *
a299266cddc1ae14d76d725a660bb278816bc151vboxsync*******************************************************************************/
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync/** The name of the settings files. */
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync/*******************************************************************************
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync* Structures and Typedefs *
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync*******************************************************************************/
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync/** Pointer to const massager settings. */
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsynctypedef struct SCMSETTINGSBASE const *PCSCMSETTINGSBASE;
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync * SVN property.
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsynctypedef struct SCMSVNPROP
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync /** The property. */
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync /** The value.
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync * When used to record updates, this can be set to NULL to trigger the
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync * deletion of the property. */
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync/** Pointer to a SVN property. */
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync/** Pointer to a const SVN property. */
b2c35a7024c4c308b429c81b203b3bcbd44ee60cvboxsync * Rewriter state.
b2c35a7024c4c308b429c81b203b3bcbd44ee60cvboxsynctypedef struct SCMRWSTATE
b2c35a7024c4c308b429c81b203b3bcbd44ee60cvboxsync /** The filename. */
b2c35a7024c4c308b429c81b203b3bcbd44ee60cvboxsync /** Set after the printing the first verbose message about a file under
b2c35a7024c4c308b429c81b203b3bcbd44ee60cvboxsync * rewrite. */
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync /** The number of SVN property changes. */
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync /** Pointer to an array of SVN property changes. */
b2c35a7024c4c308b429c81b203b3bcbd44ee60cvboxsync/** Pointer to the rewriter state. */
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * A rewriter.
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * This works like a stream editor, reading @a pIn, modifying it and writing it
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * to @a pOut.
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * @returns true if any changes were made, false if not.
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * @param pIn The input stream.
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * @param pOut The output stream.
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * @param pSettings The settings.
b2c35a7024c4c308b429c81b203b3bcbd44ee60cvboxsynctypedef bool (*PFNSCMREWRITER)(PSCMRWSTATE pState, PSCMSTREAM pIn, PSCMSTREAM pOut, PCSCMSETTINGSBASE pSettings);
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * Configuration entry.
a299266cddc1ae14d76d725a660bb278816bc151vboxsynctypedef struct SCMCFGENTRY
a299266cddc1ae14d76d725a660bb278816bc151vboxsync /** Number of rewriters. */
a299266cddc1ae14d76d725a660bb278816bc151vboxsync /** Pointer to an array of rewriters. */
a299266cddc1ae14d76d725a660bb278816bc151vboxsync /** File pattern (simple). */
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * Diff state.
a299266cddc1ae14d76d725a660bb278816bc151vboxsynctypedef struct SCMDIFFSTATE
a299266cddc1ae14d76d725a660bb278816bc151vboxsync /** Whether to ignore end of line markers when diffing. */
a299266cddc1ae14d76d725a660bb278816bc151vboxsync /** Whether to ignore trailing whitespace. */
a299266cddc1ae14d76d725a660bb278816bc151vboxsync /** Whether to ignore leading whitespace. */
a299266cddc1ae14d76d725a660bb278816bc151vboxsync /** Whether to print special characters in human readable form or not. */
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync /** The tab size. */
a299266cddc1ae14d76d725a660bb278816bc151vboxsync /** Where to push the diff. */
a299266cddc1ae14d76d725a660bb278816bc151vboxsync/** Pointer to a diff state. */
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * Source Code Massager Settings.
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync /** Only process files that are part of a SVN working copy. */
4bcaf5d320bf0d88910212509c37bdd634e0879evboxsync /** Only recurse into directories containing an .svn dir. */
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync /** Set svn:eol-style if missing or incorrect. */
ad27e1d5e48ca41245120c331cc88b50464813cevboxsync /** Set svn:executable according to type (unusually this means deleting it). */
4a4d802b46dfabbfd36e88822ff7b17421120469vboxsync /** Set svn:keyword if completely or partially missing. */
ad27e1d5e48ca41245120c331cc88b50464813cevboxsync /** Only consider files matching these patterns. This is only applied to the
4bcaf5d320bf0d88910212509c37bdd634e0879evboxsync * base names. */
4bcaf5d320bf0d88910212509c37bdd634e0879evboxsync /** Filter out files matching the following patterns. This is applied to base
ad27e1d5e48ca41245120c331cc88b50464813cevboxsync * names as well as the absolute paths. */
4bcaf5d320bf0d88910212509c37bdd634e0879evboxsync /** Filter out directories matching the following patterns. This is applied
ad27e1d5e48ca41245120c331cc88b50464813cevboxsync * to base names as well as the absolute paths. All absolute paths ends with a
4bcaf5d320bf0d88910212509c37bdd634e0879evboxsync * slash and dot ("/."). */
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync/** Pointer to massager settings. */
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * Option identifiers.
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * @note The first chunk, down to SCMOPT_TAB_SIZE, are alternately set &
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * clear. So, the option setting a flag (boolean) will have an even
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * number and the one clearing it will have an odd number.
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * @note Down to SCMOPT_LAST_SETTINGS corresponds exactly to SCMSETTINGSBASE.
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * File/dir pattern + options.
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync/** Pointer to a pattern + option pair. */
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync/** Pointer to a settings set. */
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * Settings set.
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * This structure is constructed from the command line arguments or any
ad27e1d5e48ca41245120c331cc88b50464813cevboxsync * .scm-settings file found in a directory we recurse into. When recursing in
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * and out of a directory, we push and pop a settings set for it.
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * The .scm-settings file has two kinds of setttings, first there are the
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * unqualified base settings and then there are the settings which applies to a
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * set of files or directories. The former are lines with command line options.
ad27e1d5e48ca41245120c331cc88b50464813cevboxsync * For the latter, the options are preceded by a string pattern and a colon.
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * The pattern specifies which files (and/or directories) the options applies
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * We parse the base options into the Base member and put the others into the
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * paPairs array.
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsynctypedef struct SCMSETTINGS
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync /** Pointer to the setting file below us in the stack. */
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync /** Pointer to the setting file above us in the stack. */
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync /** File/dir patterns and their options. */
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync /** The number of entires in paPairs. */
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync /** The base settings that was read out of the file. */
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync/** Pointer to a const settings set. */
a299266cddc1ae14d76d725a660bb278816bc151vboxsync/*******************************************************************************
a299266cddc1ae14d76d725a660bb278816bc151vboxsync* Internal Functions *
a299266cddc1ae14d76d725a660bb278816bc151vboxsync*******************************************************************************/
b2c35a7024c4c308b429c81b203b3bcbd44ee60cvboxsyncstatic bool rewrite_StripTrailingBlanks(PSCMRWSTATE pState, PSCMSTREAM pIn, PSCMSTREAM pOut, PCSCMSETTINGSBASE pSettings);
b2c35a7024c4c308b429c81b203b3bcbd44ee60cvboxsyncstatic bool rewrite_ExpandTabs(PSCMRWSTATE pState, PSCMSTREAM pIn, PSCMSTREAM pOut, PCSCMSETTINGSBASE pSettings);
b2c35a7024c4c308b429c81b203b3bcbd44ee60cvboxsyncstatic bool rewrite_ForceNativeEol(PSCMRWSTATE pState, PSCMSTREAM pIn, PSCMSTREAM pOut, PCSCMSETTINGSBASE pSettings);
b2c35a7024c4c308b429c81b203b3bcbd44ee60cvboxsyncstatic bool rewrite_ForceLF(PSCMRWSTATE pState, PSCMSTREAM pIn, PSCMSTREAM pOut, PCSCMSETTINGSBASE pSettings);
b2c35a7024c4c308b429c81b203b3bcbd44ee60cvboxsyncstatic bool rewrite_ForceCRLF(PSCMRWSTATE pState, PSCMSTREAM pIn, PSCMSTREAM pOut, PCSCMSETTINGSBASE pSettings);
b2c35a7024c4c308b429c81b203b3bcbd44ee60cvboxsyncstatic bool rewrite_AdjustTrailingLines(PSCMRWSTATE pState, PSCMSTREAM pIn, PSCMSTREAM pOut, PCSCMSETTINGSBASE pSettings);
4a4d802b46dfabbfd36e88822ff7b17421120469vboxsyncstatic bool rewrite_SvnNoExecutable(PSCMRWSTATE pState, PSCMSTREAM pIn, PSCMSTREAM pOut, PCSCMSETTINGSBASE pSettings);
4a4d802b46dfabbfd36e88822ff7b17421120469vboxsyncstatic bool rewrite_SvnKeywords(PSCMRWSTATE pState, PSCMSTREAM pIn, PSCMSTREAM pOut, PCSCMSETTINGSBASE pSettings);
b2c35a7024c4c308b429c81b203b3bcbd44ee60cvboxsyncstatic bool rewrite_Makefile_kup(PSCMRWSTATE pState, PSCMSTREAM pIn, PSCMSTREAM pOut, PCSCMSETTINGSBASE pSettings);
b2c35a7024c4c308b429c81b203b3bcbd44ee60cvboxsyncstatic bool rewrite_Makefile_kmk(PSCMRWSTATE pState, PSCMSTREAM pIn, PSCMSTREAM pOut, PCSCMSETTINGSBASE pSettings);
b2c35a7024c4c308b429c81b203b3bcbd44ee60cvboxsyncstatic bool rewrite_C_and_CPP(PSCMRWSTATE pState, PSCMSTREAM pIn, PSCMSTREAM pOut, PCSCMSETTINGSBASE pSettings);
a299266cddc1ae14d76d725a660bb278816bc151vboxsync/*******************************************************************************
a299266cddc1ae14d76d725a660bb278816bc151vboxsync* Global Variables *
a299266cddc1ae14d76d725a660bb278816bc151vboxsync*******************************************************************************/
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsyncstatic bool g_fDryRun = true;
a299266cddc1ae14d76d725a660bb278816bc151vboxsyncstatic bool g_fDiffSpecialChars = true;
a299266cddc1ae14d76d725a660bb278816bc151vboxsyncstatic bool g_fDiffIgnoreEol = false;
a299266cddc1ae14d76d725a660bb278816bc151vboxsyncstatic bool g_fDiffIgnoreLeadingWS = false;
a299266cddc1ae14d76d725a660bb278816bc151vboxsyncstatic bool g_fDiffIgnoreTrailingWS = false;
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync/** The global settings. */
b2c35a7024c4c308b429c81b203b3bcbd44ee60cvboxsync /* .fConvertEol = */ true,
b2c35a7024c4c308b429c81b203b3bcbd44ee60cvboxsync /* .fConvertTabs = */ true,
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync /* .fForceFinalEol = */ true,
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync /* .fForceTrailingLine = */ false,
b2c35a7024c4c308b429c81b203b3bcbd44ee60cvboxsync /* .fStripTrailingBlanks = */ true,
b2c35a7024c4c308b429c81b203b3bcbd44ee60cvboxsync /* .fStripTrailingLines = */ true,
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync /* .fOnlySvnFiles = */ false,
4bcaf5d320bf0d88910212509c37bdd634e0879evboxsync /* .fOnlySvnDirs = */ false,
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync /* .fSetSvnEol = */ false,
4a4d802b46dfabbfd36e88822ff7b17421120469vboxsync /* .fSetSvnExecutable = */ false,
4a4d802b46dfabbfd36e88822ff7b17421120469vboxsync /* .fSetSvnKeywords = */ false,
e45e3ae4a834169539e689759ba6b3ac71bfe40fvboxsync /* .pszFilterOutFiles = */ (char *)"*.exe|*.com|20*-*-*.log",
e45e3ae4a834169539e689759ba6b3ac71bfe40fvboxsync /* .pszFilterOutDirs = */ (char *)".svn|.hg|.git|CVS",
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync/** Option definitions for the base settings. */
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync { "--convert-eol", SCMOPT_CONVERT_EOL, RTGETOPT_REQ_NOTHING },
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync { "--no-convert-eol", SCMOPT_NO_CONVERT_EOL, RTGETOPT_REQ_NOTHING },
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync { "--convert-tabs", SCMOPT_CONVERT_TABS, RTGETOPT_REQ_NOTHING },
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync { "--no-convert-tabs", SCMOPT_NO_CONVERT_TABS, RTGETOPT_REQ_NOTHING },
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync { "--force-final-eol", SCMOPT_FORCE_FINAL_EOL, RTGETOPT_REQ_NOTHING },
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync { "--no-force-final-eol", SCMOPT_NO_FORCE_FINAL_EOL, RTGETOPT_REQ_NOTHING },
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync { "--force-trailing-line", SCMOPT_FORCE_TRAILING_LINE, RTGETOPT_REQ_NOTHING },
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync { "--no-force-trailing-line", SCMOPT_NO_FORCE_TRAILING_LINE, RTGETOPT_REQ_NOTHING },
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync { "--strip-trailing-blanks", SCMOPT_STRIP_TRAILING_BLANKS, RTGETOPT_REQ_NOTHING },
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync { "--no-strip-trailing-blanks", SCMOPT_NO_STRIP_TRAILING_BLANKS, RTGETOPT_REQ_NOTHING },
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync { "--strip-trailing-lines", SCMOPT_STRIP_TRAILING_LINES, RTGETOPT_REQ_NOTHING },
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync { "--strip-no-trailing-lines", SCMOPT_NO_STRIP_TRAILING_LINES, RTGETOPT_REQ_NOTHING },
4bcaf5d320bf0d88910212509c37bdd634e0879evboxsync { "--only-svn-dirs", SCMOPT_ONLY_SVN_DIRS, RTGETOPT_REQ_NOTHING },
4bcaf5d320bf0d88910212509c37bdd634e0879evboxsync { "--not-only-svn-dirs", SCMOPT_NOT_ONLY_SVN_DIRS, RTGETOPT_REQ_NOTHING },
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync { "--only-svn-files", SCMOPT_ONLY_SVN_FILES, RTGETOPT_REQ_NOTHING },
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync { "--not-only-svn-files", SCMOPT_NOT_ONLY_SVN_FILES, RTGETOPT_REQ_NOTHING },
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync { "--set-svn-eol", SCMOPT_SET_SVN_EOL, RTGETOPT_REQ_NOTHING },
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync { "--dont-set-svn-eol", SCMOPT_DONT_SET_SVN_EOL, RTGETOPT_REQ_NOTHING },
4a4d802b46dfabbfd36e88822ff7b17421120469vboxsync { "--set-svn-executable", SCMOPT_SET_SVN_EXECUTABLE, RTGETOPT_REQ_NOTHING },
4a4d802b46dfabbfd36e88822ff7b17421120469vboxsync { "--dont-set-svn-executable", SCMOPT_DONT_SET_SVN_EXECUTABLE, RTGETOPT_REQ_NOTHING },
4a4d802b46dfabbfd36e88822ff7b17421120469vboxsync { "--set-svn-keywords", SCMOPT_SET_SVN_KEYWORDS, RTGETOPT_REQ_NOTHING },
4a4d802b46dfabbfd36e88822ff7b17421120469vboxsync { "--dont-set-svn-keywords", SCMOPT_DONT_SET_SVN_KEYWORDS, RTGETOPT_REQ_NOTHING },
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync { "--tab-size", SCMOPT_TAB_SIZE, RTGETOPT_REQ_UINT8 },
e45e3ae4a834169539e689759ba6b3ac71bfe40fvboxsync { "--filter-out-dirs", SCMOPT_FILTER_OUT_DIRS, RTGETOPT_REQ_STRING },
e45e3ae4a834169539e689759ba6b3ac71bfe40fvboxsync { "--filter-files", SCMOPT_FILTER_FILES, RTGETOPT_REQ_STRING },
e45e3ae4a834169539e689759ba6b3ac71bfe40fvboxsync { "--filter-out-files", SCMOPT_FILTER_OUT_FILES, RTGETOPT_REQ_STRING },
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync/** Consider files matching the following patterns (base names only). */
a299266cddc1ae14d76d725a660bb278816bc151vboxsyncstatic PFNSCMREWRITER const g_aRewritersFor_Makefile_kup[] =
a299266cddc1ae14d76d725a660bb278816bc151vboxsyncstatic PFNSCMREWRITER const g_aRewritersFor_Makefile_kmk[] =
a299266cddc1ae14d76d725a660bb278816bc151vboxsyncstatic PFNSCMREWRITER const g_aRewritersFor_C_and_CPP[] =
4a4d802b46dfabbfd36e88822ff7b17421120469vboxsyncstatic PFNSCMREWRITER const g_aRewritersFor_H_and_HPP[] =
a299266cddc1ae14d76d725a660bb278816bc151vboxsyncstatic PFNSCMREWRITER const g_aRewritersFor_ShellScripts[] =
a299266cddc1ae14d76d725a660bb278816bc151vboxsyncstatic PFNSCMREWRITER const g_aRewritersFor_BatchFiles[] =
a299266cddc1ae14d76d725a660bb278816bc151vboxsync { RT_ELEMENTS(g_aRewritersFor_Makefile_kup), &g_aRewritersFor_Makefile_kup[0], "Makefile.kup" },
4a4d802b46dfabbfd36e88822ff7b17421120469vboxsync { RT_ELEMENTS(g_aRewritersFor_Makefile_kmk), &g_aRewritersFor_Makefile_kmk[0], "Makefile.kmk|Config.kmk" },
4a4d802b46dfabbfd36e88822ff7b17421120469vboxsync { RT_ELEMENTS(g_aRewritersFor_C_and_CPP), &g_aRewritersFor_C_and_CPP[0], "*.c|*.cpp|*.C|*.CPP|*.cxx|*.cc" },
4a4d802b46dfabbfd36e88822ff7b17421120469vboxsync { RT_ELEMENTS(g_aRewritersFor_H_and_HPP), &g_aRewritersFor_H_and_HPP[0], "*.h|*.hpp" },
d0445e5c26b62718e727032ae46626f5d5db7ae5vboxsync { RT_ELEMENTS(g_aRewritersFor_RC), &g_aRewritersFor_RC[0], "*.rc" },
a299266cddc1ae14d76d725a660bb278816bc151vboxsync { RT_ELEMENTS(g_aRewritersFor_ShellScripts), &g_aRewritersFor_ShellScripts[0], "*.sh|configure" },
a299266cddc1ae14d76d725a660bb278816bc151vboxsync { RT_ELEMENTS(g_aRewritersFor_BatchFiles), &g_aRewritersFor_BatchFiles[0], "*.bat|*.cmd|*.btm|*.vbs|*.ps1" },
a299266cddc1ae14d76d725a660bb278816bc151vboxsync/* -=-=-=-=-=- diff -=-=-=-=-=- */
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * Prints a range of lines with a prefix.
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * @param pState The diff state.
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * @param chPrefix The prefix.
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * @param pStream The stream to get the lines from.
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * @param iLine The first line.
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * @param cLines The number of lines.
a299266cddc1ae14d76d725a660bb278816bc151vboxsyncstatic void scmDiffPrintLines(PSCMDIFFSTATE pState, char chPrefix, PSCMSTREAM pStream, size_t iLine, size_t cLines)
a299266cddc1ae14d76d725a660bb278816bc151vboxsync while (cLines-- > 0)
a299266cddc1ae14d76d725a660bb278816bc151vboxsync const char *pchLine = ScmStreamGetLineByNo(pStream, iLine, &cchLine, &enmEol);
0d1ceffcc16b8999752140e739adb27132655ee8vboxsync const char *pchTab = (const char *)memchr(pchLine, '\t', cchLine);
0d1ceffcc16b8999752140e739adb27132655ee8vboxsync RTStrmWrite(pState->pDiff, pchStart, pchTab - pchStart);
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync size_t cchTab = pState->cchTab - offVir % pState->cchTab;
0d1ceffcc16b8999752140e739adb27132655ee8vboxsync case 4: RTStrmPutStr(pState->pDiff, "[TA]"); break;
0d1ceffcc16b8999752140e739adb27132655ee8vboxsync case 5: RTStrmPutStr(pState->pDiff, "[TAB]"); break;
0d1ceffcc16b8999752140e739adb27132655ee8vboxsync default: RTStrmPrintf(pState->pDiff, "[TAB%.*s]", cchTab - 5, g_szTabSpaces); break;
0d1ceffcc16b8999752140e739adb27132655ee8vboxsync pchTab = (const char *)memchr(pchStart, '\t', cchLine - (pchStart - pchLine));
ad27e1d5e48ca41245120c331cc88b50464813cevboxsync * Reports a difference and propels the streams to the lines following the
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * @returns New pState->cDiff value (just to return something).
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * @param pState The diff state. The cDiffs member will be
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * incremented.
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * @param cMatches The resync length.
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * @param iLeft Where the difference starts on the left side.
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * @param cLeft How long it is on this side. ~(size_t)0 is used
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * to indicate that it goes all the way to the end.
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * @param iRight Where the difference starts on the right side.
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * @param cRight How long it is.
a299266cddc1ae14d76d725a660bb278816bc151vboxsyncstatic size_t scmDiffReport(PSCMDIFFSTATE pState, size_t cMatches,
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * Adjust the input.
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * Print header if it's the first difference
a299266cddc1ae14d76d725a660bb278816bc151vboxsync RTStrmPrintf(pState->pDiff, "diff %s %s\n", pState->pszFilename, pState->pszFilename);
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * Emit the change description.
a299266cddc1ae14d76d725a660bb278816bc151vboxsync RTStrmPrintf(pState->pDiff, "%zu,%zu%c%zu,%zu\n", iLeft + 1, iLeft + cLeft, ch, iRight + 1, iRight + cRight);
a299266cddc1ae14d76d725a660bb278816bc151vboxsync RTStrmPrintf(pState->pDiff, "%zu,%zu%c%zu\n", iLeft + 1, iLeft + cLeft, ch, iRight + 1);
a299266cddc1ae14d76d725a660bb278816bc151vboxsync RTStrmPrintf(pState->pDiff, "%zu%c%zu,%zu\n", iLeft + 1, ch, iRight + 1, iRight + cRight);
a299266cddc1ae14d76d725a660bb278816bc151vboxsync RTStrmPrintf(pState->pDiff, "%zu%c%zu\n", iLeft + 1, ch, iRight + 1);
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * And the lines.
a299266cddc1ae14d76d725a660bb278816bc151vboxsync scmDiffPrintLines(pState, '<', pState->pLeft, iLeft, cLeft);
a299266cddc1ae14d76d725a660bb278816bc151vboxsync scmDiffPrintLines(pState, '>', pState->pRight, iRight, cRight);
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * Reposition the streams (safely ignores return value).
a299266cddc1ae14d76d725a660bb278816bc151vboxsync ScmStreamSeekByLine(pState->pLeft, iLeft + cLeft + cMatches);
a299266cddc1ae14d76d725a660bb278816bc151vboxsync ScmStreamSeekByLine(pState->pRight, iRight + cRight + cMatches);
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * Helper for scmDiffCompare that takes care of trailing spaces and stuff
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * like that.
a299266cddc1ae14d76d725a660bb278816bc151vboxsyncstatic bool scmDiffCompareSlow(PSCMDIFFSTATE pState,
a299266cddc1ae14d76d725a660bb278816bc151vboxsync const char *pchLeft, size_t cchLeft, SCMEOL enmEolLeft,
a299266cddc1ae14d76d725a660bb278816bc151vboxsync const char *pchRight, size_t cchRight, SCMEOL enmEolRight)
a299266cddc1ae14d76d725a660bb278816bc151vboxsync while (cchLeft > 0 && RT_C_IS_SPACE(pchLeft[cchLeft - 1]))
a299266cddc1ae14d76d725a660bb278816bc151vboxsync while (cchRight > 0 && RT_C_IS_SPACE(pchRight[cchRight - 1]))
a299266cddc1ae14d76d725a660bb278816bc151vboxsync || (enmEolLeft != enmEolRight && !pState->fIgnoreEol)
a299266cddc1ae14d76d725a660bb278816bc151vboxsync return false;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync return true;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * Compare two lines.
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * @returns true if the are equal, false if not.
a299266cddc1ae14d76d725a660bb278816bc151vboxsyncDECLINLINE(bool) scmDiffCompare(PSCMDIFFSTATE pState,
a299266cddc1ae14d76d725a660bb278816bc151vboxsync const char *pchLeft, size_t cchLeft, SCMEOL enmEolLeft,
a299266cddc1ae14d76d725a660bb278816bc151vboxsync const char *pchRight, size_t cchRight, SCMEOL enmEolRight)
a299266cddc1ae14d76d725a660bb278816bc151vboxsync || (enmEolLeft != enmEolRight && !pState->fIgnoreEol)
a299266cddc1ae14d76d725a660bb278816bc151vboxsync return false;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync return true;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * Compares two sets of lines from the two files.
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * @returns true if they matches, false if they don't.
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * @param pState The diff state.
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * @param iLeft Where to start in the left stream.
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * @param iRight Where to start in the right stream.
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * @param cLines How many lines to compare.
a299266cddc1ae14d76d725a660bb278816bc151vboxsyncstatic bool scmDiffCompareLines(PSCMDIFFSTATE pState, size_t iLeft, size_t iRight, size_t cLines)
a299266cddc1ae14d76d725a660bb278816bc151vboxsync const char *pchLeft = ScmStreamGetLineByNo(pState->pLeft, iLeft + iLine, &cchLeft, &enmEolLeft);
a299266cddc1ae14d76d725a660bb278816bc151vboxsync const char *pchRight = ScmStreamGetLineByNo(pState->pRight, iRight + iLine, &cchRight, &enmEolRight);
a299266cddc1ae14d76d725a660bb278816bc151vboxsync if (!scmDiffCompare(pState, pchLeft, cchLeft, enmEolLeft, pchRight, cchRight, enmEolRight))
a299266cddc1ae14d76d725a660bb278816bc151vboxsync return false;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync return true;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * Resynchronize the two streams and reports the difference.
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * Upon return, the streams will be positioned after the block of @a cMatches
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * lines where it resynchronized them.
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * @returns pState->cDiffs (just so we can use it in a return statement).
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * @param pState The state.
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * @param cMatches The number of lines that needs to match for the
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * stream to be considered synchronized again.
a299266cddc1ae14d76d725a660bb278816bc151vboxsyncstatic size_t scmDiffSynchronize(PSCMDIFFSTATE pState, size_t cMatches)
a299266cddc1ae14d76d725a660bb278816bc151vboxsync size_t const iStartLeft = ScmStreamTellLine(pState->pLeft) - 1;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync size_t const iStartRight = ScmStreamTellLine(pState->pRight) - 1;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * Compare each new line from each of the streams will all the preceding
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * ones, including iStartLeft/Right.
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * Get the next line in the left stream and compare it against all the
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * preceding lines on the right side.
a299266cddc1ae14d76d725a660bb278816bc151vboxsync const char *pchLine = ScmStreamGetLineByNo(pState->pLeft, iStartLeft + iRange, &cchLine, &enmEol);
a299266cddc1ae14d76d725a660bb278816bc151vboxsync return scmDiffReport(pState, 0, iStartLeft, ~(size_t)0, iStartRight, ~(size_t)0);
a299266cddc1ae14d76d725a660bb278816bc151vboxsync for (size_t iRight = cMatches - 1; iRight < iRange; iRight++)
a299266cddc1ae14d76d725a660bb278816bc151vboxsync const char *pchRight = ScmStreamGetLineByNo(pState->pRight, iStartRight + iRight,
a299266cddc1ae14d76d725a660bb278816bc151vboxsync if ( scmDiffCompare(pState, pchLine, cchLine, enmEol, pchRight, cchRight, enmEolRight)
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * Get the next line in the right stream and compare it against all the
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * lines on the right side.
a299266cddc1ae14d76d725a660bb278816bc151vboxsync pchLine = ScmStreamGetLineByNo(pState->pRight, iStartRight + iRange, &cchLine, &enmEol);
a299266cddc1ae14d76d725a660bb278816bc151vboxsync return scmDiffReport(pState, 0, iStartLeft, ~(size_t)0, iStartRight, ~(size_t)0);
a299266cddc1ae14d76d725a660bb278816bc151vboxsync for (size_t iLeft = cMatches - 1; iLeft <= iRange; iLeft++)
a299266cddc1ae14d76d725a660bb278816bc151vboxsync const char *pchLeft = ScmStreamGetLineByNo(pState->pLeft, iStartLeft + iLeft,
a299266cddc1ae14d76d725a660bb278816bc151vboxsync if ( scmDiffCompare(pState, pchLeft, cchLeft, enmEolLeft, pchLine, cchLine, enmEol)
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * Creates a diff of the changes between the streams @a pLeft and @a pRight.
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * This currently only implements the simplest diff format, so no contexts.
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * Also, note that we won't detect differences in the final newline of the
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * @returns The number of differences.
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * @param pszFilename The filename.
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * @param pLeft The left side stream.
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * @param pRight The right side stream.
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * @param fIgnoreEol Whether to ignore end of line markers.
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * @param fIgnoreLeadingWhite Set if leading white space should be ignored.
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * @param fIgnoreTrailingWhite Set if trailing white space should be ignored.
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * @param fSpecialChars Whether to print special chars in a human
0d1ceffcc16b8999752140e739adb27132655ee8vboxsync * readable form or not.
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * @param cchTab The tab size.
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * @param pDiff Where to write the diff.
a299266cddc1ae14d76d725a660bb278816bc151vboxsyncsize_t ScmDiffStreams(const char *pszFilename, PSCMSTREAM pLeft, PSCMSTREAM pRight, bool fIgnoreEol,
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync bool fIgnoreLeadingWhite, bool fIgnoreTrailingWhite, bool fSpecialChars,
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * Set up the diff state.
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * Compare them line by line.
a299266cddc1ae14d76d725a660bb278816bc151vboxsync const char *pchLeft;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync const char *pchRight;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync pchLeft = ScmStreamGetLine(pLeft, &cchLeft, &enmEolLeft);
a299266cddc1ae14d76d725a660bb278816bc151vboxsync pchRight = ScmStreamGetLine(pRight, &cchRight, &enmEolRight);
a299266cddc1ae14d76d725a660bb278816bc151vboxsync if (!scmDiffCompare(&State, pchLeft, cchLeft, enmEolLeft, pchRight, cchRight, enmEolRight))
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * Deal with any remaining differences.
a299266cddc1ae14d76d725a660bb278816bc151vboxsync scmDiffReport(&State, 0, ScmStreamTellLine(pLeft) - 1, ~(size_t)0, ScmStreamTellLine(pRight), 0);
a299266cddc1ae14d76d725a660bb278816bc151vboxsync scmDiffReport(&State, 0, ScmStreamTellLine(pLeft), 0, ScmStreamTellLine(pRight) - 1, ~(size_t)0);
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * Report any errors.
a299266cddc1ae14d76d725a660bb278816bc151vboxsync RTMsgError("Left diff stream error: %Rrc\n", ScmStreamGetStatus(pLeft));
a299266cddc1ae14d76d725a660bb278816bc151vboxsync RTMsgError("Right diff stream error: %Rrc\n", ScmStreamGetStatus(pRight));
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync/* -=-=-=-=-=- settings -=-=-=-=-=- */
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * Init a settings structure with settings from @a pSrc.
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * @returns IPRT status code
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * @param pSettings The settings.
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * @param pSrc The source settings.
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsyncstatic int scmSettingsBaseInitAndCopy(PSCMSETTINGSBASE pSettings, PCSCMSETTINGSBASE pSrc)
e45e3ae4a834169539e689759ba6b3ac71bfe40fvboxsync int rc = RTStrDupEx(&pSettings->pszFilterFiles, pSrc->pszFilterFiles);
e45e3ae4a834169539e689759ba6b3ac71bfe40fvboxsync rc = RTStrDupEx(&pSettings->pszFilterOutFiles, pSrc->pszFilterOutFiles);
e45e3ae4a834169539e689759ba6b3ac71bfe40fvboxsync rc = RTStrDupEx(&pSettings->pszFilterOutDirs, pSrc->pszFilterOutDirs);
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * Init a settings structure.
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * @returns IPRT status code
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * @param pSettings The settings.
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsyncstatic int scmSettingsBaseInit(PSCMSETTINGSBASE pSettings)
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync return scmSettingsBaseInitAndCopy(pSettings, &g_Defaults);
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * Deletes the settings, i.e. free any dynamically allocated content.
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * @param pSettings The settings.
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsyncstatic void scmSettingsBaseDelete(PSCMSETTINGSBASE pSettings)
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * Processes a RTGetOpt result.
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * @retval VINF_SUCCESS if handled.
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * @retval VERR_OUT_OF_RANGE if the option value was out of range.
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * @retval VERR_GETOPT_UNKNOWN_OPTION if the option was not recognized.
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * @param pSettings The settings to change.
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * @param rc The RTGetOpt return value.
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * @param pValueUnion The RTGetOpt value union.
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsyncstatic int scmSettingsBaseHandleOpt(PSCMSETTINGSBASE pSettings, int rc, PRTGETOPTUNION pValueUnion)
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync RTMsgError("Invalid tab size: %u - must be in {1..%u}\n",
e45e3ae4a834169539e689759ba6b3ac71bfe40fvboxsync case SCMOPT_FILTER_OUT_DIRS: ppsz = &pSettings->pszFilterOutDirs; break;
e45e3ae4a834169539e689759ba6b3ac71bfe40fvboxsync case SCMOPT_FILTER_FILES: ppsz = &pSettings->pszFilterFiles; break;
e45e3ae4a834169539e689759ba6b3ac71bfe40fvboxsync case SCMOPT_FILTER_OUT_FILES: ppsz = &pSettings->pszFilterOutFiles; break;
e45e3ae4a834169539e689759ba6b3ac71bfe40fvboxsync * An empty string zaps the current list.
e45e3ae4a834169539e689759ba6b3ac71bfe40fvboxsync * Non-empty strings are appended to the pattern list.
e45e3ae4a834169539e689759ba6b3ac71bfe40fvboxsync * Strip leading and trailing pattern separators before attempting
e45e3ae4a834169539e689759ba6b3ac71bfe40fvboxsync * to append it. If it's just separators, don't do anything.
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * Parses an option string.
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * @returns IPRT status code.
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * @param pBase The base settings structure to apply the options
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * @param pszOptions The options to parse.
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsyncstatic int scmSettingsBaseParseString(PSCMSETTINGSBASE pBase, const char *pszLine)
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync int rc = RTGetOptArgvFromString(&papszArgs, &cArgs, pszLine, NULL);
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync rc = RTGetOptInit(&GetOptState, cArgs, papszArgs, &g_aScmOpts[0], RT_ELEMENTS(g_aScmOpts), 0, 0 /*fFlags*/);
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync while ((rc = RTGetOpt(&GetOptState, &ValueUnion)) != 0)
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync rc = scmSettingsBaseHandleOpt(pBase, rc, &ValueUnion);
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * Parses an unterminated option string.
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * @returns IPRT status code.
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * @param pBase The base settings structure to apply the options
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * @param pchLine The line.
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * @param cchLine The line length.
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsyncstatic int scmSettingsBaseParseStringN(PSCMSETTINGSBASE pBase, const char *pchLine, size_t cchLine)
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync int rc = scmSettingsBaseParseString(pBase, pszLine);
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * Verifies the options string.
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * @returns IPRT status code.
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * @param pszOptions The options to verify .
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsyncstatic int scmSettingsBaseVerifyString(const char *pszOptions)
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync rc = scmSettingsBaseParseString(&Base, pszOptions);
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * Loads settings found in editor and SCM settings directives within the
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * document (@a pStream).
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * @returns IPRT status code.
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * @param pBase The settings base to load settings into.
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * @param pStream The stream to scan for settings directives.
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsyncstatic int scmSettingsBaseLoadFromDocument(PSCMSETTINGSBASE pBase, PSCMSTREAM pStream)
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync /** @todo Editor and SCM settings directives in documents. */
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * Creates a new settings file struct, cloning @a pSettings.
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * @returns IPRT status code.
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * @param ppSettings Where to return the new struct.
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * @param pSettingsBase The settings to inherit from.
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsyncstatic int scmSettingsCreate(PSCMSETTINGS *ppSettings, PCSCMSETTINGSBASE pSettingsBase)
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync PSCMSETTINGS pSettings = (PSCMSETTINGS)RTMemAlloc(sizeof(*pSettings));
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync int rc = scmSettingsBaseInitAndCopy(&pSettings->Base, pSettingsBase);
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * Destroys a settings structure.
ad27e1d5e48ca41245120c331cc88b50464813cevboxsync * @param pSettings The settings structure to destroy. NULL is OK.
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsyncstatic void scmSettingsDestroy(PSCMSETTINGS pSettings)
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * Adds a pattern/options pair to the settings structure.
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * @returns IPRT status code.
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * @param pSettings The settings.
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * @param pchLine The line containing the unparsed pair.
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * @param cchLine The length of the line.
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsyncstatic int scmSettingsAddPair(PSCMSETTINGS pSettings, const char *pchLine, size_t cchLine)
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * Split the string.
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync const char *pchOptions = (const char *)memchr(pchLine, ':', cchLine);
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync /* strip spaces everywhere */
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync while (cchPattern > 0 && RT_C_IS_SPACE(pchLine[cchPattern - 1]))
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync while (cchOptions > 0 && RT_C_IS_SPACE(pchOptions[cchOptions - 1]))
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync while (cchOptions > 0 && RT_C_IS_SPACE(*pchOptions))
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync /* Quietly ignore empty patterns and empty options. */
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * Add the pair and verify the option string.
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync void *pvNew = RTMemRealloc(pSettings->paPairs, (iPair + 32) * sizeof(pSettings->paPairs[0]));
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync pSettings->paPairs[iPair].pszPattern = RTStrDupN(pchLine, cchPattern);
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync pSettings->paPairs[iPair].pszOptions = RTStrDupN(pchOptions, cchOptions);
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync rc = scmSettingsBaseVerifyString(pSettings->paPairs[iPair].pszOptions);
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * Loads in the settings from @a pszFilename.
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * @returns IPRT status code.
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * @param pSettings Where to load the settings file.
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * @param pszFilename The file to load.
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsyncstatic int scmSettingsLoadFile(PSCMSETTINGS pSettings, const char *pszFilename)
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync int rc = ScmStreamInitForReading(&Stream, pszFilename);
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync RTMsgError("%s: ScmStreamInitForReading -> %Rrc\n", pszFilename, rc);
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync const char *pchLine;
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync while ((pchLine = ScmStreamGetLine(&Stream, &cchLine, &enmEol)) != NULL)
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync /* Ignore leading spaces. */
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync /* Ignore empty lines and comment lines. */
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync /* What kind of line is it? */
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync const char *pchColon = (const char *)memchr(pchLine, ':', cchLine);
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync rc = scmSettingsAddPair(pSettings, pchLine, cchLine);
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync rc = scmSettingsBaseParseStringN(&pSettings->Base, pchLine, cchLine);
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync RTMsgError("%s:%d: %Rrc\n", pszFilename, ScmStreamTellLine(&Stream), rc);
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync RTMsgError("%s: ScmStreamGetStatus- > %Rrc\n", pszFilename, rc);
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * Parse the specified settings file creating a new settings struct from it.
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * @returns IPRT status code
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * @param ppSettings Where to return the new settings.
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * @param pszFilename The file to parse.
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * @param pSettingsBase The base settings we inherit from.
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsyncstatic int scmSettingsCreateFromFile(PSCMSETTINGS *ppSettings, const char *pszFilename, PCSCMSETTINGSBASE pSettingsBase)
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync int rc = scmSettingsCreate(&pSettings, pSettingsBase);
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * Create an initial settings structure when starting processing a new file or
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * directory.
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * This will look for .scm-settings files from the root and down to the
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * specified directory, combining them into the returned settings structure.
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * @returns IPRT status code.
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * @param ppSettings Where to return the pointer to the top stack
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * @param pBaseSettings The base settings we inherit from (globals
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * typically).
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * @param pszPath The absolute path to the new directory or file.
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsyncstatic int scmSettingsCreateForPath(PSCMSETTINGS *ppSettings, PCSCMSETTINGSBASE pBaseSettings, const char *pszPath)
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * We'll be working with a stack copy of the path.
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync if (cchDir >= sizeof(szFile) - sizeof(SCM_SETTINGS_FILENAME))
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * Create the bottom-most settings.
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync int rc = scmSettingsCreate(&pSettings, pBaseSettings);
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * Enumerate the path components from the root and down. Load any setting
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * files we find.
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync size_t cComponents = RTPathCountComponents(pszPath);
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync rc = RTPathCopyComponents(szFile, sizeof(szFile), pszPath, i);
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync rc = RTPathAppend(szFile, sizeof(szFile), SCM_SETTINGS_FILENAME);
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * Pushes a new settings set onto the stack.
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * @param ppSettingsStack The pointer to the pointer to the top stack
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * element. This will be used as input and output.
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * @param pSettings The settings to push onto the stack.
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsyncstatic void scmSettingsStackPush(PSCMSETTINGS *ppSettingsStack, PSCMSETTINGS pSettings)
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * Pushes the settings of the specified directory onto the stack.
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * We will load any .scm-settings in the directory. A stack entry is added even
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * if no settings file was found.
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * @returns IPRT status code.
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * @param ppSettingsStack The pointer to the pointer to the top stack
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * element. This will be used as input and output.
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * @param pszDir The directory to do this for.
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsyncstatic int scmSettingsStackPushDir(PSCMSETTINGS *ppSettingsStack, const char *pszDir)
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync int rc = RTPathJoin(szFile, sizeof(szFile), pszDir, SCM_SETTINGS_FILENAME);
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync rc = scmSettingsCreate(&pSettings, &(*ppSettingsStack)->Base);
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * Pops a settings set off the stack.
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * @returns The popped setttings.
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * @param ppSettingsStack The pointer to the pointer to the top stack
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * element. This will be used as input and output.
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsyncstatic PSCMSETTINGS scmSettingsStackPop(PSCMSETTINGS *ppSettingsStack)
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * Pops and destroys the top entry of the stack.
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * @param ppSettingsStack The pointer to the pointer to the top stack
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * element. This will be used as input and output.
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsyncstatic void scmSettingsStackPopAndDestroy(PSCMSETTINGS *ppSettingsStack)
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync scmSettingsDestroy(scmSettingsStackPop(ppSettingsStack));
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * Constructs the base settings for the specified file name.
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * @returns IPRT status code.
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * @param pSettingsStack The top element on the settings stack.
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * @param pszFilename The file name.
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * @param pszBasename The base name (pointer within @a pszFilename).
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * @param cchBasename The length of the base name. (For passing to
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * RTStrSimplePatternMultiMatch.)
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * @param pBase Base settings to initialize.
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsyncstatic int scmSettingsStackMakeFileBase(PCSCMSETTINGS pSettingsStack, const char *pszFilename,
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync const char *pszBasename, size_t cchBasename, PSCMSETTINGSBASE pBase)
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync int rc = scmSettingsBaseInitAndCopy(pBase, &pSettingsStack->Base);
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync /* find the bottom entry in the stack. */
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync /* Work our way up thru the stack and look for matching pairs. */
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync if ( RTStrSimplePatternMultiMatch(pCur->paPairs[i].pszPattern, RTSTR_MAX,
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync || RTStrSimplePatternMultiMatch(pCur->paPairs[i].pszPattern, RTSTR_MAX,
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync rc = scmSettingsBaseParseString(pBase, pCur->paPairs[i].pszOptions);
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync /* advance */
a299266cddc1ae14d76d725a660bb278816bc151vboxsync/* -=-=-=-=-=- misc -=-=-=-=-=- */
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * Prints a verbose message if the level is high enough.
b2c35a7024c4c308b429c81b203b3bcbd44ee60cvboxsync * @param pState The rewrite state. Optional.
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * @param iLevel The required verbosity level.
b2c35a7024c4c308b429c81b203b3bcbd44ee60cvboxsync * @param pszFormat The message format string. Can be NULL if we
b2c35a7024c4c308b429c81b203b3bcbd44ee60cvboxsync * only want to trigger the per file message.
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * @param ... Format arguments.
b2c35a7024c4c308b429c81b203b3bcbd44ee60cvboxsyncstatic void ScmVerbose(PSCMRWSTATE pState, int iLevel, const char *pszFormat, ...)
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync RTPrintf("%s: info: --= Rewriting '%s' =--\n", g_szProgName, pState->pszFilename);
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync ? "%s: info: "
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync : "%s: info: ",
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync/* -=-=-=-=-=- subversion -=-=-=-=-=- */
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync * Callback that is call for each path to search.
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsyncstatic DECLCALLBACK(int) scmSvnFindSvnBinaryCallback(char const *pchPath, size_t cchPath, void *pvUser1, void *pvUser2)
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync * Finds the svn binary.
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync * @param pszPath Where to store it. Worst case, we'll return
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync * "svn" here.
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync * @param cchPath The size of the buffer pointed to by @a pszPath.
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsyncstatic void scmSvnFindSvnBinary(char *pszPath, size_t cchPath)
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync /** @todo code page fun... */
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync int rc = RTPathTraverseList(pszEnvVar, ';', scmSvnFindSvnBinaryCallback, pszPath, (void *)cchPath);
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync int rc = RTPathTraverseList(pszEnvVar, ':', scmSvnFindSvnBinaryCallback, pszPath, (void *)cchPath);
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync * Construct a dot svn filename for the file being rewritten.
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync * @returns IPRT status code.
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync * @param pState The rewrite state (for the name).
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync * @param pszDir The directory, including ".svn/".
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync * @param pszSuff The filename suffix.
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync * @param pszDst The output buffer. RTPATH_MAX in size.
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsyncstatic int scmSvnConstructName(PSCMRWSTATE pState, const char *pszDir, const char *pszSuff, char *pszDst)
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync strcpy(pszDst, pState->pszFilename); /* ASSUMES sizeof(szBuf) <= sizeof(szPath) */
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync rc = RTPathAppend(pszDst, RTPATH_MAX, RTPathFilename(pState->pszFilename));
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync * Interprets the specified string as decimal numbers.
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync * @returns true if parsed successfully, false if not.
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync * @param pch The string (not terminated).
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync * @param cch The string length.
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync * @param pu Where to return the value.
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsyncstatic bool scmSvnReadNumber(const char *pch, size_t cch, size_t *pu)
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync while (cch-- > 0)
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync return false;
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync return true;
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync#endif /* SCM_WITHOUT_LIBSVN */
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync * Checks if the file we're operating on is part of a SVN working copy.
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync * @returns true if it is, false if it isn't or we cannot tell.
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync * @param pState The rewrite state to work on.
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsyncstatic bool scmSvnIsInWorkingCopy(PSCMRWSTATE pState)
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync * Hack: check if the .svn/text-base/<file>.svn-base file exists.
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync int rc = scmSvnConstructName(pState, ".svn/text-base/", ".svn-base", szPath);
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync return false;
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync * Queries the value of an SVN property.
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync * This will automatically adjust for scheduled changes.
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync * @returns IPRT status code.
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync * @retval VERR_INVALID_STATE if not a SVN WC file.
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync * @retval VERR_NOT_FOUND if the property wasn't found.
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync * @param pState The rewrite state to work on.
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync * @param pszName The property name.
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync * @param ppszValue Where to return the property value. Free this
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync * using RTStrFree. Optional.
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsyncstatic int scmSvnQueryProperty(PSCMRWSTATE pState, const char *pszName, char **ppszValue)
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync * Look it up in the scheduled changes.
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync while (i-- > 0)
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync if (!strcmp(pState->paSvnPropChanges[i].pszName, pszName))
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync const char *pszValue = pState->paSvnPropChanges[i].pszValue;
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync * Hack: Read the .svn/props/<file>.svn-work file exists.
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync int rc = scmSvnConstructName(pState, ".svn/props/", ".svn-work", szPath);
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync rc = scmSvnConstructName(pState, ".svn/prop-base/", ".svn-base", szPath);
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync * The current format is K len\n<name>\nV len\n<value>\n" ... END.
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync const char *pchLine;
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync while ((pchLine = ScmStreamGetLine(&Stream, &cchLine, &enmEol)) != NULL)
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync * Parse the 'K num' / 'END' line.
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync || !scmSvnReadNumber(&pchLine[2], cchLine - 2, &cchKey)
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync RTMsgError("%s:%u: Unexpected data '%.*s'\n", szPath, ScmStreamTellLine(&Stream), cchLine, pchLine);
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync * Match the key and skip to the value line. Don't bother with
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync * names containing EOL markers.
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync pchLine = ScmStreamGetLine(&Stream, &cchLine, &enmEol);
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync if (RT_FAILURE(ScmStreamSeekAbsolute(&Stream, offKey + cchKey)))
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync if (RT_FAILURE(ScmStreamSeekByLine(&Stream, ScmStreamTellLine(&Stream) + 1)))
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync * Read and Parse the 'V num' line.
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync pchLine = ScmStreamGetLine(&Stream, &cchLine, &enmEol);
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync || !scmSvnReadNumber(&pchLine[2], cchLine - 2, &cchValue)
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync RTMsgError("%s:%u: Unexpected data '%.*s'\n", szPath, ScmStreamTellLine(&Stream), cchLine, pchLine);
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync * If we have a match, allocate a return buffer and read the
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync * value into it. Otherwise skip this value and continue
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync * searching.
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync if (RT_FAILURE(ScmStreamSeekRelative(&Stream, cchValue)))
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync if (RT_FAILURE(ScmStreamSeekByLine(&Stream, ScmStreamTellLine(&Stream) + 1)))
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync * Schedules the setting of a property.
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync * @returns IPRT status code.
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync * @retval VERR_INVALID_STATE if not a SVN WC file.
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync * @param pState The rewrite state to work on.
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync * @param pszName The name of the property to set.
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync * @param pszValue The value. NULL means deleting it.
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsyncstatic int scmSvnSetProperty(PSCMRWSTATE pState, const char *pszName, const char *pszValue)
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync * Update any existing entry first.
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync while (i-- > 0)
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync if (!strcmp(pState->paSvnPropChanges[i].pszName, pszName))
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync * Insert a new entry.
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync if ((i % 32) == 0)
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync void *pvNew = RTMemRealloc(pState->paSvnPropChanges, (i + 32) * sizeof(SCMSVNPROP));
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync pState->paSvnPropChanges[i].pszName = RTStrDup(pszName);
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync pState->paSvnPropChanges[i].pszValue = pszValue ? RTStrDup(pszValue) : NULL;
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync && (pState->paSvnPropChanges[i].pszValue || !pszValue) )
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync * Schedules a property deletion.
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync * @returns IPRT status code.
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync * @param pState The rewrite state to work on.
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync * @param pszName The name of the property to delete.
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsyncstatic int scmSvnDelProperty(PSCMRWSTATE pState, const char *pszName)
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync * Applies any SVN property changes to the work copy of the file.
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync * @returns IPRT status code.
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync * @param pState The rewrite state which SVN property changes
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync * should be applied.
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync while (i-- > 0)
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync const char *pszName = pState->paSvnPropChanges[i].pszName;
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync const char *pszValue = pState->paSvnPropChanges[i].pszValue;
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync ScmVerbose(pState, 0, "svn ps '%s' '%s' %s\n", pszName, pszValue, pState->pszFilename);
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync ScmVerbose(pState, 0, "svn pd '%s' %s\n", pszName, pszValue, pState->pszFilename);
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync * Applies any SVN property changes to the work copy of the file.
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync * @returns IPRT status code.
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync * @param pState The rewrite state which SVN property changes
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync * should be applied.
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync * This sucks. We gotta find svn(.exe).
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync scmSvnFindSvnBinary(s_szSvnPath, sizeof(s_szSvnPath));
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync * Iterate thru the changes and apply them by starting the svn client.
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync for (size_t i = 0; i <pState->cSvnPropChanges; i++)
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync apszArgv[1] = pState->paSvnPropChanges[i].pszValue ? "ps" : "pd";
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync apszArgv[iArg++] = pState->paSvnPropChanges[i].pszValue;
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync ScmVerbose(pState, 2, "executing: %s %s %s %s %s\n",
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync apszArgv[0], apszArgv[1], apszArgv[2], apszArgv[3], apszArgv[4]);
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync int rc = RTProcCreate(s_szSvnPath, apszArgv, RTENV_DEFAULT, 0 /*fFlags*/, &pid);
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync rc = RTProcWait(pid, RTPROCWAIT_FLAGS_BLOCK, &Status);
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync pState->pszFilename, apszArgv[0], apszArgv[1], apszArgv[2], apszArgv[3], apszArgv[4],
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync Status.enmReason == RTPROCEXITREASON_NORMAL ? "exit code"
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync : Status.enmReason == RTPROCEXITREASON_SIGNAL ? "signal"
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync : Status.enmReason == RTPROCEXITREASON_ABEND ? "abnormal end"
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync : "abducted by alien",
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync RTMsgError("%s: error executing %s %s %s %s %s: %Rrc\n",
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync pState->pszFilename, apszArgv[0], apszArgv[1], apszArgv[2], apszArgv[3], apszArgv[4], rc);
a299266cddc1ae14d76d725a660bb278816bc151vboxsync/* -=-=-=-=-=- rewriters -=-=-=-=-=- */
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * Strip trailing blanks (space & tab).
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * @returns True if modified, false if not.
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * @param pIn The input stream.
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * @param pOut The output stream.
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * @param pSettings The settings.
b2c35a7024c4c308b429c81b203b3bcbd44ee60cvboxsyncstatic bool rewrite_StripTrailingBlanks(PSCMRWSTATE pState, PSCMSTREAM pIn, PSCMSTREAM pOut, PCSCMSETTINGSBASE pSettings)
a299266cddc1ae14d76d725a660bb278816bc151vboxsync return false;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync bool fModified = false;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync const char *pchLine;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync while ((pchLine = ScmStreamGetLine(pIn, &cchLine, &enmEol)) != NULL)
a299266cddc1ae14d76d725a660bb278816bc151vboxsync rc = ScmStreamPutLine(pOut, pchLine, cchLine, enmEol);
a299266cddc1ae14d76d725a660bb278816bc151vboxsync while (cchLine > 0 && RT_C_IS_BLANK(pchLine[cchLine - 1]))
a299266cddc1ae14d76d725a660bb278816bc151vboxsync rc = ScmStreamPutLine(pOut, pchLine, cchLine, enmEol);
a299266cddc1ae14d76d725a660bb278816bc151vboxsync return false;
b2c35a7024c4c308b429c81b203b3bcbd44ee60cvboxsync ScmVerbose(pState, 2, " * Stripped trailing blanks\n");
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * Expand tabs.
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * @returns True if modified, false if not.
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * @param pIn The input stream.
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * @param pOut The output stream.
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * @param pSettings The settings.
b2c35a7024c4c308b429c81b203b3bcbd44ee60cvboxsyncstatic bool rewrite_ExpandTabs(PSCMRWSTATE pState, PSCMSTREAM pIn, PSCMSTREAM pOut, PCSCMSETTINGSBASE pSettings)
a299266cddc1ae14d76d725a660bb278816bc151vboxsync return false;
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync bool fModified = false;
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync const char *pchLine;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync while ((pchLine = ScmStreamGetLine(pIn, &cchLine, &enmEol)) != NULL)
a299266cddc1ae14d76d725a660bb278816bc151vboxsync const char *pchTab = (const char *)memchr(pchLine, '\t', cchLine);
a299266cddc1ae14d76d725a660bb278816bc151vboxsync rc = ScmStreamPutLine(pOut, pchLine, cchLine, enmEol);
a299266cddc1ae14d76d725a660bb278816bc151vboxsync pchTab = (const char *)memchr(pchChunk, '\t', cchLeft);
a299266cddc1ae14d76d725a660bb278816bc151vboxsync rc = ScmStreamPutLine(pOut, pchChunk, cchLeft, enmEol);
a299266cddc1ae14d76d725a660bb278816bc151vboxsync return false;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * Worker for rewrite_ForceNativeEol, rewrite_ForceLF and rewrite_ForceCRLF.
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * @returns true if modifications were made, false if not.
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * @param pIn The input stream.
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * @param pOut The output stream.
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * @param pSettings The settings.
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * @param enmDesiredEol The desired end of line indicator type.
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync * @param pszDesiredSvnEol The desired svn:eol-style.
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsyncstatic bool rewrite_ForceEol(PSCMRWSTATE pState, PSCMSTREAM pIn, PSCMSTREAM pOut, PCSCMSETTINGSBASE pSettings,
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync SCMEOL enmDesiredEol, const char *pszDesiredSvnEol)
a299266cddc1ae14d76d725a660bb278816bc151vboxsync return false;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync bool fModified = false;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync const char *pchLine;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync while ((pchLine = ScmStreamGetLine(pIn, &cchLine, &enmEol)) != NULL)
a299266cddc1ae14d76d725a660bb278816bc151vboxsync int rc = ScmStreamPutLine(pOut, pchLine, cchLine, enmEol);
a299266cddc1ae14d76d725a660bb278816bc151vboxsync return false;
b2c35a7024c4c308b429c81b203b3bcbd44ee60cvboxsync ScmVerbose(pState, 2, " * Converted EOL markers\n");
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync /* Check svn:eol-style if appropriate */
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync int rc = scmSvnQueryProperty(pState, "svn:eol-style", &pszEol);
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync if ( (RT_SUCCESS(rc) && strcmp(pszEol, pszDesiredSvnEol))
4a4d802b46dfabbfd36e88822ff7b17421120469vboxsync ScmVerbose(pState, 2, " * Setting svn:eol-style to %s (missing)\n", pszDesiredSvnEol);
4a4d802b46dfabbfd36e88822ff7b17421120469vboxsync ScmVerbose(pState, 2, " * Setting svn:eol-style to %s (was: %s)\n", pszDesiredSvnEol, pszEol);
4a4d802b46dfabbfd36e88822ff7b17421120469vboxsync int rc2 = scmSvnSetProperty(pState, "svn:eol-style", pszDesiredSvnEol);
4a4d802b46dfabbfd36e88822ff7b17421120469vboxsync RTMsgError("scmSvnSetProperty: %Rrc\n", rc2); /** @todo propagate the error somehow... */
56689b5c06781615da91826b9f9df665826a0b92vboxsync /** @todo also check the subversion svn:eol-style state! */
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * Force native end of line indicator.
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * @returns true if modifications were made, false if not.
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * @param pIn The input stream.
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * @param pOut The output stream.
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * @param pSettings The settings.
b2c35a7024c4c308b429c81b203b3bcbd44ee60cvboxsyncstatic bool rewrite_ForceNativeEol(PSCMRWSTATE pState, PSCMSTREAM pIn, PSCMSTREAM pOut, PCSCMSETTINGSBASE pSettings)
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync return rewrite_ForceEol(pState, pIn, pOut, pSettings, SCMEOL_CRLF, "native");
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync return rewrite_ForceEol(pState, pIn, pOut, pSettings, SCMEOL_LF, "native");
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * Force the stream to use LF as the end of line indicator.
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * @returns true if modifications were made, false if not.
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * @param pIn The input stream.
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * @param pOut The output stream.
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * @param pSettings The settings.
b2c35a7024c4c308b429c81b203b3bcbd44ee60cvboxsyncstatic bool rewrite_ForceLF(PSCMRWSTATE pState, PSCMSTREAM pIn, PSCMSTREAM pOut, PCSCMSETTINGSBASE pSettings)
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync return rewrite_ForceEol(pState, pIn, pOut, pSettings, SCMEOL_LF, "LF");
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * Force the stream to use CRLF as the end of line indicator.
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * @returns true if modifications were made, false if not.
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * @param pIn The input stream.
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * @param pOut The output stream.
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * @param pSettings The settings.
b2c35a7024c4c308b429c81b203b3bcbd44ee60cvboxsyncstatic bool rewrite_ForceCRLF(PSCMRWSTATE pState, PSCMSTREAM pIn, PSCMSTREAM pOut, PCSCMSETTINGSBASE pSettings)
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync return rewrite_ForceEol(pState, pIn, pOut, pSettings, SCMEOL_CRLF, "CRLF");
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * Strip trailing blank lines and/or make sure there is exactly one blank line
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * at the end of the file.
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * @returns true if modifications were made, false if not.
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * @param pIn The input stream.
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * @param pOut The output stream.
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * @param pSettings The settings.
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * @remarks ASSUMES trailing white space has been removed already.
b2c35a7024c4c308b429c81b203b3bcbd44ee60cvboxsyncstatic bool rewrite_AdjustTrailingLines(PSCMRWSTATE pState, PSCMSTREAM pIn, PSCMSTREAM pOut, PCSCMSETTINGSBASE pSettings)
a299266cddc1ae14d76d725a660bb278816bc151vboxsync return false;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync /* Empty files remains empty. */
a299266cddc1ae14d76d725a660bb278816bc151vboxsync return false;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync /* Figure out if we need to adjust the number of lines or not. */
a299266cddc1ae14d76d725a660bb278816bc151vboxsync && ScmStreamGetEolByLine(pIn, cLinesNew - 1) == SCMEOL_NONE;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync return false;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync /* Copy the number of lines we've arrived at. */
a299266cddc1ae14d76d725a660bb278816bc151vboxsync ScmStreamPutLine(pOut, "", 0, ScmStreamGetEol(pIn));
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync /* Fix missing EOL if required. */
b2c35a7024c4c308b429c81b203b3bcbd44ee60cvboxsync ScmVerbose(pState, 2, " * Adjusted trailing blank lines\n");
a299266cddc1ae14d76d725a660bb278816bc151vboxsync return true;
4a4d802b46dfabbfd36e88822ff7b17421120469vboxsync * Make sure there is no svn:executable keyword on the current file.
4a4d802b46dfabbfd36e88822ff7b17421120469vboxsync * @returns false - the state carries these kinds of changes.
4a4d802b46dfabbfd36e88822ff7b17421120469vboxsync * @param pState The rewriter state.
4a4d802b46dfabbfd36e88822ff7b17421120469vboxsync * @param pIn The input stream.
4a4d802b46dfabbfd36e88822ff7b17421120469vboxsync * @param pOut The output stream.
4a4d802b46dfabbfd36e88822ff7b17421120469vboxsync * @param pSettings The settings.
4a4d802b46dfabbfd36e88822ff7b17421120469vboxsyncstatic bool rewrite_SvnNoExecutable(PSCMRWSTATE pState, PSCMSTREAM pIn, PSCMSTREAM pOut, PCSCMSETTINGSBASE pSettings)
4a4d802b46dfabbfd36e88822ff7b17421120469vboxsync return false;
4a4d802b46dfabbfd36e88822ff7b17421120469vboxsync int rc = scmSvnQueryProperty(pState, "svn:executable", NULL);
4a4d802b46dfabbfd36e88822ff7b17421120469vboxsync ScmVerbose(pState, 2, " * removing svn:executable\n");
4a4d802b46dfabbfd36e88822ff7b17421120469vboxsync RTMsgError("scmSvnSetProperty: %Rrc\n", rc); /** @todo error propagation here.. */
4a4d802b46dfabbfd36e88822ff7b17421120469vboxsync return false;
4a4d802b46dfabbfd36e88822ff7b17421120469vboxsync * Make sure the Id and Revision keywords are expanded.
4a4d802b46dfabbfd36e88822ff7b17421120469vboxsync * @returns false - the state carries these kinds of changes.
4a4d802b46dfabbfd36e88822ff7b17421120469vboxsync * @param pState The rewriter state.
4a4d802b46dfabbfd36e88822ff7b17421120469vboxsync * @param pIn The input stream.
4a4d802b46dfabbfd36e88822ff7b17421120469vboxsync * @param pOut The output stream.
4a4d802b46dfabbfd36e88822ff7b17421120469vboxsync * @param pSettings The settings.
4a4d802b46dfabbfd36e88822ff7b17421120469vboxsyncstatic bool rewrite_SvnKeywords(PSCMRWSTATE pState, PSCMSTREAM pIn, PSCMSTREAM pOut, PCSCMSETTINGSBASE pSettings)
4a4d802b46dfabbfd36e88822ff7b17421120469vboxsync return false;
4a4d802b46dfabbfd36e88822ff7b17421120469vboxsync int rc = scmSvnQueryProperty(pState, "svn:keywords", &pszKeywords);
4a4d802b46dfabbfd36e88822ff7b17421120469vboxsync && ( !strstr(pszKeywords, "Id") /** @todo need some function for finding a word in a string. */
4a4d802b46dfabbfd36e88822ff7b17421120469vboxsync if (!strstr(pszKeywords, "Id") && !strstr(pszKeywords, "Revision"))
4a4d802b46dfabbfd36e88822ff7b17421120469vboxsync ScmVerbose(pState, 2, " * changing svn:keywords to '%s'\n", pszKeywords);
4a4d802b46dfabbfd36e88822ff7b17421120469vboxsync rc = scmSvnSetProperty(pState, "svn:keywords", pszKeywords);
4a4d802b46dfabbfd36e88822ff7b17421120469vboxsync RTMsgError("scmSvnSetProperty: %Rrc\n", rc); /** @todo error propagation here.. */
4a4d802b46dfabbfd36e88822ff7b17421120469vboxsync RTMsgError("RTStrAppend: %Rrc\n", rc); /** @todo error propagation here.. */
4a4d802b46dfabbfd36e88822ff7b17421120469vboxsync ScmVerbose(pState, 2, " * setting svn:keywords to 'Id Revision'\n");
4a4d802b46dfabbfd36e88822ff7b17421120469vboxsync rc = scmSvnSetProperty(pState, "svn:keywords", "Id Revision");
4a4d802b46dfabbfd36e88822ff7b17421120469vboxsync RTMsgError("scmSvnSetProperty: %Rrc\n", rc); /** @todo error propagation here.. */
4a4d802b46dfabbfd36e88822ff7b17421120469vboxsync return false;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * Makefile.kup are empty files, enforce this.
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * @returns true if modifications were made, false if not.
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * @param pIn The input stream.
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * @param pOut The output stream.
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * @param pSettings The settings.
b2c35a7024c4c308b429c81b203b3bcbd44ee60cvboxsyncstatic bool rewrite_Makefile_kup(PSCMRWSTATE pState, PSCMSTREAM pIn, PSCMSTREAM pOut, PCSCMSETTINGSBASE pSettings)
a299266cddc1ae14d76d725a660bb278816bc151vboxsync /* These files should be zero bytes. */
a299266cddc1ae14d76d725a660bb278816bc151vboxsync return false;
b2c35a7024c4c308b429c81b203b3bcbd44ee60cvboxsync ScmVerbose(pState, 2, " * Truncated file to zero bytes\n");
a299266cddc1ae14d76d725a660bb278816bc151vboxsync return true;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * Rewrite a kBuild makefile.
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * @returns true if modifications were made, false if not.
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * @param pIn The input stream.
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * @param pOut The output stream.
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * @param pSettings The settings.
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * Ideas for Makefile.kmk and Config.kmk:
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * - sort if1of/ifn1of sets.
ad27e1d5e48ca41245120c331cc88b50464813cevboxsync * - line continuation slashes should only be preceded by one space.
b2c35a7024c4c308b429c81b203b3bcbd44ee60cvboxsyncstatic bool rewrite_Makefile_kmk(PSCMRWSTATE pState, PSCMSTREAM pIn, PSCMSTREAM pOut, PCSCMSETTINGSBASE pSettings)
a299266cddc1ae14d76d725a660bb278816bc151vboxsync return false;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * Rewrite a C/C++ source or header file.
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * @returns true if modifications were made, false if not.
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * @param pIn The input stream.
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * @param pOut The output stream.
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * @param pSettings The settings.
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * Ideas for C/C++:
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * - space after if, while, for, switch
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * - spaces in for (i=0;i<x;i++)
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * - complex conditional, bird style.
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * - remove unnecessary parentheses.
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * - sort defined RT_OS_*|| and RT_ARCH
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * - sizeof without parenthesis.
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * - defined without parenthesis.
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * - trailing spaces.
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * - parameter indentation.
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * - space after comma.
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * - while (x--); -> multi line + comment.
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * - else statement;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * - space between function and left parenthesis.
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * - TODO, XXX, @todo cleanup.
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * - Space before/after '*'.
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * - ensure new line at end of file.
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * - Indentation of precompiler statements (#ifdef, #defines).
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * - space between functions.
98f3fccfd724f9a7ea850014a749f81c2a895c70vboxsync * - string.h -> iprt/string.h, stdarg.h -> iprt/stdarg.h, etc.
b2c35a7024c4c308b429c81b203b3bcbd44ee60cvboxsyncstatic bool rewrite_C_and_CPP(PSCMRWSTATE pState, PSCMSTREAM pIn, PSCMSTREAM pOut, PCSCMSETTINGSBASE pSettings)
a299266cddc1ae14d76d725a660bb278816bc151vboxsync return false;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync/* -=-=-=-=-=- file and directory processing -=-=-=-=-=- */
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * Processes a file.
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * @returns IPRT status code.
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync * @param pState The rewriter state.
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * @param pszFilename The file name.
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * @param pszBasename The base name (pointer within @a pszFilename).
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * @param cchBasename The length of the base name. (For passing to
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * RTStrSimplePatternMultiMatch.)
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * @param pBaseSettings The base settings to use. It's OK to modify
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsyncstatic int scmProcessFileInner(PSCMRWSTATE pState, const char *pszFilename, const char *pszBasename, size_t cchBasename,
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * Do the file level filtering.
e45e3ae4a834169539e689759ba6b3ac71bfe40fvboxsync && !RTStrSimplePatternMultiMatch(pBaseSettings->pszFilterFiles, RTSTR_MAX, pszBasename, cchBasename, NULL))
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync ScmVerbose(NULL, 5, "skipping '%s': file filter mismatch\n", pszFilename);
e45e3ae4a834169539e689759ba6b3ac71bfe40fvboxsync && ( RTStrSimplePatternMultiMatch(pBaseSettings->pszFilterOutFiles, RTSTR_MAX, pszBasename, cchBasename, NULL)
e45e3ae4a834169539e689759ba6b3ac71bfe40fvboxsync || RTStrSimplePatternMultiMatch(pBaseSettings->pszFilterOutFiles, RTSTR_MAX, pszFilename, RTSTR_MAX, NULL)) )
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync ScmVerbose(NULL, 5, "skipping '%s': filterd out\n", pszFilename);
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync ScmVerbose(NULL, 5, "skipping '%s': not in SVN WC\n", pszFilename);
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * Try find a matching rewrite config for this filename.
a299266cddc1ae14d76d725a660bb278816bc151vboxsync for (size_t iCfg = 0; iCfg < RT_ELEMENTS(g_aConfigs); iCfg++)
a299266cddc1ae14d76d725a660bb278816bc151vboxsync if (RTStrSimplePatternMultiMatch(g_aConfigs[iCfg].pszFilePattern, RTSTR_MAX, pszBasename, cchBasename, NULL))
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync ScmVerbose(NULL, 4, "skipping '%s': no rewriters configured\n", pszFilename);
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync ScmVerbose(pState, 4, "matched \"%s\"\n", pCfg->pszFilePattern);
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * Create an input stream from the file and check that it's text.
a299266cddc1ae14d76d725a660bb278816bc151vboxsync int rc = ScmStreamInitForReading(&Stream1, pszFilename);
a299266cddc1ae14d76d725a660bb278816bc151vboxsync RTMsgError("Failed to read '%s': %Rrc\n", pszFilename, rc);
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * Gather SCM and editor settings from the stream.
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync rc = scmSettingsBaseLoadFromDocument(pBaseSettings, &Stream1);
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * Create two more streams for output and push the text thru all the
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * rewriters, switching the two streams around when something is
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * actually rewritten. Stream1 remains unchanged.
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync bool fModified = false;
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync for (size_t iRw = 0; iRw < pCfg->cRewriters; iRw++)
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync bool fRc = pCfg->papfnRewriter[iRw](pState, pIn, pOut, pBaseSettings);
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync * If rewritten, write it back to disk.
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync ScmVerbose(pState, 1, "writing modified file to \"%s%s\"\n", pszFilename, g_pszChangedSuff);
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync rc = ScmStreamWriteToFile(pIn, "%s%s", pszFilename, g_pszChangedSuff);
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync RTMsgError("Error writing '%s%s': %Rrc\n", pszFilename, g_pszChangedSuff, rc);
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync ScmDiffStreams(pszFilename, &Stream1, pIn, g_fDiffIgnoreEol, g_fDiffIgnoreLeadingWS,
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync g_fDiffIgnoreTrailingWS, g_fDiffSpecialChars, pBaseSettings->cchTab, g_pStdOut);
4a4d802b46dfabbfd36e88822ff7b17421120469vboxsync ScmVerbose(pState, 2, "would have modified the file \"%s%s\"\n", pszFilename, g_pszChangedSuff);
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync * If pending SVN property changes, apply them.
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync RTMsgError("%s: failed to apply SVN property changes (%Rrc)\n", pszFilename, rc);
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync RTMsgError("%s: stream error %Rrc\n", pszFilename);
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync RTMsgError("Failed to init stream for writing: %Rrc\n", rc);
a299266cddc1ae14d76d725a660bb278816bc151vboxsync RTMsgError("Failed to init stream for writing: %Rrc\n", rc);
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync RTMsgError("scmSettingsBaseLoadFromDocument: %Rrc\n", rc);
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync ScmVerbose(pState, 4, "not text file: \"%s\"\n", pszFilename);
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * Processes a file.
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * This is just a wrapper for scmProcessFileInner for avoid wasting stack in the
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * directory recursion method.
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * @returns IPRT status code.
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * @param pszFilename The file name.
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * @param pszBasename The base name (pointer within @a pszFilename).
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * @param cchBasename The length of the base name. (For passing to
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * RTStrSimplePatternMultiMatch.)
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * @param pSettingsStack The settings stack (pointer to the top element).
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsyncstatic int scmProcessFile(const char *pszFilename, const char *pszBasename, size_t cchBasename,
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync int rc = scmSettingsStackMakeFileBase(pSettingsStack, pszFilename, pszBasename, cchBasename, &Base);
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync rc = scmProcessFileInner(&State, pszFilename, pszBasename, cchBasename, &Base);
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync while (i-- > 0)
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * Tries to correct RTDIRENTRY_UNKNOWN.
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * @returns Corrected type.
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * @param pszPath The path to the object in question.
a299266cddc1ae14d76d725a660bb278816bc151vboxsyncstatic RTDIRENTRYTYPE scmFigureUnknownType(const char *pszPath)
a299266cddc1ae14d76d725a660bb278816bc151vboxsync int rc = RTPathQueryInfo(pszPath, &Info, RTFSOBJATTRADD_NOTHING);
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * Recurse into a sub-directory and process all the files and directories.
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * @returns IPRT status code.
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * @param pszBuf Path buffer containing the directory path on
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * entry. This ends with a dot. This is passed
ad27e1d5e48ca41245120c331cc88b50464813cevboxsync * along when recursing in order to save stack space
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * and avoid needless copying.
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * @param cchDir Length of our path in pszbuf.
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * @param pEntry Directory entry buffer. This is also passed
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * along when recursing to save stack space.
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * @param pSettingsStack The settings stack (pointer to the top element).
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * @param iRecursion The recursion depth. This is used to restrict
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * the recursions.
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsyncstatic int scmProcessDirTreeRecursion(char *pszBuf, size_t cchDir, PRTDIRENTRY pEntry,
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * Make sure we stop somewhere.
a299266cddc1ae14d76d725a660bb278816bc151vboxsync RTMsgError("recursion too deep: %d\n", iRecursion);
4bcaf5d320bf0d88910212509c37bdd634e0879evboxsync * Check if it's excluded by --only-svn-dir.
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * Try open and read the directory.
939e2ecb812c6402abcc63e7d615c5444acfd02evboxsync rc = RTDirOpenFiltered(&pDir, pszBuf, RTDIRFILTER_NONE, 0);
a299266cddc1ae14d76d725a660bb278816bc151vboxsync RTMsgError("Failed to enumerate directory '%s': %Rrc", pszBuf, rc);
a299266cddc1ae14d76d725a660bb278816bc151vboxsync /* Read the next entry. */
a299266cddc1ae14d76d725a660bb278816bc151vboxsync /* Skip '.' and '..'. */
a299266cddc1ae14d76d725a660bb278816bc151vboxsync /* Enter it into the buffer so we've got a full name to work
a299266cddc1ae14d76d725a660bb278816bc151vboxsync with when needed. */
a299266cddc1ae14d76d725a660bb278816bc151vboxsync RTMsgError("Skipping too long entry: %s", pEntry->szName);
a299266cddc1ae14d76d725a660bb278816bc151vboxsync memcpy(&pszBuf[cchDir - 1], pEntry->szName, pEntry->cbName + 1);
a299266cddc1ae14d76d725a660bb278816bc151vboxsync /* Figure the type. */
a299266cddc1ae14d76d725a660bb278816bc151vboxsync /* Process the file or directory, skip the rest. */
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync rc = scmProcessFile(pszBuf, pEntry->szName, pEntry->cbName, pSettingsStack);
a299266cddc1ae14d76d725a660bb278816bc151vboxsync /* Append the dot for the benefit of the pattern matching. */
a299266cddc1ae14d76d725a660bb278816bc151vboxsync RTMsgError("Skipping too deep dir entry: %s", pEntry->szName);
a299266cddc1ae14d76d725a660bb278816bc151vboxsync memcpy(&pszBuf[cchDir - 1 + pEntry->cbName], "/.", sizeof("/."));
a299266cddc1ae14d76d725a660bb278816bc151vboxsync size_t cchSubDir = cchDir - 1 + pEntry->cbName + sizeof("/.") - 1;
e45e3ae4a834169539e689759ba6b3ac71bfe40fvboxsync || ( !RTStrSimplePatternMultiMatch(pSettingsStack->Base.pszFilterOutDirs, RTSTR_MAX,
e45e3ae4a834169539e689759ba6b3ac71bfe40fvboxsync && !RTStrSimplePatternMultiMatch(pSettingsStack->Base.pszFilterOutDirs, RTSTR_MAX,
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync rc = scmSettingsStackPushDir(&pSettingsStack, pszBuf);
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync rc = scmProcessDirTreeRecursion(pszBuf, cchSubDir, pEntry, pSettingsStack, iRecursion + 1);
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * Process a directory tree.
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * @returns IPRT status code.
da0b2d0ebcbeb635e76686254cc10c70faa37ee6vboxsync * @param pszDir The directory to start with. This is pointer to
da0b2d0ebcbeb635e76686254cc10c70faa37ee6vboxsync * a RTPATH_MAX sized buffer.
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsyncstatic int scmProcessDirTree(char *pszDir, PSCMSETTINGS pSettingsStack)
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * Setup the recursion.
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync rc = scmProcessDirTreeRecursion(pszDir, strlen(pszDir), &Entry, pSettingsStack, 0);
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * Processes a file or directory specified as an command line argument.
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * @returns IPRT status code
ad27e1d5e48ca41245120c331cc88b50464813cevboxsync * @param pszSomething What we found in the command line arguments.
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * @param pSettingsStack The settings stack (pointer to the top element).
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsyncstatic int scmProcessSomething(const char *pszSomething, PSCMSETTINGS pSettingsStack)
da0b2d0ebcbeb635e76686254cc10c70faa37ee6vboxsync int rc = RTPathAbs(pszSomething, szBuf, sizeof(szBuf));
56689b5c06781615da91826b9f9df665826a0b92vboxsync RTPathChangeToUnixSlashes(szBuf, false /*fForce*/);
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync rc = scmSettingsCreateForPath(&pSettings, &pSettingsStack->Base, szBuf);
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync rc = scmProcessFile(szBuf, pszBasename, cchBasename, pSettingsStack);
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync PSCMSETTINGS pPopped = scmSettingsStackPop(&pSettingsStack);
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * Init the settings.
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * Parse arguments and process input in order (because this is the only
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * thing that works at the moment).
b2c35a7024c4c308b429c81b203b3bcbd44ee60cvboxsync static RTGETOPTDEF s_aOpts[14 + RT_ELEMENTS(g_aScmOpts)] =
a299266cddc1ae14d76d725a660bb278816bc151vboxsync { "--diff-ignore-eol", SCMOPT_DIFF_IGNORE_EOL, RTGETOPT_REQ_NOTHING },
a299266cddc1ae14d76d725a660bb278816bc151vboxsync { "--diff-no-ignore-eol", SCMOPT_DIFF_NO_IGNORE_EOL, RTGETOPT_REQ_NOTHING },
a299266cddc1ae14d76d725a660bb278816bc151vboxsync { "--diff-ignore-space", SCMOPT_DIFF_IGNORE_SPACE, RTGETOPT_REQ_NOTHING },
a299266cddc1ae14d76d725a660bb278816bc151vboxsync { "--diff-no-ignore-space", SCMOPT_DIFF_NO_IGNORE_SPACE, RTGETOPT_REQ_NOTHING },
a299266cddc1ae14d76d725a660bb278816bc151vboxsync { "--diff-ignore-leading-space", SCMOPT_DIFF_IGNORE_LEADING_SPACE, RTGETOPT_REQ_NOTHING },
a299266cddc1ae14d76d725a660bb278816bc151vboxsync { "--diff-no-ignore-leading-space", SCMOPT_DIFF_NO_IGNORE_LEADING_SPACE, RTGETOPT_REQ_NOTHING },
a299266cddc1ae14d76d725a660bb278816bc151vboxsync { "--diff-ignore-trailing-space", SCMOPT_DIFF_IGNORE_TRAILING_SPACE, RTGETOPT_REQ_NOTHING },
a299266cddc1ae14d76d725a660bb278816bc151vboxsync { "--diff-no-ignore-trailing-space", SCMOPT_DIFF_NO_IGNORE_TRAILING_SPACE, RTGETOPT_REQ_NOTHING },
a299266cddc1ae14d76d725a660bb278816bc151vboxsync { "--diff-special-chars", SCMOPT_DIFF_SPECIAL_CHARS, RTGETOPT_REQ_NOTHING },
a299266cddc1ae14d76d725a660bb278816bc151vboxsync { "--diff-no-special-chars", SCMOPT_DIFF_NO_SPECIAL_CHARS, RTGETOPT_REQ_NOTHING },
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync memcpy(&s_aOpts[RT_ELEMENTS(s_aOpts) - RT_ELEMENTS(g_aScmOpts)], &g_aScmOpts[0], sizeof(g_aScmOpts));
b2c35a7024c4c308b429c81b203b3bcbd44ee60cvboxsync rc = RTGetOptInit(&GetOptState, argc, argv, &s_aOpts[0], RT_ELEMENTS(s_aOpts), 1, RTGETOPTINIT_FLAGS_OPTS_FIRST);
a299266cddc1ae14d76d725a660bb278816bc151vboxsync while ((rc = RTGetOpt(&GetOptState, &ValueUnion)) != 0)
a299266cddc1ae14d76d725a660bb278816bc151vboxsync "Usage: %s [options] <files & dirs>\n"
b2c35a7024c4c308b429c81b203b3bcbd44ee60cvboxsync bool fAdvanceTwo = false;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync if ((s_aOpts[i].fFlags & RTGETOPT_REQ_MASK) == RTGETOPT_REQ_NOTHING)
b2c35a7024c4c308b429c81b203b3bcbd44ee60cvboxsync RTPrintf(" %s, %s\n", s_aOpts[i].pszLong, s_aOpts[i + 1].pszLong);
a299266cddc1ae14d76d725a660bb278816bc151vboxsync else if ((s_aOpts[i].fFlags & RTGETOPT_REQ_MASK) == RTGETOPT_REQ_STRING)
b2c35a7024c4c308b429c81b203b3bcbd44ee60cvboxsync case SCMOPT_CONVERT_EOL: RTPrintf(" Default: %RTbool\n", g_Defaults.fConvertEol); break;
b2c35a7024c4c308b429c81b203b3bcbd44ee60cvboxsync case SCMOPT_CONVERT_TABS: RTPrintf(" Default: %RTbool\n", g_Defaults.fConvertTabs); break;
b2c35a7024c4c308b429c81b203b3bcbd44ee60cvboxsync case SCMOPT_FORCE_FINAL_EOL: RTPrintf(" Default: %RTbool\n", g_Defaults.fForceFinalEol); break;
b2c35a7024c4c308b429c81b203b3bcbd44ee60cvboxsync case SCMOPT_FORCE_TRAILING_LINE: RTPrintf(" Default: %RTbool\n", g_Defaults.fForceTrailingLine); break;
b2c35a7024c4c308b429c81b203b3bcbd44ee60cvboxsync case SCMOPT_STRIP_TRAILING_BLANKS: RTPrintf(" Default: %RTbool\n", g_Defaults.fStripTrailingBlanks); break;
b2c35a7024c4c308b429c81b203b3bcbd44ee60cvboxsync case SCMOPT_STRIP_TRAILING_LINES: RTPrintf(" Default: %RTbool\n", g_Defaults.fStripTrailingLines); break;
4bcaf5d320bf0d88910212509c37bdd634e0879evboxsync case SCMOPT_ONLY_SVN_DIRS: RTPrintf(" Default: %RTbool\n", g_Defaults.fOnlySvnDirs); break;
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync case SCMOPT_ONLY_SVN_FILES: RTPrintf(" Default: %RTbool\n", g_Defaults.fOnlySvnFiles); break;
4a4d802b46dfabbfd36e88822ff7b17421120469vboxsync case SCMOPT_SET_SVN_EOL: RTPrintf(" Default: %RTbool\n", g_Defaults.fSetSvnEol); break;
4a4d802b46dfabbfd36e88822ff7b17421120469vboxsync case SCMOPT_SET_SVN_EXECUTABLE: RTPrintf(" Default: %RTbool\n", g_Defaults.fSetSvnExecutable); break;
4a4d802b46dfabbfd36e88822ff7b17421120469vboxsync case SCMOPT_SET_SVN_KEYWORDS: RTPrintf(" Default: %RTbool\n", g_Defaults.fSetSvnKeywords); break;
b2c35a7024c4c308b429c81b203b3bcbd44ee60cvboxsync case SCMOPT_TAB_SIZE: RTPrintf(" Default: %u\n", g_Defaults.cchTab); break;
b2c35a7024c4c308b429c81b203b3bcbd44ee60cvboxsync case SCMOPT_FILTER_OUT_DIRS: RTPrintf(" Default: %s\n", g_Defaults.pszFilterOutDirs); break;
b2c35a7024c4c308b429c81b203b3bcbd44ee60cvboxsync case SCMOPT_FILTER_FILES: RTPrintf(" Default: %s\n", g_Defaults.pszFilterFiles); break;
b2c35a7024c4c308b429c81b203b3bcbd44ee60cvboxsync case SCMOPT_FILTER_OUT_FILES: RTPrintf(" Default: %s\n", g_Defaults.pszFilterOutFiles); break;
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync /* The following is assuming that svn does it's job here. */
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync const char *psz = RTStrStripL(strchr(s_szRev, ' '));
a299266cddc1ae14d76d725a660bb278816bc151vboxsync g_fDiffIgnoreTrailingWS = g_fDiffIgnoreLeadingWS = true;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync g_fDiffIgnoreTrailingWS = g_fDiffIgnoreLeadingWS = false;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync RTPrintf("%s: Warning! This program will make changes to your source files and\n"
a299266cddc1ae14d76d725a660bb278816bc151vboxsync "%s: there is a slight risk that bugs or a full disk may cause\n"
a299266cddc1ae14d76d725a660bb278816bc151vboxsync "%s: LOSS OF DATA. So, please make sure you have checked in\n"
cea38eeef9a0a2060a343a9bf2b82a1f51963b46vboxsync "%s: all your changes already. If you didn't, then don't blame\n"
a299266cddc1ae14d76d725a660bb278816bc151vboxsync "%s: anyone for not warning you!\n"
a299266cddc1ae14d76d725a660bb278816bc151vboxsync "%s: Press any key to continue...\n",
a299266cddc1ae14d76d725a660bb278816bc151vboxsync g_szProgName, g_szProgName, g_szProgName, g_szProgName, g_szProgName,
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync rc = scmProcessSomething(ValueUnion.psz, pSettings);