scm.cpp revision e99772f9bf09219c532812c859fbeea513c67e65
a299266cddc1ae14d76d725a660bb278816bc151vboxsync/* $Id$ */
a299266cddc1ae14d76d725a660bb278816bc151vboxsync/** @file
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * IPRT Testcase / Tool - Source Code Massager.
a299266cddc1ae14d76d725a660bb278816bc151vboxsync */
a299266cddc1ae14d76d725a660bb278816bc151vboxsync
a299266cddc1ae14d76d725a660bb278816bc151vboxsync/*
e99772f9bf09219c532812c859fbeea513c67e65vboxsync * Copyright (C) 2010-2012 Oracle Corporation
a299266cddc1ae14d76d725a660bb278816bc151vboxsync *
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
a299266cddc1ae14d76d725a660bb278816bc151vboxsync/*******************************************************************************
a299266cddc1ae14d76d725a660bb278816bc151vboxsync* Header Files *
a299266cddc1ae14d76d725a660bb278816bc151vboxsync*******************************************************************************/
a299266cddc1ae14d76d725a660bb278816bc151vboxsync#include <iprt/assert.h>
a299266cddc1ae14d76d725a660bb278816bc151vboxsync#include <iprt/ctype.h>
a299266cddc1ae14d76d725a660bb278816bc151vboxsync#include <iprt/dir.h>
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync#include <iprt/env.h>
a299266cddc1ae14d76d725a660bb278816bc151vboxsync#include <iprt/file.h>
a299266cddc1ae14d76d725a660bb278816bc151vboxsync#include <iprt/err.h>
a299266cddc1ae14d76d725a660bb278816bc151vboxsync#include <iprt/getopt.h>
a299266cddc1ae14d76d725a660bb278816bc151vboxsync#include <iprt/initterm.h>
a299266cddc1ae14d76d725a660bb278816bc151vboxsync#include <iprt/mem.h>
a299266cddc1ae14d76d725a660bb278816bc151vboxsync#include <iprt/message.h>
a299266cddc1ae14d76d725a660bb278816bc151vboxsync#include <iprt/param.h>
a299266cddc1ae14d76d725a660bb278816bc151vboxsync#include <iprt/path.h>
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync#include <iprt/process.h>
a299266cddc1ae14d76d725a660bb278816bc151vboxsync#include <iprt/stream.h>
a299266cddc1ae14d76d725a660bb278816bc151vboxsync#include <iprt/string.h>
a299266cddc1ae14d76d725a660bb278816bc151vboxsync
e99772f9bf09219c532812c859fbeea513c67e65vboxsync#include "scmstream.h"
e99772f9bf09219c532812c859fbeea513c67e65vboxsync
a299266cddc1ae14d76d725a660bb278816bc151vboxsync
a299266cddc1ae14d76d725a660bb278816bc151vboxsync/*******************************************************************************
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync* Defined Constants And Macros *
a299266cddc1ae14d76d725a660bb278816bc151vboxsync*******************************************************************************/
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync/** The name of the settings files. */
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync#define SCM_SETTINGS_FILENAME ".scm-settings"
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync/*******************************************************************************
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync* Structures and Typedefs *
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync*******************************************************************************/
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync/** Pointer to const massager settings. */
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsynctypedef struct SCMSETTINGSBASE const *PCSCMSETTINGSBASE;
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync/**
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync * SVN property.
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync */
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsynctypedef struct SCMSVNPROP
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync{
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync /** The property. */
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync char *pszName;
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync /** The value.
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync * When used to record updates, this can be set to NULL to trigger the
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync * deletion of the property. */
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync char *pszValue;
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync} SCMSVNPROP;
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync/** Pointer to a SVN property. */
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsynctypedef SCMSVNPROP *PSCMSVNPROP;
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync/** Pointer to a const SVN property. */
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsynctypedef SCMSVNPROP const *PCSCMSVNPROP;
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync
b2c35a7024c4c308b429c81b203b3bcbd44ee60cvboxsync/**
b2c35a7024c4c308b429c81b203b3bcbd44ee60cvboxsync * Rewriter state.
b2c35a7024c4c308b429c81b203b3bcbd44ee60cvboxsync */
b2c35a7024c4c308b429c81b203b3bcbd44ee60cvboxsynctypedef struct SCMRWSTATE
b2c35a7024c4c308b429c81b203b3bcbd44ee60cvboxsync{
b2c35a7024c4c308b429c81b203b3bcbd44ee60cvboxsync /** The filename. */
b2c35a7024c4c308b429c81b203b3bcbd44ee60cvboxsync const char *pszFilename;
b2c35a7024c4c308b429c81b203b3bcbd44ee60cvboxsync /** Set after the printing the first verbose message about a file under
b2c35a7024c4c308b429c81b203b3bcbd44ee60cvboxsync * rewrite. */
b2c35a7024c4c308b429c81b203b3bcbd44ee60cvboxsync bool fFirst;
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync /** The number of SVN property changes. */
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync size_t cSvnPropChanges;
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync /** Pointer to an array of SVN property changes. */
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync PSCMSVNPROP paSvnPropChanges;
b2c35a7024c4c308b429c81b203b3bcbd44ee60cvboxsync} SCMRWSTATE;
b2c35a7024c4c308b429c81b203b3bcbd44ee60cvboxsync/** Pointer to the rewriter state. */
b2c35a7024c4c308b429c81b203b3bcbd44ee60cvboxsynctypedef SCMRWSTATE *PSCMRWSTATE;
b2c35a7024c4c308b429c81b203b3bcbd44ee60cvboxsync
a299266cddc1ae14d76d725a660bb278816bc151vboxsync/**
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * A rewriter.
a299266cddc1ae14d76d725a660bb278816bc151vboxsync *
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * This works like a stream editor, reading @a pIn, modifying it and writing it
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * to @a pOut.
a299266cddc1ae14d76d725a660bb278816bc151vboxsync *
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.
a299266cddc1ae14d76d725a660bb278816bc151vboxsync */
b2c35a7024c4c308b429c81b203b3bcbd44ee60cvboxsynctypedef bool (*PFNSCMREWRITER)(PSCMRWSTATE pState, PSCMSTREAM pIn, PSCMSTREAM pOut, PCSCMSETTINGSBASE pSettings);
a299266cddc1ae14d76d725a660bb278816bc151vboxsync
a299266cddc1ae14d76d725a660bb278816bc151vboxsync
a299266cddc1ae14d76d725a660bb278816bc151vboxsync/**
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * Configuration entry.
a299266cddc1ae14d76d725a660bb278816bc151vboxsync */
a299266cddc1ae14d76d725a660bb278816bc151vboxsynctypedef struct SCMCFGENTRY
a299266cddc1ae14d76d725a660bb278816bc151vboxsync{
a299266cddc1ae14d76d725a660bb278816bc151vboxsync /** Number of rewriters. */
a299266cddc1ae14d76d725a660bb278816bc151vboxsync size_t cRewriters;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync /** Pointer to an array of rewriters. */
a299266cddc1ae14d76d725a660bb278816bc151vboxsync PFNSCMREWRITER const *papfnRewriter;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync /** File pattern (simple). */
a299266cddc1ae14d76d725a660bb278816bc151vboxsync const char *pszFilePattern;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync} SCMCFGENTRY;
a299266cddc1ae14d76d725a660bb278816bc151vboxsynctypedef SCMCFGENTRY *PSCMCFGENTRY;
a299266cddc1ae14d76d725a660bb278816bc151vboxsynctypedef SCMCFGENTRY const *PCSCMCFGENTRY;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync
a299266cddc1ae14d76d725a660bb278816bc151vboxsync
a299266cddc1ae14d76d725a660bb278816bc151vboxsync/**
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * Diff state.
a299266cddc1ae14d76d725a660bb278816bc151vboxsync */
a299266cddc1ae14d76d725a660bb278816bc151vboxsynctypedef struct SCMDIFFSTATE
a299266cddc1ae14d76d725a660bb278816bc151vboxsync{
a299266cddc1ae14d76d725a660bb278816bc151vboxsync size_t cDiffs;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync const char *pszFilename;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync
a299266cddc1ae14d76d725a660bb278816bc151vboxsync PSCMSTREAM pLeft;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync PSCMSTREAM pRight;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync
a299266cddc1ae14d76d725a660bb278816bc151vboxsync /** Whether to ignore end of line markers when diffing. */
a299266cddc1ae14d76d725a660bb278816bc151vboxsync bool fIgnoreEol;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync /** Whether to ignore trailing whitespace. */
a299266cddc1ae14d76d725a660bb278816bc151vboxsync bool fIgnoreTrailingWhite;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync /** Whether to ignore leading whitespace. */
a299266cddc1ae14d76d725a660bb278816bc151vboxsync bool fIgnoreLeadingWhite;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync /** Whether to print special characters in human readable form or not. */
a299266cddc1ae14d76d725a660bb278816bc151vboxsync bool fSpecialChars;
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync /** The tab size. */
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync size_t cchTab;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync /** Where to push the diff. */
a299266cddc1ae14d76d725a660bb278816bc151vboxsync PRTSTREAM pDiff;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync} SCMDIFFSTATE;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync/** Pointer to a diff state. */
a299266cddc1ae14d76d725a660bb278816bc151vboxsynctypedef SCMDIFFSTATE *PSCMDIFFSTATE;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync/**
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * Source Code Massager Settings.
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync */
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsynctypedef struct SCMSETTINGSBASE
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync{
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync bool fConvertEol;
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync bool fConvertTabs;
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync bool fForceFinalEol;
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync bool fForceTrailingLine;
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync bool fStripTrailingBlanks;
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync bool fStripTrailingLines;
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync /** Only process files that are part of a SVN working copy. */
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync bool fOnlySvnFiles;
4bcaf5d320bf0d88910212509c37bdd634e0879evboxsync /** Only recurse into directories containing an .svn dir. */
4bcaf5d320bf0d88910212509c37bdd634e0879evboxsync bool fOnlySvnDirs;
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync /** Set svn:eol-style if missing or incorrect. */
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync bool fSetSvnEol;
ad27e1d5e48ca41245120c331cc88b50464813cevboxsync /** Set svn:executable according to type (unusually this means deleting it). */
4a4d802b46dfabbfd36e88822ff7b17421120469vboxsync bool fSetSvnExecutable;
4a4d802b46dfabbfd36e88822ff7b17421120469vboxsync /** Set svn:keyword if completely or partially missing. */
4a4d802b46dfabbfd36e88822ff7b17421120469vboxsync bool fSetSvnKeywords;
4bcaf5d320bf0d88910212509c37bdd634e0879evboxsync /** */
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync unsigned cchTab;
ad27e1d5e48ca41245120c331cc88b50464813cevboxsync /** Only consider files matching these patterns. This is only applied to the
4bcaf5d320bf0d88910212509c37bdd634e0879evboxsync * base names. */
e45e3ae4a834169539e689759ba6b3ac71bfe40fvboxsync char *pszFilterFiles;
4bcaf5d320bf0d88910212509c37bdd634e0879evboxsync /** Filter out files matching the following patterns. This is applied to base
ad27e1d5e48ca41245120c331cc88b50464813cevboxsync * names as well as the absolute paths. */
e45e3ae4a834169539e689759ba6b3ac71bfe40fvboxsync char *pszFilterOutFiles;
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 ("/."). */
e45e3ae4a834169539e689759ba6b3ac71bfe40fvboxsync char *pszFilterOutDirs;
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync} SCMSETTINGSBASE;
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync/** Pointer to massager settings. */
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsynctypedef SCMSETTINGSBASE *PSCMSETTINGSBASE;
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync/**
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * Option identifiers.
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync *
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 */
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsynctypedef enum SCMOPT
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync{
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync SCMOPT_CONVERT_EOL = 10000,
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync SCMOPT_NO_CONVERT_EOL,
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync SCMOPT_CONVERT_TABS,
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync SCMOPT_NO_CONVERT_TABS,
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync SCMOPT_FORCE_FINAL_EOL,
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync SCMOPT_NO_FORCE_FINAL_EOL,
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync SCMOPT_FORCE_TRAILING_LINE,
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync SCMOPT_NO_FORCE_TRAILING_LINE,
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync SCMOPT_STRIP_TRAILING_BLANKS,
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync SCMOPT_NO_STRIP_TRAILING_BLANKS,
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync SCMOPT_STRIP_TRAILING_LINES,
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync SCMOPT_NO_STRIP_TRAILING_LINES,
4bcaf5d320bf0d88910212509c37bdd634e0879evboxsync SCMOPT_ONLY_SVN_DIRS,
4bcaf5d320bf0d88910212509c37bdd634e0879evboxsync SCMOPT_NOT_ONLY_SVN_DIRS,
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync SCMOPT_ONLY_SVN_FILES,
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync SCMOPT_NOT_ONLY_SVN_FILES,
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync SCMOPT_SET_SVN_EOL,
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync SCMOPT_DONT_SET_SVN_EOL,
4a4d802b46dfabbfd36e88822ff7b17421120469vboxsync SCMOPT_SET_SVN_EXECUTABLE,
4a4d802b46dfabbfd36e88822ff7b17421120469vboxsync SCMOPT_DONT_SET_SVN_EXECUTABLE,
4a4d802b46dfabbfd36e88822ff7b17421120469vboxsync SCMOPT_SET_SVN_KEYWORDS,
4a4d802b46dfabbfd36e88822ff7b17421120469vboxsync SCMOPT_DONT_SET_SVN_KEYWORDS,
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync SCMOPT_TAB_SIZE,
e45e3ae4a834169539e689759ba6b3ac71bfe40fvboxsync SCMOPT_FILTER_OUT_DIRS,
e45e3ae4a834169539e689759ba6b3ac71bfe40fvboxsync SCMOPT_FILTER_FILES,
e45e3ae4a834169539e689759ba6b3ac71bfe40fvboxsync SCMOPT_FILTER_OUT_FILES,
e45e3ae4a834169539e689759ba6b3ac71bfe40fvboxsync SCMOPT_LAST_SETTINGS = SCMOPT_FILTER_OUT_FILES,
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync //
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync SCMOPT_DIFF_IGNORE_EOL,
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync SCMOPT_DIFF_NO_IGNORE_EOL,
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync SCMOPT_DIFF_IGNORE_SPACE,
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync SCMOPT_DIFF_NO_IGNORE_SPACE,
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync SCMOPT_DIFF_IGNORE_LEADING_SPACE,
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync SCMOPT_DIFF_NO_IGNORE_LEADING_SPACE,
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync SCMOPT_DIFF_IGNORE_TRAILING_SPACE,
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync SCMOPT_DIFF_NO_IGNORE_TRAILING_SPACE,
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync SCMOPT_DIFF_SPECIAL_CHARS,
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync SCMOPT_DIFF_NO_SPECIAL_CHARS,
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync SCMOPT_END
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync} SCMOPT;
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync/**
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * File/dir pattern + options.
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync */
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsynctypedef struct SCMPATRNOPTPAIR
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync{
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync char *pszPattern;
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync char *pszOptions;
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync} SCMPATRNOPTPAIR;
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync/** Pointer to a pattern + option pair. */
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsynctypedef SCMPATRNOPTPAIR *PSCMPATRNOPTPAIR;
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync/** Pointer to a settings set. */
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsynctypedef struct SCMSETTINGS *PSCMSETTINGS;
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync/**
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * Settings set.
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync *
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 *
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 * to.
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync *
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * We parse the base options into the Base member and put the others into the
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * paPairs array.
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync */
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsynctypedef struct SCMSETTINGS
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync{
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync /** Pointer to the setting file below us in the stack. */
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync PSCMSETTINGS pDown;
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync /** Pointer to the setting file above us in the stack. */
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync PSCMSETTINGS pUp;
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync /** File/dir patterns and their options. */
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync PSCMPATRNOPTPAIR paPairs;
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync /** The number of entires in paPairs. */
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync uint32_t cPairs;
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync /** The base settings that was read out of the file. */
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync SCMSETTINGSBASE Base;
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync} SCMSETTINGS;
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync/** Pointer to a const settings set. */
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsynctypedef SCMSETTINGS const *PCSCMSETTINGS;
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync
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
a299266cddc1ae14d76d725a660bb278816bc151vboxsync/*******************************************************************************
a299266cddc1ae14d76d725a660bb278816bc151vboxsync* Global Variables *
a299266cddc1ae14d76d725a660bb278816bc151vboxsync*******************************************************************************/
a299266cddc1ae14d76d725a660bb278816bc151vboxsyncstatic const char g_szProgName[] = "scm";
a299266cddc1ae14d76d725a660bb278816bc151vboxsyncstatic const char *g_pszChangedSuff = "";
a299266cddc1ae14d76d725a660bb278816bc151vboxsyncstatic const char g_szTabSpaces[16+1] = " ";
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;
a299266cddc1ae14d76d725a660bb278816bc151vboxsyncstatic int g_iVerbosity = 2;//99; //0;
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync/** The global settings. */
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsyncstatic SCMSETTINGSBASE const g_Defaults =
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync{
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,
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync /* .cchTab = */ 8,
e45e3ae4a834169539e689759ba6b3ac71bfe40fvboxsync /* .pszFilterFiles = */ (char *)"",
e45e3ae4a834169539e689759ba6b3ac71bfe40fvboxsync /* .pszFilterOutFiles = */ (char *)"*.exe|*.com|20*-*-*.log",
e45e3ae4a834169539e689759ba6b3ac71bfe40fvboxsync /* .pszFilterOutDirs = */ (char *)".svn|.hg|.git|CVS",
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync};
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync/** Option definitions for the base settings. */
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsyncstatic RTGETOPTDEF g_aScmOpts[] =
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync{
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};
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync/** Consider files matching the following patterns (base names only). */
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsyncstatic const char *g_pszFileFilter = NULL;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync
a299266cddc1ae14d76d725a660bb278816bc151vboxsyncstatic PFNSCMREWRITER const g_aRewritersFor_Makefile_kup[] =
a299266cddc1ae14d76d725a660bb278816bc151vboxsync{
4a4d802b46dfabbfd36e88822ff7b17421120469vboxsync rewrite_SvnNoExecutable,
a299266cddc1ae14d76d725a660bb278816bc151vboxsync rewrite_Makefile_kup
a299266cddc1ae14d76d725a660bb278816bc151vboxsync};
a299266cddc1ae14d76d725a660bb278816bc151vboxsync
a299266cddc1ae14d76d725a660bb278816bc151vboxsyncstatic PFNSCMREWRITER const g_aRewritersFor_Makefile_kmk[] =
a299266cddc1ae14d76d725a660bb278816bc151vboxsync{
a299266cddc1ae14d76d725a660bb278816bc151vboxsync rewrite_ForceNativeEol,
a299266cddc1ae14d76d725a660bb278816bc151vboxsync rewrite_StripTrailingBlanks,
a299266cddc1ae14d76d725a660bb278816bc151vboxsync rewrite_AdjustTrailingLines,
4a4d802b46dfabbfd36e88822ff7b17421120469vboxsync rewrite_SvnNoExecutable,
4a4d802b46dfabbfd36e88822ff7b17421120469vboxsync rewrite_SvnKeywords,
a299266cddc1ae14d76d725a660bb278816bc151vboxsync rewrite_Makefile_kmk
a299266cddc1ae14d76d725a660bb278816bc151vboxsync};
a299266cddc1ae14d76d725a660bb278816bc151vboxsync
a299266cddc1ae14d76d725a660bb278816bc151vboxsyncstatic PFNSCMREWRITER const g_aRewritersFor_C_and_CPP[] =
a299266cddc1ae14d76d725a660bb278816bc151vboxsync{
a299266cddc1ae14d76d725a660bb278816bc151vboxsync rewrite_ForceNativeEol,
a299266cddc1ae14d76d725a660bb278816bc151vboxsync rewrite_ExpandTabs,
a299266cddc1ae14d76d725a660bb278816bc151vboxsync rewrite_StripTrailingBlanks,
a299266cddc1ae14d76d725a660bb278816bc151vboxsync rewrite_AdjustTrailingLines,
4a4d802b46dfabbfd36e88822ff7b17421120469vboxsync rewrite_SvnNoExecutable,
4a4d802b46dfabbfd36e88822ff7b17421120469vboxsync rewrite_SvnKeywords,
4a4d802b46dfabbfd36e88822ff7b17421120469vboxsync rewrite_C_and_CPP
4a4d802b46dfabbfd36e88822ff7b17421120469vboxsync};
4a4d802b46dfabbfd36e88822ff7b17421120469vboxsync
4a4d802b46dfabbfd36e88822ff7b17421120469vboxsyncstatic PFNSCMREWRITER const g_aRewritersFor_H_and_HPP[] =
4a4d802b46dfabbfd36e88822ff7b17421120469vboxsync{
4a4d802b46dfabbfd36e88822ff7b17421120469vboxsync rewrite_ForceNativeEol,
4a4d802b46dfabbfd36e88822ff7b17421120469vboxsync rewrite_ExpandTabs,
4a4d802b46dfabbfd36e88822ff7b17421120469vboxsync rewrite_StripTrailingBlanks,
4a4d802b46dfabbfd36e88822ff7b17421120469vboxsync rewrite_AdjustTrailingLines,
4a4d802b46dfabbfd36e88822ff7b17421120469vboxsync rewrite_SvnNoExecutable,
a299266cddc1ae14d76d725a660bb278816bc151vboxsync rewrite_C_and_CPP
a299266cddc1ae14d76d725a660bb278816bc151vboxsync};
a299266cddc1ae14d76d725a660bb278816bc151vboxsync
d0445e5c26b62718e727032ae46626f5d5db7ae5vboxsyncstatic PFNSCMREWRITER const g_aRewritersFor_RC[] =
d0445e5c26b62718e727032ae46626f5d5db7ae5vboxsync{
d0445e5c26b62718e727032ae46626f5d5db7ae5vboxsync rewrite_ForceNativeEol,
d0445e5c26b62718e727032ae46626f5d5db7ae5vboxsync rewrite_ExpandTabs,
d0445e5c26b62718e727032ae46626f5d5db7ae5vboxsync rewrite_StripTrailingBlanks,
4a4d802b46dfabbfd36e88822ff7b17421120469vboxsync rewrite_AdjustTrailingLines,
4a4d802b46dfabbfd36e88822ff7b17421120469vboxsync rewrite_SvnNoExecutable,
4a4d802b46dfabbfd36e88822ff7b17421120469vboxsync rewrite_SvnKeywords
d0445e5c26b62718e727032ae46626f5d5db7ae5vboxsync};
d0445e5c26b62718e727032ae46626f5d5db7ae5vboxsync
a299266cddc1ae14d76d725a660bb278816bc151vboxsyncstatic PFNSCMREWRITER const g_aRewritersFor_ShellScripts[] =
a299266cddc1ae14d76d725a660bb278816bc151vboxsync{
a299266cddc1ae14d76d725a660bb278816bc151vboxsync rewrite_ForceLF,
a299266cddc1ae14d76d725a660bb278816bc151vboxsync rewrite_ExpandTabs,
a299266cddc1ae14d76d725a660bb278816bc151vboxsync rewrite_StripTrailingBlanks
a299266cddc1ae14d76d725a660bb278816bc151vboxsync};
a299266cddc1ae14d76d725a660bb278816bc151vboxsync
a299266cddc1ae14d76d725a660bb278816bc151vboxsyncstatic PFNSCMREWRITER const g_aRewritersFor_BatchFiles[] =
a299266cddc1ae14d76d725a660bb278816bc151vboxsync{
0d1ceffcc16b8999752140e739adb27132655ee8vboxsync rewrite_ForceCRLF,
a299266cddc1ae14d76d725a660bb278816bc151vboxsync rewrite_ExpandTabs,
a299266cddc1ae14d76d725a660bb278816bc151vboxsync rewrite_StripTrailingBlanks
a299266cddc1ae14d76d725a660bb278816bc151vboxsync};
a299266cddc1ae14d76d725a660bb278816bc151vboxsync
a299266cddc1ae14d76d725a660bb278816bc151vboxsyncstatic SCMCFGENTRY const g_aConfigs[] =
a299266cddc1ae14d76d725a660bb278816bc151vboxsync{
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};
a299266cddc1ae14d76d725a660bb278816bc151vboxsync
a299266cddc1ae14d76d725a660bb278816bc151vboxsync
a299266cddc1ae14d76d725a660bb278816bc151vboxsync/* -=-=-=-=-=- diff -=-=-=-=-=- */
a299266cddc1ae14d76d725a660bb278816bc151vboxsync
a299266cddc1ae14d76d725a660bb278816bc151vboxsync
a299266cddc1ae14d76d725a660bb278816bc151vboxsync/**
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * Prints a range of lines with a prefix.
a299266cddc1ae14d76d725a660bb278816bc151vboxsync *
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.
a299266cddc1ae14d76d725a660bb278816bc151vboxsync */
a299266cddc1ae14d76d725a660bb278816bc151vboxsyncstatic void scmDiffPrintLines(PSCMDIFFSTATE pState, char chPrefix, PSCMSTREAM pStream, size_t iLine, size_t cLines)
a299266cddc1ae14d76d725a660bb278816bc151vboxsync{
a299266cddc1ae14d76d725a660bb278816bc151vboxsync while (cLines-- > 0)
a299266cddc1ae14d76d725a660bb278816bc151vboxsync {
a299266cddc1ae14d76d725a660bb278816bc151vboxsync SCMEOL enmEol;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync size_t cchLine;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync const char *pchLine = ScmStreamGetLineByNo(pStream, iLine, &cchLine, &enmEol);
a299266cddc1ae14d76d725a660bb278816bc151vboxsync
a299266cddc1ae14d76d725a660bb278816bc151vboxsync RTStrmPutCh(pState->pDiff, chPrefix);
a299266cddc1ae14d76d725a660bb278816bc151vboxsync if (pchLine && cchLine)
0d1ceffcc16b8999752140e739adb27132655ee8vboxsync {
0d1ceffcc16b8999752140e739adb27132655ee8vboxsync if (!pState->fSpecialChars)
0d1ceffcc16b8999752140e739adb27132655ee8vboxsync RTStrmWrite(pState->pDiff, pchLine, cchLine);
0d1ceffcc16b8999752140e739adb27132655ee8vboxsync else
0d1ceffcc16b8999752140e739adb27132655ee8vboxsync {
0d1ceffcc16b8999752140e739adb27132655ee8vboxsync size_t offVir = 0;
0d1ceffcc16b8999752140e739adb27132655ee8vboxsync const char *pchStart = pchLine;
0d1ceffcc16b8999752140e739adb27132655ee8vboxsync const char *pchTab = (const char *)memchr(pchLine, '\t', cchLine);
0d1ceffcc16b8999752140e739adb27132655ee8vboxsync while (pchTab)
0d1ceffcc16b8999752140e739adb27132655ee8vboxsync {
0d1ceffcc16b8999752140e739adb27132655ee8vboxsync RTStrmWrite(pState->pDiff, pchStart, pchTab - pchStart);
0d1ceffcc16b8999752140e739adb27132655ee8vboxsync offVir += pchTab - pchStart;
0d1ceffcc16b8999752140e739adb27132655ee8vboxsync
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync size_t cchTab = pState->cchTab - offVir % pState->cchTab;
0d1ceffcc16b8999752140e739adb27132655ee8vboxsync switch (cchTab)
0d1ceffcc16b8999752140e739adb27132655ee8vboxsync {
0d1ceffcc16b8999752140e739adb27132655ee8vboxsync case 1: RTStrmPutStr(pState->pDiff, "."); break;
0d1ceffcc16b8999752140e739adb27132655ee8vboxsync case 2: RTStrmPutStr(pState->pDiff, ".."); break;
0d1ceffcc16b8999752140e739adb27132655ee8vboxsync case 3: RTStrmPutStr(pState->pDiff, "[T]"); break;
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 }
0d1ceffcc16b8999752140e739adb27132655ee8vboxsync offVir += cchTab;
0d1ceffcc16b8999752140e739adb27132655ee8vboxsync
0d1ceffcc16b8999752140e739adb27132655ee8vboxsync /* next */
0d1ceffcc16b8999752140e739adb27132655ee8vboxsync pchStart = pchTab + 1;
0d1ceffcc16b8999752140e739adb27132655ee8vboxsync pchTab = (const char *)memchr(pchStart, '\t', cchLine - (pchStart - pchLine));
0d1ceffcc16b8999752140e739adb27132655ee8vboxsync }
0d1ceffcc16b8999752140e739adb27132655ee8vboxsync size_t cchLeft = cchLine - (pchStart - pchLine);
0d1ceffcc16b8999752140e739adb27132655ee8vboxsync if (cchLeft)
0d1ceffcc16b8999752140e739adb27132655ee8vboxsync RTStrmWrite(pState->pDiff, pchStart, cchLeft);
0d1ceffcc16b8999752140e739adb27132655ee8vboxsync }
0d1ceffcc16b8999752140e739adb27132655ee8vboxsync }
a299266cddc1ae14d76d725a660bb278816bc151vboxsync
a299266cddc1ae14d76d725a660bb278816bc151vboxsync if (!pState->fSpecialChars)
a299266cddc1ae14d76d725a660bb278816bc151vboxsync RTStrmPutCh(pState->pDiff, '\n');
a299266cddc1ae14d76d725a660bb278816bc151vboxsync else if (enmEol == SCMEOL_LF)
a299266cddc1ae14d76d725a660bb278816bc151vboxsync RTStrmPutStr(pState->pDiff, "[LF]\n");
a299266cddc1ae14d76d725a660bb278816bc151vboxsync else if (enmEol == SCMEOL_CRLF)
a299266cddc1ae14d76d725a660bb278816bc151vboxsync RTStrmPutStr(pState->pDiff, "[CRLF]\n");
a299266cddc1ae14d76d725a660bb278816bc151vboxsync else
a299266cddc1ae14d76d725a660bb278816bc151vboxsync RTStrmPutStr(pState->pDiff, "[NONE]\n");
a299266cddc1ae14d76d725a660bb278816bc151vboxsync
a299266cddc1ae14d76d725a660bb278816bc151vboxsync iLine++;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync }
a299266cddc1ae14d76d725a660bb278816bc151vboxsync}
a299266cddc1ae14d76d725a660bb278816bc151vboxsync
a299266cddc1ae14d76d725a660bb278816bc151vboxsync
a299266cddc1ae14d76d725a660bb278816bc151vboxsync/**
ad27e1d5e48ca41245120c331cc88b50464813cevboxsync * Reports a difference and propels the streams to the lines following the
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * resync.
a299266cddc1ae14d76d725a660bb278816bc151vboxsync *
a299266cddc1ae14d76d725a660bb278816bc151vboxsync *
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.
a299266cddc1ae14d76d725a660bb278816bc151vboxsync */
a299266cddc1ae14d76d725a660bb278816bc151vboxsyncstatic size_t scmDiffReport(PSCMDIFFSTATE pState, size_t cMatches,
a299266cddc1ae14d76d725a660bb278816bc151vboxsync size_t iLeft, size_t cLeft,
a299266cddc1ae14d76d725a660bb278816bc151vboxsync size_t iRight, size_t cRight)
a299266cddc1ae14d76d725a660bb278816bc151vboxsync{
a299266cddc1ae14d76d725a660bb278816bc151vboxsync /*
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * Adjust the input.
a299266cddc1ae14d76d725a660bb278816bc151vboxsync */
a299266cddc1ae14d76d725a660bb278816bc151vboxsync if (cLeft == ~(size_t)0)
a299266cddc1ae14d76d725a660bb278816bc151vboxsync {
a299266cddc1ae14d76d725a660bb278816bc151vboxsync size_t c = ScmStreamCountLines(pState->pLeft);
a299266cddc1ae14d76d725a660bb278816bc151vboxsync if (c >= iLeft)
a299266cddc1ae14d76d725a660bb278816bc151vboxsync cLeft = c - iLeft;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync else
a299266cddc1ae14d76d725a660bb278816bc151vboxsync {
a299266cddc1ae14d76d725a660bb278816bc151vboxsync iLeft = c;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync cLeft = 0;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync }
a299266cddc1ae14d76d725a660bb278816bc151vboxsync }
a299266cddc1ae14d76d725a660bb278816bc151vboxsync
a299266cddc1ae14d76d725a660bb278816bc151vboxsync if (cRight == ~(size_t)0)
a299266cddc1ae14d76d725a660bb278816bc151vboxsync {
a299266cddc1ae14d76d725a660bb278816bc151vboxsync size_t c = ScmStreamCountLines(pState->pRight);
a299266cddc1ae14d76d725a660bb278816bc151vboxsync if (c >= iRight)
a299266cddc1ae14d76d725a660bb278816bc151vboxsync cRight = c - iRight;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync else
a299266cddc1ae14d76d725a660bb278816bc151vboxsync {
a299266cddc1ae14d76d725a660bb278816bc151vboxsync iRight = c;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync cRight = 0;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync }
a299266cddc1ae14d76d725a660bb278816bc151vboxsync }
a299266cddc1ae14d76d725a660bb278816bc151vboxsync
a299266cddc1ae14d76d725a660bb278816bc151vboxsync /*
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * Print header if it's the first difference
a299266cddc1ae14d76d725a660bb278816bc151vboxsync */
a299266cddc1ae14d76d725a660bb278816bc151vboxsync if (!pState->cDiffs)
a299266cddc1ae14d76d725a660bb278816bc151vboxsync RTStrmPrintf(pState->pDiff, "diff %s %s\n", pState->pszFilename, pState->pszFilename);
a299266cddc1ae14d76d725a660bb278816bc151vboxsync
a299266cddc1ae14d76d725a660bb278816bc151vboxsync /*
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * Emit the change description.
a299266cddc1ae14d76d725a660bb278816bc151vboxsync */
a299266cddc1ae14d76d725a660bb278816bc151vboxsync char ch = cLeft == 0
a299266cddc1ae14d76d725a660bb278816bc151vboxsync ? 'a'
a299266cddc1ae14d76d725a660bb278816bc151vboxsync : cRight == 0
a299266cddc1ae14d76d725a660bb278816bc151vboxsync ? 'd'
a299266cddc1ae14d76d725a660bb278816bc151vboxsync : 'c';
a299266cddc1ae14d76d725a660bb278816bc151vboxsync if (cLeft > 1 && cRight > 1)
a299266cddc1ae14d76d725a660bb278816bc151vboxsync RTStrmPrintf(pState->pDiff, "%zu,%zu%c%zu,%zu\n", iLeft + 1, iLeft + cLeft, ch, iRight + 1, iRight + cRight);
a299266cddc1ae14d76d725a660bb278816bc151vboxsync else if (cLeft > 1)
a299266cddc1ae14d76d725a660bb278816bc151vboxsync RTStrmPrintf(pState->pDiff, "%zu,%zu%c%zu\n", iLeft + 1, iLeft + cLeft, ch, iRight + 1);
a299266cddc1ae14d76d725a660bb278816bc151vboxsync else if (cRight > 1)
a299266cddc1ae14d76d725a660bb278816bc151vboxsync RTStrmPrintf(pState->pDiff, "%zu%c%zu,%zu\n", iLeft + 1, ch, iRight + 1, iRight + cRight);
a299266cddc1ae14d76d725a660bb278816bc151vboxsync else
a299266cddc1ae14d76d725a660bb278816bc151vboxsync RTStrmPrintf(pState->pDiff, "%zu%c%zu\n", iLeft + 1, ch, iRight + 1);
a299266cddc1ae14d76d725a660bb278816bc151vboxsync
a299266cddc1ae14d76d725a660bb278816bc151vboxsync /*
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * And the lines.
a299266cddc1ae14d76d725a660bb278816bc151vboxsync */
a299266cddc1ae14d76d725a660bb278816bc151vboxsync if (cLeft)
a299266cddc1ae14d76d725a660bb278816bc151vboxsync scmDiffPrintLines(pState, '<', pState->pLeft, iLeft, cLeft);
a299266cddc1ae14d76d725a660bb278816bc151vboxsync if (cLeft && cRight)
a299266cddc1ae14d76d725a660bb278816bc151vboxsync RTStrmPrintf(pState->pDiff, "---\n");
a299266cddc1ae14d76d725a660bb278816bc151vboxsync if (cRight)
a299266cddc1ae14d76d725a660bb278816bc151vboxsync scmDiffPrintLines(pState, '>', pState->pRight, iRight, cRight);
a299266cddc1ae14d76d725a660bb278816bc151vboxsync
a299266cddc1ae14d76d725a660bb278816bc151vboxsync /*
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * Reposition the streams (safely ignores return value).
a299266cddc1ae14d76d725a660bb278816bc151vboxsync */
a299266cddc1ae14d76d725a660bb278816bc151vboxsync ScmStreamSeekByLine(pState->pLeft, iLeft + cLeft + cMatches);
a299266cddc1ae14d76d725a660bb278816bc151vboxsync ScmStreamSeekByLine(pState->pRight, iRight + cRight + cMatches);
a299266cddc1ae14d76d725a660bb278816bc151vboxsync
a299266cddc1ae14d76d725a660bb278816bc151vboxsync pState->cDiffs++;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync return pState->cDiffs;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync}
a299266cddc1ae14d76d725a660bb278816bc151vboxsync
a299266cddc1ae14d76d725a660bb278816bc151vboxsync/**
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * Helper for scmDiffCompare that takes care of trailing spaces and stuff
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * like that.
a299266cddc1ae14d76d725a660bb278816bc151vboxsync */
a299266cddc1ae14d76d725a660bb278816bc151vboxsyncstatic bool scmDiffCompareSlow(PSCMDIFFSTATE pState,
a299266cddc1ae14d76d725a660bb278816bc151vboxsync const char *pchLeft, size_t cchLeft, SCMEOL enmEolLeft,
a299266cddc1ae14d76d725a660bb278816bc151vboxsync const char *pchRight, size_t cchRight, SCMEOL enmEolRight)
a299266cddc1ae14d76d725a660bb278816bc151vboxsync{
a299266cddc1ae14d76d725a660bb278816bc151vboxsync if (pState->fIgnoreTrailingWhite)
a299266cddc1ae14d76d725a660bb278816bc151vboxsync {
a299266cddc1ae14d76d725a660bb278816bc151vboxsync while (cchLeft > 0 && RT_C_IS_SPACE(pchLeft[cchLeft - 1]))
a299266cddc1ae14d76d725a660bb278816bc151vboxsync cchLeft--;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync while (cchRight > 0 && RT_C_IS_SPACE(pchRight[cchRight - 1]))
a299266cddc1ae14d76d725a660bb278816bc151vboxsync cchRight--;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync }
a299266cddc1ae14d76d725a660bb278816bc151vboxsync
a299266cddc1ae14d76d725a660bb278816bc151vboxsync if (pState->fIgnoreLeadingWhite)
a299266cddc1ae14d76d725a660bb278816bc151vboxsync {
a299266cddc1ae14d76d725a660bb278816bc151vboxsync while (cchLeft > 0 && RT_C_IS_SPACE(*pchLeft))
a299266cddc1ae14d76d725a660bb278816bc151vboxsync pchLeft++, cchLeft--;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync while (cchRight > 0 && RT_C_IS_SPACE(*pchRight))
a299266cddc1ae14d76d725a660bb278816bc151vboxsync pchRight++, cchRight--;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync }
a299266cddc1ae14d76d725a660bb278816bc151vboxsync
a299266cddc1ae14d76d725a660bb278816bc151vboxsync if ( cchLeft != cchRight
a299266cddc1ae14d76d725a660bb278816bc151vboxsync || (enmEolLeft != enmEolRight && !pState->fIgnoreEol)
a299266cddc1ae14d76d725a660bb278816bc151vboxsync || memcmp(pchLeft, pchRight, cchLeft))
a299266cddc1ae14d76d725a660bb278816bc151vboxsync return false;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync return true;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync}
a299266cddc1ae14d76d725a660bb278816bc151vboxsync
a299266cddc1ae14d76d725a660bb278816bc151vboxsync/**
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * Compare two lines.
a299266cddc1ae14d76d725a660bb278816bc151vboxsync *
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * @returns true if the are equal, false if not.
a299266cddc1ae14d76d725a660bb278816bc151vboxsync */
a299266cddc1ae14d76d725a660bb278816bc151vboxsyncDECLINLINE(bool) scmDiffCompare(PSCMDIFFSTATE pState,
a299266cddc1ae14d76d725a660bb278816bc151vboxsync const char *pchLeft, size_t cchLeft, SCMEOL enmEolLeft,
a299266cddc1ae14d76d725a660bb278816bc151vboxsync const char *pchRight, size_t cchRight, SCMEOL enmEolRight)
a299266cddc1ae14d76d725a660bb278816bc151vboxsync{
a299266cddc1ae14d76d725a660bb278816bc151vboxsync if ( cchLeft != cchRight
a299266cddc1ae14d76d725a660bb278816bc151vboxsync || (enmEolLeft != enmEolRight && !pState->fIgnoreEol)
a299266cddc1ae14d76d725a660bb278816bc151vboxsync || memcmp(pchLeft, pchRight, cchLeft))
a299266cddc1ae14d76d725a660bb278816bc151vboxsync {
a299266cddc1ae14d76d725a660bb278816bc151vboxsync if ( pState->fIgnoreTrailingWhite
a299266cddc1ae14d76d725a660bb278816bc151vboxsync || pState->fIgnoreTrailingWhite)
a299266cddc1ae14d76d725a660bb278816bc151vboxsync return scmDiffCompareSlow(pState,
a299266cddc1ae14d76d725a660bb278816bc151vboxsync pchLeft, cchLeft, enmEolLeft,
a299266cddc1ae14d76d725a660bb278816bc151vboxsync pchRight, cchRight, enmEolRight);
a299266cddc1ae14d76d725a660bb278816bc151vboxsync return false;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync }
a299266cddc1ae14d76d725a660bb278816bc151vboxsync return true;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync}
a299266cddc1ae14d76d725a660bb278816bc151vboxsync
a299266cddc1ae14d76d725a660bb278816bc151vboxsync/**
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * Compares two sets of lines from the two files.
a299266cddc1ae14d76d725a660bb278816bc151vboxsync *
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.
a299266cddc1ae14d76d725a660bb278816bc151vboxsync */
a299266cddc1ae14d76d725a660bb278816bc151vboxsyncstatic bool scmDiffCompareLines(PSCMDIFFSTATE pState, size_t iLeft, size_t iRight, size_t cLines)
a299266cddc1ae14d76d725a660bb278816bc151vboxsync{
a299266cddc1ae14d76d725a660bb278816bc151vboxsync for (size_t iLine = 0; iLine < cLines; iLine++)
a299266cddc1ae14d76d725a660bb278816bc151vboxsync {
a299266cddc1ae14d76d725a660bb278816bc151vboxsync SCMEOL enmEolLeft;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync size_t cchLeft;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync const char *pchLeft = ScmStreamGetLineByNo(pState->pLeft, iLeft + iLine, &cchLeft, &enmEolLeft);
a299266cddc1ae14d76d725a660bb278816bc151vboxsync
a299266cddc1ae14d76d725a660bb278816bc151vboxsync SCMEOL enmEolRight;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync size_t cchRight;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync const char *pchRight = ScmStreamGetLineByNo(pState->pRight, iRight + iLine, &cchRight, &enmEolRight);
a299266cddc1ae14d76d725a660bb278816bc151vboxsync
a299266cddc1ae14d76d725a660bb278816bc151vboxsync if (!scmDiffCompare(pState, pchLeft, cchLeft, enmEolLeft, pchRight, cchRight, enmEolRight))
a299266cddc1ae14d76d725a660bb278816bc151vboxsync return false;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync }
a299266cddc1ae14d76d725a660bb278816bc151vboxsync return true;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync}
a299266cddc1ae14d76d725a660bb278816bc151vboxsync
a299266cddc1ae14d76d725a660bb278816bc151vboxsync
a299266cddc1ae14d76d725a660bb278816bc151vboxsync/**
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * Resynchronize the two streams and reports the difference.
a299266cddc1ae14d76d725a660bb278816bc151vboxsync *
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * Upon return, the streams will be positioned after the block of @a cMatches
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * lines where it resynchronized them.
a299266cddc1ae14d76d725a660bb278816bc151vboxsync *
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.
a299266cddc1ae14d76d725a660bb278816bc151vboxsync */
a299266cddc1ae14d76d725a660bb278816bc151vboxsyncstatic size_t scmDiffSynchronize(PSCMDIFFSTATE pState, size_t cMatches)
a299266cddc1ae14d76d725a660bb278816bc151vboxsync{
a299266cddc1ae14d76d725a660bb278816bc151vboxsync size_t const iStartLeft = ScmStreamTellLine(pState->pLeft) - 1;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync size_t const iStartRight = ScmStreamTellLine(pState->pRight) - 1;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync Assert(cMatches > 0);
a299266cddc1ae14d76d725a660bb278816bc151vboxsync
a299266cddc1ae14d76d725a660bb278816bc151vboxsync /*
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * Compare each new line from each of the streams will all the preceding
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * ones, including iStartLeft/Right.
a299266cddc1ae14d76d725a660bb278816bc151vboxsync */
a299266cddc1ae14d76d725a660bb278816bc151vboxsync for (size_t iRange = 1; ; iRange++)
a299266cddc1ae14d76d725a660bb278816bc151vboxsync {
a299266cddc1ae14d76d725a660bb278816bc151vboxsync /*
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * Get the next line in the left stream and compare it against all the
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * preceding lines on the right side.
a299266cddc1ae14d76d725a660bb278816bc151vboxsync */
a299266cddc1ae14d76d725a660bb278816bc151vboxsync SCMEOL enmEol;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync size_t cchLine;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync const char *pchLine = ScmStreamGetLineByNo(pState->pLeft, iStartLeft + iRange, &cchLine, &enmEol);
a299266cddc1ae14d76d725a660bb278816bc151vboxsync if (!pchLine)
a299266cddc1ae14d76d725a660bb278816bc151vboxsync return scmDiffReport(pState, 0, iStartLeft, ~(size_t)0, iStartRight, ~(size_t)0);
a299266cddc1ae14d76d725a660bb278816bc151vboxsync
a299266cddc1ae14d76d725a660bb278816bc151vboxsync for (size_t iRight = cMatches - 1; iRight < iRange; iRight++)
a299266cddc1ae14d76d725a660bb278816bc151vboxsync {
a299266cddc1ae14d76d725a660bb278816bc151vboxsync SCMEOL enmEolRight;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync size_t cchRight;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync const char *pchRight = ScmStreamGetLineByNo(pState->pRight, iStartRight + iRight,
a299266cddc1ae14d76d725a660bb278816bc151vboxsync &cchRight, &enmEolRight);
a299266cddc1ae14d76d725a660bb278816bc151vboxsync if ( scmDiffCompare(pState, pchLine, cchLine, enmEol, pchRight, cchRight, enmEolRight)
a299266cddc1ae14d76d725a660bb278816bc151vboxsync && scmDiffCompareLines(pState,
a299266cddc1ae14d76d725a660bb278816bc151vboxsync iStartLeft + iRange + 1 - cMatches,
a299266cddc1ae14d76d725a660bb278816bc151vboxsync iStartRight + iRight + 1 - cMatches,
a299266cddc1ae14d76d725a660bb278816bc151vboxsync cMatches - 1)
a299266cddc1ae14d76d725a660bb278816bc151vboxsync )
a299266cddc1ae14d76d725a660bb278816bc151vboxsync return scmDiffReport(pState, cMatches,
a299266cddc1ae14d76d725a660bb278816bc151vboxsync iStartLeft, iRange + 1 - cMatches,
a299266cddc1ae14d76d725a660bb278816bc151vboxsync iStartRight, iRight + 1 - cMatches);
a299266cddc1ae14d76d725a660bb278816bc151vboxsync }
a299266cddc1ae14d76d725a660bb278816bc151vboxsync
a299266cddc1ae14d76d725a660bb278816bc151vboxsync /*
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * Get the next line in the right stream and compare it against all the
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * lines on the right side.
a299266cddc1ae14d76d725a660bb278816bc151vboxsync */
a299266cddc1ae14d76d725a660bb278816bc151vboxsync pchLine = ScmStreamGetLineByNo(pState->pRight, iStartRight + iRange, &cchLine, &enmEol);
a299266cddc1ae14d76d725a660bb278816bc151vboxsync if (!pchLine)
a299266cddc1ae14d76d725a660bb278816bc151vboxsync return scmDiffReport(pState, 0, iStartLeft, ~(size_t)0, iStartRight, ~(size_t)0);
a299266cddc1ae14d76d725a660bb278816bc151vboxsync
a299266cddc1ae14d76d725a660bb278816bc151vboxsync for (size_t iLeft = cMatches - 1; iLeft <= iRange; iLeft++)
a299266cddc1ae14d76d725a660bb278816bc151vboxsync {
a299266cddc1ae14d76d725a660bb278816bc151vboxsync SCMEOL enmEolLeft;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync size_t cchLeft;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync const char *pchLeft = ScmStreamGetLineByNo(pState->pLeft, iStartLeft + iLeft,
a299266cddc1ae14d76d725a660bb278816bc151vboxsync &cchLeft, &enmEolLeft);
a299266cddc1ae14d76d725a660bb278816bc151vboxsync if ( scmDiffCompare(pState, pchLeft, cchLeft, enmEolLeft, pchLine, cchLine, enmEol)
a299266cddc1ae14d76d725a660bb278816bc151vboxsync && scmDiffCompareLines(pState,
a299266cddc1ae14d76d725a660bb278816bc151vboxsync iStartLeft + iLeft + 1 - cMatches,
a299266cddc1ae14d76d725a660bb278816bc151vboxsync iStartRight + iRange + 1 - cMatches,
a299266cddc1ae14d76d725a660bb278816bc151vboxsync cMatches - 1)
a299266cddc1ae14d76d725a660bb278816bc151vboxsync )
a299266cddc1ae14d76d725a660bb278816bc151vboxsync return scmDiffReport(pState, cMatches,
a299266cddc1ae14d76d725a660bb278816bc151vboxsync iStartLeft, iLeft + 1 - cMatches,
a299266cddc1ae14d76d725a660bb278816bc151vboxsync iStartRight, iRange + 1 - cMatches);
a299266cddc1ae14d76d725a660bb278816bc151vboxsync }
a299266cddc1ae14d76d725a660bb278816bc151vboxsync }
a299266cddc1ae14d76d725a660bb278816bc151vboxsync}
a299266cddc1ae14d76d725a660bb278816bc151vboxsync
a299266cddc1ae14d76d725a660bb278816bc151vboxsync/**
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * Creates a diff of the changes between the streams @a pLeft and @a pRight.
a299266cddc1ae14d76d725a660bb278816bc151vboxsync *
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * This currently only implements the simplest diff format, so no contexts.
a299266cddc1ae14d76d725a660bb278816bc151vboxsync *
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * Also, note that we won't detect differences in the final newline of the
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * streams.
a299266cddc1ae14d76d725a660bb278816bc151vboxsync *
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.
a299266cddc1ae14d76d725a660bb278816bc151vboxsync */
a299266cddc1ae14d76d725a660bb278816bc151vboxsyncsize_t ScmDiffStreams(const char *pszFilename, PSCMSTREAM pLeft, PSCMSTREAM pRight, bool fIgnoreEol,
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync bool fIgnoreLeadingWhite, bool fIgnoreTrailingWhite, bool fSpecialChars,
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync size_t cchTab, PRTSTREAM pDiff)
a299266cddc1ae14d76d725a660bb278816bc151vboxsync{
a299266cddc1ae14d76d725a660bb278816bc151vboxsync#ifdef RT_STRICT
a299266cddc1ae14d76d725a660bb278816bc151vboxsync ScmStreamCheckItegrity(pLeft);
a299266cddc1ae14d76d725a660bb278816bc151vboxsync ScmStreamCheckItegrity(pRight);
a299266cddc1ae14d76d725a660bb278816bc151vboxsync#endif
a299266cddc1ae14d76d725a660bb278816bc151vboxsync
a299266cddc1ae14d76d725a660bb278816bc151vboxsync /*
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * Set up the diff state.
a299266cddc1ae14d76d725a660bb278816bc151vboxsync */
a299266cddc1ae14d76d725a660bb278816bc151vboxsync SCMDIFFSTATE State;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync State.cDiffs = 0;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync State.pszFilename = pszFilename;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync State.pLeft = pLeft;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync State.pRight = pRight;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync State.fIgnoreEol = fIgnoreEol;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync State.fIgnoreLeadingWhite = fIgnoreLeadingWhite;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync State.fIgnoreTrailingWhite = fIgnoreTrailingWhite;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync State.fSpecialChars = fSpecialChars;
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync State.cchTab = cchTab;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync State.pDiff = pDiff;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync
a299266cddc1ae14d76d725a660bb278816bc151vboxsync /*
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * Compare them line by line.
a299266cddc1ae14d76d725a660bb278816bc151vboxsync */
a299266cddc1ae14d76d725a660bb278816bc151vboxsync ScmStreamRewindForReading(pLeft);
a299266cddc1ae14d76d725a660bb278816bc151vboxsync ScmStreamRewindForReading(pRight);
a299266cddc1ae14d76d725a660bb278816bc151vboxsync const char *pchLeft;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync const char *pchRight;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync
a299266cddc1ae14d76d725a660bb278816bc151vboxsync for (;;)
a299266cddc1ae14d76d725a660bb278816bc151vboxsync {
a299266cddc1ae14d76d725a660bb278816bc151vboxsync SCMEOL enmEolLeft;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync size_t cchLeft;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync pchLeft = ScmStreamGetLine(pLeft, &cchLeft, &enmEolLeft);
a299266cddc1ae14d76d725a660bb278816bc151vboxsync
a299266cddc1ae14d76d725a660bb278816bc151vboxsync SCMEOL enmEolRight;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync size_t cchRight;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync pchRight = ScmStreamGetLine(pRight, &cchRight, &enmEolRight);
a299266cddc1ae14d76d725a660bb278816bc151vboxsync if (!pchLeft || !pchRight)
a299266cddc1ae14d76d725a660bb278816bc151vboxsync break;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync
a299266cddc1ae14d76d725a660bb278816bc151vboxsync if (!scmDiffCompare(&State, pchLeft, cchLeft, enmEolLeft, pchRight, cchRight, enmEolRight))
a299266cddc1ae14d76d725a660bb278816bc151vboxsync scmDiffSynchronize(&State, 3);
a299266cddc1ae14d76d725a660bb278816bc151vboxsync }
a299266cddc1ae14d76d725a660bb278816bc151vboxsync
a299266cddc1ae14d76d725a660bb278816bc151vboxsync /*
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * Deal with any remaining differences.
a299266cddc1ae14d76d725a660bb278816bc151vboxsync */
a299266cddc1ae14d76d725a660bb278816bc151vboxsync if (pchLeft)
a299266cddc1ae14d76d725a660bb278816bc151vboxsync scmDiffReport(&State, 0, ScmStreamTellLine(pLeft) - 1, ~(size_t)0, ScmStreamTellLine(pRight), 0);
a299266cddc1ae14d76d725a660bb278816bc151vboxsync else if (pchRight)
a299266cddc1ae14d76d725a660bb278816bc151vboxsync scmDiffReport(&State, 0, ScmStreamTellLine(pLeft), 0, ScmStreamTellLine(pRight) - 1, ~(size_t)0);
a299266cddc1ae14d76d725a660bb278816bc151vboxsync
a299266cddc1ae14d76d725a660bb278816bc151vboxsync /*
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * Report any errors.
a299266cddc1ae14d76d725a660bb278816bc151vboxsync */
a299266cddc1ae14d76d725a660bb278816bc151vboxsync if (RT_FAILURE(ScmStreamGetStatus(pLeft)))
a299266cddc1ae14d76d725a660bb278816bc151vboxsync RTMsgError("Left diff stream error: %Rrc\n", ScmStreamGetStatus(pLeft));
a299266cddc1ae14d76d725a660bb278816bc151vboxsync if (RT_FAILURE(ScmStreamGetStatus(pRight)))
a299266cddc1ae14d76d725a660bb278816bc151vboxsync RTMsgError("Right diff stream error: %Rrc\n", ScmStreamGetStatus(pRight));
a299266cddc1ae14d76d725a660bb278816bc151vboxsync
a299266cddc1ae14d76d725a660bb278816bc151vboxsync return State.cDiffs;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync}
a299266cddc1ae14d76d725a660bb278816bc151vboxsync
a299266cddc1ae14d76d725a660bb278816bc151vboxsync
a299266cddc1ae14d76d725a660bb278816bc151vboxsync
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync/* -=-=-=-=-=- settings -=-=-=-=-=- */
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync/**
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * Init a settings structure with settings from @a pSrc.
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync *
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * @returns IPRT status code
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * @param pSettings The settings.
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * @param pSrc The source settings.
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync */
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsyncstatic int scmSettingsBaseInitAndCopy(PSCMSETTINGSBASE pSettings, PCSCMSETTINGSBASE pSrc)
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync{
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync *pSettings = *pSrc;
e45e3ae4a834169539e689759ba6b3ac71bfe40fvboxsync
e45e3ae4a834169539e689759ba6b3ac71bfe40fvboxsync int rc = RTStrDupEx(&pSettings->pszFilterFiles, pSrc->pszFilterFiles);
e45e3ae4a834169539e689759ba6b3ac71bfe40fvboxsync if (RT_SUCCESS(rc))
e45e3ae4a834169539e689759ba6b3ac71bfe40fvboxsync {
e45e3ae4a834169539e689759ba6b3ac71bfe40fvboxsync rc = RTStrDupEx(&pSettings->pszFilterOutFiles, pSrc->pszFilterOutFiles);
e45e3ae4a834169539e689759ba6b3ac71bfe40fvboxsync if (RT_SUCCESS(rc))
e45e3ae4a834169539e689759ba6b3ac71bfe40fvboxsync {
e45e3ae4a834169539e689759ba6b3ac71bfe40fvboxsync rc = RTStrDupEx(&pSettings->pszFilterOutDirs, pSrc->pszFilterOutDirs);
e45e3ae4a834169539e689759ba6b3ac71bfe40fvboxsync if (RT_SUCCESS(rc))
e45e3ae4a834169539e689759ba6b3ac71bfe40fvboxsync return VINF_SUCCESS;
e45e3ae4a834169539e689759ba6b3ac71bfe40fvboxsync
e45e3ae4a834169539e689759ba6b3ac71bfe40fvboxsync RTStrFree(pSettings->pszFilterOutFiles);
e45e3ae4a834169539e689759ba6b3ac71bfe40fvboxsync }
e45e3ae4a834169539e689759ba6b3ac71bfe40fvboxsync RTStrFree(pSettings->pszFilterFiles);
e45e3ae4a834169539e689759ba6b3ac71bfe40fvboxsync }
e45e3ae4a834169539e689759ba6b3ac71bfe40fvboxsync
e45e3ae4a834169539e689759ba6b3ac71bfe40fvboxsync pSettings->pszFilterFiles = NULL;
e45e3ae4a834169539e689759ba6b3ac71bfe40fvboxsync pSettings->pszFilterOutFiles = NULL;
e45e3ae4a834169539e689759ba6b3ac71bfe40fvboxsync pSettings->pszFilterOutDirs = NULL;
e45e3ae4a834169539e689759ba6b3ac71bfe40fvboxsync return rc;
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync}
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync/**
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * Init a settings structure.
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync *
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * @returns IPRT status code
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * @param pSettings The settings.
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync */
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsyncstatic int scmSettingsBaseInit(PSCMSETTINGSBASE pSettings)
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync{
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync return scmSettingsBaseInitAndCopy(pSettings, &g_Defaults);
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync}
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync/**
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * Deletes the settings, i.e. free any dynamically allocated content.
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync *
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * @param pSettings The settings.
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync */
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsyncstatic void scmSettingsBaseDelete(PSCMSETTINGSBASE pSettings)
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync{
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync if (pSettings)
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync {
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync Assert(pSettings->cchTab != ~(unsigned)0);
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync pSettings->cchTab = ~(unsigned)0;
e45e3ae4a834169539e689759ba6b3ac71bfe40fvboxsync
e45e3ae4a834169539e689759ba6b3ac71bfe40fvboxsync RTStrFree(pSettings->pszFilterFiles);
e45e3ae4a834169539e689759ba6b3ac71bfe40fvboxsync pSettings->pszFilterFiles = NULL;
e45e3ae4a834169539e689759ba6b3ac71bfe40fvboxsync
e45e3ae4a834169539e689759ba6b3ac71bfe40fvboxsync RTStrFree(pSettings->pszFilterOutFiles);
e45e3ae4a834169539e689759ba6b3ac71bfe40fvboxsync pSettings->pszFilterOutFiles = NULL;
e45e3ae4a834169539e689759ba6b3ac71bfe40fvboxsync
e45e3ae4a834169539e689759ba6b3ac71bfe40fvboxsync RTStrFree(pSettings->pszFilterOutDirs);
e45e3ae4a834169539e689759ba6b3ac71bfe40fvboxsync pSettings->pszFilterOutDirs = NULL;
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync }
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync}
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync
e45e3ae4a834169539e689759ba6b3ac71bfe40fvboxsync
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync/**
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * Processes a RTGetOpt result.
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync *
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 *
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * @param pSettings The settings to change.
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * @param rc The RTGetOpt return value.
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * @param pValueUnion The RTGetOpt value union.
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync */
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsyncstatic int scmSettingsBaseHandleOpt(PSCMSETTINGSBASE pSettings, int rc, PRTGETOPTUNION pValueUnion)
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync{
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync switch (rc)
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync {
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync case SCMOPT_CONVERT_EOL:
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync pSettings->fConvertEol = true;
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync return VINF_SUCCESS;
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync case SCMOPT_NO_CONVERT_EOL:
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync pSettings->fConvertEol = false;
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync return VINF_SUCCESS;
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync case SCMOPT_CONVERT_TABS:
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync pSettings->fConvertTabs = true;
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync return VINF_SUCCESS;
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync case SCMOPT_NO_CONVERT_TABS:
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync pSettings->fConvertTabs = false;
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync return VINF_SUCCESS;
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync case SCMOPT_FORCE_FINAL_EOL:
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync pSettings->fForceFinalEol = true;
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync return VINF_SUCCESS;
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync case SCMOPT_NO_FORCE_FINAL_EOL:
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync pSettings->fForceFinalEol = false;
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync return VINF_SUCCESS;
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync case SCMOPT_FORCE_TRAILING_LINE:
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync pSettings->fForceTrailingLine = true;
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync return VINF_SUCCESS;
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync case SCMOPT_NO_FORCE_TRAILING_LINE:
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync pSettings->fForceTrailingLine = false;
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync return VINF_SUCCESS;
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync case SCMOPT_STRIP_TRAILING_BLANKS:
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync pSettings->fStripTrailingBlanks = true;
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync return VINF_SUCCESS;
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync case SCMOPT_NO_STRIP_TRAILING_BLANKS:
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync pSettings->fStripTrailingBlanks = false;
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync return VINF_SUCCESS;
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync case SCMOPT_STRIP_TRAILING_LINES:
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync pSettings->fStripTrailingLines = true;
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync return VINF_SUCCESS;
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync case SCMOPT_NO_STRIP_TRAILING_LINES:
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync pSettings->fStripTrailingLines = false;
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync return VINF_SUCCESS;
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync
4bcaf5d320bf0d88910212509c37bdd634e0879evboxsync case SCMOPT_ONLY_SVN_DIRS:
4bcaf5d320bf0d88910212509c37bdd634e0879evboxsync pSettings->fOnlySvnDirs = true;
4bcaf5d320bf0d88910212509c37bdd634e0879evboxsync return VINF_SUCCESS;
4bcaf5d320bf0d88910212509c37bdd634e0879evboxsync case SCMOPT_NOT_ONLY_SVN_DIRS:
4bcaf5d320bf0d88910212509c37bdd634e0879evboxsync pSettings->fOnlySvnDirs = false;
4bcaf5d320bf0d88910212509c37bdd634e0879evboxsync return VINF_SUCCESS;
4bcaf5d320bf0d88910212509c37bdd634e0879evboxsync
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync case SCMOPT_ONLY_SVN_FILES:
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync pSettings->fOnlySvnFiles = true;
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync return VINF_SUCCESS;
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync case SCMOPT_NOT_ONLY_SVN_FILES:
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync pSettings->fOnlySvnFiles = false;
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync return VINF_SUCCESS;
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync case SCMOPT_SET_SVN_EOL:
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync pSettings->fSetSvnEol = true;
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync return VINF_SUCCESS;
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync case SCMOPT_DONT_SET_SVN_EOL:
4a4d802b46dfabbfd36e88822ff7b17421120469vboxsync pSettings->fSetSvnEol = false;
4a4d802b46dfabbfd36e88822ff7b17421120469vboxsync return VINF_SUCCESS;
4a4d802b46dfabbfd36e88822ff7b17421120469vboxsync
4a4d802b46dfabbfd36e88822ff7b17421120469vboxsync case SCMOPT_SET_SVN_EXECUTABLE:
4a4d802b46dfabbfd36e88822ff7b17421120469vboxsync pSettings->fSetSvnExecutable = true;
4a4d802b46dfabbfd36e88822ff7b17421120469vboxsync return VINF_SUCCESS;
4a4d802b46dfabbfd36e88822ff7b17421120469vboxsync case SCMOPT_DONT_SET_SVN_EXECUTABLE:
4a4d802b46dfabbfd36e88822ff7b17421120469vboxsync pSettings->fSetSvnExecutable = false;
4a4d802b46dfabbfd36e88822ff7b17421120469vboxsync return VINF_SUCCESS;
4a4d802b46dfabbfd36e88822ff7b17421120469vboxsync
4a4d802b46dfabbfd36e88822ff7b17421120469vboxsync case SCMOPT_SET_SVN_KEYWORDS:
4a4d802b46dfabbfd36e88822ff7b17421120469vboxsync pSettings->fSetSvnKeywords = true;
4a4d802b46dfabbfd36e88822ff7b17421120469vboxsync return VINF_SUCCESS;
4a4d802b46dfabbfd36e88822ff7b17421120469vboxsync case SCMOPT_DONT_SET_SVN_KEYWORDS:
4a4d802b46dfabbfd36e88822ff7b17421120469vboxsync pSettings->fSetSvnKeywords = false;
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync return VINF_SUCCESS;
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync case SCMOPT_TAB_SIZE:
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync if ( pValueUnion->u8 < 1
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync || pValueUnion->u8 >= RT_ELEMENTS(g_szTabSpaces))
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync {
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync RTMsgError("Invalid tab size: %u - must be in {1..%u}\n",
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync pValueUnion->u8, RT_ELEMENTS(g_szTabSpaces) - 1);
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync return VERR_OUT_OF_RANGE;
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync }
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync pSettings->cchTab = pValueUnion->u8;
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync return VINF_SUCCESS;
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync
e45e3ae4a834169539e689759ba6b3ac71bfe40fvboxsync case SCMOPT_FILTER_OUT_DIRS:
e45e3ae4a834169539e689759ba6b3ac71bfe40fvboxsync case SCMOPT_FILTER_FILES:
e45e3ae4a834169539e689759ba6b3ac71bfe40fvboxsync case SCMOPT_FILTER_OUT_FILES:
e45e3ae4a834169539e689759ba6b3ac71bfe40fvboxsync {
4d41bf71a71dd2c00d0c4e0006571b9e07b484c3vboxsync char **ppsz = NULL;
e45e3ae4a834169539e689759ba6b3ac71bfe40fvboxsync switch (rc)
e45e3ae4a834169539e689759ba6b3ac71bfe40fvboxsync {
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 }
e45e3ae4a834169539e689759ba6b3ac71bfe40fvboxsync
e45e3ae4a834169539e689759ba6b3ac71bfe40fvboxsync /*
e45e3ae4a834169539e689759ba6b3ac71bfe40fvboxsync * An empty string zaps the current list.
e45e3ae4a834169539e689759ba6b3ac71bfe40fvboxsync */
e45e3ae4a834169539e689759ba6b3ac71bfe40fvboxsync if (!*pValueUnion->psz)
e45e3ae4a834169539e689759ba6b3ac71bfe40fvboxsync return RTStrATruncate(ppsz, 0);
e45e3ae4a834169539e689759ba6b3ac71bfe40fvboxsync
e45e3ae4a834169539e689759ba6b3ac71bfe40fvboxsync /*
e45e3ae4a834169539e689759ba6b3ac71bfe40fvboxsync * Non-empty strings are appended to the pattern list.
e45e3ae4a834169539e689759ba6b3ac71bfe40fvboxsync *
e45e3ae4a834169539e689759ba6b3ac71bfe40fvboxsync * Strip leading and trailing pattern separators before attempting
e45e3ae4a834169539e689759ba6b3ac71bfe40fvboxsync * to append it. If it's just separators, don't do anything.
e45e3ae4a834169539e689759ba6b3ac71bfe40fvboxsync */
e45e3ae4a834169539e689759ba6b3ac71bfe40fvboxsync const char *pszSrc = pValueUnion->psz;
e45e3ae4a834169539e689759ba6b3ac71bfe40fvboxsync while (*pszSrc == '|')
e45e3ae4a834169539e689759ba6b3ac71bfe40fvboxsync pszSrc++;
e45e3ae4a834169539e689759ba6b3ac71bfe40fvboxsync size_t cchSrc = strlen(pszSrc);
e45e3ae4a834169539e689759ba6b3ac71bfe40fvboxsync while (cchSrc > 0 && pszSrc[cchSrc - 1] == '|')
e45e3ae4a834169539e689759ba6b3ac71bfe40fvboxsync cchSrc--;
e45e3ae4a834169539e689759ba6b3ac71bfe40fvboxsync if (!cchSrc)
e45e3ae4a834169539e689759ba6b3ac71bfe40fvboxsync return VINF_SUCCESS;
e45e3ae4a834169539e689759ba6b3ac71bfe40fvboxsync
e45e3ae4a834169539e689759ba6b3ac71bfe40fvboxsync return RTStrAAppendExN(ppsz, 2,
e45e3ae4a834169539e689759ba6b3ac71bfe40fvboxsync "|", *ppsz && **ppsz ? 1 : 0,
e45e3ae4a834169539e689759ba6b3ac71bfe40fvboxsync pszSrc, cchSrc);
e45e3ae4a834169539e689759ba6b3ac71bfe40fvboxsync }
e45e3ae4a834169539e689759ba6b3ac71bfe40fvboxsync
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync default:
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync return VERR_GETOPT_UNKNOWN_OPTION;
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync }
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync}
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync/**
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * Parses an option string.
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync *
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * @returns IPRT status code.
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * @param pBase The base settings structure to apply the options
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * to.
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * @param pszOptions The options to parse.
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync */
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsyncstatic int scmSettingsBaseParseString(PSCMSETTINGSBASE pBase, const char *pszLine)
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync{
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync int cArgs;
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync char **papszArgs;
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync int rc = RTGetOptArgvFromString(&papszArgs, &cArgs, pszLine, NULL);
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync if (RT_SUCCESS(rc))
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync {
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync RTGETOPTUNION ValueUnion;
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync RTGETOPTSTATE GetOptState;
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync rc = RTGetOptInit(&GetOptState, cArgs, papszArgs, &g_aScmOpts[0], RT_ELEMENTS(g_aScmOpts), 0, 0 /*fFlags*/);
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync if (RT_SUCCESS(rc))
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync {
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync while ((rc = RTGetOpt(&GetOptState, &ValueUnion)) != 0)
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync {
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync rc = scmSettingsBaseHandleOpt(pBase, rc, &ValueUnion);
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync if (RT_FAILURE(rc))
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync break;
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync }
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync }
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync RTGetOptArgvFree(papszArgs);
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync }
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync return rc;
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync}
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync/**
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * Parses an unterminated option string.
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync *
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * @returns IPRT status code.
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * @param pBase The base settings structure to apply the options
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * to.
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * @param pchLine The line.
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * @param cchLine The line length.
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync */
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsyncstatic int scmSettingsBaseParseStringN(PSCMSETTINGSBASE pBase, const char *pchLine, size_t cchLine)
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync{
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync char *pszLine = RTStrDupN(pchLine, cchLine);
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync if (!pszLine)
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync return VERR_NO_MEMORY;
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync int rc = scmSettingsBaseParseString(pBase, pszLine);
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync RTStrFree(pszLine);
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync return rc;
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync}
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync/**
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * Verifies the options string.
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync *
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * @returns IPRT status code.
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * @param pszOptions The options to verify .
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync */
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsyncstatic int scmSettingsBaseVerifyString(const char *pszOptions)
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync{
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync SCMSETTINGSBASE Base;
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync int rc = scmSettingsBaseInit(&Base);
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync if (RT_SUCCESS(rc))
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync {
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync rc = scmSettingsBaseParseString(&Base, pszOptions);
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync scmSettingsBaseDelete(&Base);
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync }
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync return rc;
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync}
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync/**
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * Loads settings found in editor and SCM settings directives within the
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * document (@a pStream).
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync *
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.
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync */
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsyncstatic int scmSettingsBaseLoadFromDocument(PSCMSETTINGSBASE pBase, PSCMSTREAM pStream)
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync{
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync /** @todo Editor and SCM settings directives in documents. */
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync return VINF_SUCCESS;
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync}
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync/**
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * Creates a new settings file struct, cloning @a pSettings.
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync *
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * @returns IPRT status code.
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * @param ppSettings Where to return the new struct.
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * @param pSettingsBase The settings to inherit from.
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync */
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsyncstatic int scmSettingsCreate(PSCMSETTINGS *ppSettings, PCSCMSETTINGSBASE pSettingsBase)
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync{
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync PSCMSETTINGS pSettings = (PSCMSETTINGS)RTMemAlloc(sizeof(*pSettings));
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync if (!pSettings)
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync return VERR_NO_MEMORY;
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync int rc = scmSettingsBaseInitAndCopy(&pSettings->Base, pSettingsBase);
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync if (RT_SUCCESS(rc))
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync {
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync pSettings->pDown = NULL;
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync pSettings->pUp = NULL;
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync pSettings->paPairs = NULL;
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync pSettings->cPairs = 0;
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync *ppSettings = pSettings;
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync return VINF_SUCCESS;
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync }
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync RTMemFree(pSettings);
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync return rc;
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync}
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync/**
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * Destroys a settings structure.
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync *
ad27e1d5e48ca41245120c331cc88b50464813cevboxsync * @param pSettings The settings structure to destroy. NULL is OK.
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync */
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsyncstatic void scmSettingsDestroy(PSCMSETTINGS pSettings)
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync{
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync if (pSettings)
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync {
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync scmSettingsBaseDelete(&pSettings->Base);
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync for (size_t i = 0; i < pSettings->cPairs; i++)
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync {
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync RTStrFree(pSettings->paPairs[i].pszPattern);
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync RTStrFree(pSettings->paPairs[i].pszOptions);
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync pSettings->paPairs[i].pszPattern = NULL;
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync pSettings->paPairs[i].pszOptions = NULL;
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync }
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync RTMemFree(pSettings->paPairs);
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync pSettings->paPairs = NULL;
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync RTMemFree(pSettings);
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync }
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync}
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync/**
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * Adds a pattern/options pair to the settings structure.
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync *
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.
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync */
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsyncstatic int scmSettingsAddPair(PSCMSETTINGS pSettings, const char *pchLine, size_t cchLine)
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync{
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync /*
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * Split the string.
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync */
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync const char *pchOptions = (const char *)memchr(pchLine, ':', cchLine);
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync if (!pchOptions)
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync return VERR_INVALID_PARAMETER;
a2d2faa1528d1752b2bb4da5469495fe5436e0f0vboxsync size_t cchPattern = pchOptions - pchLine;
a2d2faa1528d1752b2bb4da5469495fe5436e0f0vboxsync size_t cchOptions = cchLine - cchPattern - 1;
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync pchOptions++;
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync /* strip spaces everywhere */
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync while (cchPattern > 0 && RT_C_IS_SPACE(pchLine[cchPattern - 1]))
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync cchPattern--;
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync while (cchPattern > 0 && RT_C_IS_SPACE(*pchLine))
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync cchPattern--, pchLine++;
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync while (cchOptions > 0 && RT_C_IS_SPACE(pchOptions[cchOptions - 1]))
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync cchOptions--;
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync while (cchOptions > 0 && RT_C_IS_SPACE(*pchOptions))
bb48f1a46f469da79b8d15cae8deee8c199448a0vboxsync cchOptions--, pchOptions++;
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync /* Quietly ignore empty patterns and empty options. */
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync if (!cchOptions || !cchPattern)
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync return VINF_SUCCESS;
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync /*
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * Add the pair and verify the option string.
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync */
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync uint32_t iPair = pSettings->cPairs;
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync if ((iPair % 32) == 0)
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync {
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync void *pvNew = RTMemRealloc(pSettings->paPairs, (iPair + 32) * sizeof(pSettings->paPairs[0]));
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync if (!pvNew)
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync return VERR_NO_MEMORY;
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync pSettings->paPairs = (PSCMPATRNOPTPAIR)pvNew;
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync }
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync pSettings->paPairs[iPair].pszPattern = RTStrDupN(pchLine, cchPattern);
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync pSettings->paPairs[iPair].pszOptions = RTStrDupN(pchOptions, cchOptions);
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync int rc;
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync if ( pSettings->paPairs[iPair].pszPattern
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync && pSettings->paPairs[iPair].pszOptions)
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync rc = scmSettingsBaseVerifyString(pSettings->paPairs[iPair].pszOptions);
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync else
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync rc = VERR_NO_MEMORY;
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync if (RT_SUCCESS(rc))
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync pSettings->cPairs = iPair + 1;
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync else
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync {
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync RTStrFree(pSettings->paPairs[iPair].pszPattern);
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync RTStrFree(pSettings->paPairs[iPair].pszOptions);
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync }
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync return rc;
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync}
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync/**
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * Loads in the settings from @a pszFilename.
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync *
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * @returns IPRT status code.
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * @param pSettings Where to load the settings file.
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * @param pszFilename The file to load.
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync */
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsyncstatic int scmSettingsLoadFile(PSCMSETTINGS pSettings, const char *pszFilename)
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync{
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync SCMSTREAM Stream;
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync int rc = ScmStreamInitForReading(&Stream, pszFilename);
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync if (RT_FAILURE(rc))
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync {
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync RTMsgError("%s: ScmStreamInitForReading -> %Rrc\n", pszFilename, rc);
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync return rc;
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync }
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync SCMEOL enmEol;
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync const char *pchLine;
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync size_t cchLine;
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync while ((pchLine = ScmStreamGetLine(&Stream, &cchLine, &enmEol)) != NULL)
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync {
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync /* Ignore leading spaces. */
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync while (cchLine > 0 && RT_C_IS_SPACE(*pchLine))
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync pchLine++, cchLine--;
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync /* Ignore empty lines and comment lines. */
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync if (cchLine < 1 || *pchLine == '#')
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync continue;
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync /* What kind of line is it? */
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync const char *pchColon = (const char *)memchr(pchLine, ':', cchLine);
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync if (pchColon)
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync rc = scmSettingsAddPair(pSettings, pchLine, cchLine);
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync else
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync rc = scmSettingsBaseParseStringN(&pSettings->Base, pchLine, cchLine);
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync if (RT_FAILURE(rc))
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync {
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync RTMsgError("%s:%d: %Rrc\n", pszFilename, ScmStreamTellLine(&Stream), rc);
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync break;
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync }
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync }
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync if (RT_SUCCESS(rc))
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync {
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync rc = ScmStreamGetStatus(&Stream);
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync if (RT_FAILURE(rc))
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync RTMsgError("%s: ScmStreamGetStatus- > %Rrc\n", pszFilename, rc);
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync }
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync ScmStreamDelete(&Stream);
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync return rc;
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync}
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync/**
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * Parse the specified settings file creating a new settings struct from it.
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync *
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.
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync */
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsyncstatic int scmSettingsCreateFromFile(PSCMSETTINGS *ppSettings, const char *pszFilename, PCSCMSETTINGSBASE pSettingsBase)
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync{
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync PSCMSETTINGS pSettings;
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync int rc = scmSettingsCreate(&pSettings, pSettingsBase);
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync if (RT_SUCCESS(rc))
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync {
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync rc = scmSettingsLoadFile(pSettings, pszFilename);
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync if (RT_SUCCESS(rc))
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync {
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync *ppSettings = pSettings;
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync return VINF_SUCCESS;
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync }
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync scmSettingsDestroy(pSettings);
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync }
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync *ppSettings = NULL;
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync return rc;
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync}
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync/**
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * Create an initial settings structure when starting processing a new file or
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * directory.
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync *
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 *
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * @returns IPRT status code.
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * @param ppSettings Where to return the pointer to the top stack
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * object.
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * @param pBaseSettings The base settings we inherit from (globals
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * typically).
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * @param pszPath The absolute path to the new directory or file.
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync */
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsyncstatic int scmSettingsCreateForPath(PSCMSETTINGS *ppSettings, PCSCMSETTINGSBASE pBaseSettings, const char *pszPath)
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync{
f285bb149147cccd6109e5487e744df17c04da82vboxsync *ppSettings = NULL; /* try shut up gcc. */
f285bb149147cccd6109e5487e744df17c04da82vboxsync
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync /*
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * We'll be working with a stack copy of the path.
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync */
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync char szFile[RTPATH_MAX];
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync size_t cchDir = strlen(pszPath);
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync if (cchDir >= sizeof(szFile) - sizeof(SCM_SETTINGS_FILENAME))
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync return VERR_FILENAME_TOO_LONG;
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync /*
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * Create the bottom-most settings.
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync */
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync PSCMSETTINGS pSettings;
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync int rc = scmSettingsCreate(&pSettings, pBaseSettings);
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync if (RT_FAILURE(rc))
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync return rc;
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync /*
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * Enumerate the path components from the root and down. Load any setting
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * files we find.
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync */
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync size_t cComponents = RTPathCountComponents(pszPath);
b2c35a7024c4c308b429c81b203b3bcbd44ee60cvboxsync for (size_t i = 1; i <= cComponents; i++)
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync {
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync rc = RTPathCopyComponents(szFile, sizeof(szFile), pszPath, i);
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync if (RT_SUCCESS(rc))
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync rc = RTPathAppend(szFile, sizeof(szFile), SCM_SETTINGS_FILENAME);
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync if (RT_FAILURE(rc))
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync break;
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync if (RTFileExists(szFile))
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync {
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync rc = scmSettingsLoadFile(pSettings, szFile);
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync if (RT_FAILURE(rc))
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync break;
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync }
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync }
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync if (RT_SUCCESS(rc))
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync *ppSettings = pSettings;
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync else
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync scmSettingsDestroy(pSettings);
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync return rc;
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync}
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync/**
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * Pushes a new settings set onto the stack.
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync *
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.
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync */
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsyncstatic void scmSettingsStackPush(PSCMSETTINGS *ppSettingsStack, PSCMSETTINGS pSettings)
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync{
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync PSCMSETTINGS pOld = *ppSettingsStack;
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync pSettings->pDown = pOld;
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync pSettings->pUp = NULL;
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync if (pOld)
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync pOld->pUp = pSettings;
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync *ppSettingsStack = pSettings;
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync}
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync/**
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * Pushes the settings of the specified directory onto the stack.
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync *
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * We will load any .scm-settings in the directory. A stack entry is added even
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * if no settings file was found.
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync *
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.
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync */
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsyncstatic int scmSettingsStackPushDir(PSCMSETTINGS *ppSettingsStack, const char *pszDir)
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync{
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync char szFile[RTPATH_MAX];
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync int rc = RTPathJoin(szFile, sizeof(szFile), pszDir, SCM_SETTINGS_FILENAME);
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync if (RT_SUCCESS(rc))
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync {
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync PSCMSETTINGS pSettings;
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync rc = scmSettingsCreate(&pSettings, &(*ppSettingsStack)->Base);
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync if (RT_SUCCESS(rc))
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync {
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync if (RTFileExists(szFile))
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync rc = scmSettingsLoadFile(pSettings, szFile);
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync if (RT_SUCCESS(rc))
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync {
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync scmSettingsStackPush(ppSettingsStack, pSettings);
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync return VINF_SUCCESS;
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync }
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync scmSettingsDestroy(pSettings);
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync }
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync }
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync return rc;
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync}
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync/**
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * Pops a settings set off the stack.
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync *
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.
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync */
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsyncstatic PSCMSETTINGS scmSettingsStackPop(PSCMSETTINGS *ppSettingsStack)
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync{
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync PSCMSETTINGS pRet = *ppSettingsStack;
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync PSCMSETTINGS pNew = pRet ? pRet->pDown : NULL;
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync *ppSettingsStack = pNew;
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync if (pNew)
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync pNew->pUp = NULL;
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync if (pRet)
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync {
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync pRet->pUp = NULL;
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync pRet->pDown = NULL;
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync }
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync return pRet;
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync}
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync/**
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * Pops and destroys the top entry of the stack.
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync *
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * @param ppSettingsStack The pointer to the pointer to the top stack
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * element. This will be used as input and output.
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync */
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsyncstatic void scmSettingsStackPopAndDestroy(PSCMSETTINGS *ppSettingsStack)
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync{
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync scmSettingsDestroy(scmSettingsStackPop(ppSettingsStack));
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync}
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync/**
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * Constructs the base settings for the specified file name.
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync *
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.
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync */
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsyncstatic int scmSettingsStackMakeFileBase(PCSCMSETTINGS pSettingsStack, const char *pszFilename,
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync const char *pszBasename, size_t cchBasename, PSCMSETTINGSBASE pBase)
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync{
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync int rc = scmSettingsBaseInitAndCopy(pBase, &pSettingsStack->Base);
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync if (RT_SUCCESS(rc))
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync {
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync /* find the bottom entry in the stack. */
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync PCSCMSETTINGS pCur = pSettingsStack;
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync while (pCur->pDown)
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync pCur = pCur->pDown;
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync /* Work our way up thru the stack and look for matching pairs. */
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync while (pCur)
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync {
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync size_t const cPairs = pCur->cPairs;
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync if (cPairs)
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync {
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync for (size_t i = 0; i < cPairs; i++)
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync if ( RTStrSimplePatternMultiMatch(pCur->paPairs[i].pszPattern, RTSTR_MAX,
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync pszBasename, cchBasename, NULL)
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync || RTStrSimplePatternMultiMatch(pCur->paPairs[i].pszPattern, RTSTR_MAX,
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync pszFilename, RTSTR_MAX, NULL))
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync {
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync rc = scmSettingsBaseParseString(pBase, pCur->paPairs[i].pszOptions);
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync if (RT_FAILURE(rc))
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync break;
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync }
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync if (RT_FAILURE(rc))
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync break;
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync }
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync /* advance */
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync pCur = pCur->pUp;
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync }
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync }
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync if (RT_FAILURE(rc))
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync scmSettingsBaseDelete(pBase);
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync return rc;
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync}
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync
a299266cddc1ae14d76d725a660bb278816bc151vboxsync
a299266cddc1ae14d76d725a660bb278816bc151vboxsync/* -=-=-=-=-=- misc -=-=-=-=-=- */
a299266cddc1ae14d76d725a660bb278816bc151vboxsync
a299266cddc1ae14d76d725a660bb278816bc151vboxsync
a299266cddc1ae14d76d725a660bb278816bc151vboxsync/**
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * Prints a verbose message if the level is high enough.
a299266cddc1ae14d76d725a660bb278816bc151vboxsync *
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.
a299266cddc1ae14d76d725a660bb278816bc151vboxsync */
b2c35a7024c4c308b429c81b203b3bcbd44ee60cvboxsyncstatic void ScmVerbose(PSCMRWSTATE pState, int iLevel, const char *pszFormat, ...)
a299266cddc1ae14d76d725a660bb278816bc151vboxsync{
a299266cddc1ae14d76d725a660bb278816bc151vboxsync if (iLevel <= g_iVerbosity)
a299266cddc1ae14d76d725a660bb278816bc151vboxsync {
b2c35a7024c4c308b429c81b203b3bcbd44ee60cvboxsync if (pState && !pState->fFirst)
b2c35a7024c4c308b429c81b203b3bcbd44ee60cvboxsync {
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync RTPrintf("%s: info: --= Rewriting '%s' =--\n", g_szProgName, pState->pszFilename);
b2c35a7024c4c308b429c81b203b3bcbd44ee60cvboxsync pState->fFirst = true;
b2c35a7024c4c308b429c81b203b3bcbd44ee60cvboxsync }
b2c35a7024c4c308b429c81b203b3bcbd44ee60cvboxsync if (pszFormat)
b2c35a7024c4c308b429c81b203b3bcbd44ee60cvboxsync {
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync RTPrintf(pState
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync ? "%s: info: "
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync : "%s: info: ",
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync g_szProgName);
b2c35a7024c4c308b429c81b203b3bcbd44ee60cvboxsync va_list va;
b2c35a7024c4c308b429c81b203b3bcbd44ee60cvboxsync va_start(va, pszFormat);
b2c35a7024c4c308b429c81b203b3bcbd44ee60cvboxsync RTPrintfV(pszFormat, va);
b2c35a7024c4c308b429c81b203b3bcbd44ee60cvboxsync va_end(va);
b2c35a7024c4c308b429c81b203b3bcbd44ee60cvboxsync }
a299266cddc1ae14d76d725a660bb278816bc151vboxsync }
a299266cddc1ae14d76d725a660bb278816bc151vboxsync}
a299266cddc1ae14d76d725a660bb278816bc151vboxsync
a299266cddc1ae14d76d725a660bb278816bc151vboxsync
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync/* -=-=-=-=-=- subversion -=-=-=-=-=- */
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync#define SCM_WITHOUT_LIBSVN
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync#ifdef SCM_WITHOUT_LIBSVN
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync/**
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync * Callback that is call for each path to search.
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync */
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsyncstatic DECLCALLBACK(int) scmSvnFindSvnBinaryCallback(char const *pchPath, size_t cchPath, void *pvUser1, void *pvUser2)
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync{
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync char *pszDst = (char *)pvUser1;
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync size_t cchDst = (size_t)pvUser2;
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync if (cchDst > cchPath)
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync {
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync memcpy(pszDst, pchPath, cchPath);
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync pszDst[cchPath] = '\0';
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync#if defined(RT_OS_WINDOWS) || defined(RT_OS_OS2)
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync int rc = RTPathAppend(pszDst, cchDst, "svn.exe");
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync#else
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync int rc = RTPathAppend(pszDst, cchDst, "svn");
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync#endif
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync if ( RT_SUCCESS(rc)
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync && RTFileExists(pszDst))
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync return VINF_SUCCESS;
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync }
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync return VERR_TRY_AGAIN;
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync}
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync/**
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync * Finds the svn binary.
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync *
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.
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync */
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsyncstatic void scmSvnFindSvnBinary(char *pszPath, size_t cchPath)
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync{
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync /** @todo code page fun... */
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync Assert(cchPath >= sizeof("svn"));
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync#ifdef RT_OS_WINDOWS
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync const char *pszEnvVar = RTEnvGet("Path");
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync#else
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync const char *pszEnvVar = RTEnvGet("PATH");
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync#endif
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync if (pszPath)
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync {
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync#if defined(RT_OS_WINDOWS) || defined(RT_OS_OS2)
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync int rc = RTPathTraverseList(pszEnvVar, ';', scmSvnFindSvnBinaryCallback, pszPath, (void *)cchPath);
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync#else
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync int rc = RTPathTraverseList(pszEnvVar, ':', scmSvnFindSvnBinaryCallback, pszPath, (void *)cchPath);
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync#endif
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync if (RT_SUCCESS(rc))
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync return;
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync }
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync strcpy(pszPath, "svn");
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync}
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync/**
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync * Construct a dot svn filename for the file being rewritten.
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync *
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.
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync */
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsyncstatic int scmSvnConstructName(PSCMRWSTATE pState, const char *pszDir, const char *pszSuff, char *pszDst)
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync{
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync strcpy(pszDst, pState->pszFilename); /* ASSUMES sizeof(szBuf) <= sizeof(szPath) */
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync RTPathStripFilename(pszDst);
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync int rc = RTPathAppend(pszDst, RTPATH_MAX, pszDir);
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync if (RT_SUCCESS(rc))
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync {
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync rc = RTPathAppend(pszDst, RTPATH_MAX, RTPathFilename(pState->pszFilename));
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync if (RT_SUCCESS(rc))
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync {
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync size_t cchDst = strlen(pszDst);
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync size_t cchSuff = strlen(pszSuff);
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync if (cchDst + cchSuff < RTPATH_MAX)
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync {
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync memcpy(&pszDst[cchDst], pszSuff, cchSuff + 1);
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync return VINF_SUCCESS;
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync }
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync else
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync rc = VERR_BUFFER_OVERFLOW;
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync }
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync }
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync return rc;
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync}
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync/**
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync * Interprets the specified string as decimal numbers.
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync *
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.
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync */
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsyncstatic bool scmSvnReadNumber(const char *pch, size_t cch, size_t *pu)
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync{
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync size_t u = 0;
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync while (cch-- > 0)
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync {
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync char ch = *pch++;
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync if (ch < '0' || ch > '9')
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync return false;
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync u *= 10;
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync u += ch - '0';
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync }
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync *pu = u;
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync return true;
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync}
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync#endif /* SCM_WITHOUT_LIBSVN */
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync/**
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync * Checks if the file we're operating on is part of a SVN working copy.
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync *
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync * @returns true if it is, false if it isn't or we cannot tell.
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync * @param pState The rewrite state to work on.
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync */
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsyncstatic bool scmSvnIsInWorkingCopy(PSCMRWSTATE pState)
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync{
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync#ifdef SCM_WITHOUT_LIBSVN
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync /*
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync * Hack: check if the .svn/text-base/<file>.svn-base file exists.
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync */
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync char szPath[RTPATH_MAX];
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync int rc = scmSvnConstructName(pState, ".svn/text-base/", ".svn-base", szPath);
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync if (RT_SUCCESS(rc))
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync return RTFileExists(szPath);
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync#else
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync NOREF(pState);
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync#endif
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync return false;
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync}
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync/**
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync * Queries the value of an SVN property.
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync *
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync * This will automatically adjust for scheduled changes.
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync *
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.
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync */
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsyncstatic int scmSvnQueryProperty(PSCMRWSTATE pState, const char *pszName, char **ppszValue)
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync{
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync /*
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync * Look it up in the scheduled changes.
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync */
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync uint32_t i = pState->cSvnPropChanges;
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync while (i-- > 0)
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync if (!strcmp(pState->paSvnPropChanges[i].pszName, pszName))
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync {
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync const char *pszValue = pState->paSvnPropChanges[i].pszValue;
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync if (!pszValue)
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync return VERR_NOT_FOUND;
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync if (ppszValue)
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync return RTStrDupEx(ppszValue, pszValue);
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync return VINF_SUCCESS;
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync }
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync#ifdef SCM_WITHOUT_LIBSVN
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync /*
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync * Hack: Read the .svn/props/<file>.svn-work file exists.
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync */
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync char szPath[RTPATH_MAX];
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync int rc = scmSvnConstructName(pState, ".svn/props/", ".svn-work", szPath);
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync if (RT_SUCCESS(rc) && !RTFileExists(szPath))
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync rc = scmSvnConstructName(pState, ".svn/prop-base/", ".svn-base", szPath);
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync if (RT_SUCCESS(rc))
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync {
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync SCMSTREAM Stream;
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync rc = ScmStreamInitForReading(&Stream, szPath);
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync if (RT_SUCCESS(rc))
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync {
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync /*
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync * The current format is K len\n<name>\nV len\n<value>\n" ... END.
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync */
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync rc = VERR_NOT_FOUND;
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync size_t const cchName = strlen(pszName);
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync SCMEOL enmEol;
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync size_t cchLine;
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync const char *pchLine;
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync while ((pchLine = ScmStreamGetLine(&Stream, &cchLine, &enmEol)) != NULL)
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync {
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync /*
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync * Parse the 'K num' / 'END' line.
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync */
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync if ( cchLine == 3
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync && !memcmp(pchLine, "END", 3))
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync break;
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync size_t cchKey;
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync if ( cchLine < 3
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync || pchLine[0] != 'K'
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync || pchLine[1] != ' '
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync || !scmSvnReadNumber(&pchLine[2], cchLine - 2, &cchKey)
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync || cchKey == 0
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync || cchKey > 4096)
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync {
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync RTMsgError("%s:%u: Unexpected data '%.*s'\n", szPath, ScmStreamTellLine(&Stream), cchLine, pchLine);
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync rc = VERR_PARSE_ERROR;
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync break;
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync }
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync /*
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync * Match the key and skip to the value line. Don't bother with
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync * names containing EOL markers.
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync */
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync size_t const offKey = ScmStreamTell(&Stream);
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync bool fMatch = cchName == cchKey;
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync if (fMatch)
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync {
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync pchLine = ScmStreamGetLine(&Stream, &cchLine, &enmEol);
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync if (!pchLine)
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync break;
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync fMatch = cchLine == cchName
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync && !memcmp(pchLine, pszName, cchName);
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync }
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync if (RT_FAILURE(ScmStreamSeekAbsolute(&Stream, offKey + cchKey)))
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync break;
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync if (RT_FAILURE(ScmStreamSeekByLine(&Stream, ScmStreamTellLine(&Stream) + 1)))
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync break;
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync /*
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync * Read and Parse the 'V num' line.
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync */
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync pchLine = ScmStreamGetLine(&Stream, &cchLine, &enmEol);
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync if (!pchLine)
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync break;
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync size_t cchValue;
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync if ( cchLine < 3
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync || pchLine[0] != 'V'
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync || pchLine[1] != ' '
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync || !scmSvnReadNumber(&pchLine[2], cchLine - 2, &cchValue)
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync || cchValue > _1M)
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync {
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync RTMsgError("%s:%u: Unexpected data '%.*s'\n", szPath, ScmStreamTellLine(&Stream), cchLine, pchLine);
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync rc = VERR_PARSE_ERROR;
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync break;
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync }
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync /*
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 */
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync if (fMatch)
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync {
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync if (!ppszValue)
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync rc = VINF_SUCCESS;
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync else
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync {
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync char *pszValue;
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync rc = RTStrAllocEx(&pszValue, cchValue + 1);
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync if (RT_SUCCESS(rc))
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync {
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync rc = ScmStreamRead(&Stream, pszValue, cchValue);
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync if (RT_SUCCESS(rc))
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync *ppszValue = pszValue;
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync else
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync RTStrFree(pszValue);
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync }
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync }
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync break;
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync }
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync if (RT_FAILURE(ScmStreamSeekRelative(&Stream, cchValue)))
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync break;
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync if (RT_FAILURE(ScmStreamSeekByLine(&Stream, ScmStreamTellLine(&Stream) + 1)))
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync break;
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync }
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync if (RT_FAILURE(ScmStreamGetStatus(&Stream)))
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync {
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync rc = ScmStreamGetStatus(&Stream);
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync RTMsgError("%s: stream error %Rrc\n", szPath, rc);
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync }
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync ScmStreamDelete(&Stream);
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync }
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync }
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync if (rc == VERR_FILE_NOT_FOUND)
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync rc = VERR_NOT_FOUND;
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync return rc;
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync#else
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync NOREF(pState);
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync#endif
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync return VERR_NOT_FOUND;
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync}
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync/**
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync * Schedules the setting of a property.
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync *
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.
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync */
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsyncstatic int scmSvnSetProperty(PSCMRWSTATE pState, const char *pszName, const char *pszValue)
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync{
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync /*
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync * Update any existing entry first.
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync */
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync size_t i = pState->cSvnPropChanges;
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync while (i-- > 0)
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync if (!strcmp(pState->paSvnPropChanges[i].pszName, pszName))
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync {
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync if (!pszValue)
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync {
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync RTStrFree(pState->paSvnPropChanges[i].pszValue);
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync pState->paSvnPropChanges[i].pszValue = NULL;
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync }
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync else
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync {
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync char *pszCopy;
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync int rc = RTStrDupEx(&pszCopy, pszValue);
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync if (RT_FAILURE(rc))
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync return rc;
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync pState->paSvnPropChanges[i].pszValue = pszCopy;
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync }
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync return VINF_SUCCESS;
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync }
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync /*
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync * Insert a new entry.
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync */
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync i = pState->cSvnPropChanges;
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync if ((i % 32) == 0)
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync {
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync void *pvNew = RTMemRealloc(pState->paSvnPropChanges, (i + 32) * sizeof(SCMSVNPROP));
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync if (!pvNew)
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync return VERR_NO_MEMORY;
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync pState->paSvnPropChanges = (PSCMSVNPROP)pvNew;
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync }
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync pState->paSvnPropChanges[i].pszName = RTStrDup(pszName);
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync pState->paSvnPropChanges[i].pszValue = pszValue ? RTStrDup(pszValue) : NULL;
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync if ( pState->paSvnPropChanges[i].pszName
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync && (pState->paSvnPropChanges[i].pszValue || !pszValue) )
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync pState->cSvnPropChanges = i + 1;
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync else
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync {
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync RTStrFree(pState->paSvnPropChanges[i].pszName);
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync pState->paSvnPropChanges[i].pszName = NULL;
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync RTStrFree(pState->paSvnPropChanges[i].pszValue);
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync pState->paSvnPropChanges[i].pszValue = NULL;
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync return VERR_NO_MEMORY;
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync }
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync return VINF_SUCCESS;
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync}
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync/**
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync * Schedules a property deletion.
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync *
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync * @returns IPRT status code.
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync * @param pState The rewrite state to work on.
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync * @param pszName The name of the property to delete.
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync */
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsyncstatic int scmSvnDelProperty(PSCMRWSTATE pState, const char *pszName)
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync{
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync return scmSvnSetProperty(pState, pszName, NULL);
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync}
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync/**
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync * Applies any SVN property changes to the work copy of the file.
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync *
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync * @returns IPRT status code.
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync * @param pState The rewrite state which SVN property changes
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync * should be applied.
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync */
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsyncstatic int scmSvnDisplayChanges(PSCMRWSTATE pState)
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync{
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync size_t i = pState->cSvnPropChanges;
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync while (i-- > 0)
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync {
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync const char *pszName = pState->paSvnPropChanges[i].pszName;
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync const char *pszValue = pState->paSvnPropChanges[i].pszValue;
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync if (pszValue)
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync ScmVerbose(pState, 0, "svn ps '%s' '%s' %s\n", pszName, pszValue, pState->pszFilename);
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync else
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync ScmVerbose(pState, 0, "svn pd '%s' %s\n", pszName, pszValue, pState->pszFilename);
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync }
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync return VINF_SUCCESS;
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync}
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync/**
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync * Applies any SVN property changes to the work copy of the file.
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync *
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync * @returns IPRT status code.
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync * @param pState The rewrite state which SVN property changes
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync * should be applied.
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync */
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsyncstatic int scmSvnApplyChanges(PSCMRWSTATE pState)
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync{
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync#ifdef SCM_WITHOUT_LIBSVN
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync /*
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync * This sucks. We gotta find svn(.exe).
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync */
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync static char s_szSvnPath[RTPATH_MAX];
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync if (s_szSvnPath[0] == '\0')
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync scmSvnFindSvnBinary(s_szSvnPath, sizeof(s_szSvnPath));
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync /*
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync * Iterate thru the changes and apply them by starting the svn client.
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync */
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync for (size_t i = 0; i <pState->cSvnPropChanges; i++)
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync {
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync const char *apszArgv[6];
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync apszArgv[0] = s_szSvnPath;
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync apszArgv[1] = pState->paSvnPropChanges[i].pszValue ? "ps" : "pd";
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync apszArgv[2] = pState->paSvnPropChanges[i].pszName;
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync int iArg = 3;
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync if (pState->paSvnPropChanges[i].pszValue)
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync apszArgv[iArg++] = pState->paSvnPropChanges[i].pszValue;
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync apszArgv[iArg++] = pState->pszFilename;
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync apszArgv[iArg++] = NULL;
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync ScmVerbose(pState, 2, "executing: %s %s %s %s %s\n",
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync apszArgv[0], apszArgv[1], apszArgv[2], apszArgv[3], apszArgv[4]);
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync RTPROCESS pid;
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync int rc = RTProcCreate(s_szSvnPath, apszArgv, RTENV_DEFAULT, 0 /*fFlags*/, &pid);
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync if (RT_SUCCESS(rc))
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync {
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync RTPROCSTATUS Status;
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync rc = RTProcWait(pid, RTPROCWAIT_FLAGS_BLOCK, &Status);
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync if ( RT_SUCCESS(rc)
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync && ( Status.enmReason != RTPROCEXITREASON_NORMAL
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync || Status.iStatus != 0) )
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync {
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync RTMsgError("%s: %s %s %s %s %s -> %s %u\n",
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 Status.iStatus);
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync return VERR_GENERAL_FAILURE;
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync }
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync }
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync if (RT_FAILURE(rc))
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync {
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);
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync return rc;
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync }
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync }
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync return VINF_SUCCESS;
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync#else
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync return VERR_NOT_IMPLEMENTED;
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync#endif
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync}
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync
a299266cddc1ae14d76d725a660bb278816bc151vboxsync/* -=-=-=-=-=- rewriters -=-=-=-=-=- */
a299266cddc1ae14d76d725a660bb278816bc151vboxsync
a299266cddc1ae14d76d725a660bb278816bc151vboxsync
a299266cddc1ae14d76d725a660bb278816bc151vboxsync/**
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * Strip trailing blanks (space & tab).
a299266cddc1ae14d76d725a660bb278816bc151vboxsync *
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.
a299266cddc1ae14d76d725a660bb278816bc151vboxsync */
b2c35a7024c4c308b429c81b203b3bcbd44ee60cvboxsyncstatic bool rewrite_StripTrailingBlanks(PSCMRWSTATE pState, PSCMSTREAM pIn, PSCMSTREAM pOut, PCSCMSETTINGSBASE pSettings)
a299266cddc1ae14d76d725a660bb278816bc151vboxsync{
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync if (!pSettings->fStripTrailingBlanks)
a299266cddc1ae14d76d725a660bb278816bc151vboxsync return false;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync
a299266cddc1ae14d76d725a660bb278816bc151vboxsync bool fModified = false;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync SCMEOL enmEol;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync size_t cchLine;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync const char *pchLine;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync while ((pchLine = ScmStreamGetLine(pIn, &cchLine, &enmEol)) != NULL)
a299266cddc1ae14d76d725a660bb278816bc151vboxsync {
a299266cddc1ae14d76d725a660bb278816bc151vboxsync int rc;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync if ( cchLine == 0
a299266cddc1ae14d76d725a660bb278816bc151vboxsync || !RT_C_IS_BLANK(pchLine[cchLine - 1]) )
a299266cddc1ae14d76d725a660bb278816bc151vboxsync rc = ScmStreamPutLine(pOut, pchLine, cchLine, enmEol);
a299266cddc1ae14d76d725a660bb278816bc151vboxsync else
a299266cddc1ae14d76d725a660bb278816bc151vboxsync {
a299266cddc1ae14d76d725a660bb278816bc151vboxsync cchLine--;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync while (cchLine > 0 && RT_C_IS_BLANK(pchLine[cchLine - 1]))
a299266cddc1ae14d76d725a660bb278816bc151vboxsync cchLine--;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync rc = ScmStreamPutLine(pOut, pchLine, cchLine, enmEol);
a299266cddc1ae14d76d725a660bb278816bc151vboxsync fModified = true;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync }
a299266cddc1ae14d76d725a660bb278816bc151vboxsync if (RT_FAILURE(rc))
a299266cddc1ae14d76d725a660bb278816bc151vboxsync return false;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync }
a299266cddc1ae14d76d725a660bb278816bc151vboxsync if (fModified)
b2c35a7024c4c308b429c81b203b3bcbd44ee60cvboxsync ScmVerbose(pState, 2, " * Stripped trailing blanks\n");
a299266cddc1ae14d76d725a660bb278816bc151vboxsync return fModified;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync}
a299266cddc1ae14d76d725a660bb278816bc151vboxsync
a299266cddc1ae14d76d725a660bb278816bc151vboxsync/**
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * Expand tabs.
a299266cddc1ae14d76d725a660bb278816bc151vboxsync *
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.
a299266cddc1ae14d76d725a660bb278816bc151vboxsync */
b2c35a7024c4c308b429c81b203b3bcbd44ee60cvboxsyncstatic bool rewrite_ExpandTabs(PSCMRWSTATE pState, PSCMSTREAM pIn, PSCMSTREAM pOut, PCSCMSETTINGSBASE pSettings)
a299266cddc1ae14d76d725a660bb278816bc151vboxsync{
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync if (!pSettings->fConvertTabs)
a299266cddc1ae14d76d725a660bb278816bc151vboxsync return false;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync size_t const cchTab = pSettings->cchTab;
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync bool fModified = false;
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync SCMEOL enmEol;
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync size_t cchLine;
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync const char *pchLine;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync while ((pchLine = ScmStreamGetLine(pIn, &cchLine, &enmEol)) != NULL)
a299266cddc1ae14d76d725a660bb278816bc151vboxsync {
a299266cddc1ae14d76d725a660bb278816bc151vboxsync int rc;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync const char *pchTab = (const char *)memchr(pchLine, '\t', cchLine);
a299266cddc1ae14d76d725a660bb278816bc151vboxsync if (!pchTab)
a299266cddc1ae14d76d725a660bb278816bc151vboxsync rc = ScmStreamPutLine(pOut, pchLine, cchLine, enmEol);
a299266cddc1ae14d76d725a660bb278816bc151vboxsync else
a299266cddc1ae14d76d725a660bb278816bc151vboxsync {
a299266cddc1ae14d76d725a660bb278816bc151vboxsync size_t offTab = 0;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync const char *pchChunk = pchLine;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync for (;;)
a299266cddc1ae14d76d725a660bb278816bc151vboxsync {
a299266cddc1ae14d76d725a660bb278816bc151vboxsync size_t cchChunk = pchTab - pchChunk;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync offTab += cchChunk;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync ScmStreamWrite(pOut, pchChunk, cchChunk);
a299266cddc1ae14d76d725a660bb278816bc151vboxsync
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync size_t cchToTab = cchTab - offTab % cchTab;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync ScmStreamWrite(pOut, g_szTabSpaces, cchToTab);
a299266cddc1ae14d76d725a660bb278816bc151vboxsync offTab += cchToTab;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync
a299266cddc1ae14d76d725a660bb278816bc151vboxsync pchChunk = pchTab + 1;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync size_t cchLeft = cchLine - (pchChunk - pchLine);
a299266cddc1ae14d76d725a660bb278816bc151vboxsync pchTab = (const char *)memchr(pchChunk, '\t', cchLeft);
a299266cddc1ae14d76d725a660bb278816bc151vboxsync if (!pchTab)
a299266cddc1ae14d76d725a660bb278816bc151vboxsync {
a299266cddc1ae14d76d725a660bb278816bc151vboxsync rc = ScmStreamPutLine(pOut, pchChunk, cchLeft, enmEol);
a299266cddc1ae14d76d725a660bb278816bc151vboxsync break;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync }
a299266cddc1ae14d76d725a660bb278816bc151vboxsync }
a299266cddc1ae14d76d725a660bb278816bc151vboxsync
a299266cddc1ae14d76d725a660bb278816bc151vboxsync fModified = true;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync }
a299266cddc1ae14d76d725a660bb278816bc151vboxsync if (RT_FAILURE(rc))
a299266cddc1ae14d76d725a660bb278816bc151vboxsync return false;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync }
a299266cddc1ae14d76d725a660bb278816bc151vboxsync if (fModified)
b2c35a7024c4c308b429c81b203b3bcbd44ee60cvboxsync ScmVerbose(pState, 2, " * Expanded tabs\n");
a299266cddc1ae14d76d725a660bb278816bc151vboxsync return fModified;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync}
a299266cddc1ae14d76d725a660bb278816bc151vboxsync
a299266cddc1ae14d76d725a660bb278816bc151vboxsync/**
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * Worker for rewrite_ForceNativeEol, rewrite_ForceLF and rewrite_ForceCRLF.
a299266cddc1ae14d76d725a660bb278816bc151vboxsync *
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.
a299266cddc1ae14d76d725a660bb278816bc151vboxsync */
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsyncstatic bool rewrite_ForceEol(PSCMRWSTATE pState, PSCMSTREAM pIn, PSCMSTREAM pOut, PCSCMSETTINGSBASE pSettings,
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync SCMEOL enmDesiredEol, const char *pszDesiredSvnEol)
a299266cddc1ae14d76d725a660bb278816bc151vboxsync{
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync if (!pSettings->fConvertEol)
a299266cddc1ae14d76d725a660bb278816bc151vboxsync return false;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync
a299266cddc1ae14d76d725a660bb278816bc151vboxsync bool fModified = false;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync SCMEOL enmEol;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync size_t cchLine;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync const char *pchLine;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync while ((pchLine = ScmStreamGetLine(pIn, &cchLine, &enmEol)) != NULL)
a299266cddc1ae14d76d725a660bb278816bc151vboxsync {
a299266cddc1ae14d76d725a660bb278816bc151vboxsync if ( enmEol != enmDesiredEol
a299266cddc1ae14d76d725a660bb278816bc151vboxsync && enmEol != SCMEOL_NONE)
a299266cddc1ae14d76d725a660bb278816bc151vboxsync {
a299266cddc1ae14d76d725a660bb278816bc151vboxsync fModified = true;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync enmEol = enmDesiredEol;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync }
a299266cddc1ae14d76d725a660bb278816bc151vboxsync int rc = ScmStreamPutLine(pOut, pchLine, cchLine, enmEol);
a299266cddc1ae14d76d725a660bb278816bc151vboxsync if (RT_FAILURE(rc))
a299266cddc1ae14d76d725a660bb278816bc151vboxsync return false;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync }
a299266cddc1ae14d76d725a660bb278816bc151vboxsync if (fModified)
b2c35a7024c4c308b429c81b203b3bcbd44ee60cvboxsync ScmVerbose(pState, 2, " * Converted EOL markers\n");
56689b5c06781615da91826b9f9df665826a0b92vboxsync
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync /* Check svn:eol-style if appropriate */
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync if ( pSettings->fSetSvnEol
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync && scmSvnIsInWorkingCopy(pState))
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync {
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync char *pszEol;
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync int rc = scmSvnQueryProperty(pState, "svn:eol-style", &pszEol);
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync if ( (RT_SUCCESS(rc) && strcmp(pszEol, pszDesiredSvnEol))
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync || rc == VERR_NOT_FOUND)
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync {
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync if (rc == VERR_NOT_FOUND)
4a4d802b46dfabbfd36e88822ff7b17421120469vboxsync ScmVerbose(pState, 2, " * Setting svn:eol-style to %s (missing)\n", pszDesiredSvnEol);
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync else
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 if (RT_FAILURE(rc2))
4a4d802b46dfabbfd36e88822ff7b17421120469vboxsync RTMsgError("scmSvnSetProperty: %Rrc\n", rc2); /** @todo propagate the error somehow... */
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync }
4a4d802b46dfabbfd36e88822ff7b17421120469vboxsync if (RT_SUCCESS(rc))
4a4d802b46dfabbfd36e88822ff7b17421120469vboxsync RTStrFree(pszEol);
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync }
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync
56689b5c06781615da91826b9f9df665826a0b92vboxsync /** @todo also check the subversion svn:eol-style state! */
a299266cddc1ae14d76d725a660bb278816bc151vboxsync return fModified;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync}
a299266cddc1ae14d76d725a660bb278816bc151vboxsync
a299266cddc1ae14d76d725a660bb278816bc151vboxsync/**
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * Force native end of line indicator.
a299266cddc1ae14d76d725a660bb278816bc151vboxsync *
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 */
b2c35a7024c4c308b429c81b203b3bcbd44ee60cvboxsyncstatic bool rewrite_ForceNativeEol(PSCMRWSTATE pState, PSCMSTREAM pIn, PSCMSTREAM pOut, PCSCMSETTINGSBASE pSettings)
a299266cddc1ae14d76d725a660bb278816bc151vboxsync{
a299266cddc1ae14d76d725a660bb278816bc151vboxsync#if defined(RT_OS_WINDOWS) || defined(RT_OS_OS2)
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync return rewrite_ForceEol(pState, pIn, pOut, pSettings, SCMEOL_CRLF, "native");
a299266cddc1ae14d76d725a660bb278816bc151vboxsync#else
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync return rewrite_ForceEol(pState, pIn, pOut, pSettings, SCMEOL_LF, "native");
a299266cddc1ae14d76d725a660bb278816bc151vboxsync#endif
a299266cddc1ae14d76d725a660bb278816bc151vboxsync}
a299266cddc1ae14d76d725a660bb278816bc151vboxsync
a299266cddc1ae14d76d725a660bb278816bc151vboxsync/**
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * Force the stream to use LF as the end of line indicator.
a299266cddc1ae14d76d725a660bb278816bc151vboxsync *
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 */
b2c35a7024c4c308b429c81b203b3bcbd44ee60cvboxsyncstatic bool rewrite_ForceLF(PSCMRWSTATE pState, PSCMSTREAM pIn, PSCMSTREAM pOut, PCSCMSETTINGSBASE pSettings)
a299266cddc1ae14d76d725a660bb278816bc151vboxsync{
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync return rewrite_ForceEol(pState, pIn, pOut, pSettings, SCMEOL_LF, "LF");
a299266cddc1ae14d76d725a660bb278816bc151vboxsync}
a299266cddc1ae14d76d725a660bb278816bc151vboxsync
a299266cddc1ae14d76d725a660bb278816bc151vboxsync/**
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * Force the stream to use CRLF as the end of line indicator.
a299266cddc1ae14d76d725a660bb278816bc151vboxsync *
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 */
b2c35a7024c4c308b429c81b203b3bcbd44ee60cvboxsyncstatic bool rewrite_ForceCRLF(PSCMRWSTATE pState, PSCMSTREAM pIn, PSCMSTREAM pOut, PCSCMSETTINGSBASE pSettings)
a299266cddc1ae14d76d725a660bb278816bc151vboxsync{
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync return rewrite_ForceEol(pState, pIn, pOut, pSettings, SCMEOL_CRLF, "CRLF");
a299266cddc1ae14d76d725a660bb278816bc151vboxsync}
a299266cddc1ae14d76d725a660bb278816bc151vboxsync
a299266cddc1ae14d76d725a660bb278816bc151vboxsync/**
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * Strip trailing blank lines and/or make sure there is exactly one blank line
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * at the end of the file.
a299266cddc1ae14d76d725a660bb278816bc151vboxsync *
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 *
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * @remarks ASSUMES trailing white space has been removed already.
a299266cddc1ae14d76d725a660bb278816bc151vboxsync */
b2c35a7024c4c308b429c81b203b3bcbd44ee60cvboxsyncstatic bool rewrite_AdjustTrailingLines(PSCMRWSTATE pState, PSCMSTREAM pIn, PSCMSTREAM pOut, PCSCMSETTINGSBASE pSettings)
a299266cddc1ae14d76d725a660bb278816bc151vboxsync{
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync if ( !pSettings->fStripTrailingLines
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync && !pSettings->fForceTrailingLine
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync && !pSettings->fForceFinalEol)
a299266cddc1ae14d76d725a660bb278816bc151vboxsync return false;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync
a299266cddc1ae14d76d725a660bb278816bc151vboxsync size_t const cLines = ScmStreamCountLines(pIn);
a299266cddc1ae14d76d725a660bb278816bc151vboxsync
a299266cddc1ae14d76d725a660bb278816bc151vboxsync /* Empty files remains empty. */
a299266cddc1ae14d76d725a660bb278816bc151vboxsync if (cLines <= 1)
a299266cddc1ae14d76d725a660bb278816bc151vboxsync return false;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync
a299266cddc1ae14d76d725a660bb278816bc151vboxsync /* Figure out if we need to adjust the number of lines or not. */
a299266cddc1ae14d76d725a660bb278816bc151vboxsync size_t cLinesNew = cLines;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync if ( pSettings->fStripTrailingLines
a299266cddc1ae14d76d725a660bb278816bc151vboxsync && ScmStreamIsWhiteLine(pIn, cLinesNew - 1))
a299266cddc1ae14d76d725a660bb278816bc151vboxsync {
a299266cddc1ae14d76d725a660bb278816bc151vboxsync while ( cLinesNew > 1
a299266cddc1ae14d76d725a660bb278816bc151vboxsync && ScmStreamIsWhiteLine(pIn, cLinesNew - 2))
a299266cddc1ae14d76d725a660bb278816bc151vboxsync cLinesNew--;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync }
a299266cddc1ae14d76d725a660bb278816bc151vboxsync
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync if ( pSettings->fForceTrailingLine
a299266cddc1ae14d76d725a660bb278816bc151vboxsync && !ScmStreamIsWhiteLine(pIn, cLinesNew - 1))
a299266cddc1ae14d76d725a660bb278816bc151vboxsync cLinesNew++;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync bool fFixMissingEol = pSettings->fForceFinalEol
a299266cddc1ae14d76d725a660bb278816bc151vboxsync && ScmStreamGetEolByLine(pIn, cLinesNew - 1) == SCMEOL_NONE;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync
a299266cddc1ae14d76d725a660bb278816bc151vboxsync if ( !fFixMissingEol
a299266cddc1ae14d76d725a660bb278816bc151vboxsync && cLines == cLinesNew)
a299266cddc1ae14d76d725a660bb278816bc151vboxsync return false;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync
a299266cddc1ae14d76d725a660bb278816bc151vboxsync /* Copy the number of lines we've arrived at. */
a299266cddc1ae14d76d725a660bb278816bc151vboxsync ScmStreamRewindForReading(pIn);
a299266cddc1ae14d76d725a660bb278816bc151vboxsync
a299266cddc1ae14d76d725a660bb278816bc151vboxsync size_t cCopied = RT_MIN(cLinesNew, cLines);
a299266cddc1ae14d76d725a660bb278816bc151vboxsync ScmStreamCopyLines(pOut, pIn, cCopied);
a299266cddc1ae14d76d725a660bb278816bc151vboxsync
a299266cddc1ae14d76d725a660bb278816bc151vboxsync if (cCopied != cLinesNew)
a299266cddc1ae14d76d725a660bb278816bc151vboxsync {
a299266cddc1ae14d76d725a660bb278816bc151vboxsync while (cCopied++ < cLinesNew)
a299266cddc1ae14d76d725a660bb278816bc151vboxsync ScmStreamPutLine(pOut, "", 0, ScmStreamGetEol(pIn));
a299266cddc1ae14d76d725a660bb278816bc151vboxsync }
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync /* Fix missing EOL if required. */
a299266cddc1ae14d76d725a660bb278816bc151vboxsync else if (fFixMissingEol)
a299266cddc1ae14d76d725a660bb278816bc151vboxsync {
a299266cddc1ae14d76d725a660bb278816bc151vboxsync if (ScmStreamGetEol(pIn) == SCMEOL_LF)
a299266cddc1ae14d76d725a660bb278816bc151vboxsync ScmStreamWrite(pOut, "\n", 1);
a299266cddc1ae14d76d725a660bb278816bc151vboxsync else
a299266cddc1ae14d76d725a660bb278816bc151vboxsync ScmStreamWrite(pOut, "\r\n", 2);
a299266cddc1ae14d76d725a660bb278816bc151vboxsync }
a299266cddc1ae14d76d725a660bb278816bc151vboxsync
b2c35a7024c4c308b429c81b203b3bcbd44ee60cvboxsync ScmVerbose(pState, 2, " * Adjusted trailing blank lines\n");
a299266cddc1ae14d76d725a660bb278816bc151vboxsync return true;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync}
a299266cddc1ae14d76d725a660bb278816bc151vboxsync
4a4d802b46dfabbfd36e88822ff7b17421120469vboxsync/**
4a4d802b46dfabbfd36e88822ff7b17421120469vboxsync * Make sure there is no svn:executable keyword on the current file.
4a4d802b46dfabbfd36e88822ff7b17421120469vboxsync *
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.
4a4d802b46dfabbfd36e88822ff7b17421120469vboxsync */
4a4d802b46dfabbfd36e88822ff7b17421120469vboxsyncstatic bool rewrite_SvnNoExecutable(PSCMRWSTATE pState, PSCMSTREAM pIn, PSCMSTREAM pOut, PCSCMSETTINGSBASE pSettings)
4a4d802b46dfabbfd36e88822ff7b17421120469vboxsync{
4a4d802b46dfabbfd36e88822ff7b17421120469vboxsync if ( !pSettings->fSetSvnExecutable
4a4d802b46dfabbfd36e88822ff7b17421120469vboxsync || !scmSvnIsInWorkingCopy(pState))
4a4d802b46dfabbfd36e88822ff7b17421120469vboxsync return false;
4a4d802b46dfabbfd36e88822ff7b17421120469vboxsync
4a4d802b46dfabbfd36e88822ff7b17421120469vboxsync int rc = scmSvnQueryProperty(pState, "svn:executable", NULL);
4a4d802b46dfabbfd36e88822ff7b17421120469vboxsync if (RT_SUCCESS(rc))
4a4d802b46dfabbfd36e88822ff7b17421120469vboxsync {
4a4d802b46dfabbfd36e88822ff7b17421120469vboxsync ScmVerbose(pState, 2, " * removing svn:executable\n");
4a4d802b46dfabbfd36e88822ff7b17421120469vboxsync rc = scmSvnDelProperty(pState, "svn:executable");
4a4d802b46dfabbfd36e88822ff7b17421120469vboxsync if (RT_FAILURE(rc))
4a4d802b46dfabbfd36e88822ff7b17421120469vboxsync RTMsgError("scmSvnSetProperty: %Rrc\n", rc); /** @todo error propagation here.. */
4a4d802b46dfabbfd36e88822ff7b17421120469vboxsync }
4a4d802b46dfabbfd36e88822ff7b17421120469vboxsync return false;
4a4d802b46dfabbfd36e88822ff7b17421120469vboxsync}
4a4d802b46dfabbfd36e88822ff7b17421120469vboxsync
4a4d802b46dfabbfd36e88822ff7b17421120469vboxsync/**
4a4d802b46dfabbfd36e88822ff7b17421120469vboxsync * Make sure the Id and Revision keywords are expanded.
4a4d802b46dfabbfd36e88822ff7b17421120469vboxsync *
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.
4a4d802b46dfabbfd36e88822ff7b17421120469vboxsync */
4a4d802b46dfabbfd36e88822ff7b17421120469vboxsyncstatic bool rewrite_SvnKeywords(PSCMRWSTATE pState, PSCMSTREAM pIn, PSCMSTREAM pOut, PCSCMSETTINGSBASE pSettings)
4a4d802b46dfabbfd36e88822ff7b17421120469vboxsync{
4a4d802b46dfabbfd36e88822ff7b17421120469vboxsync if ( !pSettings->fSetSvnKeywords
4a4d802b46dfabbfd36e88822ff7b17421120469vboxsync || !scmSvnIsInWorkingCopy(pState))
4a4d802b46dfabbfd36e88822ff7b17421120469vboxsync return false;
4a4d802b46dfabbfd36e88822ff7b17421120469vboxsync
4a4d802b46dfabbfd36e88822ff7b17421120469vboxsync char *pszKeywords;
4a4d802b46dfabbfd36e88822ff7b17421120469vboxsync int rc = scmSvnQueryProperty(pState, "svn:keywords", &pszKeywords);
4a4d802b46dfabbfd36e88822ff7b17421120469vboxsync if ( RT_SUCCESS(rc)
4a4d802b46dfabbfd36e88822ff7b17421120469vboxsync && ( !strstr(pszKeywords, "Id") /** @todo need some function for finding a word in a string. */
4a4d802b46dfabbfd36e88822ff7b17421120469vboxsync || !strstr(pszKeywords, "Revision")) )
4a4d802b46dfabbfd36e88822ff7b17421120469vboxsync {
4a4d802b46dfabbfd36e88822ff7b17421120469vboxsync if (!strstr(pszKeywords, "Id") && !strstr(pszKeywords, "Revision"))
4a4d802b46dfabbfd36e88822ff7b17421120469vboxsync rc = RTStrAAppend(&pszKeywords, " Id Revision");
4a4d802b46dfabbfd36e88822ff7b17421120469vboxsync else if (!strstr(pszKeywords, "Id"))
4a4d802b46dfabbfd36e88822ff7b17421120469vboxsync rc = RTStrAAppend(&pszKeywords, " Id");
4a4d802b46dfabbfd36e88822ff7b17421120469vboxsync else
4a4d802b46dfabbfd36e88822ff7b17421120469vboxsync rc = RTStrAAppend(&pszKeywords, " Revision");
4a4d802b46dfabbfd36e88822ff7b17421120469vboxsync if (RT_SUCCESS(rc))
4a4d802b46dfabbfd36e88822ff7b17421120469vboxsync {
4a4d802b46dfabbfd36e88822ff7b17421120469vboxsync ScmVerbose(pState, 2, " * changing svn:keywords to '%s'\n", pszKeywords);
4a4d802b46dfabbfd36e88822ff7b17421120469vboxsync rc = scmSvnSetProperty(pState, "svn:keywords", pszKeywords);
4a4d802b46dfabbfd36e88822ff7b17421120469vboxsync if (RT_FAILURE(rc))
4a4d802b46dfabbfd36e88822ff7b17421120469vboxsync RTMsgError("scmSvnSetProperty: %Rrc\n", rc); /** @todo error propagation here.. */
4a4d802b46dfabbfd36e88822ff7b17421120469vboxsync }
4a4d802b46dfabbfd36e88822ff7b17421120469vboxsync else
4a4d802b46dfabbfd36e88822ff7b17421120469vboxsync RTMsgError("RTStrAppend: %Rrc\n", rc); /** @todo error propagation here.. */
4a4d802b46dfabbfd36e88822ff7b17421120469vboxsync RTStrFree(pszKeywords);
4a4d802b46dfabbfd36e88822ff7b17421120469vboxsync }
4a4d802b46dfabbfd36e88822ff7b17421120469vboxsync else if (rc == VERR_NOT_FOUND)
4a4d802b46dfabbfd36e88822ff7b17421120469vboxsync {
4a4d802b46dfabbfd36e88822ff7b17421120469vboxsync ScmVerbose(pState, 2, " * setting svn:keywords to 'Id Revision'\n");
4a4d802b46dfabbfd36e88822ff7b17421120469vboxsync rc = scmSvnSetProperty(pState, "svn:keywords", "Id Revision");
4a4d802b46dfabbfd36e88822ff7b17421120469vboxsync if (RT_FAILURE(rc))
4a4d802b46dfabbfd36e88822ff7b17421120469vboxsync RTMsgError("scmSvnSetProperty: %Rrc\n", rc); /** @todo error propagation here.. */
4a4d802b46dfabbfd36e88822ff7b17421120469vboxsync }
4a4d802b46dfabbfd36e88822ff7b17421120469vboxsync else if (RT_SUCCESS(rc))
4a4d802b46dfabbfd36e88822ff7b17421120469vboxsync RTStrFree(pszKeywords);
4a4d802b46dfabbfd36e88822ff7b17421120469vboxsync
4a4d802b46dfabbfd36e88822ff7b17421120469vboxsync return false;
4a4d802b46dfabbfd36e88822ff7b17421120469vboxsync}
4a4d802b46dfabbfd36e88822ff7b17421120469vboxsync
a299266cddc1ae14d76d725a660bb278816bc151vboxsync/**
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * Makefile.kup are empty files, enforce this.
a299266cddc1ae14d76d725a660bb278816bc151vboxsync *
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 */
b2c35a7024c4c308b429c81b203b3bcbd44ee60cvboxsyncstatic bool rewrite_Makefile_kup(PSCMRWSTATE pState, PSCMSTREAM pIn, PSCMSTREAM pOut, PCSCMSETTINGSBASE pSettings)
a299266cddc1ae14d76d725a660bb278816bc151vboxsync{
a299266cddc1ae14d76d725a660bb278816bc151vboxsync /* These files should be zero bytes. */
a299266cddc1ae14d76d725a660bb278816bc151vboxsync if (pIn->cb == 0)
a299266cddc1ae14d76d725a660bb278816bc151vboxsync return false;
b2c35a7024c4c308b429c81b203b3bcbd44ee60cvboxsync ScmVerbose(pState, 2, " * Truncated file to zero bytes\n");
a299266cddc1ae14d76d725a660bb278816bc151vboxsync return true;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync}
a299266cddc1ae14d76d725a660bb278816bc151vboxsync
a299266cddc1ae14d76d725a660bb278816bc151vboxsync/**
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * Rewrite a kBuild makefile.
a299266cddc1ae14d76d725a660bb278816bc151vboxsync *
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 *
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * @todo
a299266cddc1ae14d76d725a660bb278816bc151vboxsync *
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * Ideas for Makefile.kmk and Config.kmk:
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * - sort if1of/ifn1of sets.
ad27e1d5e48ca41245120c331cc88b50464813cevboxsync * - line continuation slashes should only be preceded by one space.
a299266cddc1ae14d76d725a660bb278816bc151vboxsync */
b2c35a7024c4c308b429c81b203b3bcbd44ee60cvboxsyncstatic bool rewrite_Makefile_kmk(PSCMRWSTATE pState, PSCMSTREAM pIn, PSCMSTREAM pOut, PCSCMSETTINGSBASE pSettings)
a299266cddc1ae14d76d725a660bb278816bc151vboxsync{
a299266cddc1ae14d76d725a660bb278816bc151vboxsync return false;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync}
a299266cddc1ae14d76d725a660bb278816bc151vboxsync
a299266cddc1ae14d76d725a660bb278816bc151vboxsync/**
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * Rewrite a C/C++ source or header file.
a299266cddc1ae14d76d725a660bb278816bc151vboxsync *
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 *
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * @todo
a299266cddc1ae14d76d725a660bb278816bc151vboxsync *
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.
a299266cddc1ae14d76d725a660bb278816bc151vboxsync */
b2c35a7024c4c308b429c81b203b3bcbd44ee60cvboxsyncstatic bool rewrite_C_and_CPP(PSCMRWSTATE pState, PSCMSTREAM pIn, PSCMSTREAM pOut, PCSCMSETTINGSBASE pSettings)
a299266cddc1ae14d76d725a660bb278816bc151vboxsync{
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync
a299266cddc1ae14d76d725a660bb278816bc151vboxsync return false;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync}
a299266cddc1ae14d76d725a660bb278816bc151vboxsync
a299266cddc1ae14d76d725a660bb278816bc151vboxsync/* -=-=-=-=-=- file and directory processing -=-=-=-=-=- */
a299266cddc1ae14d76d725a660bb278816bc151vboxsync
a299266cddc1ae14d76d725a660bb278816bc151vboxsync/**
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * Processes a file.
a299266cddc1ae14d76d725a660bb278816bc151vboxsync *
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
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * these.
a299266cddc1ae14d76d725a660bb278816bc151vboxsync */
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsyncstatic int scmProcessFileInner(PSCMRWSTATE pState, const char *pszFilename, const char *pszBasename, size_t cchBasename,
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync PSCMSETTINGSBASE pBaseSettings)
a299266cddc1ae14d76d725a660bb278816bc151vboxsync{
a299266cddc1ae14d76d725a660bb278816bc151vboxsync /*
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * Do the file level filtering.
a299266cddc1ae14d76d725a660bb278816bc151vboxsync */
e45e3ae4a834169539e689759ba6b3ac71bfe40fvboxsync if ( pBaseSettings->pszFilterFiles
e45e3ae4a834169539e689759ba6b3ac71bfe40fvboxsync && *pBaseSettings->pszFilterFiles
e45e3ae4a834169539e689759ba6b3ac71bfe40fvboxsync && !RTStrSimplePatternMultiMatch(pBaseSettings->pszFilterFiles, RTSTR_MAX, pszBasename, cchBasename, NULL))
a299266cddc1ae14d76d725a660bb278816bc151vboxsync {
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync ScmVerbose(NULL, 5, "skipping '%s': file filter mismatch\n", pszFilename);
a299266cddc1ae14d76d725a660bb278816bc151vboxsync return VINF_SUCCESS;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync }
e45e3ae4a834169539e689759ba6b3ac71bfe40fvboxsync if ( pBaseSettings->pszFilterOutFiles
e45e3ae4a834169539e689759ba6b3ac71bfe40fvboxsync && *pBaseSettings->pszFilterOutFiles
e45e3ae4a834169539e689759ba6b3ac71bfe40fvboxsync && ( RTStrSimplePatternMultiMatch(pBaseSettings->pszFilterOutFiles, RTSTR_MAX, pszBasename, cchBasename, NULL)
e45e3ae4a834169539e689759ba6b3ac71bfe40fvboxsync || RTStrSimplePatternMultiMatch(pBaseSettings->pszFilterOutFiles, RTSTR_MAX, pszFilename, RTSTR_MAX, NULL)) )
a299266cddc1ae14d76d725a660bb278816bc151vboxsync {
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync ScmVerbose(NULL, 5, "skipping '%s': filterd out\n", pszFilename);
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync return VINF_SUCCESS;
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync }
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync if ( pBaseSettings->fOnlySvnFiles
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync && !scmSvnIsInWorkingCopy(pState))
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync {
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync ScmVerbose(NULL, 5, "skipping '%s': not in SVN WC\n", pszFilename);
a299266cddc1ae14d76d725a660bb278816bc151vboxsync return VINF_SUCCESS;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync }
a299266cddc1ae14d76d725a660bb278816bc151vboxsync
a299266cddc1ae14d76d725a660bb278816bc151vboxsync /*
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * Try find a matching rewrite config for this filename.
a299266cddc1ae14d76d725a660bb278816bc151vboxsync */
a299266cddc1ae14d76d725a660bb278816bc151vboxsync PCSCMCFGENTRY pCfg = NULL;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync for (size_t iCfg = 0; iCfg < RT_ELEMENTS(g_aConfigs); iCfg++)
a299266cddc1ae14d76d725a660bb278816bc151vboxsync if (RTStrSimplePatternMultiMatch(g_aConfigs[iCfg].pszFilePattern, RTSTR_MAX, pszBasename, cchBasename, NULL))
a299266cddc1ae14d76d725a660bb278816bc151vboxsync {
a299266cddc1ae14d76d725a660bb278816bc151vboxsync pCfg = &g_aConfigs[iCfg];
a299266cddc1ae14d76d725a660bb278816bc151vboxsync break;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync }
a299266cddc1ae14d76d725a660bb278816bc151vboxsync if (!pCfg)
a299266cddc1ae14d76d725a660bb278816bc151vboxsync {
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync ScmVerbose(NULL, 4, "skipping '%s': no rewriters configured\n", pszFilename);
a299266cddc1ae14d76d725a660bb278816bc151vboxsync return VINF_SUCCESS;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync }
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync ScmVerbose(pState, 4, "matched \"%s\"\n", pCfg->pszFilePattern);
a299266cddc1ae14d76d725a660bb278816bc151vboxsync
a299266cddc1ae14d76d725a660bb278816bc151vboxsync /*
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * Create an input stream from the file and check that it's text.
a299266cddc1ae14d76d725a660bb278816bc151vboxsync */
a299266cddc1ae14d76d725a660bb278816bc151vboxsync SCMSTREAM Stream1;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync int rc = ScmStreamInitForReading(&Stream1, pszFilename);
a299266cddc1ae14d76d725a660bb278816bc151vboxsync if (RT_FAILURE(rc))
a299266cddc1ae14d76d725a660bb278816bc151vboxsync {
a299266cddc1ae14d76d725a660bb278816bc151vboxsync RTMsgError("Failed to read '%s': %Rrc\n", pszFilename, rc);
a299266cddc1ae14d76d725a660bb278816bc151vboxsync return rc;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync }
a299266cddc1ae14d76d725a660bb278816bc151vboxsync if (ScmStreamIsText(&Stream1))
a299266cddc1ae14d76d725a660bb278816bc151vboxsync {
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync ScmVerbose(pState, 3, NULL);
a299266cddc1ae14d76d725a660bb278816bc151vboxsync
a299266cddc1ae14d76d725a660bb278816bc151vboxsync /*
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * Gather SCM and editor settings from the stream.
a299266cddc1ae14d76d725a660bb278816bc151vboxsync */
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync rc = scmSettingsBaseLoadFromDocument(pBaseSettings, &Stream1);
a299266cddc1ae14d76d725a660bb278816bc151vboxsync if (RT_SUCCESS(rc))
a299266cddc1ae14d76d725a660bb278816bc151vboxsync {
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync ScmStreamRewindForReading(&Stream1);
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync /*
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 */
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync SCMSTREAM Stream2;
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync rc = ScmStreamInitForWriting(&Stream2, &Stream1);
a299266cddc1ae14d76d725a660bb278816bc151vboxsync if (RT_SUCCESS(rc))
a299266cddc1ae14d76d725a660bb278816bc151vboxsync {
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync SCMSTREAM Stream3;
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync rc = ScmStreamInitForWriting(&Stream3, &Stream1);
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync if (RT_SUCCESS(rc))
a299266cddc1ae14d76d725a660bb278816bc151vboxsync {
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync bool fModified = false;
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync PSCMSTREAM pIn = &Stream1;
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync PSCMSTREAM pOut = &Stream2;
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync for (size_t iRw = 0; iRw < pCfg->cRewriters; iRw++)
a299266cddc1ae14d76d725a660bb278816bc151vboxsync {
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync bool fRc = pCfg->papfnRewriter[iRw](pState, pIn, pOut, pBaseSettings);
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync if (fRc)
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync {
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync PSCMSTREAM pTmp = pOut;
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync pOut = pIn == &Stream1 ? &Stream3 : pIn;
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync pIn = pTmp;
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync fModified = true;
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync }
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync ScmStreamRewindForReading(pIn);
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync ScmStreamRewindForWriting(pOut);
a299266cddc1ae14d76d725a660bb278816bc151vboxsync }
a299266cddc1ae14d76d725a660bb278816bc151vboxsync
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync rc = ScmStreamGetStatus(&Stream1);
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync if (RT_SUCCESS(rc))
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync rc = ScmStreamGetStatus(&Stream2);
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync if (RT_SUCCESS(rc))
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync rc = ScmStreamGetStatus(&Stream3);
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync if (RT_SUCCESS(rc))
a299266cddc1ae14d76d725a660bb278816bc151vboxsync {
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync /*
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync * If rewritten, write it back to disk.
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync */
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync if (fModified)
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync {
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync if (!g_fDryRun)
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync {
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync ScmVerbose(pState, 1, "writing modified file to \"%s%s\"\n", pszFilename, g_pszChangedSuff);
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync rc = ScmStreamWriteToFile(pIn, "%s%s", pszFilename, g_pszChangedSuff);
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync if (RT_FAILURE(rc))
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync RTMsgError("Error writing '%s%s': %Rrc\n", pszFilename, g_pszChangedSuff, rc);
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync }
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync else
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync {
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync ScmVerbose(pState, 1, NULL);
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 }
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync }
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync /*
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync * If pending SVN property changes, apply them.
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync */
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync if (pState->cSvnPropChanges && RT_SUCCESS(rc))
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync {
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync if (!g_fDryRun)
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync {
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync rc = scmSvnApplyChanges(pState);
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync if (RT_FAILURE(rc))
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync RTMsgError("%s: failed to apply SVN property changes (%Rrc)\n", pszFilename, rc);
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync }
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync else
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync scmSvnDisplayChanges(pState);
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync }
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync
b8795afd31d95dd5bf668aa9034df0c985080bc0vboxsync if (!fModified && !pState->cSvnPropChanges)
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync ScmVerbose(pState, 3, "no change\n", pszFilename);
a299266cddc1ae14d76d725a660bb278816bc151vboxsync }
a299266cddc1ae14d76d725a660bb278816bc151vboxsync else
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync RTMsgError("%s: stream error %Rrc\n", pszFilename);
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync ScmStreamDelete(&Stream3);
a299266cddc1ae14d76d725a660bb278816bc151vboxsync }
a299266cddc1ae14d76d725a660bb278816bc151vboxsync else
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync RTMsgError("Failed to init stream for writing: %Rrc\n", rc);
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync ScmStreamDelete(&Stream2);
a299266cddc1ae14d76d725a660bb278816bc151vboxsync }
a299266cddc1ae14d76d725a660bb278816bc151vboxsync else
a299266cddc1ae14d76d725a660bb278816bc151vboxsync RTMsgError("Failed to init stream for writing: %Rrc\n", rc);
a299266cddc1ae14d76d725a660bb278816bc151vboxsync }
a299266cddc1ae14d76d725a660bb278816bc151vboxsync else
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync RTMsgError("scmSettingsBaseLoadFromDocument: %Rrc\n", rc);
a299266cddc1ae14d76d725a660bb278816bc151vboxsync }
a299266cddc1ae14d76d725a660bb278816bc151vboxsync else
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync ScmVerbose(pState, 4, "not text file: \"%s\"\n", pszFilename);
a299266cddc1ae14d76d725a660bb278816bc151vboxsync ScmStreamDelete(&Stream1);
a299266cddc1ae14d76d725a660bb278816bc151vboxsync
a299266cddc1ae14d76d725a660bb278816bc151vboxsync return rc;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync}
a299266cddc1ae14d76d725a660bb278816bc151vboxsync
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync/**
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * Processes a file.
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync *
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * This is just a wrapper for scmProcessFileInner for avoid wasting stack in the
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * directory recursion method.
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync *
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).
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync */
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsyncstatic int scmProcessFile(const char *pszFilename, const char *pszBasename, size_t cchBasename,
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync PSCMSETTINGS pSettingsStack)
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync{
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync SCMSETTINGSBASE Base;
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync int rc = scmSettingsStackMakeFileBase(pSettingsStack, pszFilename, pszBasename, cchBasename, &Base);
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync if (RT_SUCCESS(rc))
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync {
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync SCMRWSTATE State;
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync State.fFirst = false;
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync State.pszFilename = pszFilename;
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync State.cSvnPropChanges = 0;
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync State.paSvnPropChanges = NULL;
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync rc = scmProcessFileInner(&State, pszFilename, pszBasename, cchBasename, &Base);
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync size_t i = State.cSvnPropChanges;
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync while (i-- > 0)
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync {
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync RTStrFree(State.paSvnPropChanges[i].pszName);
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync RTStrFree(State.paSvnPropChanges[i].pszValue);
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync }
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync RTMemFree(State.paSvnPropChanges);
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync scmSettingsBaseDelete(&Base);
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync }
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync return rc;
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync}
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync
a299266cddc1ae14d76d725a660bb278816bc151vboxsync/**
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * Tries to correct RTDIRENTRY_UNKNOWN.
a299266cddc1ae14d76d725a660bb278816bc151vboxsync *
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * @returns Corrected type.
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * @param pszPath The path to the object in question.
a299266cddc1ae14d76d725a660bb278816bc151vboxsync */
a299266cddc1ae14d76d725a660bb278816bc151vboxsyncstatic RTDIRENTRYTYPE scmFigureUnknownType(const char *pszPath)
a299266cddc1ae14d76d725a660bb278816bc151vboxsync{
a299266cddc1ae14d76d725a660bb278816bc151vboxsync RTFSOBJINFO Info;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync int rc = RTPathQueryInfo(pszPath, &Info, RTFSOBJATTRADD_NOTHING);
a299266cddc1ae14d76d725a660bb278816bc151vboxsync if (RT_FAILURE(rc))
a299266cddc1ae14d76d725a660bb278816bc151vboxsync return RTDIRENTRYTYPE_UNKNOWN;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync if (RTFS_IS_DIRECTORY(Info.Attr.fMode))
a299266cddc1ae14d76d725a660bb278816bc151vboxsync return RTDIRENTRYTYPE_DIRECTORY;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync if (RTFS_IS_FILE(Info.Attr.fMode))
a299266cddc1ae14d76d725a660bb278816bc151vboxsync return RTDIRENTRYTYPE_FILE;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync return RTDIRENTRYTYPE_UNKNOWN;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync}
a299266cddc1ae14d76d725a660bb278816bc151vboxsync
a299266cddc1ae14d76d725a660bb278816bc151vboxsync/**
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * Recurse into a sub-directory and process all the files and directories.
a299266cddc1ae14d76d725a660bb278816bc151vboxsync *
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.
a299266cddc1ae14d76d725a660bb278816bc151vboxsync */
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsyncstatic int scmProcessDirTreeRecursion(char *pszBuf, size_t cchDir, PRTDIRENTRY pEntry,
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync PSCMSETTINGS pSettingsStack, unsigned iRecursion)
a299266cddc1ae14d76d725a660bb278816bc151vboxsync{
4bcaf5d320bf0d88910212509c37bdd634e0879evboxsync int rc;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync Assert(cchDir > 1 && pszBuf[cchDir - 1] == '.');
a299266cddc1ae14d76d725a660bb278816bc151vboxsync
a299266cddc1ae14d76d725a660bb278816bc151vboxsync /*
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * Make sure we stop somewhere.
a299266cddc1ae14d76d725a660bb278816bc151vboxsync */
a299266cddc1ae14d76d725a660bb278816bc151vboxsync if (iRecursion > 128)
a299266cddc1ae14d76d725a660bb278816bc151vboxsync {
a299266cddc1ae14d76d725a660bb278816bc151vboxsync RTMsgError("recursion too deep: %d\n", iRecursion);
a299266cddc1ae14d76d725a660bb278816bc151vboxsync return VINF_SUCCESS; /* ignore */
a299266cddc1ae14d76d725a660bb278816bc151vboxsync }
a299266cddc1ae14d76d725a660bb278816bc151vboxsync
4bcaf5d320bf0d88910212509c37bdd634e0879evboxsync /*
4bcaf5d320bf0d88910212509c37bdd634e0879evboxsync * Check if it's excluded by --only-svn-dir.
4bcaf5d320bf0d88910212509c37bdd634e0879evboxsync */
4bcaf5d320bf0d88910212509c37bdd634e0879evboxsync if (pSettingsStack->Base.fOnlySvnDirs)
4bcaf5d320bf0d88910212509c37bdd634e0879evboxsync {
4bcaf5d320bf0d88910212509c37bdd634e0879evboxsync rc = RTPathAppend(pszBuf, RTPATH_MAX, ".svn");
4bcaf5d320bf0d88910212509c37bdd634e0879evboxsync if (RT_FAILURE(rc))
4bcaf5d320bf0d88910212509c37bdd634e0879evboxsync {
4bcaf5d320bf0d88910212509c37bdd634e0879evboxsync RTMsgError("RTPathAppend: %Rrc\n", rc);
4bcaf5d320bf0d88910212509c37bdd634e0879evboxsync return rc;
4bcaf5d320bf0d88910212509c37bdd634e0879evboxsync }
4bcaf5d320bf0d88910212509c37bdd634e0879evboxsync if (!RTDirExists(pszBuf))
4bcaf5d320bf0d88910212509c37bdd634e0879evboxsync return VINF_SUCCESS;
4bcaf5d320bf0d88910212509c37bdd634e0879evboxsync
4bcaf5d320bf0d88910212509c37bdd634e0879evboxsync Assert(RTPATH_IS_SLASH(pszBuf[cchDir]));
4bcaf5d320bf0d88910212509c37bdd634e0879evboxsync pszBuf[cchDir] = '\0';
4bcaf5d320bf0d88910212509c37bdd634e0879evboxsync pszBuf[cchDir - 1] = '.';
4bcaf5d320bf0d88910212509c37bdd634e0879evboxsync }
4bcaf5d320bf0d88910212509c37bdd634e0879evboxsync
a299266cddc1ae14d76d725a660bb278816bc151vboxsync /*
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * Try open and read the directory.
a299266cddc1ae14d76d725a660bb278816bc151vboxsync */
a299266cddc1ae14d76d725a660bb278816bc151vboxsync PRTDIR pDir;
939e2ecb812c6402abcc63e7d615c5444acfd02evboxsync rc = RTDirOpenFiltered(&pDir, pszBuf, RTDIRFILTER_NONE, 0);
a299266cddc1ae14d76d725a660bb278816bc151vboxsync if (RT_FAILURE(rc))
a299266cddc1ae14d76d725a660bb278816bc151vboxsync {
a299266cddc1ae14d76d725a660bb278816bc151vboxsync RTMsgError("Failed to enumerate directory '%s': %Rrc", pszBuf, rc);
a299266cddc1ae14d76d725a660bb278816bc151vboxsync return rc;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync }
a299266cddc1ae14d76d725a660bb278816bc151vboxsync for (;;)
a299266cddc1ae14d76d725a660bb278816bc151vboxsync {
a299266cddc1ae14d76d725a660bb278816bc151vboxsync /* Read the next entry. */
a299266cddc1ae14d76d725a660bb278816bc151vboxsync rc = RTDirRead(pDir, pEntry, NULL);
a299266cddc1ae14d76d725a660bb278816bc151vboxsync if (RT_FAILURE(rc))
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync {
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync if (rc == VERR_NO_MORE_FILES)
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync rc = VINF_SUCCESS;
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync else
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync RTMsgError("RTDirRead -> %Rrc\n", rc);
a299266cddc1ae14d76d725a660bb278816bc151vboxsync break;
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync }
a299266cddc1ae14d76d725a660bb278816bc151vboxsync
a299266cddc1ae14d76d725a660bb278816bc151vboxsync /* Skip '.' and '..'. */
a299266cddc1ae14d76d725a660bb278816bc151vboxsync if ( pEntry->szName[0] == '.'
a299266cddc1ae14d76d725a660bb278816bc151vboxsync && ( pEntry->cbName == 1
a299266cddc1ae14d76d725a660bb278816bc151vboxsync || ( pEntry->cbName == 2
a299266cddc1ae14d76d725a660bb278816bc151vboxsync && pEntry->szName[1] == '.')))
a299266cddc1ae14d76d725a660bb278816bc151vboxsync continue;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync
a299266cddc1ae14d76d725a660bb278816bc151vboxsync /* Enter it into the buffer so we've got a full name to work
a299266cddc1ae14d76d725a660bb278816bc151vboxsync with when needed. */
a299266cddc1ae14d76d725a660bb278816bc151vboxsync if (pEntry->cbName + cchDir >= RTPATH_MAX)
a299266cddc1ae14d76d725a660bb278816bc151vboxsync {
a299266cddc1ae14d76d725a660bb278816bc151vboxsync RTMsgError("Skipping too long entry: %s", pEntry->szName);
a299266cddc1ae14d76d725a660bb278816bc151vboxsync continue;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync }
a299266cddc1ae14d76d725a660bb278816bc151vboxsync memcpy(&pszBuf[cchDir - 1], pEntry->szName, pEntry->cbName + 1);
a299266cddc1ae14d76d725a660bb278816bc151vboxsync
a299266cddc1ae14d76d725a660bb278816bc151vboxsync /* Figure the type. */
a299266cddc1ae14d76d725a660bb278816bc151vboxsync RTDIRENTRYTYPE enmType = pEntry->enmType;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync if (enmType == RTDIRENTRYTYPE_UNKNOWN)
a299266cddc1ae14d76d725a660bb278816bc151vboxsync enmType = scmFigureUnknownType(pszBuf);
a299266cddc1ae14d76d725a660bb278816bc151vboxsync
a299266cddc1ae14d76d725a660bb278816bc151vboxsync /* Process the file or directory, skip the rest. */
a299266cddc1ae14d76d725a660bb278816bc151vboxsync if (enmType == RTDIRENTRYTYPE_FILE)
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync rc = scmProcessFile(pszBuf, pEntry->szName, pEntry->cbName, pSettingsStack);
a299266cddc1ae14d76d725a660bb278816bc151vboxsync else if (enmType == RTDIRENTRYTYPE_DIRECTORY)
a299266cddc1ae14d76d725a660bb278816bc151vboxsync {
a299266cddc1ae14d76d725a660bb278816bc151vboxsync /* Append the dot for the benefit of the pattern matching. */
a299266cddc1ae14d76d725a660bb278816bc151vboxsync if (pEntry->cbName + cchDir + 5 >= RTPATH_MAX)
a299266cddc1ae14d76d725a660bb278816bc151vboxsync {
a299266cddc1ae14d76d725a660bb278816bc151vboxsync RTMsgError("Skipping too deep dir entry: %s", pEntry->szName);
a299266cddc1ae14d76d725a660bb278816bc151vboxsync continue;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync }
a299266cddc1ae14d76d725a660bb278816bc151vboxsync memcpy(&pszBuf[cchDir - 1 + pEntry->cbName], "/.", sizeof("/."));
a299266cddc1ae14d76d725a660bb278816bc151vboxsync size_t cchSubDir = cchDir - 1 + pEntry->cbName + sizeof("/.") - 1;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync
e45e3ae4a834169539e689759ba6b3ac71bfe40fvboxsync if ( !pSettingsStack->Base.pszFilterOutDirs
e45e3ae4a834169539e689759ba6b3ac71bfe40fvboxsync || !*pSettingsStack->Base.pszFilterOutDirs
e45e3ae4a834169539e689759ba6b3ac71bfe40fvboxsync || ( !RTStrSimplePatternMultiMatch(pSettingsStack->Base.pszFilterOutDirs, RTSTR_MAX,
e45e3ae4a834169539e689759ba6b3ac71bfe40fvboxsync pEntry->szName, pEntry->cbName, NULL)
e45e3ae4a834169539e689759ba6b3ac71bfe40fvboxsync && !RTStrSimplePatternMultiMatch(pSettingsStack->Base.pszFilterOutDirs, RTSTR_MAX,
e45e3ae4a834169539e689759ba6b3ac71bfe40fvboxsync pszBuf, cchSubDir, NULL)
e45e3ae4a834169539e689759ba6b3ac71bfe40fvboxsync )
a299266cddc1ae14d76d725a660bb278816bc151vboxsync )
a299266cddc1ae14d76d725a660bb278816bc151vboxsync {
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync rc = scmSettingsStackPushDir(&pSettingsStack, pszBuf);
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync if (RT_SUCCESS(rc))
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync {
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync rc = scmProcessDirTreeRecursion(pszBuf, cchSubDir, pEntry, pSettingsStack, iRecursion + 1);
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync scmSettingsStackPopAndDestroy(&pSettingsStack);
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync }
a299266cddc1ae14d76d725a660bb278816bc151vboxsync }
a299266cddc1ae14d76d725a660bb278816bc151vboxsync }
a299266cddc1ae14d76d725a660bb278816bc151vboxsync if (RT_FAILURE(rc))
a299266cddc1ae14d76d725a660bb278816bc151vboxsync break;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync }
a299266cddc1ae14d76d725a660bb278816bc151vboxsync RTDirClose(pDir);
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync return rc;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync
a299266cddc1ae14d76d725a660bb278816bc151vboxsync}
a299266cddc1ae14d76d725a660bb278816bc151vboxsync
a299266cddc1ae14d76d725a660bb278816bc151vboxsync/**
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * Process a directory tree.
a299266cddc1ae14d76d725a660bb278816bc151vboxsync *
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * @returns IPRT status code.
da0b2d0ebcbeb635e76686254cc10c70faa37ee6vboxsync * @param pszDir The directory to start with. This is pointer to
da0b2d0ebcbeb635e76686254cc10c70faa37ee6vboxsync * a RTPATH_MAX sized buffer.
a299266cddc1ae14d76d725a660bb278816bc151vboxsync */
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsyncstatic int scmProcessDirTree(char *pszDir, PSCMSETTINGS pSettingsStack)
a299266cddc1ae14d76d725a660bb278816bc151vboxsync{
a299266cddc1ae14d76d725a660bb278816bc151vboxsync /*
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * Setup the recursion.
a299266cddc1ae14d76d725a660bb278816bc151vboxsync */
da0b2d0ebcbeb635e76686254cc10c70faa37ee6vboxsync int rc = RTPathAppend(pszDir, RTPATH_MAX, ".");
a299266cddc1ae14d76d725a660bb278816bc151vboxsync if (RT_SUCCESS(rc))
a299266cddc1ae14d76d725a660bb278816bc151vboxsync {
da0b2d0ebcbeb635e76686254cc10c70faa37ee6vboxsync RTDIRENTRY Entry;
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync rc = scmProcessDirTreeRecursion(pszDir, strlen(pszDir), &Entry, pSettingsStack, 0);
a299266cddc1ae14d76d725a660bb278816bc151vboxsync }
da0b2d0ebcbeb635e76686254cc10c70faa37ee6vboxsync else
da0b2d0ebcbeb635e76686254cc10c70faa37ee6vboxsync RTMsgError("RTPathAppend: %Rrc\n", rc);
da0b2d0ebcbeb635e76686254cc10c70faa37ee6vboxsync return rc;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync}
a299266cddc1ae14d76d725a660bb278816bc151vboxsync
a299266cddc1ae14d76d725a660bb278816bc151vboxsync
a299266cddc1ae14d76d725a660bb278816bc151vboxsync/**
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * Processes a file or directory specified as an command line argument.
a299266cddc1ae14d76d725a660bb278816bc151vboxsync *
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).
a299266cddc1ae14d76d725a660bb278816bc151vboxsync */
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsyncstatic int scmProcessSomething(const char *pszSomething, PSCMSETTINGS pSettingsStack)
a299266cddc1ae14d76d725a660bb278816bc151vboxsync{
da0b2d0ebcbeb635e76686254cc10c70faa37ee6vboxsync char szBuf[RTPATH_MAX];
da0b2d0ebcbeb635e76686254cc10c70faa37ee6vboxsync int rc = RTPathAbs(pszSomething, szBuf, sizeof(szBuf));
da0b2d0ebcbeb635e76686254cc10c70faa37ee6vboxsync if (RT_SUCCESS(rc))
a299266cddc1ae14d76d725a660bb278816bc151vboxsync {
56689b5c06781615da91826b9f9df665826a0b92vboxsync RTPathChangeToUnixSlashes(szBuf, false /*fForce*/);
56689b5c06781615da91826b9f9df665826a0b92vboxsync
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync PSCMSETTINGS pSettings;
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync rc = scmSettingsCreateForPath(&pSettings, &pSettingsStack->Base, szBuf);
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync if (RT_SUCCESS(rc))
da0b2d0ebcbeb635e76686254cc10c70faa37ee6vboxsync {
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync scmSettingsStackPush(&pSettingsStack, pSettings);
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync if (RTFileExists(szBuf))
da0b2d0ebcbeb635e76686254cc10c70faa37ee6vboxsync {
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync const char *pszBasename = RTPathFilename(szBuf);
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync if (pszBasename)
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync {
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync size_t cchBasename = strlen(pszBasename);
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync rc = scmProcessFile(szBuf, pszBasename, cchBasename, pSettingsStack);
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync }
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync else
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync {
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync RTMsgError("RTPathFilename: NULL\n");
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync rc = VERR_IS_A_DIRECTORY;
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync }
da0b2d0ebcbeb635e76686254cc10c70faa37ee6vboxsync }
da0b2d0ebcbeb635e76686254cc10c70faa37ee6vboxsync else
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync rc = scmProcessDirTree(szBuf, pSettingsStack);
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync PSCMSETTINGS pPopped = scmSettingsStackPop(&pSettingsStack);
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync Assert(pPopped == pSettings);
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync scmSettingsDestroy(pSettings);
da0b2d0ebcbeb635e76686254cc10c70faa37ee6vboxsync }
da0b2d0ebcbeb635e76686254cc10c70faa37ee6vboxsync else
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync RTMsgError("scmSettingsInitStack: %Rrc\n", rc);
a299266cddc1ae14d76d725a660bb278816bc151vboxsync }
da0b2d0ebcbeb635e76686254cc10c70faa37ee6vboxsync else
da0b2d0ebcbeb635e76686254cc10c70faa37ee6vboxsync RTMsgError("RTPathAbs: %Rrc\n", rc);
da0b2d0ebcbeb635e76686254cc10c70faa37ee6vboxsync return rc;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync}
a299266cddc1ae14d76d725a660bb278816bc151vboxsync
a299266cddc1ae14d76d725a660bb278816bc151vboxsyncint main(int argc, char **argv)
a299266cddc1ae14d76d725a660bb278816bc151vboxsync{
230bd8589bba39933ac5ec21482d6186d675e604vboxsync int rc = RTR3InitExe(argc, &argv, 0);
a299266cddc1ae14d76d725a660bb278816bc151vboxsync if (RT_FAILURE(rc))
a299266cddc1ae14d76d725a660bb278816bc151vboxsync return 1;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync /*
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync * Init the settings.
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync */
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync PSCMSETTINGS pSettings;
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync rc = scmSettingsCreate(&pSettings, &g_Defaults);
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync if (RT_FAILURE(rc))
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync {
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync RTMsgError("scmSettingsCreate: %Rrc\n", rc);
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync return 1;
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync }
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync
a299266cddc1ae14d76d725a660bb278816bc151vboxsync /*
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * Parse arguments and process input in order (because this is the only
a299266cddc1ae14d76d725a660bb278816bc151vboxsync * thing that works at the moment).
a299266cddc1ae14d76d725a660bb278816bc151vboxsync */
b2c35a7024c4c308b429c81b203b3bcbd44ee60cvboxsync static RTGETOPTDEF s_aOpts[14 + RT_ELEMENTS(g_aScmOpts)] =
a299266cddc1ae14d76d725a660bb278816bc151vboxsync {
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync { "--dry-run", 'd', RTGETOPT_REQ_NOTHING },
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync { "--real-run", 'D', RTGETOPT_REQ_NOTHING },
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync { "--file-filter", 'f', RTGETOPT_REQ_STRING },
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync { "--quiet", 'q', RTGETOPT_REQ_NOTHING },
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync { "--verbose", 'v', RTGETOPT_REQ_NOTHING },
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 },
a299266cddc1ae14d76d725a660bb278816bc151vboxsync };
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync memcpy(&s_aOpts[RT_ELEMENTS(s_aOpts) - RT_ELEMENTS(g_aScmOpts)], &g_aScmOpts[0], sizeof(g_aScmOpts));
a299266cddc1ae14d76d725a660bb278816bc151vboxsync
a299266cddc1ae14d76d725a660bb278816bc151vboxsync RTGETOPTUNION ValueUnion;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync RTGETOPTSTATE GetOptState;
b2c35a7024c4c308b429c81b203b3bcbd44ee60cvboxsync rc = RTGetOptInit(&GetOptState, argc, argv, &s_aOpts[0], RT_ELEMENTS(s_aOpts), 1, RTGETOPTINIT_FLAGS_OPTS_FIRST);
a299266cddc1ae14d76d725a660bb278816bc151vboxsync AssertReleaseRCReturn(rc, 1);
a299266cddc1ae14d76d725a660bb278816bc151vboxsync size_t cProcessed = 0;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync
a299266cddc1ae14d76d725a660bb278816bc151vboxsync while ((rc = RTGetOpt(&GetOptState, &ValueUnion)) != 0)
a299266cddc1ae14d76d725a660bb278816bc151vboxsync {
a299266cddc1ae14d76d725a660bb278816bc151vboxsync switch (rc)
a299266cddc1ae14d76d725a660bb278816bc151vboxsync {
a299266cddc1ae14d76d725a660bb278816bc151vboxsync case 'd':
a299266cddc1ae14d76d725a660bb278816bc151vboxsync g_fDryRun = true;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync break;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync case 'D':
a299266cddc1ae14d76d725a660bb278816bc151vboxsync g_fDryRun = false;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync break;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync
a299266cddc1ae14d76d725a660bb278816bc151vboxsync case 'f':
a299266cddc1ae14d76d725a660bb278816bc151vboxsync g_pszFileFilter = ValueUnion.psz;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync break;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync
a299266cddc1ae14d76d725a660bb278816bc151vboxsync case 'h':
4bcaf5d320bf0d88910212509c37bdd634e0879evboxsync RTPrintf("VirtualBox Source Code Massager\n"
a299266cddc1ae14d76d725a660bb278816bc151vboxsync "\n"
a299266cddc1ae14d76d725a660bb278816bc151vboxsync "Usage: %s [options] <files & dirs>\n"
a299266cddc1ae14d76d725a660bb278816bc151vboxsync "\n"
a299266cddc1ae14d76d725a660bb278816bc151vboxsync "Options:\n", g_szProgName);
a299266cddc1ae14d76d725a660bb278816bc151vboxsync for (size_t i = 0; i < RT_ELEMENTS(s_aOpts); i++)
b2c35a7024c4c308b429c81b203b3bcbd44ee60cvboxsync {
b2c35a7024c4c308b429c81b203b3bcbd44ee60cvboxsync bool fAdvanceTwo = false;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync if ((s_aOpts[i].fFlags & RTGETOPT_REQ_MASK) == RTGETOPT_REQ_NOTHING)
b2c35a7024c4c308b429c81b203b3bcbd44ee60cvboxsync {
4bcaf5d320bf0d88910212509c37bdd634e0879evboxsync fAdvanceTwo = i + 1 < RT_ELEMENTS(s_aOpts)
4bcaf5d320bf0d88910212509c37bdd634e0879evboxsync && ( strstr(s_aOpts[i+1].pszLong, "-no-") != NULL
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync || strstr(s_aOpts[i+1].pszLong, "-not-") != NULL
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync || strstr(s_aOpts[i+1].pszLong, "-dont-") != NULL
cec3b04587a02f0dc7d0cc679e9a0de19b730e2cvboxsync );
4bcaf5d320bf0d88910212509c37bdd634e0879evboxsync if (fAdvanceTwo)
b2c35a7024c4c308b429c81b203b3bcbd44ee60cvboxsync RTPrintf(" %s, %s\n", s_aOpts[i].pszLong, s_aOpts[i + 1].pszLong);
b2c35a7024c4c308b429c81b203b3bcbd44ee60cvboxsync else
b2c35a7024c4c308b429c81b203b3bcbd44ee60cvboxsync RTPrintf(" %s\n", s_aOpts[i].pszLong);
b2c35a7024c4c308b429c81b203b3bcbd44ee60cvboxsync }
a299266cddc1ae14d76d725a660bb278816bc151vboxsync else if ((s_aOpts[i].fFlags & RTGETOPT_REQ_MASK) == RTGETOPT_REQ_STRING)
a299266cddc1ae14d76d725a660bb278816bc151vboxsync RTPrintf(" %s string\n", s_aOpts[i].pszLong);
a299266cddc1ae14d76d725a660bb278816bc151vboxsync else
a299266cddc1ae14d76d725a660bb278816bc151vboxsync RTPrintf(" %s value\n", s_aOpts[i].pszLong);
b2c35a7024c4c308b429c81b203b3bcbd44ee60cvboxsync switch (s_aOpts[i].iShort)
b2c35a7024c4c308b429c81b203b3bcbd44ee60cvboxsync {
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;
b2c35a7024c4c308b429c81b203b3bcbd44ee60cvboxsync }
b2c35a7024c4c308b429c81b203b3bcbd44ee60cvboxsync i += fAdvanceTwo;
b2c35a7024c4c308b429c81b203b3bcbd44ee60cvboxsync }
a299266cddc1ae14d76d725a660bb278816bc151vboxsync return 1;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync
a299266cddc1ae14d76d725a660bb278816bc151vboxsync case 'q':
a299266cddc1ae14d76d725a660bb278816bc151vboxsync g_iVerbosity = 0;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync break;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync
a299266cddc1ae14d76d725a660bb278816bc151vboxsync case 'v':
a299266cddc1ae14d76d725a660bb278816bc151vboxsync g_iVerbosity++;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync break;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync case 'V':
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync {
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync /* The following is assuming that svn does it's job here. */
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync static const char s_szRev[] = "$Revision$";
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync const char *psz = RTStrStripL(strchr(s_szRev, ' '));
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync RTPrintf("r%.*s\n", strchr(psz, ' ') - psz, psz);
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync return 0;
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync }
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync
a299266cddc1ae14d76d725a660bb278816bc151vboxsync case SCMOPT_DIFF_IGNORE_EOL:
a299266cddc1ae14d76d725a660bb278816bc151vboxsync g_fDiffIgnoreEol = true;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync break;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync case SCMOPT_DIFF_NO_IGNORE_EOL:
a299266cddc1ae14d76d725a660bb278816bc151vboxsync g_fDiffIgnoreEol = false;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync break;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync
a299266cddc1ae14d76d725a660bb278816bc151vboxsync case SCMOPT_DIFF_IGNORE_SPACE:
a299266cddc1ae14d76d725a660bb278816bc151vboxsync g_fDiffIgnoreTrailingWS = g_fDiffIgnoreLeadingWS = true;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync break;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync case SCMOPT_DIFF_NO_IGNORE_SPACE:
a299266cddc1ae14d76d725a660bb278816bc151vboxsync g_fDiffIgnoreTrailingWS = g_fDiffIgnoreLeadingWS = false;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync break;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync
a299266cddc1ae14d76d725a660bb278816bc151vboxsync case SCMOPT_DIFF_IGNORE_LEADING_SPACE:
a299266cddc1ae14d76d725a660bb278816bc151vboxsync g_fDiffIgnoreLeadingWS = true;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync break;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync case SCMOPT_DIFF_NO_IGNORE_LEADING_SPACE:
a299266cddc1ae14d76d725a660bb278816bc151vboxsync g_fDiffIgnoreLeadingWS = false;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync break;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync
a299266cddc1ae14d76d725a660bb278816bc151vboxsync case SCMOPT_DIFF_IGNORE_TRAILING_SPACE:
a299266cddc1ae14d76d725a660bb278816bc151vboxsync g_fDiffIgnoreTrailingWS = true;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync break;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync case SCMOPT_DIFF_NO_IGNORE_TRAILING_SPACE:
a299266cddc1ae14d76d725a660bb278816bc151vboxsync g_fDiffIgnoreTrailingWS = false;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync break;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync
a299266cddc1ae14d76d725a660bb278816bc151vboxsync case SCMOPT_DIFF_SPECIAL_CHARS:
a299266cddc1ae14d76d725a660bb278816bc151vboxsync g_fDiffSpecialChars = true;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync break;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync case SCMOPT_DIFF_NO_SPECIAL_CHARS:
a299266cddc1ae14d76d725a660bb278816bc151vboxsync g_fDiffSpecialChars = false;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync break;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync
a299266cddc1ae14d76d725a660bb278816bc151vboxsync case VINF_GETOPT_NOT_OPTION:
a299266cddc1ae14d76d725a660bb278816bc151vboxsync {
a299266cddc1ae14d76d725a660bb278816bc151vboxsync if (!g_fDryRun)
a299266cddc1ae14d76d725a660bb278816bc151vboxsync {
a299266cddc1ae14d76d725a660bb278816bc151vboxsync if (!cProcessed)
a299266cddc1ae14d76d725a660bb278816bc151vboxsync {
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:\n"
a299266cddc1ae14d76d725a660bb278816bc151vboxsync "%s: Press any key to continue...\n",
a299266cddc1ae14d76d725a660bb278816bc151vboxsync g_szProgName, g_szProgName, g_szProgName, g_szProgName, g_szProgName,
a299266cddc1ae14d76d725a660bb278816bc151vboxsync g_szProgName, g_szProgName);
a299266cddc1ae14d76d725a660bb278816bc151vboxsync RTStrmGetCh(g_pStdIn);
a299266cddc1ae14d76d725a660bb278816bc151vboxsync }
a299266cddc1ae14d76d725a660bb278816bc151vboxsync cProcessed++;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync }
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync rc = scmProcessSomething(ValueUnion.psz, pSettings);
a299266cddc1ae14d76d725a660bb278816bc151vboxsync if (RT_FAILURE(rc))
a299266cddc1ae14d76d725a660bb278816bc151vboxsync return rc;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync break;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync }
a299266cddc1ae14d76d725a660bb278816bc151vboxsync
a299266cddc1ae14d76d725a660bb278816bc151vboxsync default:
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync {
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync int rc2 = scmSettingsBaseHandleOpt(&pSettings->Base, rc, &ValueUnion);
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync if (RT_SUCCESS(rc2))
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync break;
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync if (rc2 != VERR_GETOPT_UNKNOWN_OPTION)
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync return 2;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync return RTGetOptPrintError(rc, &ValueUnion);
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync }
a299266cddc1ae14d76d725a660bb278816bc151vboxsync }
a299266cddc1ae14d76d725a660bb278816bc151vboxsync }
a299266cddc1ae14d76d725a660bb278816bc151vboxsync
6578276195b5b6a53ef2fc44f96a3348c516d3f5vboxsync scmSettingsDestroy(pSettings);
a299266cddc1ae14d76d725a660bb278816bc151vboxsync return 0;
a299266cddc1ae14d76d725a660bb278816bc151vboxsync}
a299266cddc1ae14d76d725a660bb278816bc151vboxsync