summaryrefslogtreecommitdiff
path: root/registry/tools
diff options
context:
space:
mode:
authorJan Holesovsky <kendy@suse.cz>2011-03-23 16:59:59 +0100
committerJan Holesovsky <kendy@suse.cz>2011-03-23 16:59:59 +0100
commit4be7cca60bc7cc0a066b7384d56624266dc0dfcf (patch)
tree990b1fda00fca6f26ff74fd29552687b4e3c37ed /registry/tools
parent79a6c0f8a28b43c36c3b02dc5e116f2d17e92ef0 (diff)
parenta24842b43a687808376f69d4bdbb45fcddde73c4 (diff)
Merge commit 'ooo/DEV300_m103'
Conflicts: codemaker/source/bonobowrappermaker/corbaoptions.cxx codemaker/source/cppumaker/cppuoptions.cxx codemaker/source/cunomaker/cunooptions.cxx codemaker/source/idlmaker/idloptions.cxx codemaker/source/javamaker/javaoptions.cxx cppu/source/typelib/typelib.cxx idlc/source/options.cxx offapi/com/sun/star/util/PathSubstitution.idl offapi/drafts/com/sun/star/form/ListEntryEvent.idl offapi/drafts/com/sun/star/form/XBindableValue.idl offapi/drafts/com/sun/star/form/XListEntryListener.idl offapi/drafts/com/sun/star/form/XListEntrySink.idl offapi/drafts/com/sun/star/form/XListEntrySource.idl offapi/drafts/com/sun/star/form/XValueBinding.idl registry/tools/checksingleton.cxx registry/tools/options.hxx registry/tools/regcompare.cxx registry/tools/regmerge.cxx sal/cppunittester/cppunittester.cxx sal/osl/unx/socket.c sal/osl/w32/diagnose.c sal/prj/d.lst sal/rtl/source/alloc_fini.cxx sal/rtl/source/alloc_global.c sal/rtl/source/makefile.mk
Diffstat (limited to 'registry/tools')
-rw-r--r--registry/tools/checksingleton.cxx460
-rw-r--r--registry/tools/fileurl.cxx90
-rw-r--r--registry/tools/fileurl.hxx43
-rw-r--r--registry/tools/makefile.mk18
-rw-r--r--registry/tools/options.cxx153
-rw-r--r--registry/tools/options.hxx67
-rw-r--r--registry/tools/rdbedit.cxx318
-rw-r--r--registry/tools/regcompare.cxx1556
-rw-r--r--registry/tools/regmerge.cxx278
-rw-r--r--registry/tools/regview.cxx72
10 files changed, 1570 insertions, 1485 deletions
diff --git a/registry/tools/checksingleton.cxx b/registry/tools/checksingleton.cxx
index 8f470bee4da8..502be9638c44 100644
--- a/registry/tools/checksingleton.cxx
+++ b/registry/tools/checksingleton.cxx
@@ -29,297 +29,150 @@
// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_registry.hxx"
-#include <stdio.h>
-#include <string.h>
-
#include "registry/registry.hxx"
#include "registry/reflread.hxx"
-#include <rtl/ustring.hxx>
-#include <rtl/alloc.h>
-#include <osl/process.h>
-#include <osl/diagnose.h>
-#include <osl/thread.h>
-#include <osl/file.hxx>
-
-#ifdef SAL_UNX
-#define SEPARATOR '/'
-#else
-#define SEPARATOR '\\'
-#endif
+#include "fileurl.hxx"
+#include "options.hxx"
-using namespace ::rtl;
-using namespace ::osl;
+#include "rtl/ustring.hxx"
+#include "osl/diagnose.h"
-sal_Bool isFileUrl(const OString& fileName)
-{
- if (fileName.indexOf("file://") == 0 )
- return sal_True;
- return sal_False;
-}
-
-OUString convertToFileUrl(const OString& fileName)
-{
- if ( isFileUrl(fileName) )
- {
- return OStringToOUString(fileName, osl_getThreadTextEncoding());
- }
+#include <stdio.h>
+#include <string.h>
- OUString uUrlFileName;
- OUString uFileName(fileName.getStr(), fileName.getLength(), osl_getThreadTextEncoding());
- if ( fileName.indexOf('.') == 0 || fileName.indexOf(SEPARATOR) < 0 )
- {
- OUString uWorkingDir;
- if (osl_getProcessWorkingDir(&uWorkingDir.pData) != osl_Process_E_None)
- {
- OSL_ASSERT(false);
- }
- if (FileBase::getAbsoluteFileURL(uWorkingDir, uFileName, uUrlFileName)
- != FileBase::E_None)
- {
- OSL_ASSERT(false);
- }
- } else
- {
- if (FileBase::getFileURLFromSystemPath(uFileName, uUrlFileName)
- != FileBase::E_None)
- {
- OSL_ASSERT(false);
- }
- }
+#include <vector>
+#include <string>
- return uUrlFileName;
-}
+using namespace rtl;
+using namespace registry::tools;
#define U2S( s ) \
OUStringToOString(s, RTL_TEXTENCODING_UTF8).getStr()
#define S2U( s ) \
OStringToOUString(s, RTL_TEXTENCODING_UTF8)
-struct LessString
-{
- sal_Bool operator()(const OUString& str1, const OUString& str2) const
- {
- return (str1 < str2);
- }
-};
-
-class Options
+class Options_Impl : public Options
{
public:
- Options()
- : m_bForceOutput(sal_False)
- {}
- ~Options()
+ explicit Options_Impl(char const * program)
+ : Options (program), m_bForceOutput(false)
{}
- sal_Bool initOptions(int ac, char* av[], sal_Bool bCmdFile=sal_False);
-
- OString prepareHelp();
- OString prepareVersion();
-
- const OString& getProgramName()
- { return m_program; }
- const OString& getIndexReg()
+ std::string const & getIndexReg() const
{ return m_indexRegName; }
- const OString& getTypeReg()
+ std::string const & getTypeReg() const
{ return m_typeRegName; }
- sal_Bool hasBase()
- { return m_base.getLength() > 0; }
- const OString& getBase()
+ bool hasBase() const
+ { return (m_base.getLength() > 0); }
+ const OString & getBase() const
{ return m_base; }
- sal_Bool forceOutput()
+ bool forceOutput() const
{ return m_bForceOutput; }
+
protected:
- OString m_program;
- OString m_indexRegName;
- OString m_typeRegName;
+ virtual void printUsage_Impl() const;
+ virtual bool initOptions_Impl (std::vector< std::string > & rArgs);
+
+ std::string m_indexRegName;
+ std::string m_typeRegName;
OString m_base;
- sal_Bool m_bForceOutput;
+ bool m_bForceOutput;
};
-sal_Bool Options::initOptions(int ac, char* av[], sal_Bool bCmdFile)
+// virtual
+void Options_Impl::printUsage_Impl() const
{
- sal_Bool bRet = sal_True;
- sal_uInt16 i=0;
+ std::string const & rProgName = getProgramName();
+ fprintf(stderr,
+ "Usage: %s -r<filename> -o<filename> [-options] | @<filename>\n", rProgName.c_str()
+ );
+ fprintf(stderr,
+ " -o<filename> = filename specifies the name of the new singleton index registry.\n"
+ " -r<filename> = filename specifies the name of the type registry.\n"
+ " @<filename> = filename specifies a command file.\n"
+ "Options:\n"
+ " -b<name> = name specifies the name of a start key. The types will be searched\n"
+ " under this key in the type registry.\n"
+ " -f = force the output of all found singletons.\n"
+ " -h|-? = print this help message and exit.\n"
+ );
+ fprintf(stderr,
+ "\n%s Version 1.0\n\n", rProgName.c_str()
+ );
+}
- if (!bCmdFile)
+// virtual
+bool Options_Impl::initOptions_Impl(std::vector< std::string > & rArgs)
+{
+ std::vector< std::string >::const_iterator first = rArgs.begin(), last = rArgs.end();
+ for (; first != last; ++first)
{
- bCmdFile = sal_True;
-
- m_program = av[0];
-
- if (ac < 2)
+ std::string option (*first);
+ if ((*first)[0] != '-')
{
- fprintf(stderr, "%s", prepareHelp().getStr());
- bRet = sal_False;
+ return badOption("invalid", option.c_str());
}
-
- i = 1;
- } else
- {
- i = 0;
- }
-
- char *s=NULL;
- for (; i < ac; i++)
- {
- if (av[i][0] == '-')
+ switch ((*first)[1])
{
- switch (av[i][1])
+ case 'r':
+ case 'R':
{
- case 'r':
- case 'R':
- if (av[i][2] == '\0')
- {
- if (i < ac - 1 && av[i+1][0] != '-')
- {
- i++;
- s = av[i];
- } else
- {
- fprintf(stderr, "%s: invalid option '%s'\n", m_program.getStr(), av[i]);
- bRet = sal_False;
- break;
- }
- } else
- {
- s = av[i] + 2;
- }
- m_typeRegName = OString(s);
- break;
- case 'o':
- case 'O':
- if (av[i][2] == '\0')
- {
- if (i < ac - 1 && av[i+1][0] != '-')
- {
- i++;
- s = av[i];
- } else
- {
- fprintf(stderr, "%s: invalid option '%s'\n", m_program.getStr(), av[i]);
- bRet = sal_False;
- break;
- }
- } else
- {
- s = av[i] + 2;
- }
- m_indexRegName = OString(s);
- break;
- case 'b':
- case 'B':
- if (av[i][2] == '\0')
- {
- if (i < ac - 1 && av[i+1][0] != '-')
- {
- i++;
- s = av[i];
- } else
- {
- fprintf(stderr, "%s: invalid option '%s'\n", m_program.getStr(), av[i]);
- bRet = sal_False;
- break;
- }
- } else
- {
- s = av[i] + 2;
- }
- m_base = OString(s);
- break;
- case 'f':
- case 'F':
- if (av[i][2] != '\0')
- {
- fprintf(stderr, "%s: invalid option '%s'\n", m_program.getStr(), av[i]);
- bRet = sal_False;
- }
- m_bForceOutput = sal_True;
- break;
- case 'h':
- case '?':
- if (av[i][2] != '\0')
- {
- fprintf(stderr, "%s: invalid option '%s'\n", m_program.getStr(), av[i]);
- bRet = sal_False;
- } else
- {
- fprintf(stdout, "%s", prepareHelp().getStr());
- exit(0);
- }
- break;
- default:
- fprintf(stderr, "%s: unknown option '%s'\n", m_program.getStr(), av[i]);
- bRet = sal_False;
- break;
+ if (!((++first != last) && ((*first)[0] != '-')))
+ {
+ return badOption("invalid", option.c_str());
+ }
+ m_typeRegName = OString((*first).c_str(), (*first).size());
+ break;
}
- } else
- {
- if (av[i][0] == '@')
+ case 'o':
+ case 'O':
{
- FILE* cmdFile = fopen(av[i]+1, "r");
- if( cmdFile == NULL )
- {
- fprintf(stderr, "%s", prepareHelp().getStr());
- bRet = sal_False;
- } else
+ if (!((++first != last) && ((*first)[0] != '-')))
{
- int rargc=0;
- char* rargv[512];
- char buffer[512];
-
- while ( fscanf(cmdFile, "%s", buffer) != EOF )
- {
- rargv[rargc]= strdup(buffer);
- rargc++;
- }
- fclose(cmdFile);
-
- bRet = initOptions(rargc, rargv, bCmdFile);
-
- for (long j=0; j < rargc; j++)
- {
- free(rargv[j]);
- }
+ return badOption("invalid", option.c_str());
+ }
+ m_indexRegName = (*first);
+ break;
+ }
+ case 'b':
+ case 'B':
+ {
+ if (!((++first != last) && ((*first)[0] != '-')))
+ {
+ return badOption("invalid", option.c_str());
+ }
+ m_base = OString((*first).c_str(), (*first).size());
+ break;
+ }
+ case 'f':
+ case 'F':
+ {
+ if ((*first).size() > 2)
+ {
+ return badOption("invalid", option.c_str());
}
- } else
+ m_bForceOutput = sal_True;
+ break;
+ }
+ case 'h':
+ case '?':
{
- fprintf(stderr, "%s: unknown option '%s'\n", m_program.getStr(), av[i]);
- bRet = sal_False;
+ if ((*first).size() > 2)
+ {
+ return badOption("invalid", option.c_str());
+ }
+ return printUsage();
+ // break; // unreachable
}
+ default:
+ return badOption("unknown", option.c_str());
+ // break; // unreachable
}
}
-
- return bRet;
-}
-
-OString Options::prepareHelp()
-{
- OString help("\nusing: ");
- help += m_program + " -r<filename> -o<filename> [-options] | @<filename>\n";
- help += " -o<filename> = filename specifies the name of the new singleton index registry.\n";
- help += " -r<filename> = filename specifies the name of the type registry.\n";
- help += " @<filename> = filename specifies a command file.\n";
- help += "Options:\n";
- help += " -b<name> = name specifies the name of a start key. The types will be searched\n";
- help += " under this key in the type registry.\n";
- help += " -f = force the output of all found singletons.\n";
- help += " -h|-? = print this help message and exit.\n";
- help += prepareVersion();
-
- return help;
+ return true;
}
-OString Options::prepareVersion()
-{
- OString version("\nSun Microsystems (R) ");
- version += m_program + " Version 1.0\n\n";
- return version;
-}
-
-static Options options;
-
-static sal_Bool checkSingletons(RegistryKey& singletonKey, RegistryKey& typeKey)
+static sal_Bool checkSingletons(Options_Impl const & options, RegistryKey& singletonKey, RegistryKey& typeKey)
{
RegValueType valueType = RG_VALUETYPE_NOT_DEFINED;
sal_uInt32 size = 0;
@@ -327,24 +180,22 @@ static sal_Bool checkSingletons(RegistryKey& singletonKey, RegistryKey& typeKey)
sal_Bool bRet = sal_False;
RegError e = typeKey.getValueInfo(tmpName, &valueType, &size);
-
- if ( e != REG_VALUE_NOT_EXISTS && e != REG_INVALID_VALUE && valueType == RG_VALUETYPE_BINARY)
+ if ((e != REG_VALUE_NOT_EXISTS) && (e != REG_INVALID_VALUE) && (valueType == RG_VALUETYPE_BINARY))
{
- RegistryKey entryKey;
- RegValue value = rtl_allocateMemory(size);
-
- typeKey.getValue(tmpName, value);
-
- RegistryTypeReader reader((sal_uInt8*)value, size, sal_False);
+ std::vector< sal_uInt8 > value(size);
+ typeKey.getValue(tmpName, &value[0]); // @@@ broken api: write to buffer w/o buffer size.
+ RegistryTypeReader reader(&value[0], value.size(), sal_False);
if ( reader.isValid() && reader.getTypeClass() == RT_TYPE_SINGLETON )
{
- OUString singletonName = reader.getTypeName().replace('/', '.');
+ RegistryKey entryKey;
+ OUString singletonName = reader.getTypeName().replace('/', '.');
if ( singletonKey.createKey(singletonName, entryKey) )
{
fprintf(stderr, "%s: could not create SINGLETONS entry for \"%s\"\n",
- options.getProgramName().getStr(), U2S( singletonName ));
- } else
+ options.getProgramName().c_str(), U2S( singletonName ));
+ }
+ else
{
bRet = sal_True;
OUString value2 = reader.getSuperTypeName();
@@ -353,30 +204,26 @@ static sal_Bool checkSingletons(RegistryKey& singletonKey, RegistryKey& typeKey)
(RegValue)value2.getStr(), sizeof(sal_Unicode)* (value2.getLength()+1)) )
{
fprintf(stderr, "%s: could not create data entry for singleton \"%s\"\n",
- options.getProgramName().getStr(), U2S( singletonName ));
+ options.getProgramName().c_str(), U2S( singletonName ));
}
if ( options.forceOutput() )
{
fprintf(stderr, "%s: create SINGLETON entry for \"%s\" -> \"%s\"\n",
- options.getProgramName().getStr(), U2S( singletonName ), U2S(value2));
+ options.getProgramName().c_str(), U2S( singletonName ), U2S(value2));
}
}
}
-
- rtl_freeMemory(value);
}
RegistryKeyArray subKeys;
-
typeKey.openSubKeys(tmpName, subKeys);
sal_uInt32 length = subKeys.getLength();
- RegistryKey elementKey;
for (sal_uInt32 i = 0; i < length; i++)
{
- elementKey = subKeys.getElement(i);
- if ( checkSingletons(singletonKey, elementKey) )
+ RegistryKey elementKey = subKeys.getElement(i);
+ if ( checkSingletons(options, singletonKey, elementKey) )
{
bRet = sal_True;
}
@@ -390,69 +237,85 @@ int main( int argc, char * argv[] )
int _cdecl main( int argc, char * argv[] )
#endif
{
- if ( !options.initOptions(argc, argv) )
+ std::vector< std::string > args;
+ for (int i = 1; i < argc; i++)
{
- exit(1);
+ int result = Options::checkArgument(args, argv[i], strlen(argv[i]));
+ if (result != 0)
+ {
+ // failure.
+ return (result);
+ }
}
- OUString indexRegName( convertToFileUrl(options.getIndexReg()) );
- OUString typeRegName( convertToFileUrl(options.getTypeReg()) );
+ Options_Impl options(argv[0]);
+ if (!options.initOptions(args))
+ {
+ options.printUsage();
+ return (1);
+ }
+ OUString indexRegName( convertToFileUrl(options.getIndexReg().c_str(), options.getIndexReg().size()) );
Registry indexReg;
- Registry typeReg;
-
if ( indexReg.open(indexRegName, REG_READWRITE) )
{
if ( indexReg.create(indexRegName) )
{
fprintf(stderr, "%s: open registry \"%s\" failed\n",
- options.getProgramName().getStr(), options.getIndexReg().getStr());
- exit(2);
+ options.getProgramName().c_str(), options.getIndexReg().c_str());
+ return (2);
}
}
+
+ OUString typeRegName( convertToFileUrl(options.getTypeReg().c_str(), options.getTypeReg().size()) );
+ Registry typeReg;
if ( typeReg.open(typeRegName, REG_READONLY) )
{
fprintf(stderr, "%s: open registry \"%s\" failed\n",
- options.getProgramName().getStr(), options.getTypeReg().getStr());
- exit(3);
+ options.getProgramName().c_str(), options.getTypeReg().c_str());
+ return (3);
}
- RegistryKey indexRoot, typeRoot;
+ RegistryKey indexRoot;
if ( indexReg.openRootKey(indexRoot) )
{
fprintf(stderr, "%s: open root key of registry \"%s\" failed\n",
- options.getProgramName().getStr(), options.getIndexReg().getStr());
- exit(4);
+ options.getProgramName().c_str(), options.getIndexReg().c_str());
+ return (4);
}
+
+ RegistryKey typeRoot;
if ( typeReg.openRootKey(typeRoot) )
{
fprintf(stderr, "%s: open root key of registry \"%s\" failed\n",
- options.getProgramName().getStr(), options.getTypeReg().getStr());
- exit(5);
+ options.getProgramName().c_str(), options.getTypeReg().c_str());
+ return (5);
}
- RegistryKey singletonKey, typeKey;
+ RegistryKey typeKey;
if ( options.hasBase() )
{
if ( typeRoot.openKey(S2U(options.getBase()), typeKey) )
{
fprintf(stderr, "%s: open base key of registry \"%s\" failed\n",
- options.getProgramName().getStr(), options.getTypeReg().getStr());
- exit(6);
+ options.getProgramName().c_str(), options.getTypeReg().c_str());
+ return (6);
}
- } else
+ }
+ else
{
typeKey = typeRoot;
}
+ RegistryKey singletonKey;
if ( indexRoot.createKey(OUString(RTL_CONSTASCII_USTRINGPARAM("SINGLETONS")), singletonKey) )
{
fprintf(stderr, "%s: open/create SINGLETONS key of registry \"%s\" failed\n",
- options.getProgramName().getStr(), options.getIndexReg().getStr());
- exit(7);
+ options.getProgramName().c_str(), options.getIndexReg().c_str());
+ return (7);
}
- sal_Bool bSingletonsExist = checkSingletons(singletonKey, typeKey);
+ sal_Bool bSingletonsExist = checkSingletons(options, singletonKey, typeKey);
indexRoot.releaseKey();
typeRoot.releaseKey();
@@ -461,25 +324,24 @@ int _cdecl main( int argc, char * argv[] )
if ( indexReg.close() )
{
fprintf(stderr, "%s: closing registry \"%s\" failed\n",
- options.getProgramName().getStr(), options.getIndexReg().getStr());
- exit(9);
+ options.getProgramName().c_str(), options.getIndexReg().c_str());
+ return (9);
}
if ( !bSingletonsExist )
{
if ( indexReg.destroy(OUString()) )
{
fprintf(stderr, "%s: destroy registry \"%s\" failed\n",
- options.getProgramName().getStr(), options.getIndexReg().getStr());
- exit(10);
+ options.getProgramName().c_str(), options.getIndexReg().c_str());
+ return (10);
}
}
if ( typeReg.close() )
{
fprintf(stderr, "%s: closing registry \"%s\" failed\n",
- options.getProgramName().getStr(), options.getTypeReg().getStr());
- exit(11);
+ options.getProgramName().c_str(), options.getTypeReg().c_str());
+ return (11);
}
}
-
-/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ \ No newline at end of file
diff --git a/registry/tools/fileurl.cxx b/registry/tools/fileurl.cxx
new file mode 100644
index 000000000000..e3561888c674
--- /dev/null
+++ b/registry/tools/fileurl.cxx
@@ -0,0 +1,90 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+#include "fileurl.hxx"
+
+#include "rtl/ustring.hxx"
+#include "osl/diagnose.h"
+#include "osl/file.hxx"
+#include "osl/process.h"
+#include "osl/thread.h"
+
+#include <string.h>
+
+#ifdef SAL_UNX
+#define SEPARATOR '/'
+#else
+#define SEPARATOR '\\'
+#endif
+
+using rtl::OUString;
+using osl::FileBase;
+
+namespace registry
+{
+namespace tools
+{
+
+OUString convertToFileUrl(char const * filename, size_t length)
+{
+ OUString const uFileName(filename, length, osl_getThreadTextEncoding());
+ if (strncmp(filename, "file://", 7) == 0)
+ {
+ // already a FileUrl.
+ return uFileName;
+ }
+
+ OUString uFileUrl;
+ if (length > 0)
+ {
+ if ((filename[0] == '.') || (filename[0] != SEPARATOR))
+ {
+ // relative path name.
+ OUString uWorkingDir;
+ if (osl_getProcessWorkingDir(&uWorkingDir.pData) != osl_Process_E_None)
+ {
+ OSL_ASSERT(false);
+ }
+ if (FileBase::getAbsoluteFileURL(uWorkingDir, uFileName, uFileUrl) != FileBase::E_None)
+ {
+ OSL_ASSERT(false);
+ }
+ }
+ else
+ {
+ // absolute path name.
+ if (FileBase::getFileURLFromSystemPath(uFileName, uFileUrl) != FileBase::E_None)
+ {
+ OSL_ASSERT(false);
+ }
+ }
+ }
+ return uFileUrl;
+}
+
+} // namespace tools
+} // namespace registry
diff --git a/registry/tools/fileurl.hxx b/registry/tools/fileurl.hxx
new file mode 100644
index 000000000000..bbaa218f32e6
--- /dev/null
+++ b/registry/tools/fileurl.hxx
@@ -0,0 +1,43 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+#ifndef INCLUDED_REGISTRY_TOOLS_FILEURL_HXX
+#define INCLUDED_REGISTRY_TOOLS_FILEURL_HXX
+
+#include "rtl/ustring.hxx"
+
+namespace registry
+{
+namespace tools
+{
+
+rtl::OUString convertToFileUrl(char const * filename, size_t length);
+
+} // namespace tools
+} // namespace registry
+
+#endif /* INCLUDED_REGISTRY_TOOLS_FILEURL_HXX */
diff --git a/registry/tools/makefile.mk b/registry/tools/makefile.mk
index bb7d448b86e6..06ca753ff044 100644
--- a/registry/tools/makefile.mk
+++ b/registry/tools/makefile.mk
@@ -43,7 +43,7 @@ ENABLE_EXCEPTIONS := TRUE
CDEFS += -DDLL_VERSION=$(EMQ)"$(DLLPOSTFIX)$(EMQ)"
APP1TARGET= $(TARGET)
-APP1OBJS= $(OBJ)$/regmerge.obj
+APP1OBJS= $(OBJ)$/regmerge.obj $(OBJ)/fileurl.obj $(OBJ)/options.obj
APP1RPATH= UREBIN
APP1STDLIBS=\
@@ -51,7 +51,7 @@ APP1STDLIBS=\
$(REGLIB)
APP2TARGET= regview
-APP2OBJS= $(OBJ)$/regview.obj
+APP2OBJS= $(OBJ)$/regview.obj $(OBJ)/fileurl.obj
APP2RPATH= UREBIN
APP2STDLIBS=\
@@ -59,7 +59,7 @@ APP2STDLIBS=\
$(REGLIB)
APP3TARGET= regcompare
-APP3OBJS= $(OBJ)$/regcompare.obj
+APP3OBJS= $(OBJ)$/regcompare.obj $(OBJ)/fileurl.obj $(OBJ)/options.obj
APP3RPATH= SDK
APP3STDLIBS=\
@@ -68,13 +68,21 @@ APP3STDLIBS=\
$(REGLIB)
APP4TARGET= checksingleton
-APP4OBJS= $(OBJ)$/checksingleton.obj
+APP4OBJS= $(OBJ)$/checksingleton.obj $(OBJ)/fileurl.obj $(OBJ)/options.obj
APP4STDLIBS=\
$(SALLIB) \
$(SALHELPERLIB) \
$(REGLIB)
-OBJFILES = $(APP1OBJS) $(APP2OBJS) $(APP3OBJS) $(APP4OBJS)
+APP5TARGET= rdbedit
+APP5OBJS= $(OBJ)$/rdbedit.obj
+
+APP5STDLIBS=\
+ $(SALLIB) \
+ $(SALHELPERLIB) \
+ $(REGLIB)
+
+OBJFILES = $(APP1OBJS) $(APP2OBJS) $(APP3OBJS) $(APP4OBJS) $(APP5OBJS)
.INCLUDE : target.mk
diff --git a/registry/tools/options.cxx b/registry/tools/options.cxx
new file mode 100644
index 000000000000..d851825ebfb6
--- /dev/null
+++ b/registry/tools/options.cxx
@@ -0,0 +1,153 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+#include "options.hxx"
+
+#include "osl/diagnose.h"
+
+#include <stdio.h>
+#include <string.h>
+
+namespace registry
+{
+namespace tools
+{
+
+Options::Options (char const * program)
+ : m_program (program)
+{}
+
+Options::~Options()
+{}
+
+// static
+bool Options::checkArgument(std::vector< std::string> & rArgs, char const * arg, size_t len)
+{
+ bool result = ((arg != 0) && (len > 0));
+ OSL_PRECOND(result, "registry::tools::Options::checkArgument(): invalid arguments");
+ if (result)
+ {
+ OSL_TRACE("registry::tools:Options::checkArgument(): \"%s\"", arg);
+ switch (arg[0])
+ {
+ case '@':
+ if ((result = (len > 1)) == true)
+ {
+ // "@<cmdfile>"
+ result = Options::checkCommandFile(rArgs, &(arg[1]));
+ }
+ break;
+ case '-':
+ if ((result = (len > 1)) == true)
+ {
+ // "-<option>"
+ std::string option (&(arg[0]), 2);
+ rArgs.push_back(option);
+ if (len > 2)
+ {
+ // "-<option><param>"
+ std::string param(&(arg[2]), len - 2);
+ rArgs.push_back(param);
+ }
+ }
+ break;
+ default:
+ rArgs.push_back(std::string(arg, len));
+ break;
+ }
+ }
+ return (result);
+}
+
+// static
+bool Options::checkCommandFile(std::vector< std::string > & rArgs, char const * filename)
+{
+ FILE * fp = fopen(filename, "r");
+ if (fp == 0)
+ {
+ fprintf(stderr, "ERROR: Can't open command file \"%s\"\n", filename);
+ return (false);
+ }
+
+ std::string buffer;
+ buffer.reserve(256);
+
+ bool quoted = false;
+ int c = EOF;
+ while ((c = fgetc(fp)) != EOF)
+ {
+ switch(c)
+ {
+ case '\"':
+ quoted = !quoted;
+ break;
+ case ' ':
+ case '\t':
+ case '\r':
+ case '\n':
+ if (!quoted)
+ {
+ if (!buffer.empty())
+ {
+ if (!checkArgument(rArgs, buffer.c_str(), buffer.size()))
+ {
+ // failure.
+ (void) fclose(fp);
+ return false;
+ }
+ buffer.clear();
+ }
+ break;
+ }
+ default:
+ // quoted white-space fall through
+ buffer.push_back(sal::static_int_cast<char>(c));
+ break;
+ }
+ }
+ return (fclose(fp) == 0);
+}
+
+bool Options::initOptions (std::vector< std::string > & rArgs)
+{
+ return initOptions_Impl (rArgs);
+}
+
+bool Options::badOption (char const * reason, char const * option) const
+{
+ (void) fprintf(stderr, "%s: %s option '%s'\n", m_program.c_str(), reason, option);
+ return printUsage();
+}
+
+bool Options::printUsage() const
+{
+ printUsage_Impl();
+ return false;
+}
+
+} // namespace tools
+} // namespace registry
diff --git a/registry/tools/options.hxx b/registry/tools/options.hxx
new file mode 100644
index 000000000000..8e4c97877e3b
--- /dev/null
+++ b/registry/tools/options.hxx
@@ -0,0 +1,67 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+#ifndef INCLUDED_REGISTRY_TOOLS_OPTIONS_HXX
+#define INCLUDED_REGISTRY_TOOLS_OPTIONS_HXX
+
+#include <string>
+#include <vector>
+
+namespace registry
+{
+namespace tools
+{
+class Options
+{
+ std::string m_program;
+
+ Options (Options const &);
+ Options & operator= (Options const &);
+
+public:
+ explicit Options (char const * program);
+ virtual ~Options();
+
+ static bool checkArgument (std::vector< std::string > & rArgs, char const * arg, size_t len);
+
+ bool initOptions (std::vector< std::string > & rArgs);
+ bool badOption (char const * reason, char const * option) const;
+
+ std::string const & getProgramName() const { return m_program; }
+ bool printUsage() const;
+
+protected:
+ static bool checkCommandFile(std::vector< std::string > & rArgs, char const * filename);
+
+ virtual bool initOptions_Impl(std::vector< std::string > & rArgs) = 0;
+ virtual void printUsage_Impl() const = 0;
+};
+
+} // namespace tools
+} // namespace registry
+
+#endif /* INCLUDED_REGISTRY_TOOLS_OPTIONS_HXX */
diff --git a/registry/tools/rdbedit.cxx b/registry/tools/rdbedit.cxx
new file mode 100644
index 000000000000..c2b3d6a3dcf3
--- /dev/null
+++ b/registry/tools/rdbedit.cxx
@@ -0,0 +1,318 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_registry.hxx"
+
+#include <stdio.h>
+#include <string.h>
+
+#include "registry/registry.hxx"
+#include "registry/reflread.hxx"
+#include <rtl/ustring.hxx>
+#include <rtl/alloc.h>
+#include <osl/process.h>
+#include <osl/diagnose.h>
+#include <osl/thread.h>
+#include <osl/file.hxx>
+
+#ifdef SAL_UNX
+#define SEPARATOR '/'
+#else
+#define SEPARATOR '\\'
+#endif
+
+using namespace ::rtl;
+using namespace ::osl;
+
+sal_Bool isFileUrl(const OString& fileName)
+{
+ if (fileName.indexOf("file://") == 0 )
+ return sal_True;
+ return sal_False;
+}
+
+OUString convertToFileUrl(const OString& fileName)
+{
+ if ( isFileUrl(fileName) )
+ {
+ return OStringToOUString(fileName, osl_getThreadTextEncoding());
+ }
+
+ OUString uUrlFileName;
+ OUString uFileName(fileName.getStr(), fileName.getLength(), osl_getThreadTextEncoding());
+ if ( fileName.indexOf('.') == 0 || fileName.indexOf(SEPARATOR) < 0 )
+ {
+ OUString uWorkingDir;
+ if (osl_getProcessWorkingDir(&uWorkingDir.pData) != osl_Process_E_None)
+ {
+ OSL_ASSERT(false);
+ }
+ if (FileBase::getAbsoluteFileURL(uWorkingDir, uFileName, uUrlFileName)
+ != FileBase::E_None)
+ {
+ OSL_ASSERT(false);
+ }
+ } else
+ {
+ if (FileBase::getFileURLFromSystemPath(uFileName, uUrlFileName)
+ != FileBase::E_None)
+ {
+ OSL_ASSERT(false);
+ }
+ }
+
+ return uUrlFileName;
+}
+
+#define U2S( s ) \
+ OUStringToOString(s, RTL_TEXTENCODING_UTF8).getStr()
+#define S2U( s ) \
+ OStringToOUString(s, RTL_TEXTENCODING_UTF8)
+
+struct LessString
+{
+ sal_Bool operator()(const OUString& str1, const OUString& str2) const
+ {
+ return (str1 < str2);
+ }
+};
+
+enum Command {
+ DELETEKEY
+};
+
+class Options
+{
+public:
+ Options()
+ : m_bVerbose(false)
+ {}
+ ~Options()
+ {}
+
+ bool initOptions(int ac, char* av[]);
+
+ OString prepareHelp();
+ OString prepareVersion();
+
+ const OString& getProgramName()
+ { return m_program; }
+ const OString& getTypeReg()
+ { return m_typeRegName; }
+ const OString& getKeyName()
+ { return m_keyName; }
+ const Command getCommand()
+ { return m_command; }
+ bool verbose()
+ { return m_bVerbose; }
+protected:
+ OString m_program;
+ OString m_typeRegName;
+ OString m_keyName;
+ Command m_command;
+ bool m_bVerbose;
+};
+
+bool Options::initOptions(int ac, char* av[])
+{
+ bool bRet = true;
+ sal_uInt16 i=1;
+
+ if (ac < 2)
+ {
+ fprintf(stderr, "%s", prepareHelp().getStr());
+ bRet = sal_False;
+ }
+
+ m_program = av[0];
+ sal_Int32 index = -1;
+ if ((index=m_program.lastIndexOf(SEPARATOR)) > 0)
+ m_program = av[0]+index+1;
+
+ char *s=NULL;
+ for (; i < ac; i++)
+ {
+ if (av[i][0] == '-')
+ {
+ switch (av[i][1])
+ {
+ case 'r':
+ case 'R':
+ if (av[i][2] == '\0')
+ {
+ if (i < ac - 1 && av[i+1][0] != '-')
+ {
+ i++;
+ s = av[i];
+ } else
+ {
+ fprintf(stderr, "%s: invalid option '%s'\n", m_program.getStr(), av[i]);
+ bRet = sal_False;
+ break;
+ }
+ } else
+ {
+ s = av[i] + 2;
+ }
+ m_typeRegName = OString(s);
+ break;
+ case 'd':
+ case 'D':
+ if (av[i][2] == '\0')
+ {
+ if (i < ac - 1 && av[i+1][0] != '-')
+ {
+ i++;
+ s = av[i];
+ } else
+ {
+ fprintf(stderr, "%s: invalid option '%s'\n", m_program.getStr(), av[i]);
+ bRet = sal_False;
+ break;
+ }
+ } else
+ {
+ s = av[i] + 2;
+ }
+ m_keyName = OString(s);
+ break;
+ case 'v':
+ case 'V':
+ if (av[i][2] != '\0')
+ {
+ fprintf(stderr, "%s: invalid option '%s'\n", m_program.getStr(), av[i]);
+ bRet = sal_False;
+ }
+ m_bVerbose = true;
+ break;
+ case 'h':
+ case '?':
+ if (av[i][2] != '\0')
+ {
+ fprintf(stderr, "%s: invalid option '%s'\n", m_program.getStr(), av[i]);
+ bRet = false;
+ } else
+ {
+ fprintf(stdout, "%s", prepareHelp().getStr());
+ exit(0);
+ }
+ break;
+ default:
+ fprintf(stderr, "%s: unknown option '%s'\n", m_program.getStr(), av[i]);
+ bRet = false;
+ break;
+ }
+ } else
+ {
+ fprintf(stderr, "%s: unknown option '%s'\n", m_program.getStr(), av[i]);
+ bRet = false;
+ }
+ }
+
+ return bRet;
+}
+
+OString Options::prepareHelp()
+{
+ OString help("\nusing: ");
+ help += m_program + " -r<filename> <command>\n";
+ help += " -r<filename> = filename specifies the name of the type registry.\n";
+ help += "Commands:\n";
+ help += " -d <keyname> = delete the specified key from the registry. Keyname\n";
+ help += " specifies the name of the key that get deleted.\n";
+ help += " -v = verbose output.\n";
+ help += " -h|-? = print this help message and exit.\n";
+ help += prepareVersion();
+
+ return help;
+}
+
+OString Options::prepareVersion()
+{
+ OString version(m_program);
+ version += " Version 1.0\n\n";
+ return version;
+}
+
+static Options options;
+
+
+#if (defined UNX) || (defined OS2) || (defined __MINGW32__)
+int main( int argc, char * argv[] )
+#else
+int _cdecl main( int argc, char * argv[] )
+#endif
+{
+ if ( !options.initOptions(argc, argv) )
+ {
+ exit(1);
+ }
+
+ OUString typeRegName( convertToFileUrl(options.getTypeReg()) );
+
+ Registry typeReg;
+
+ if ( typeReg.open(typeRegName, REG_READWRITE) )
+ {
+ fprintf(stderr, "%s: open registry \"%s\" failed\n",
+ options.getProgramName().getStr(), options.getTypeReg().getStr());
+ exit(2);
+ }
+
+ RegistryKey typeRoot;
+ if ( typeReg.openRootKey(typeRoot) )
+ {
+ fprintf(stderr, "%s: open root key of registry \"%s\" failed\n",
+ options.getProgramName().getStr(), options.getTypeReg().getStr());
+ exit(3);
+ }
+
+ if ( options.getCommand() == DELETEKEY )
+ {
+ if ( typeRoot.deleteKey(S2U(options.getKeyName())) )
+ {
+ fprintf(stderr, "%s: delete key \"%s\" of registry \"%s\" failed\n",
+ options.getProgramName().getStr(), options.getKeyName().getStr(), options.getTypeReg().getStr());
+ exit(4);
+ } else {
+ if (options.verbose())
+ fprintf(stderr, "%s: delete key \"%s\" of registry \"%s\"\n",
+ options.getProgramName().getStr(), options.getKeyName().getStr(), options.getTypeReg().getStr());
+ }
+ }
+
+ typeRoot.releaseKey();
+ if ( typeReg.close() )
+ {
+ fprintf(stderr, "%s: closing registry \"%s\" failed\n",
+ options.getProgramName().getStr(), options.getTypeReg().getStr());
+ exit(5);
+ }
+}
+
+
diff --git a/registry/tools/regcompare.cxx b/registry/tools/regcompare.cxx
index c6089d509380..7758c4a74066 100644
--- a/registry/tools/regcompare.cxx
+++ b/registry/tools/regcompare.cxx
@@ -29,409 +29,266 @@
// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_registry.hxx"
-#include <stdio.h>
-#include <string.h>
-
-#include <set>
-#include <vector>
#include "registry/registry.hxx"
#include "registry/reader.hxx"
#include "registry/version.h"
+#include "fileurl.hxx"
+#include "options.hxx"
+
#include <rtl/ustring.hxx>
-#include <rtl/alloc.h>
-#include <osl/process.h>
#include <osl/diagnose.h>
-#include <osl/thread.h>
-#include <osl/file.hxx>
-#ifdef SAL_UNX
-#define SEPARATOR '/'
-#else
-#define SEPARATOR '\\'
-#endif
+#include <stdio.h>
+#include <string.h>
-using namespace ::rtl;
-using namespace ::osl;
+#include <set>
+#include <vector>
+#include <string>
-OUString shortName(const OUString& fullName)
-{
- return fullName.copy(fullName.lastIndexOf('/') + 1);
-}
+using namespace rtl;
+using namespace registry::tools;
-sal_Bool isFileUrl(const OString& fileName)
-{
- if (fileName.indexOf("file://") == 0 )
- return sal_True;
- return sal_False;
-}
+typedef std::set< rtl::OUString > StringSet;
-OUString convertToFileUrl(const OString& fileName)
+class Options_Impl : public Options
{
- if ( isFileUrl(fileName) )
- {
- return OStringToOUString(fileName, osl_getThreadTextEncoding());
- }
-
- OUString uUrlFileName;
- OUString uFileName(fileName.getStr(), fileName.getLength(), osl_getThreadTextEncoding());
- if ( fileName.indexOf('.') == 0 || fileName.indexOf(SEPARATOR) < 0 )
- {
- OUString uWorkingDir;
- if (osl_getProcessWorkingDir(&uWorkingDir.pData) != osl_Process_E_None)
- {
- OSL_ASSERT(false);
- }
- if (FileBase::getAbsoluteFileURL(uWorkingDir, uFileName, uUrlFileName)
- != FileBase::E_None)
- {
- OSL_ASSERT(false);
- }
- } else
- {
- if (FileBase::getFileURLFromSystemPath(uFileName, uUrlFileName)
- != FileBase::E_None)
- {
- OSL_ASSERT(false);
- }
- }
+public:
+ explicit Options_Impl(char const * program)
+ : Options(program),
+ m_bFullCheck(false),
+ m_bForceOutput(false),
+ m_bUnoTypeCheck(false),
+ m_checkUnpublished(false)
+ {}
- return uUrlFileName;
-}
+ std::string const & getRegName1() const { return m_regName1; }
+ std::string const & getRegName2() const { return m_regName2; }
-#define U2S( s ) \
- OUStringToOString(s, RTL_TEXTENCODING_UTF8).getStr()
-#define S2U( s ) \
- OStringToOUString(s, RTL_TEXTENCODING_UTF8)
+ bool isStartKeyValid() const { return (m_startKey.getLength() > 0); }
+ OUString const & getStartKey() const { return m_startKey; }
+ bool matchedWithExcludeKey( const OUString& keyName) const;
-struct LessString
-{
- sal_Bool operator()(const OUString& str1, const OUString& str2) const
- {
- return (str1 < str2);
- }
-};
+ bool fullCheck() const { return m_bFullCheck; }
+ bool forceOutput() const { return m_bForceOutput; }
+ bool unoTypeCheck() const { return m_bUnoTypeCheck; }
+ bool checkUnpublished() const { return m_checkUnpublished; }
-typedef ::std::set< OUString > StringSet;
+protected:
+ bool setRegName_Impl(char c, std::string const & param);
-class Options
-{
-public:
- Options()
- : m_bFullCheck(sal_False)
- , m_bForceOutput(sal_False)
- , m_bUnoTypeCheck(sal_False)
- , m_checkUnpublished(false)
- {}
- ~Options()
- {}
+ virtual void printUsage_Impl() const;
+ virtual bool initOptions_Impl (std::vector< std::string > & rArgs);
- sal_Bool initOptions(int ac, char* av[], sal_Bool bCmdFile=sal_False);
-
- OString prepareHelp();
- OString prepareVersion();
-
- const OString& getProgramName()
- { return m_program; }
- const OString& getRegName1()
- { return m_regName1; }
- const OString& getRegName2()
- { return m_regName2; }
- sal_Bool isStartKeyValid()
- { return (m_startKey.getLength() > 0); };
- const OString& getStartKey()
- { return m_startKey; }
- sal_Bool existsExcludeKeys()
- { return !m_excludeKeys.empty(); };
- StringSet& getExcludeKeys()
- { return m_excludeKeys; }
- sal_Bool matchedWithExcludeKey( const OUString& keyName);
- sal_Bool fullCheck()
- { return m_bFullCheck; }
- sal_Bool forceOutput()
- { return m_bForceOutput; }
- sal_Bool unoTypeCheck()
- { return m_bUnoTypeCheck; }
- bool checkUnpublished() const { return m_checkUnpublished; }
-protected:
- OString m_program;
- OString m_regName1;
- OString m_regName2;
- OString m_startKey;
+ std::string m_regName1;
+ std::string m_regName2;
+ OUString m_startKey;
StringSet m_excludeKeys;
- sal_Bool m_bFullCheck;
- sal_Bool m_bForceOutput;
- sal_Bool m_bUnoTypeCheck;
+ bool m_bFullCheck;
+ bool m_bForceOutput;
+ bool m_bUnoTypeCheck;
bool m_checkUnpublished;
};
-sal_Bool Options::initOptions(int ac, char* av[], sal_Bool bCmdFile)
-{
- sal_Bool bRet = sal_True;
- sal_uInt16 i=0;
+#define U2S( s ) OUStringToOString(s, RTL_TEXTENCODING_UTF8).getStr()
- if (!bCmdFile)
- {
- bCmdFile = sal_True;
+inline rtl::OUString makeOUString (std::string const & s)
+{
+ return rtl::OUString(s.c_str(), s.size(), RTL_TEXTENCODING_UTF8, OSTRING_TO_OUSTRING_CVTFLAGS);
+}
- m_program = av[0];
+inline rtl::OUString shortName(rtl::OUString const & fullName)
+{
+ return fullName.copy(fullName.lastIndexOf('/') + 1);
+}
- if (ac < 2)
- {
- fprintf(stdout, "%s", prepareHelp().getStr());
- bRet = sal_False;
- }
+bool Options_Impl::setRegName_Impl(char c, std::string const & param)
+{
+ bool one = (c == '1'), two = (c == '2');
+ if (one)
+ m_regName1 = param;
+ if (two)
+ m_regName2 = param;
+ return (one || two);
+}
- i = 1;
- } else
- {
- i = 0;
- }
+//virtual
+void Options_Impl::printUsage_Impl() const
+{
+ std::string const & rProgName = getProgramName();
+ fprintf(stderr,
+ "Usage: %s -r1<filename> -r2<filename> [-options] | @<filename>\n", rProgName.c_str()
+ );
+ fprintf(stderr,
+ " -r1<filename> = filename specifies the name of the first registry.\n"
+ " -r2<filename> = filename specifies the name of the second registry.\n"
+ " @<filename> = filename specifies a command file.\n"
+ "Options:\n"
+ " -s<name> = name specifies the name of a start key. If no start key\n"
+ " |S<name> is specified the comparison starts with the root key.\n"
+ " -x<name> = name specifies the name of a key which won't be compared. All\n"
+ " |X<name> subkeys won't be compared also. This option can be used more than once.\n"
+ " -f|F = force the detailed output of any diffenrences. Default\n"
+ " is that only the number of differences is returned.\n"
+ " -c|C = make a complete check, that means any differences will be\n"
+ " detected. Default is only a compatibility check that means\n"
+ " only UNO typelibrary entries will be checked.\n"
+ " -t|T = make an UNO type compatiblity check. This means that registry 2\n"
+ " will be checked against registry 1. If a interface in r2 contains\n"
+ " more methods or the methods are in a different order as in r1, r2 is\n"
+ " incompatible to r1. But if a service in r2 supports more properties as\n"
+ " in r1 and the new properties are 'optional' it is compatible.\n"
+ " -u|U = additionally check types that are unpublished in registry 1.\n"
+ " -h|-? = print this help message and exit.\n"
+ );
+ fprintf(stderr,
+ "\n%s Version 1.0\n\n", rProgName.c_str()
+ );
+}
- char *s=NULL;
- for (; i < ac; i++)
+// virtual
+bool Options_Impl::initOptions_Impl (std::vector< std::string > & rArgs)
+{
+ std::vector< std::string >::const_iterator first = rArgs.begin(), last = rArgs.end();
+ for (; first != last; ++first)
{
- if (av[i][0] == '-')
+ if ((*first)[0] != '-')
+ {
+ return badOption("invalid", (*first).c_str());
+ }
+ switch ((*first)[1])
{
- switch (av[i][1])
+ case 'r':
+ case 'R':
{
- case 'r':
- case 'R':
+ if (!((++first != last) && ((*first)[0] != '-')))
{
- sal_Bool bFirst = sal_True;
- if (av[i][2] == '2')
- {
- bFirst = sal_False;
- } else if (av[i][2] != '1')
- {
- fprintf(stdout, "%s: invalid option '%s'\n", m_program.getStr(), av[i]);
- }
- if (av[i][3] == '\0')
- {
- if (i < ac - 1 && av[i+1][0] != '-')
- {
- i++;
- s = av[i];
- } else
- {
- fprintf(stdout, "%s: invalid option '%s'\n", m_program.getStr(), av[i]);
- bRet = sal_False;
- break;
- }
- } else
- {
- s = av[i] + 2;
- }
+ return badOption("invalid", (*first).c_str());
+ }
- if ( bFirst )
- {
- m_regName1 = OString(s);
- } else
+ std::string option(*first), param;
+ if (option.size() == 1)
+ {
+ // "-r<n><space><param>"
+ if (!((++first != last) && ((*first)[0] != '-')))
{
- m_regName2 = OString(s);
+ return badOption("invalid", (*first).c_str());
}
+ param = (*first);
}
- break;
- case 's':
- case 'S':
- if (av[i][2] == '\0')
- {
- if (i < ac - 1 && av[i+1][0] != '-')
- {
- i++;
- s = av[i];
- } else
- {
- fprintf(stdout, "%s: invalid option '%s'\n", m_program.getStr(), av[i]);
- bRet = sal_False;
- break;
- }
- } else
- {
- s = av[i] + 2;
- }
- m_startKey = OString(s);
- break;
- case 'x':
- case 'X':
- if (av[i][2] == '\0')
- {
- if (i < ac - 1 && av[i+1][0] != '-')
- {
- i++;
- s = av[i];
- } else
- {
- fprintf(stdout, "%s: invalid option '%s'\n", m_program.getStr(), av[i]);
- bRet = sal_False;
- break;
- }
- } else
- {
- s = av[i] + 2;
- }
- m_excludeKeys.insert(S2U(s));
- break;
- case 'c':
- case 'C':
- if (av[i][2] != '\0')
- {
- fprintf(stdout, "%s: invalid option '%s'\n", m_program.getStr(), av[i]);
- }
- m_bFullCheck = sal_True;
- break;
- case 'f':
- case 'F':
- if (av[i][2] != '\0')
- {
- fprintf(stdout, "%s: invalid option '%s'\n", m_program.getStr(), av[i]);
- bRet = sal_False;
- }
- m_bForceOutput = sal_True;
- break;
- case 't':
- case 'T':
- if (av[i][2] != '\0')
- {
- fprintf(stdout, "%s: invalid option '%s'\n", m_program.getStr(), av[i]);
- }
- m_bUnoTypeCheck = sal_True;
- break;
- case 'u':
- case 'U':
- if (av[i][2] != '\0')
- {
- fprintf(stdout, "%s: invalid option '%s'\n", m_program.getStr(), av[i]);
- }
- m_checkUnpublished = true;
- break;
- case 'h':
- case '?':
- if (av[i][2] != '\0')
- {
- fprintf(stdout, "%s: invalid option '%s'\n", m_program.getStr(), av[i]);
- bRet = sal_False;
- } else
- {
- fprintf(stdout, "%s", prepareHelp().getStr());
- exit(0);
- }
- break;
- default:
- fprintf(stdout, "%s: unknown option '%s'\n", m_program.getStr(), av[i]);
- bRet = sal_False;
- break;
+ else
+ {
+ // "-r<n><param>"
+ param = std::string(&(option[1]), option.size() - 1);
+ }
+ if (!setRegName_Impl(option[0], param))
+ {
+ return badOption("invalid", option.c_str());
+ }
+ break;
}
- } else
- {
- if (av[i][0] == '@')
+ case 's':
+ case 'S':
{
- FILE* cmdFile = fopen(av[i]+1, "r");
- if( cmdFile == NULL )
- {
- fprintf(stdout, "%s", prepareHelp().getStr());
- bRet = sal_False;
- } else
+ if (!((++first != last) && ((*first)[0] != '-')))
{
- int rargc=0;
- char* rargv[512];
- char buffer[512];
-
- while ( fscanf(cmdFile, "%s", buffer) != EOF )
- {
- rargv[rargc]= strdup(buffer);
- rargc++;
- }
- fclose(cmdFile);
-
- bRet = initOptions(rargc, rargv, bCmdFile);
-
- for (long j=0; j < rargc; j++)
- {
- free(rargv[j]);
- }
+ return badOption("invalid", (*first).c_str());
+ }
+ m_startKey = makeOUString(*first);
+ break;
+ }
+ case 'x':
+ case 'X':
+ {
+ if (!((++first != last) && ((*first)[0] != '-')))
+ {
+ return badOption("invalid", (*first).c_str());
+ }
+ m_excludeKeys.insert(makeOUString(*first));
+ break;
+ }
+ case 'f':
+ case 'F':
+ {
+ if ((*first).size() > 2)
+ {
+ return badOption("invalid", (*first).c_str());
+ }
+ m_bForceOutput = sal_True;
+ break;
+ }
+ case 'c':
+ case 'C':
+ {
+ if ((*first).size() > 2)
+ {
+ return badOption("invalid", (*first).c_str());
+ }
+ m_bFullCheck = sal_True;
+ break;
+ }
+ case 't':
+ case 'T':
+ {
+ if ((*first).size() > 2)
+ {
+ return badOption("invalid", (*first).c_str());
+ }
+ m_bUnoTypeCheck = sal_True;
+ break;
+ }
+ case 'u':
+ case 'U':
+ {
+ if ((*first).size() > 2)
+ {
+ return badOption("invalid", (*first).c_str());
}
- } else
+ m_checkUnpublished = true;
+ break;
+ }
+ case 'h':
+ case '?':
{
- fprintf(stdout, "%s: unknown option '%s'\n", m_program.getStr(), av[i]);
- bRet = sal_False;
+ if ((*first).size() > 2)
+ {
+ return badOption("invalid", (*first).c_str());
+ }
+ return printUsage();
+ // break; // Unreachable
+ }
+ default:
+ {
+ return badOption("unknown", (*first).c_str());
+ // break; // Unreachable
}
}
}
- if ( bRet )
+ if ( m_regName1.size() == 0 )
{
- if ( m_regName1.getLength() == 0 )
- {
- fprintf(stdout, "%s: missing option '-r1'\n", m_program.getStr());
- bRet = sal_False;
- }
- if ( m_regName2.getLength() == 0 )
- {
- fprintf(stdout, "%s: missing option '-r2'\n", m_program.getStr());
- bRet = sal_False;
- }
+ return badOption("missing", "-r1");
}
-
- return bRet;
-}
-
-OString Options::prepareHelp()
-{
- OString help("\nusing: ");
- help += m_program + " -r1<filename> -r2<filename> [-options] | @<filename>\n";
- help += " -r1<filename> = filename specifies the name of the first registry.\n";
- help += " -r2<filename> = filename specifies the name of the second registry.\n";
- help += " @<filename> = filename specifies a command file.\n";
- help += "Options:\n";
- help += " -s<name> = name specifies the name of a start key. If no start key\n";
- help += " |S<name> is specified the comparison starts with the root key.\n";
- help += " -x<name> = name specifies the name of a key which won't be compared. All\n";
- help += " |X<name> subkeys won't be compared also. This option can be used more than once.\n";
- help += " -f|F = force the detailed output of any diffenrences. Default\n";
- help += " is that only the number of differences is returned.\n";
- help += " -c|C = make a complete check, that means any differences will be\n";
- help += " detected. Default is only a compatibility check that means\n";
- help += " only UNO typelibrary entries will be checked.\n";
- help += " -t|T = make an UNO type compatiblity check. This means that registry 2\n";
- help += " will be checked against registry 1. If a interface in r2 contains\n";
- help += " more methods or the methods are in a different order as in r1, r2 is\n";
- help += " incompatible to r1. But if a service in r2 supports more properties as\n";
- help += " in r1 and the new properties are 'optonal' it is compatible.\n";
- help += " -u|U = additionally check types that are unpublished in registry 1.\n";
- help += " -h|-? = print this help message and exit.\n";
- help += prepareVersion();
-
- return help;
-}
-
-OString Options::prepareVersion()
-{
- OString version("\nSun Microsystems (R) ");
- version += m_program + " Version 1.0\n\n";
- return version;
+ if ( m_regName2.size() == 0 )
+ {
+ return badOption("missing", "-r2");
+ }
+ return true;
}
-sal_Bool Options::matchedWithExcludeKey( const OUString& keyName)
+bool Options_Impl::matchedWithExcludeKey( const OUString& keyName) const
{
- if ( m_excludeKeys.empty() )
- return sal_False;
-
- StringSet::const_iterator iter = m_excludeKeys.begin();
- StringSet::const_iterator end = m_excludeKeys.end();
-
- while ( iter != end )
+ if (!m_excludeKeys.empty())
{
- if ( keyName.indexOf(*iter) == 0)
- return sal_True;
-
- ++iter;
+ StringSet::const_iterator first = m_excludeKeys.begin(), last = m_excludeKeys.end();
+ for (; first != last; ++first)
+ {
+ if (keyName.indexOf(*first) == 0)
+ return true;
+ }
}
-
- return sal_False;
+ return false;
}
-static Options options;
-
static char const * getTypeClass(RTTypeClass typeClass)
{
switch (typeClass)
@@ -551,6 +408,7 @@ static char const * getConstValueType(RTConstValue& constValue)
return "NONE";
}
}
+
static void printConstValue(RTConstValue& constValue)
{
switch (constValue.m_type)
@@ -603,9 +461,17 @@ static void printConstValue(RTConstValue& constValue)
}
}
-static sal_uInt32 checkConstValue(const OUString& keyName,
+static void dumpTypeClass(sal_Bool & rbDump, RTTypeClass typeClass, OUString const & keyName)
+{
+ if (rbDump)
+ fprintf(stdout, "%s: %s\n", getTypeClass(typeClass), U2S(keyName));
+ rbDump = sal_False;
+}
+
+static sal_uInt32 checkConstValue(Options_Impl const & options,
+ const OUString& keyName,
RTTypeClass typeClass,
- sal_Bool& bDump,
+ sal_Bool & bDump,
RTConstValue& constValue1,
RTConstValue& constValue2,
sal_uInt16 index1)
@@ -619,11 +485,7 @@ static sal_uInt32 checkConstValue(const OUString& keyName,
{
if ( options.forceOutput() && !options.unoTypeCheck() )
{
- if ( bDump )
- {
- fprintf(stdout, "%s: %s\n", getTypeClass(typeClass), U2S(keyName));
- bDump = sal_False;
- }
+ dumpTypeClass(bDump, typeClass, keyName);
fprintf(stdout, " Field %d: Value1 = %s != Value2 = %s\n", index1,
constValue1.m_value.aBool ? "TRUE" : "FALSE",
constValue2.m_value.aBool ? "TRUE" : "FALSE");
@@ -636,11 +498,7 @@ static sal_uInt32 checkConstValue(const OUString& keyName,
{
if ( options.forceOutput() && !options.unoTypeCheck() )
{
- if ( bDump )
- {
- fprintf(stdout, "%s: %s\n", getTypeClass(typeClass), U2S(keyName));
- bDump = sal_False;
- }
+ dumpTypeClass(bDump, typeClass, keyName);
fprintf(stdout, " Field %d: Value1 = %d != Value2 = %d\n", index1,
constValue1.m_value.aByte, constValue2.m_value.aByte);
}
@@ -652,11 +510,7 @@ static sal_uInt32 checkConstValue(const OUString& keyName,
{
if ( options.forceOutput() && !options.unoTypeCheck() )
{
- if ( bDump )
- {
- fprintf(stdout, "%s: %s\n", getTypeClass(typeClass), U2S(keyName));
- bDump = sal_False;
- }
+ dumpTypeClass(bDump, typeClass, keyName);
fprintf(stdout, " Field %d: Value1 = %d != Value2 = %d\n", index1,
constValue1.m_value.aShort, constValue2.m_value.aShort);
}
@@ -668,11 +522,7 @@ static sal_uInt32 checkConstValue(const OUString& keyName,
{
if ( options.forceOutput() && !options.unoTypeCheck() )
{
- if ( bDump )
- {
- fprintf(stdout, "%s: %s\n", getTypeClass(typeClass), U2S(keyName));
- bDump = sal_False;
- }
+ dumpTypeClass(bDump, typeClass, keyName);
fprintf(stdout, " Field %d: Value1 = %d != Value2 = %d\n", index1,
constValue1.m_value.aUShort, constValue2.m_value.aUShort);
}
@@ -684,11 +534,7 @@ static sal_uInt32 checkConstValue(const OUString& keyName,
{
if ( options.forceOutput() && !options.unoTypeCheck() )
{
- if ( bDump )
- {
- fprintf(stdout, "%s: %s\n", getTypeClass(typeClass), U2S(keyName));
- bDump = sal_False;
- }
+ dumpTypeClass(bDump, typeClass, keyName);
fprintf(stdout, " Field %d: Value1 = %ld != Value2 = %ld\n", index1,
sal::static_int_cast< long >(constValue1.m_value.aLong),
sal::static_int_cast< long >(constValue2.m_value.aLong));
@@ -701,11 +547,7 @@ static sal_uInt32 checkConstValue(const OUString& keyName,
{
if ( options.forceOutput() && !options.unoTypeCheck() )
{
- if ( bDump )
- {
- fprintf(stdout, "%s: %s\n", getTypeClass(typeClass), U2S(keyName));
- bDump = sal_False;
- }
+ dumpTypeClass(bDump, typeClass, keyName);
fprintf(stdout, " Field %d: Value1 = %lu != Value2 = %lu\n", index1,
sal::static_int_cast< unsigned long >(constValue1.m_value.aULong),
sal::static_int_cast< unsigned long >(constValue2.m_value.aULong));
@@ -718,11 +560,7 @@ static sal_uInt32 checkConstValue(const OUString& keyName,
{
if ( options.forceOutput() && !options.unoTypeCheck() )
{
- if ( bDump )
- {
- fprintf(stdout, "%s: %s\n", getTypeClass(typeClass), U2S(keyName));
- bDump = sal_False;
- }
+ dumpTypeClass(bDump, typeClass, keyName);
fprintf(
stdout, " Field %d: Value1 = %s != Value2 = %s\n",
index1,
@@ -741,11 +579,7 @@ static sal_uInt32 checkConstValue(const OUString& keyName,
{
if ( options.forceOutput() && !options.unoTypeCheck() )
{
- if ( bDump )
- {
- fprintf(stdout, "%s: %s\n", getTypeClass(typeClass), U2S(keyName));
- bDump = sal_False;
- }
+ dumpTypeClass(bDump, typeClass, keyName);
fprintf(
stdout, " Field %d: Value1 = %s != Value2 = %s\n",
index1,
@@ -770,11 +604,7 @@ static sal_uInt32 checkConstValue(const OUString& keyName,
{
if ( options.forceOutput() && !options.unoTypeCheck() )
{
- if ( bDump )
- {
- fprintf(stdout, "%s: %s\n", getTypeClass(typeClass), U2S(keyName));
- bDump = sal_False;
- }
+ dumpTypeClass(bDump, typeClass, keyName);
fprintf(stdout, " Field %d: Value1 = %f != Value2 = %f\n", index1,
constValue1.m_value.aFloat, constValue2.m_value.aFloat);
}
@@ -786,11 +616,7 @@ static sal_uInt32 checkConstValue(const OUString& keyName,
{
if ( options.forceOutput() && !options.unoTypeCheck() )
{
- if ( bDump )
- {
- fprintf(stdout, "%s: %s\n", getTypeClass(typeClass), U2S(keyName));
- bDump = sal_False;
- }
+ dumpTypeClass(bDump, typeClass, keyName);
fprintf(stdout, " Field %d: Value1 = %f != Value2 = %f\n", index1,
constValue1.m_value.aDouble, constValue2.m_value.aDouble);
}
@@ -804,45 +630,37 @@ static sal_uInt32 checkConstValue(const OUString& keyName,
return 0;
}
-static sal_uInt32 checkField(const OUString& keyName,
+static sal_uInt32 checkField(Options_Impl const & options,
+ const OUString& keyName,
RTTypeClass typeClass,
- sal_Bool& bDump,
+ sal_Bool & bDump,
typereg::Reader& reader1,
typereg::Reader& reader2,
sal_uInt16 index1,
sal_uInt16 index2)
{
sal_uInt32 nError = 0;
- if ( reader1.getFieldName(index1) !=
- reader2.getFieldName(index2) )
+ if ( reader1.getFieldName(index1) != reader2.getFieldName(index2) )
{
if ( options.forceOutput() && !options.unoTypeCheck() )
{
- if ( bDump )
- {
- fprintf(stdout, "%s: %s\n", getTypeClass(typeClass), U2S(keyName));
- bDump = sal_False;
- }
+ dumpTypeClass (bDump, typeClass, keyName);
fprintf(stdout, " Field %d: Name1 = %s != Name2 = %s\n", index1,
U2S(reader1.getFieldName(index1)), U2S(reader2.getFieldName(index2)));
}
nError++;
}
- if ( reader1.getFieldTypeName(index1) !=
- reader2.getFieldTypeName(index2) )
+ if ( reader1.getFieldTypeName(index1) != reader2.getFieldTypeName(index2) )
{
if ( options.forceOutput() && !options.unoTypeCheck() )
{
- if ( bDump )
- {
- fprintf(stdout, "%s: %s\n", getTypeClass(typeClass), U2S(keyName));
- bDump = sal_False;
- }
+ dumpTypeClass (bDump, typeClass, keyName);
fprintf(stdout, " Field %d: Type1 = %s != Type2 = %s\n", index1,
U2S(reader1.getFieldTypeName(index1)), U2S(reader2.getFieldTypeName(index2)));
}
nError++;
- } else
+ }
+ else
{
RTConstValue constValue1 = reader1.getFieldValue(index1);
RTConstValue constValue2 = reader2.getFieldValue(index2);
@@ -850,11 +668,7 @@ static sal_uInt32 checkField(const OUString& keyName,
{
if ( options.forceOutput() && !options.unoTypeCheck() )
{
- if ( bDump )
- {
- fprintf(stdout, "%s: %s\n", getTypeClass(typeClass), U2S(keyName));
- bDump = sal_False;
- }
+ dumpTypeClass (bDump, typeClass, keyName);
fprintf(stdout, " Field %d: Access1 = %s != Access2 = %s\n", index1,
getConstValueType(constValue1), getConstValueType(constValue2));
fprintf(stdout, " Field %d: Value1 = ", index1);
@@ -864,9 +678,10 @@ static sal_uInt32 checkField(const OUString& keyName,
fprintf(stdout, "\n;");
}
nError++;
- } else
+ }
+ else
{
- nError += checkConstValue(keyName, typeClass, bDump, constValue1, constValue2, index1);
+ nError += checkConstValue(options, keyName, typeClass, bDump, constValue1, constValue2, index1);
}
}
@@ -874,11 +689,7 @@ static sal_uInt32 checkField(const OUString& keyName,
{
if ( options.forceOutput() && !options.unoTypeCheck() )
{
- if ( bDump )
- {
- fprintf(stdout, "%s: %s\n", getTypeClass(typeClass), U2S(keyName));
- bDump = sal_False;
- }
+ dumpTypeClass (bDump, typeClass, keyName);
fprintf(stdout, " Field %d: FieldAccess1 = %s != FieldAccess2 = %s\n", index1,
getFieldAccess(reader1.getFieldFlags(index1)).getStr(),
getFieldAccess(reader1.getFieldFlags(index2)).getStr());
@@ -886,16 +697,11 @@ static sal_uInt32 checkField(const OUString& keyName,
nError++;
}
- if ( options.fullCheck() &&
- (reader1.getFieldDocumentation(index1) != reader2.getFieldDocumentation(index2)) )
+ if ( options.fullCheck() && (reader1.getFieldDocumentation(index1) != reader2.getFieldDocumentation(index2)) )
{
if ( options.forceOutput() && !options.unoTypeCheck() )
{
- if ( bDump )
- {
- fprintf(stdout, "%s: %s\n", getTypeClass(typeClass), U2S(keyName));
- bDump = sal_False;
- }
+ dumpTypeClass (bDump, typeClass, keyName);
fprintf(stdout, " Field %d: Doku1 = %s\n Doku2 = %s\n", index1,
U2S(reader1.getFieldDocumentation(index1)), U2S(reader2.getFieldDocumentation(index2)));
}
@@ -936,24 +742,20 @@ static char const * getParamMode(RTParamMode paramMode)
}
}
-static sal_uInt32 checkMethod(const OUString& keyName,
+static sal_uInt32 checkMethod(Options_Impl const & options,
+ const OUString& keyName,
RTTypeClass typeClass,
- sal_Bool& bDump,
+ sal_Bool & bDump,
typereg::Reader& reader1,
typereg::Reader& reader2,
sal_uInt16 index)
{
sal_uInt32 nError = 0;
- if ( reader1.getMethodName(index) !=
- reader2.getMethodName(index) )
+ if ( reader1.getMethodName(index) != reader2.getMethodName(index) )
{
if ( options.forceOutput() )
{
- if ( bDump )
- {
- fprintf(stdout, "%s: %s\n", getTypeClass(typeClass), U2S(keyName));
- bDump = sal_False;
- }
+ dumpTypeClass (bDump, typeClass, keyName);
fprintf(stdout, " Method1 %d: Name1 = %s != Name2 = %s\n", index,
U2S(reader1.getMethodName(index)),
U2S(reader2.getMethodName(index)));
@@ -961,16 +763,11 @@ static sal_uInt32 checkMethod(const OUString& keyName,
nError++;
}
- if ( reader1.getMethodReturnTypeName(index) !=
- reader2.getMethodReturnTypeName(index) )
+ if ( reader1.getMethodReturnTypeName(index) != reader2.getMethodReturnTypeName(index) )
{
if ( options.forceOutput() )
{
- if ( bDump )
- {
- fprintf(stdout, "%s: %s\n", getTypeClass(typeClass), U2S(keyName));
- bDump = sal_False;
- }
+ dumpTypeClass (bDump, typeClass, keyName);
fprintf(stdout, " Method1 %d: ReturnType1 = %s != ReturnType2 = %s\n", index,
U2S(reader1.getMethodReturnTypeName(index)),
U2S(reader2.getMethodReturnTypeName(index)));
@@ -984,11 +781,7 @@ static sal_uInt32 checkMethod(const OUString& keyName,
{
if ( options.forceOutput() )
{
- if ( bDump )
- {
- fprintf(stdout, "%s: %s\n", getTypeClass(typeClass), U2S(keyName));
- bDump = sal_False;
- }
+ dumpTypeClass (bDump, typeClass, keyName);
fprintf(stdout, " Method %d : nParameters1 = %d != nParameters2 = %d\n", index, nParams1, nParams2);
}
nError++;
@@ -1000,27 +793,18 @@ static sal_uInt32 checkMethod(const OUString& keyName,
{
if ( options.forceOutput() )
{
- if ( bDump )
- {
- fprintf(stdout, "%s: %s\n", getTypeClass(typeClass), U2S(keyName));
- bDump = sal_False;
- }
+ dumpTypeClass (bDump, typeClass, keyName);
fprintf(stdout, " Method %d, Parameter %d: Type1 = %s != Type2 = %s\n", index, i,
U2S(reader1.getMethodParameterTypeName(index, i)),
U2S(reader2.getMethodParameterTypeName(index, i)));
}
nError++;
}
- if ( options.fullCheck() &&
- (reader1.getMethodParameterName(index, i) != reader2.getMethodParameterName(index, i)) )
+ if ( options.fullCheck() && (reader1.getMethodParameterName(index, i) != reader2.getMethodParameterName(index, i)) )
{
if ( options.forceOutput() )
{
- if ( bDump )
- {
- fprintf(stdout, "%s: %s\n", getTypeClass(typeClass), U2S(keyName));
- bDump = sal_False;
- }
+ dumpTypeClass (bDump, typeClass, keyName);
fprintf(stdout, " Method %d, Parameter %d: Name1 = %s != Name2 = %s\n", index, i,
U2S(reader1.getMethodParameterName(index, i)),
U2S(reader2.getMethodParameterName(index, i)));
@@ -1031,11 +815,7 @@ static sal_uInt32 checkMethod(const OUString& keyName,
{
if ( options.forceOutput() )
{
- if ( bDump )
- {
- fprintf(stdout, "%s: %s\n", getTypeClass(typeClass), U2S(keyName));
- bDump = sal_False;
- }
+ dumpTypeClass (bDump, typeClass, keyName);
fprintf(stdout, " Method %d, Parameter %d: Mode1 = %s != Mode2 = %s\n", index, i,
getParamMode(reader1.getMethodParameterFlags(index, i)),
getParamMode(reader2.getMethodParameterFlags(index, i)));
@@ -1045,20 +825,12 @@ static sal_uInt32 checkMethod(const OUString& keyName,
}
if ( i < nParams1 && options.forceOutput() )
{
- if ( bDump )
- {
- fprintf(stdout, "%s: %s\n", getTypeClass(typeClass), U2S(keyName));
- bDump = sal_False;
- }
+ dumpTypeClass (bDump, typeClass, keyName);
fprintf(stdout, " Registry1: Method %d contains %d more parameters\n", index, nParams1 - i);
}
if ( i < nParams2 && options.forceOutput() )
{
- if ( bDump )
- {
- fprintf(stdout, "%s: %s\n", getTypeClass(typeClass), U2S(keyName));
- bDump = sal_False;
- }
+ dumpTypeClass (bDump, typeClass, keyName);
fprintf(stdout, " Registry2: Method %d contains %d more parameters\n", index, nParams2 - i);
}
@@ -1068,11 +840,7 @@ static sal_uInt32 checkMethod(const OUString& keyName,
{
if ( options.forceOutput() )
{
- if ( bDump )
- {
- fprintf(stdout, "%s: %s\n", getTypeClass(typeClass), U2S(keyName));
- bDump = sal_False;
- }
+ dumpTypeClass (bDump, typeClass, keyName);
fprintf(stdout, " nExceptions1 = %d != nExceptions2 = %d\n", nExcep1, nExcep2);
}
nError++;
@@ -1083,11 +851,7 @@ static sal_uInt32 checkMethod(const OUString& keyName,
{
if ( options.forceOutput() )
{
- if ( bDump )
- {
- fprintf(stdout, "%s: %s\n", getTypeClass(typeClass), U2S(keyName));
- bDump = sal_False;
- }
+ dumpTypeClass (bDump, typeClass, keyName);
fprintf(stdout, " Method %d, Exception %d: Name1 = %s != Name2 = %s\n", index, i,
U2S(reader1.getMethodExceptionTypeName(index, i)),
U2S(reader2.getMethodExceptionTypeName(index, i)));
@@ -1097,20 +861,12 @@ static sal_uInt32 checkMethod(const OUString& keyName,
}
if ( i < nExcep1 && options.forceOutput() )
{
- if ( bDump )
- {
- fprintf(stdout, "%s: %s\n", getTypeClass(typeClass), U2S(keyName));
- bDump = sal_False;
- }
+ dumpTypeClass (bDump, typeClass, keyName);
fprintf(stdout, " Registry1: Method %d contains %d more exceptions\n", index, nExcep1 - i);
}
if ( i < nExcep2 && options.forceOutput() )
{
- if ( bDump )
- {
- fprintf(stdout, "%s: %s\n", getTypeClass(typeClass), U2S(keyName));
- bDump = sal_False;
- }
+ dumpTypeClass (bDump, typeClass, keyName);
fprintf(stdout, " Registry2: Method %d contains %d more exceptions\n", index, nExcep2 - i);
}
@@ -1118,11 +874,7 @@ static sal_uInt32 checkMethod(const OUString& keyName,
{
if ( options.forceOutput() )
{
- if ( bDump )
- {
- fprintf(stdout, "%s: %s\n", getTypeClass(typeClass), U2S(keyName));
- bDump = sal_False;
- }
+ dumpTypeClass (bDump, typeClass, keyName);
fprintf(stdout, " Method %d: Mode1 = %s != Mode2 = %s\n", index,
getMethodMode(reader1.getMethodFlags(index)),
getMethodMode(reader2.getMethodFlags(index)));
@@ -1130,16 +882,11 @@ static sal_uInt32 checkMethod(const OUString& keyName,
nError++;
}
- if ( options.fullCheck() &&
- (reader1.getMethodDocumentation(index) != reader2.getMethodDocumentation(index)) )
+ if ( options.fullCheck() && (reader1.getMethodDocumentation(index) != reader2.getMethodDocumentation(index)) )
{
if ( options.forceOutput() )
{
- if ( bDump )
- {
- fprintf(stdout, "%s: %s\n", getTypeClass(typeClass), U2S(keyName));
- bDump = sal_False;
- }
+ dumpTypeClass (bDump, typeClass, keyName);
fprintf(stdout, " Method %d: Doku1 = %s\n Doku2 = %s\n", index,
U2S(reader1.getMethodDocumentation(index)),
U2S(reader2.getMethodDocumentation(index)));
@@ -1166,73 +913,54 @@ static char const * getReferenceType(RTReferenceType refType)
}
}
-static sal_uInt32 checkReference(const OUString& keyName,
+static sal_uInt32 checkReference(Options_Impl const & options,
+ const OUString& keyName,
RTTypeClass typeClass,
- sal_Bool& bDump,
+ sal_Bool & bDump,
typereg::Reader& reader1,
typereg::Reader& reader2,
sal_uInt16 index1,
sal_uInt16 index2)
{
sal_uInt32 nError = 0;
- if ( reader1.getReferenceTypeName(index1) !=
- reader2.getReferenceTypeName(index2) )
+ if ( reader1.getReferenceTypeName(index1) != reader2.getReferenceTypeName(index2) )
{
if ( options.forceOutput() && !options.unoTypeCheck() )
{
- if ( bDump )
- {
- fprintf(stdout, "%s: %s\n", getTypeClass(typeClass), U2S(keyName));
- bDump = sal_False;
- }
+ dumpTypeClass (bDump, typeClass, keyName);
fprintf(stdout, " Reference %d: Name1 = %s != Name2 = %s\n", index1,
U2S(reader1.getReferenceTypeName(index1)),
U2S(reader2.getReferenceTypeName(index2)));
}
nError++;
}
- if ( reader1.getReferenceTypeName(index1) !=
- reader2.getReferenceTypeName(index2) )
+ if ( reader1.getReferenceTypeName(index1) != reader2.getReferenceTypeName(index2) )
{
if ( options.forceOutput() && !options.unoTypeCheck() )
{
- if ( bDump )
- {
- fprintf(stdout, "%s: %s\n", getTypeClass(typeClass), U2S(keyName));
- bDump = sal_False;
- }
+ dumpTypeClass (bDump, typeClass, keyName);
fprintf(stdout, " Reference %d: Type1 = %s != Type2 = %s\n", index1,
getReferenceType(reader1.getReferenceSort(index1)),
getReferenceType(reader2.getReferenceSort(index2)));
}
nError++;
}
- if ( options.fullCheck() &&
- (reader1.getReferenceDocumentation(index1) != reader2.getReferenceDocumentation(index2)) )
+ if ( options.fullCheck() && (reader1.getReferenceDocumentation(index1) != reader2.getReferenceDocumentation(index2)) )
{
if ( options.forceOutput() && !options.unoTypeCheck() )
{
- if ( bDump )
- {
- fprintf(stdout, "%s: %s\n", getTypeClass(typeClass), U2S(keyName));
- bDump = sal_False;
- }
+ dumpTypeClass (bDump, typeClass, keyName);
fprintf(stdout, " Reference %d: Doku1 = %s\n Doku2 = %s\n", index1,
U2S(reader1.getReferenceDocumentation(index1)),
U2S(reader2.getReferenceDocumentation(index2)));
}
nError++;
}
- if ( reader1.getReferenceFlags(index1) !=
- reader2.getReferenceFlags(index2) )
+ if ( reader1.getReferenceFlags(index1) != reader2.getReferenceFlags(index2) )
{
if ( options.forceOutput() && !options.unoTypeCheck() )
{
- if ( bDump )
- {
- fprintf(stdout, "%s: %s\n", getTypeClass(typeClass), U2S(keyName));
- bDump = sal_False;
- }
+ dumpTypeClass (bDump, typeClass, keyName);
fprintf(stdout, " Reference %d: Access1 = %s != Access2 = %s\n", index1,
getFieldAccess(reader1.getReferenceFlags(index1)).getStr(),
getFieldAccess(reader1.getReferenceFlags(index2)).getStr());
@@ -1242,9 +970,10 @@ static sal_uInt32 checkReference(const OUString& keyName,
return nError;
}
-static sal_uInt32 checkFieldsWithoutOrder(const OUString& keyName,
+static sal_uInt32 checkFieldsWithoutOrder(Options_Impl const & options,
+ const OUString& keyName,
RTTypeClass typeClass,
- sal_Bool& bDump,
+ sal_Bool & bDump,
typereg::Reader& reader1,
typereg::Reader& reader2)
{
@@ -1258,13 +987,9 @@ static sal_uInt32 checkFieldsWithoutOrder(const OUString& keyName,
{
if ( options.forceOutput() )
{
- if ( bDump )
- {
- fprintf(stdout, "%s: %s\n", getTypeClass(typeClass), U2S(keyName));
- bDump = sal_False;
- }
- fprintf(stdout, " %s1 contains %d more properties as %s2\n",
- getTypeClass(typeClass), nFields1-nFields2, getTypeClass(typeClass));
+ dumpTypeClass (bDump, typeClass, keyName);
+ fprintf(stdout, " %s1 contains %d more properties as %s2\n",
+ getTypeClass(typeClass), nFields1-nFields2, getTypeClass(typeClass));
}
}
@@ -1275,7 +1000,7 @@ static sal_uInt32 checkFieldsWithoutOrder(const OUString& keyName,
{
for (j=0; j < nFields2; j++)
{
- if (!checkField(keyName, typeClass, bDump, reader1, reader2, i, j))
+ if (!checkField(options, keyName, typeClass, bDump, reader1, reader2, i, j))
{
bFound = sal_True;
moreProps.insert(j);
@@ -1286,16 +1011,13 @@ static sal_uInt32 checkFieldsWithoutOrder(const OUString& keyName,
{
if (options.forceOutput())
{
- if ( bDump )
- {
- fprintf(stdout, "%s: %s\n", getTypeClass(typeClass), U2S(keyName));
- bDump = sal_False;
- }
+ dumpTypeClass (bDump, typeClass, keyName);
fprintf(stdout, " incompatible change: Field %d ('%s') of r1 is not longer a property of this %s in r2\n",
i, U2S(shortName(reader1.getFieldName(i))), getTypeClass(typeClass));
}
nError++;
- } else
+ }
+ else
{
bFound = sal_False;
}
@@ -1311,12 +1033,10 @@ static sal_uInt32 checkFieldsWithoutOrder(const OUString& keyName,
{
if ( options.forceOutput() )
{
- if ( bDump )
- {
- fprintf(stdout, "%s: %s\n", getTypeClass(typeClass), U2S(keyName));
- bDump = sal_False;
- }
- fprintf(stdout, " incompatible change: Field %d ('%s') of r2 is a new property compared to this %s in r1 and is not 'optional'\n",
+ dumpTypeClass (bDump, typeClass, keyName);
+ fprintf(stdout,
+ " incompatible change: Field %d ('%s') of r2 is a new property"
+ " compared to this %s in r1 and is not 'optional'\n",
j, U2S(shortName(reader2.getFieldName(j))), getTypeClass(typeClass));
}
nError++;
@@ -1328,8 +1048,11 @@ static sal_uInt32 checkFieldsWithoutOrder(const OUString& keyName,
return nError;
}
-static sal_uInt32 checkBlob(const OUString& keyName, typereg::Reader& reader1, sal_uInt32 size1,
- typereg::Reader& reader2, sal_uInt32 size2)
+static sal_uInt32 checkBlob(
+ Options_Impl const & options,
+ const OUString& keyName,
+ typereg::Reader& reader1, sal_uInt32 size1,
+ typereg::Reader& reader2, sal_uInt32 size2)
{
sal_uInt32 nError = 0;
sal_Bool bDump = sal_True;
@@ -1344,28 +1067,27 @@ static sal_uInt32 checkBlob(const OUString& keyName, typereg::Reader& reader1, s
sal::static_int_cast< unsigned long >(size2));
}
}
- if (reader1.isPublished()) {
- if (!reader2.isPublished()) {
- if (options.forceOutput()) {
- if (bDump) {
- fprintf(stdout, "?: %s\n", U2S(keyName));
- bDump = false;
- }
+ if (reader1.isPublished())
+ {
+ if (!reader2.isPublished())
+ {
+ if (options.forceOutput())
+ {
+ dumpTypeClass(bDump, /*"?"*/ reader1.getTypeClass(), keyName);
fprintf(stdout, " published in 1 but unpublished in 2\n");
}
++nError;
}
- } else if (!options.checkUnpublished()) {
+ }
+ else if (!options.checkUnpublished())
+ {
return nError;
}
if ( reader1.getTypeClass() != reader2.getTypeClass() )
{
if ( options.forceOutput() )
{
- if (bDump) {
- fprintf(stdout, "?: %s\n", U2S(keyName));
- bDump = sal_False;
- }
+ dumpTypeClass(bDump, /*"?"*/ reader1.getTypeClass(), keyName);
fprintf(stdout, " TypeClass1 = %s != TypeClass2 = %s\n",
getTypeClass(reader1.getTypeClass()),
getTypeClass(reader2.getTypeClass()));
@@ -1374,16 +1096,11 @@ static sal_uInt32 checkBlob(const OUString& keyName, typereg::Reader& reader1, s
}
RTTypeClass typeClass = reader1.getTypeClass();
-
if ( reader1.getTypeName() != reader2.getTypeName() )
{
if ( options.forceOutput() )
{
- if ( bDump )
- {
- fprintf(stdout, "%s: %s\n", getTypeClass(typeClass), U2S(keyName));
- bDump = sal_False;
- }
+ dumpTypeClass(bDump, typeClass, keyName);
fprintf(stdout, " TypeName1 = %s != TypeName2 = %s\n",
U2S(reader1.getTypeName()), U2S(reader2.getTypeName()));
}
@@ -1393,28 +1110,23 @@ static sal_uInt32 checkBlob(const OUString& keyName, typereg::Reader& reader1, s
typeClass == RT_TYPE_STRUCT ||
typeClass == RT_TYPE_EXCEPTION) )
{
- if (reader1.getSuperTypeCount() != reader2.getSuperTypeCount()) {
- if (bDump) {
- fprintf(
- stdout, "%s: %s\n", getTypeClass(typeClass), U2S(keyName));
- bDump = false;
- }
+ if (reader1.getSuperTypeCount() != reader2.getSuperTypeCount())
+ {
+ dumpTypeClass(bDump, typeClass, keyName);
fprintf(
stdout, " SuperTypeCount1 = %d != SuperTypeCount2 = %d\n",
static_cast< int >(reader1.getSuperTypeCount()),
static_cast< int >(reader2.getSuperTypeCount()));
++nError;
- } else {
- for (sal_Int16 i = 0; i < reader1.getSuperTypeCount(); ++i) {
+ } else
+ {
+ for (sal_Int16 i = 0; i < reader1.getSuperTypeCount(); ++i)
+ {
if (reader1.getSuperTypeName(i) != reader2.getSuperTypeName(i))
{
if ( options.forceOutput() )
{
- if ( bDump )
- {
- fprintf(stdout, "%s: %s\n", getTypeClass(typeClass), U2S(keyName));
- bDump = sal_False;
- }
+ dumpTypeClass(bDump, typeClass, keyName);
fprintf(stdout, " SuperTypeName1 = %s != SuperTypeName2 = %s\n",
U2S(reader1.getSuperTypeName(i)), U2S(reader2.getSuperTypeName(i)));
}
@@ -1423,6 +1135,7 @@ static sal_uInt32 checkBlob(const OUString& keyName, typereg::Reader& reader1, s
}
}
}
+
sal_uInt16 nFields1 = (sal_uInt16)reader1.getFieldCount();
sal_uInt16 nFields2 = (sal_uInt16)reader2.getFieldCount();
sal_Bool bCheckNormal = sal_True;
@@ -1440,41 +1153,31 @@ static sal_uInt32 checkBlob(const OUString& keyName, typereg::Reader& reader1, s
{
if ( options.forceOutput() )
{
- if ( bDump )
- {
- fprintf(stdout, "%s: %s\n", getTypeClass(typeClass), U2S(keyName));
- bDump = sal_False;
- }
+ dumpTypeClass(bDump, typeClass, keyName);
fprintf(stdout, " nFields1 = %d != nFields2 = %d\n", nFields1, nFields2);
}
nError++;
}
+
sal_uInt16 i;
for (i=0; i < nFields1 && i < nFields2; i++)
{
- nError += checkField(keyName, typeClass, bDump, reader1, reader2, i, i);
+ nError += checkField(options, keyName, typeClass, bDump, reader1, reader2, i, i);
}
if ( i < nFields1 && options.forceOutput() )
{
- if ( bDump )
- {
- fprintf(stdout, "%s: %s\n", getTypeClass(typeClass), U2S(keyName));
- bDump = sal_False;
- }
+ dumpTypeClass(bDump, typeClass, keyName);
fprintf(stdout, " Registry1 contains %d more fields\n", nFields1 - i);
}
if ( i < nFields2 && options.forceOutput() )
{
- if ( bDump )
- {
- fprintf(stdout, "%s: %s\n", getTypeClass(typeClass), U2S(keyName));
- bDump = sal_False;
- }
+ dumpTypeClass(bDump, typeClass, keyName);
fprintf(stdout, " Registry2 contains %d more fields\n", nFields2 - i);
}
- } else
+ }
+ else
{
- nError += checkFieldsWithoutOrder(keyName, typeClass, bDump, reader1, reader2);
+ nError += checkFieldsWithoutOrder(options, keyName, typeClass, bDump, reader1, reader2);
}
if ( typeClass == RT_TYPE_INTERFACE )
@@ -1485,19 +1188,16 @@ static sal_uInt32 checkBlob(const OUString& keyName, typereg::Reader& reader1, s
{
if ( options.forceOutput() )
{
- if ( bDump )
- {
- fprintf(stdout, "%s: %s\n", getTypeClass(typeClass), U2S(keyName));
- bDump = sal_False;
- }
+ dumpTypeClass(bDump, typeClass, keyName);
fprintf(stdout, " nMethods1 = %d != nMethods2 = %d\n", nMethods1, nMethods2);
}
nError++;
}
+
sal_uInt16 i;
for (i=0; i < nMethods1 && i < nMethods2; i++)
{
- nError += checkMethod(keyName, typeClass, bDump, reader1, reader2, i);
+ nError += checkMethod(options, keyName, typeClass, bDump, reader1, reader2, i);
}
if ( i < nMethods1 && options.forceOutput() )
{
@@ -1521,11 +1221,7 @@ static sal_uInt32 checkBlob(const OUString& keyName, typereg::Reader& reader1, s
{
if ( options.forceOutput() )
{
- if ( bDump )
- {
- fprintf(stdout, "%s: %s\n", getTypeClass(typeClass), U2S(keyName));
- bDump = sal_False;
- }
+ dumpTypeClass(bDump, typeClass, keyName);
fprintf(stdout, " service1 contains %d more references as service2\n",
nReference1-nReference2);
}
@@ -1538,7 +1234,7 @@ static sal_uInt32 checkBlob(const OUString& keyName, typereg::Reader& reader1, s
{
for (j=0; j < nReference2; j++)
{
- if (!checkReference(keyName, typeClass, bDump, reader1, reader2, i, j))
+ if (!checkReference(options, keyName, typeClass, bDump, reader1, reader2, i, j))
{
bFound = sal_True;
moreReferences.insert(j);
@@ -1549,16 +1245,15 @@ static sal_uInt32 checkBlob(const OUString& keyName, typereg::Reader& reader1, s
{
if (options.forceOutput())
{
- if ( bDump )
- {
- fprintf(stdout, "%s: %s\n", getTypeClass(typeClass), U2S(keyName));
- bDump = sal_False;
- }
- fprintf(stdout, " incompatible change: Reference %d ('%s') in 'r1' is not longer a reference of this service in 'r2'\n",
+ dumpTypeClass(bDump, typeClass, keyName);
+ fprintf(stdout,
+ " incompatible change: Reference %d ('%s') in 'r1' is not longer a reference"
+ " of this service in 'r2'\n",
i, U2S(shortName(reader1.getReferenceTypeName(i))));
}
nError++;
- } else
+ }
+ else
{
bFound = sal_False;
}
@@ -1574,12 +1269,10 @@ static sal_uInt32 checkBlob(const OUString& keyName, typereg::Reader& reader1, s
{
if ( options.forceOutput() )
{
- if ( bDump )
- {
- fprintf(stdout, "%s: %s\n", getTypeClass(typeClass), U2S(keyName));
- bDump = sal_False;
- }
- fprintf(stdout, " incompatible change: Reference %d ('%s') of r2 is a new reference compared to this service in r1 and is not 'optional'\n",
+ dumpTypeClass(bDump, typeClass, keyName);
+ fprintf(stdout,
+ " incompatible change: Reference %d ('%s') of r2 is a new reference"
+ " compared to this service in r1 and is not 'optional'\n",
j, U2S(shortName(reader2.getReferenceTypeName(j))));
}
nError++;
@@ -1587,25 +1280,23 @@ static sal_uInt32 checkBlob(const OUString& keyName, typereg::Reader& reader1, s
}
}
}
- } else
+ }
+ else
{
if ( nReference1 != nReference2 )
{
if ( options.forceOutput() )
{
- if ( bDump )
- {
- fprintf(stdout, "%s: %s\n", getTypeClass(typeClass), U2S(keyName));
- bDump = sal_False;
- }
+ dumpTypeClass(bDump, typeClass, keyName);
fprintf(stdout, " nReferences1 = %d != nReferences2 = %d\n", nReference1, nReference2);
}
nError++;
}
+
sal_uInt16 i;
for (i=0; i < nReference1 && i < nReference2; i++)
{
- nError += checkReference(keyName, typeClass, bDump, reader1, reader2, i, i);
+ nError += checkReference(options, keyName, typeClass, bDump, reader1, reader2, i, i);
}
if ( i < nReference1 && options.forceOutput() )
{
@@ -1622,38 +1313,19 @@ static sal_uInt32 checkBlob(const OUString& keyName, typereg::Reader& reader1, s
{
if ( options.forceOutput() )
{
- if ( bDump )
- {
- fprintf(stdout, "%s: %s\n", getTypeClass(typeClass), U2S(keyName));
- bDump = sal_False;
- }
+ dumpTypeClass(bDump, typeClass, keyName);
fprintf(stdout, " Doku1 = %s\n Doku2 = %s\n",
U2S(reader1.getDocumentation()), U2S(reader2.getDocumentation()));
}
nError++;
}
-/*
- if ( nError &&
- (!keyName.compareTo(OUString(RTL_CONSTASCII_USTRINGPARAM("/UCR/drafts")), 11) ||
- !keyName.compareTo(OUString(RTL_CONSTASCII_USTRINGPARAM("/drafts")), 7)) )
- {
- if ( options.forceOutput() )
- {
- if ( bDump )
- {
- fprintf(stdout, "%s: %s\n", getTypeClass(typeClass), U2S(keyName));
- bDump = sal_False;
- }
- fprintf(stdout, " Note: \"drafts\" type changed incompatible, no effect to the final API\n");
- }
- return 0;
- }
-*/
return nError;
}
-static sal_uInt32 checkValueDifference(RegistryKey& key1, RegValueType valueType1, sal_uInt32 size1,
- RegistryKey& key2, RegValueType valueType2, sal_uInt32 size2)
+static sal_uInt32 checkValueDifference(
+ Options_Impl const & options,
+ RegistryKey& key1, RegValueType valueType1, sal_uInt32 size1,
+ RegistryKey& key2, RegValueType valueType2, sal_uInt32 size2)
{
OUString tmpName;
sal_uInt32 nError = 0;
@@ -1738,39 +1410,31 @@ static sal_uInt32 checkValueDifference(RegistryKey& key1, RegValueType valueType
if ( bEqual)
{
- RegValue value1 = rtl_allocateMemory(size1);
- RegValue value2 = rtl_allocateMemory(size2);
+ std::vector< sal_uInt8 > value1(size1);
+ key1.getValue(tmpName, &value1[0]);
- key1.getValue(tmpName, value1);
- key2.getValue(tmpName, value2);
-
- bEqual = (rtl_compareMemory(value1, value2, size1) == 0 );
+ std::vector< sal_uInt8 > value2(size2);
+ key2.getValue(tmpName, &value2[0]);
+ bEqual = (rtl_compareMemory(&value1[0], &value2[0], value1.size()) == 0 );
if ( !bEqual && valueType1 == RG_VALUETYPE_BINARY && valueType2 == RG_VALUETYPE_BINARY )
{
- typereg::Reader reader1(
- value1, size1, false, TYPEREG_VERSION_1);
- typereg::Reader reader2(
- value2, size2, false, TYPEREG_VERSION_1);
-
+ typereg::Reader reader1(&value1[0], value1.size(), false, TYPEREG_VERSION_1);
+ typereg::Reader reader2(&value2[0], value2.size(), false, TYPEREG_VERSION_1);
if ( reader1.isValid() && reader2.isValid() )
{
- return checkBlob(key1.getName(), reader1, size1, reader2, size2);
+ return checkBlob(options, key1.getName(), reader1, size1, reader2, size2);
}
}
-
- rtl_freeMemory(value1);
- rtl_freeMemory(value2);
-
if ( bEqual )
{
return 0;
- } else
+ }
+ else
{
if ( options.forceOutput() )
{
- fprintf(stdout, "Difference: key values of key \"%s\" are different\n",
- U2S(key1.getName()));
+ fprintf(stdout, "Difference: key values of key \"%s\" are different\n", U2S(key1.getName()));
}
nError++;
}
@@ -1785,102 +1449,98 @@ static sal_uInt32 checkValueDifference(RegistryKey& key1, RegValueType valueType
fprintf(stdout, " Registry 1: key has no value\n");
break;
case RG_VALUETYPE_LONG:
- case RG_VALUETYPE_STRING:
- case RG_VALUETYPE_UNICODE:
- {
- RegValue value1 = rtl_allocateMemory(size1);
- key1.getValue(tmpName, value1);
-
- switch (valueType1)
{
- case RG_VALUETYPE_LONG:
+ std::vector< sal_uInt8 > value1(size1);
+ key1.getValue(tmpName, &value1[0]);
+
fprintf(stdout, " Registry 1: Value: Type = RG_VALUETYPE_LONG\n");
fprintf(
stdout, " Size = %lu\n",
sal::static_int_cast< unsigned long >(size1));
- fprintf(stdout, " Data = %p\n", value1);
- break;
- case RG_VALUETYPE_STRING:
+ fprintf(stdout, " Data = %p\n", &value1[0]);
+ }
+ break;
+ case RG_VALUETYPE_STRING:
+ {
+ std::vector< sal_uInt8 > value1(size1);
+ key1.getValue(tmpName, &value1[0]);
+
fprintf(stdout, " Registry 1: Value: Type = RG_VALUETYPE_STRING\n");
fprintf(
stdout, " Size = %lu\n",
sal::static_int_cast< unsigned long >(size1));
- fprintf(stdout, " Data = \"%s\"\n", (sal_Char*)value1);
- break;
- case RG_VALUETYPE_UNICODE:
- {
- OUString uStrValue((sal_Unicode*)value1);
+ fprintf(stdout, " Data = \"%s\"\n", reinterpret_cast<char const*>(&value1[0]));
+ }
+ break;
+ case RG_VALUETYPE_UNICODE:
+ {
+ std::vector< sal_uInt8 > value1(size1);
+ key1.getValue(tmpName, &value1[0]);
+
+ OUString uStrValue(reinterpret_cast<sal_Unicode const*>(&value1[0]));
fprintf(stdout, " Registry 1: Value: Type = RG_VALUETYPE_UNICODE\n");
fprintf(
stdout, " Size = %lu\n",
sal::static_int_cast< unsigned long >(size1));
fprintf(stdout, " Data = \"%s\"\n", U2S(uStrValue));
- }
- break;
- default:
- OSL_ASSERT(false);
- break;
}
-
- rtl_freeMemory(value1);
- }
break;
case RG_VALUETYPE_BINARY:
fprintf(stdout, " Registry 1: Value: Type = RG_VALUETYPE_BINARY\n");
break;
case RG_VALUETYPE_LONGLIST:
{
- RegistryValueList<sal_Int32> valueList;
- key1.getLongListValue(tmpName, valueList);
- fprintf(stdout, " Registry 1: Value: Type = RG_VALUETYPE_LONGLIST\n");
- fprintf(
- stdout, " Size = %lu\n",
- sal::static_int_cast< unsigned long >(size1));
- sal_uInt32 length = valueList.getLength();
- for (sal_uInt32 i=0; i<length; i++)
- {
+ RegistryValueList<sal_Int32> valueList;
+ key1.getLongListValue(tmpName, valueList);
+ fprintf(stdout, " Registry 1: Value: Type = RG_VALUETYPE_LONGLIST\n");
fprintf(
- stdout, " Data[%lu] = %ld\n",
- sal::static_int_cast< unsigned long >(i),
- sal::static_int_cast< long >(valueList.getElement(i)));
- }
+ stdout, " Size = %lu\n",
+ sal::static_int_cast< unsigned long >(size1));
+ sal_uInt32 length = valueList.getLength();
+ for (sal_uInt32 i=0; i<length; i++)
+ {
+ fprintf(
+ stdout, " Data[%lu] = %ld\n",
+ sal::static_int_cast< unsigned long >(i),
+ sal::static_int_cast< long >(valueList.getElement(i)));
+ }
}
break;
case RG_VALUETYPE_STRINGLIST:
{
- RegistryValueList<sal_Char*> valueList;
- key1.getStringListValue(tmpName, valueList);
- fprintf(stdout, " Registry 1: Value: Type = RG_VALUETYPE_STRINGLIST\n");
- fprintf(
- stdout, " Size = %lu\n",
- sal::static_int_cast< unsigned long >(size1));
- sal_uInt32 length = valueList.getLength();
- for (sal_uInt32 i=0; i<length; i++)
- {
+ RegistryValueList<sal_Char*> valueList;
+ key1.getStringListValue(tmpName, valueList);
+ fprintf(stdout, " Registry 1: Value: Type = RG_VALUETYPE_STRINGLIST\n");
fprintf(
- stdout, " Data[%lu] = \"%s\"\n",
- sal::static_int_cast< unsigned long >(i),
- valueList.getElement(i));
- }
+ stdout, " Size = %lu\n",
+ sal::static_int_cast< unsigned long >(size1));
+ sal_uInt32 length = valueList.getLength();
+ for (sal_uInt32 i=0; i<length; i++)
+ {
+ fprintf(
+ stdout, " Data[%lu] = \"%s\"\n",
+ sal::static_int_cast< unsigned long >(i),
+ valueList.getElement(i));
+ }
}
break;
case RG_VALUETYPE_UNICODELIST:
{
- RegistryValueList<sal_Unicode*> valueList;
- key1.getUnicodeListValue(tmpName, valueList);
- fprintf(stdout, " Registry 1: Value: Type = RG_VALUETYPE_UNICODELIST\n");
- fprintf(
- stdout, " Size = %lu\n",
- sal::static_int_cast< unsigned long >(size1));
- sal_uInt32 length = valueList.getLength();
- OUString uStrValue;
- for (sal_uInt32 i=0; i<length; i++)
- {
- uStrValue = OUString(valueList.getElement(i));
+ RegistryValueList<sal_Unicode*> valueList;
+ key1.getUnicodeListValue(tmpName, valueList);
+ fprintf(stdout, " Registry 1: Value: Type = RG_VALUETYPE_UNICODELIST\n");
fprintf(
- stdout, " Data[%lu] = \"%s\"\n",
- sal::static_int_cast< unsigned long >(i), U2S(uStrValue));
- }
+ stdout, " Size = %lu\n",
+ sal::static_int_cast< unsigned long >(size1));
+ sal_uInt32 length = valueList.getLength();
+ OUString uStrValue;
+ for (sal_uInt32 i=0; i<length; i++)
+ {
+ uStrValue = OUString(valueList.getElement(i));
+ fprintf(
+ stdout, " Data[%lu] = \"%s\"\n",
+ sal::static_int_cast< unsigned long >(i), U2S(uStrValue));
+ }
}
break;
}
@@ -1891,102 +1551,98 @@ static sal_uInt32 checkValueDifference(RegistryKey& key1, RegValueType valueType
fprintf(stdout, " Registry 2: key has no value\n");
break;
case RG_VALUETYPE_LONG:
- case RG_VALUETYPE_STRING:
- case RG_VALUETYPE_UNICODE:
- {
- RegValue value2 = rtl_allocateMemory(size2);
- key2.getValue(tmpName, value2);
-
- switch (valueType2)
{
- case RG_VALUETYPE_LONG:
+ std::vector< sal_uInt8 > value2(size2);
+ key2.getValue(tmpName, &value2[0]);
+
fprintf(stdout, " Registry 2: Value: Type = RG_VALUETYPE_LONG\n");
fprintf(
stdout, " Size = %lu\n",
sal::static_int_cast< unsigned long >(size2));
- fprintf(stdout, " Data = %p\n", value2);
- break;
- case RG_VALUETYPE_STRING:
+ fprintf(stdout, " Data = %p\n", &value2[0]);
+ }
+ break;
+ case RG_VALUETYPE_STRING:
+ {
+ std::vector< sal_uInt8 > value2(size2);
+ key2.getValue(tmpName, &value2[0]);
+
fprintf(stdout, " Registry 2: Value: Type = RG_VALUETYPE_STRING\n");
fprintf(
stdout, " Size = %lu\n",
sal::static_int_cast< unsigned long >(size2));
- fprintf(stdout, " Data = \"%s\"\n", (sal_Char*)value2);
- break;
- case RG_VALUETYPE_UNICODE:
- {
- OUString uStrValue((sal_Unicode*)value2);
+ fprintf(stdout, " Data = \"%s\"\n", reinterpret_cast<char const*>(&value2[0]));
+ }
+ break;
+ case RG_VALUETYPE_UNICODE:
+ {
+ std::vector< sal_uInt8 > value2(size2);
+ key2.getValue(tmpName, &value2[0]);
+
+ OUString uStrValue(reinterpret_cast<sal_Unicode const*>(&value2[0]));
fprintf(stdout, " Registry 2: Value: Type = RG_VALUETYPE_UNICODE\n");
fprintf(
stdout, " Size = %lu\n",
sal::static_int_cast< unsigned long >(size2));
fprintf(stdout, " Data = \"%s\"\n", U2S(uStrValue));
- }
- break;
- default:
- OSL_ASSERT(false);
- break;
}
-
- rtl_freeMemory(value2);
- }
break;
case RG_VALUETYPE_BINARY:
fprintf(stdout, " Registry 2: Value: Type = RG_VALUETYPE_BINARY\n");
break;
case RG_VALUETYPE_LONGLIST:
{
- RegistryValueList<sal_Int32> valueList;
- key2.getLongListValue(tmpName, valueList);
- fprintf(stdout, " Registry 2: Value: Type = RG_VALUETYPE_LONGLIST\n");
- fprintf(
- stdout, " Size = %lu\n",
- sal::static_int_cast< unsigned long >(size2));
- sal_uInt32 length = valueList.getLength();
- for (sal_uInt32 i=0; i<length; i++)
- {
+ RegistryValueList<sal_Int32> valueList;
+ key2.getLongListValue(tmpName, valueList);
+ fprintf(stdout, " Registry 2: Value: Type = RG_VALUETYPE_LONGLIST\n");
fprintf(
- stdout, " Data[%lu] = %ld\n",
- sal::static_int_cast< unsigned long >(i),
- sal::static_int_cast< long >(valueList.getElement(i)));
- }
+ stdout, " Size = %lu\n",
+ sal::static_int_cast< unsigned long >(size2));
+ sal_uInt32 length = valueList.getLength();
+ for (sal_uInt32 i=0; i<length; i++)
+ {
+ fprintf(
+ stdout, " Data[%lu] = %ld\n",
+ sal::static_int_cast< unsigned long >(i),
+ sal::static_int_cast< long >(valueList.getElement(i)));
+ }
}
break;
case RG_VALUETYPE_STRINGLIST:
{
- RegistryValueList<sal_Char*> valueList;
- key2.getStringListValue(tmpName, valueList);
- fprintf(stdout, " Registry 2: Value: Type = RG_VALUETYPE_STRINGLIST\n");
- fprintf(
- stdout, " Size = %lu\n",
- sal::static_int_cast< unsigned long >(size2));
- sal_uInt32 length = valueList.getLength();
- for (sal_uInt32 i=0; i<length; i++)
- {
+ RegistryValueList<sal_Char*> valueList;
+ key2.getStringListValue(tmpName, valueList);
+ fprintf(stdout, " Registry 2: Value: Type = RG_VALUETYPE_STRINGLIST\n");
fprintf(
- stdout, " Data[%lu] = \"%s\"\n",
- sal::static_int_cast< unsigned long >(i),
- valueList.getElement(i));
- }
+ stdout, " Size = %lu\n",
+ sal::static_int_cast< unsigned long >(size2));
+ sal_uInt32 length = valueList.getLength();
+ for (sal_uInt32 i=0; i<length; i++)
+ {
+ fprintf(
+ stdout, " Data[%lu] = \"%s\"\n",
+ sal::static_int_cast< unsigned long >(i),
+ valueList.getElement(i));
+ }
}
break;
case RG_VALUETYPE_UNICODELIST:
{
- RegistryValueList<sal_Unicode*> valueList;
- key2.getUnicodeListValue(tmpName, valueList);
- fprintf(stdout, " Registry 2: Value: Type = RG_VALUETYPE_UNICODELIST\n");
- fprintf(
- stdout, " Size = %lu\n",
- sal::static_int_cast< unsigned long >(size2));
- sal_uInt32 length = valueList.getLength();
- OUString uStrValue;
- for (sal_uInt32 i=0; i<length; i++)
- {
- uStrValue = OUString(valueList.getElement(i));
+ RegistryValueList<sal_Unicode*> valueList;
+ key2.getUnicodeListValue(tmpName, valueList);
+ fprintf(stdout, " Registry 2: Value: Type = RG_VALUETYPE_UNICODELIST\n");
fprintf(
- stdout, " Data[%lu] = \"%s\"\n",
- sal::static_int_cast< unsigned long >(i), U2S(uStrValue));
- }
+ stdout, " Size = %lu\n",
+ sal::static_int_cast< unsigned long >(size2));
+ sal_uInt32 length = valueList.getLength();
+ OUString uStrValue;
+ for (sal_uInt32 i=0; i<length; i++)
+ {
+ uStrValue = OUString(valueList.getElement(i));
+ fprintf(
+ stdout, " Data[%lu] = \"%s\"\n",
+ sal::static_int_cast< unsigned long >(i), U2S(uStrValue));
+ }
}
break;
}
@@ -1994,58 +1650,67 @@ static sal_uInt32 checkValueDifference(RegistryKey& key1, RegValueType valueType
return nError;
}
-static bool hasPublishedChildren(RegistryKey & key) {
+static bool hasPublishedChildren(Options_Impl const & options, RegistryKey & key)
+{
RegistryKeyNames subKeyNames;
key.getKeyNames(rtl::OUString(), subKeyNames);
- for (sal_uInt32 i = 0; i < subKeyNames.getLength(); ++i) {
+ for (sal_uInt32 i = 0; i < subKeyNames.getLength(); ++i)
+ {
rtl::OUString keyName(subKeyNames.getElement(i));
- if (!options.matchedWithExcludeKey(keyName)) {
+ if (!options.matchedWithExcludeKey(keyName))
+ {
keyName = keyName.copy(keyName.lastIndexOf('/') + 1);
RegistryKey subKey;
- if (!key.openKey(keyName, subKey)) {
- if (options.forceOutput()) {
+ if (!key.openKey(keyName, subKey))
+ {
+ if (options.forceOutput())
+ {
fprintf(
stdout,
("WARNING: could not open key \"%s\" in registry"
" \"%s\"\n"),
U2S(subKeyNames.getElement(i)),
- options.getRegName1().getStr());
+ options.getRegName1().c_str());
}
}
- if (subKey.isValid()) {
+ if (subKey.isValid())
+ {
RegValueType type;
sal_uInt32 size;
- if (subKey.getValueInfo(rtl::OUString(), &type, &size)
- != REG_NO_ERROR)
+ if (subKey.getValueInfo(rtl::OUString(), &type, &size) != REG_NO_ERROR)
{
- if (options.forceOutput()) {
+ if (options.forceOutput())
+ {
fprintf(
stdout,
("WARNING: could not read key \"%s\" in registry"
" \"%s\"\n"),
U2S(subKeyNames.getElement(i)),
- options.getRegName1().getStr());
+ options.getRegName1().c_str());
}
- } else if (type == RG_VALUETYPE_BINARY) {
- char * value = new char[size];
+ }
+ else if (type == RG_VALUETYPE_BINARY)
+ {
bool published = false;
- if (subKey.getValue(rtl::OUString(), value) != REG_NO_ERROR)
+ std::vector< sal_uInt8 > value(size);
+ if (subKey.getValue(rtl::OUString(), &value[0]) != REG_NO_ERROR)
{
- if (options.forceOutput()) {
+ if (options.forceOutput())
+ {
fprintf(
stdout,
("WARNING: could not read key \"%s\" in"
" registry \"%s\"\n"),
U2S(subKeyNames.getElement(i)),
- options.getRegName1().getStr());
+ options.getRegName1().c_str());
}
- } else {
- published = typereg::Reader(
- value, size, false, TYPEREG_VERSION_1).
- isPublished();
}
- delete[] value;
- if (published) {
+ else
+ {
+ published = typereg::Reader(&value[0], value.size(), false, TYPEREG_VERSION_1).isPublished();
+ }
+ if (published)
+ {
return true;
}
}
@@ -2056,7 +1721,9 @@ static bool hasPublishedChildren(RegistryKey & key) {
}
static sal_uInt32 checkDifferences(
- RegistryKey& key, StringSet& keys, RegistryKeyNames& subKeyNames1,
+ Options_Impl const & options,
+ RegistryKey& key, StringSet& keys,
+ RegistryKeyNames& subKeyNames1,
RegistryKeyNames& subKeyNames2)
{
sal_uInt32 nError = 0;
@@ -2083,81 +1750,89 @@ static sal_uInt32 checkDifferences(
if ( options.forceOutput() )
{
fprintf(stdout, "EXISTENCE: key \"%s\" exists only in registry \"%s\"\n",
- U2S(subKeyNames1.getElement(i)), options.getRegName1().getStr());
+ U2S(subKeyNames1.getElement(i)), options.getRegName1().c_str());
}
nError++;
}
else
{
rtl::OUString keyName(subKeyNames1.getElement(i));
- if (!options.matchedWithExcludeKey(keyName)) {
+ if (!options.matchedWithExcludeKey(keyName))
+ {
keyName = keyName.copy(keyName.lastIndexOf('/') + 1);
RegistryKey subKey;
- if (key.openKey(keyName, subKey)) {
- if (options.forceOutput()) {
+ if (key.openKey(keyName, subKey))
+ {
+ if (options.forceOutput())
+ {
fprintf(
stdout,
("ERROR: could not open key \"%s\" in registry"
" \"%s\"\n"),
U2S(subKeyNames1.getElement(i)),
- options.getRegName1().getStr());
+ options.getRegName1().c_str());
}
++nError;
}
- if (subKey.isValid()) {
+ if (subKey.isValid())
+ {
RegValueType type;
sal_uInt32 size;
- if (subKey.getValueInfo(rtl::OUString(), &type, &size)
- != REG_NO_ERROR)
+ if (subKey.getValueInfo(rtl::OUString(), &type, &size) != REG_NO_ERROR)
{
- if (options.forceOutput()) {
+ if (options.forceOutput())
+ {
fprintf(
stdout,
("ERROR: could not read key \"%s\" in"
" registry \"%s\"\n"),
U2S(subKeyNames1.getElement(i)),
- options.getRegName1().getStr());
+ options.getRegName1().c_str());
}
++nError;
- } else if (type == RG_VALUETYPE_BINARY) {
- char * value = new char[size];
- if (subKey.getValue(rtl::OUString(), value)
- != REG_NO_ERROR)
+ }
+ else if (type == RG_VALUETYPE_BINARY)
+ {
+ std::vector< sal_uInt8 > value(size);
+ if (subKey.getValue(rtl::OUString(), &value[0]) != REG_NO_ERROR)
{
- if (options.forceOutput()) {
+ if (options.forceOutput())
+ {
fprintf(
stdout,
("ERROR: could not read key \"%s\" in"
" registry \"%s\"\n"),
U2S(subKeyNames1.getElement(i)),
- options.getRegName1().getStr());
+ options.getRegName1().c_str());
}
++nError;
- } else {
- typereg::Reader reader(
- value, size, false, TYPEREG_VERSION_1);
- if (reader.getTypeClass() == RT_TYPE_MODULE) {
- if (options.checkUnpublished()
- || hasPublishedChildren(subKey))
+ }
+ else
+ {
+ typereg::Reader reader(&value[0], value.size(), false, TYPEREG_VERSION_1);
+ if (reader.getTypeClass() == RT_TYPE_MODULE)
+ {
+ if (options.checkUnpublished() || hasPublishedChildren(options, subKey))
{
- if (options.forceOutput()) {
+ if (options.forceOutput())
+ {
fprintf(
stdout,
("EXISTENCE: module \"%s\""
" %sexists only in registry"
" 1\n"),
- U2S(subKeyNames1.getElement(
- i)),
+ U2S(subKeyNames1.getElement(i)),
(options.checkUnpublished()
? ""
: "with published children "));
}
++nError;
}
- } else if (options.checkUnpublished()
- || reader.isPublished())
+ }
+ else if (options.checkUnpublished() || reader.isPublished())
{
- if (options.forceOutput()) {
+ if (options.forceOutput())
+ {
fprintf(
stdout,
("EXISTENCE: %spublished key \"%s\""
@@ -2168,7 +1843,6 @@ static sal_uInt32 checkDifferences(
++nError;
}
}
- delete[] value;
}
}
}
@@ -2193,7 +1867,7 @@ static sal_uInt32 checkDifferences(
if ( options.forceOutput() )
{
fprintf(stdout, "EXISTENCE: key \"%s\" exists only in registry \"%s\"\n",
- U2S(subKeyNames2.getElement(i)), options.getRegName2().getStr());
+ U2S(subKeyNames2.getElement(i)), options.getRegName2().c_str());
}
nError++;
}
@@ -2201,7 +1875,10 @@ static sal_uInt32 checkDifferences(
return nError;
}
-static sal_uInt32 compareKeys(RegistryKey& key1, RegistryKey& key2)
+static sal_uInt32 compareKeys(
+ Options_Impl const & options,
+ RegistryKey& key1,
+ RegistryKey& key2)
{
sal_uInt32 nError = 0;
@@ -2209,16 +1886,17 @@ static sal_uInt32 compareKeys(RegistryKey& key1, RegistryKey& key2)
RegValueType valueType2 = RG_VALUETYPE_NOT_DEFINED;
sal_uInt32 size1 = 0;
sal_uInt32 size2 = 0;
+
OUString tmpName;
RegError e1 = key1.getValueInfo(tmpName, &valueType1, &size1);
RegError e2 = key2.getValueInfo(tmpName, &valueType2, &size2);
-
- if ( e1 == e2 && e1 != REG_VALUE_NOT_EXISTS && e1 != REG_INVALID_VALUE )
+ if ( (e1 == e2) && (e1 != REG_VALUE_NOT_EXISTS) && (e1 != REG_INVALID_VALUE) )
{
- nError += checkValueDifference(key1, valueType1, size1, key2, valueType2, size2);
- } else
+ nError += checkValueDifference(options, key1, valueType1, size1, key2, valueType2, size2);
+ }
+ else
{
- if ( e1 != REG_INVALID_VALUE || e2 != REG_INVALID_VALUE )
+ if ( (e1 != REG_INVALID_VALUE) || (e2 != REG_INVALID_VALUE) )
{
if ( options.forceOutput() )
{
@@ -2235,16 +1913,14 @@ static sal_uInt32 compareKeys(RegistryKey& key1, RegistryKey& key2)
key2.getKeyNames(tmpName, subKeyNames2);
StringSet keys;
- nError += checkDifferences(key1, keys, subKeyNames1, subKeyNames2);
+ nError += checkDifferences(options, key1, keys, subKeyNames1, subKeyNames2);
StringSet::iterator iter = keys.begin();
StringSet::iterator end = keys.end();
- RegistryKey subKey1, subKey2;
- OUString keyName;
while ( iter != end )
{
- keyName = OUString(*iter);
+ OUString keyName(*iter);
if ( options.matchedWithExcludeKey(keyName) )
{
++iter;
@@ -2253,30 +1929,33 @@ static sal_uInt32 compareKeys(RegistryKey& key1, RegistryKey& key2)
sal_Int32 nPos = keyName.lastIndexOf( '/' );
keyName = keyName.copy( nPos != -1 ? nPos+1 : 0 );
+
+ RegistryKey subKey1;
if ( key1.openKey(keyName, subKey1) )
{
if ( options.forceOutput() )
{
fprintf(stdout, "ERROR: could not open key \"%s\" in registry \"%s\"\n",
- U2S(*iter), options.getRegName1().getStr());
+ U2S(*iter), options.getRegName1().c_str());
}
nError++;
}
+
+ RegistryKey subKey2;
if ( key2.openKey(keyName, subKey2) )
{
if ( options.forceOutput() )
{
fprintf(stdout, "ERROR: could not open key \"%s\" in registry \"%s\"\n",
- U2S(*iter), options.getRegName2().getStr());
+ U2S(*iter), options.getRegName2().c_str());
}
nError++;
}
+
if ( subKey1.isValid() && subKey2.isValid() )
{
- nError += compareKeys(subKey1, subKey2);
+ nError += compareKeys(options, subKey1, subKey2);
}
- subKey1.releaseKey();
- subKey2.releaseKey();
++iter;
}
@@ -2289,93 +1968,107 @@ int main( int argc, char * argv[] )
int _cdecl main( int argc, char * argv[] )
#endif
{
- if ( !options.initOptions(argc, argv) )
+ std::vector< std::string > args;
+
+ Options_Impl options(argv[0]);
+ for (int i = 1; i < argc; i++)
{
- exit(1);
+ if (!Options::checkArgument(args, argv[i], strlen(argv[i])))
+ {
+ // failure.
+ options.printUsage();
+ return (1);
+ }
+ }
+ if (!options.initOptions(args))
+ {
+ return (1);
}
- OUString regName1( convertToFileUrl(options.getRegName1()) );
- OUString regName2( convertToFileUrl(options.getRegName2()) );
-
- Registry reg1;
- Registry reg2;
+ OUString regName1( convertToFileUrl(options.getRegName1().c_str(), options.getRegName1().size()) );
+ OUString regName2( convertToFileUrl(options.getRegName2().c_str(), options.getRegName2().size()) );
+ Registry reg1, reg2;
if ( reg1.open(regName1, REG_READONLY) )
{
fprintf(stdout, "%s: open registry \"%s\" failed\n",
- options.getProgramName().getStr(), options.getRegName1().getStr());
- exit(2);
+ options.getProgramName().c_str(), options.getRegName1().c_str());
+ return (2);
}
if ( reg2.open(regName2, REG_READONLY) )
{
fprintf(stdout, "%s: open registry \"%s\" failed\n",
- options.getProgramName().getStr(), options.getRegName2().getStr());
- exit(3);
+ options.getProgramName().c_str(), options.getRegName2().c_str());
+ return (3);
}
RegistryKey key1, key2;
if ( reg1.openRootKey(key1) )
{
fprintf(stdout, "%s: open root key of registry \"%s\" failed\n",
- options.getProgramName().getStr(), options.getRegName1().getStr());
- exit(4);
+ options.getProgramName().c_str(), options.getRegName1().c_str());
+ return (4);
}
if ( reg2.openRootKey(key2) )
{
fprintf(stdout, "%s: open root key of registry \"%s\" failed\n",
- options.getProgramName().getStr(), options.getRegName2().getStr());
- exit(5);
+ options.getProgramName().c_str(), options.getRegName2().c_str());
+ return (5);
}
+
if ( options.isStartKeyValid() )
{
- if ( options.matchedWithExcludeKey( S2U(options.getStartKey()) ) )
+ if ( options.matchedWithExcludeKey( options.getStartKey() ) )
{
fprintf(stdout, "%s: start key is equal to one of the exclude keys\n",
- options.getProgramName().getStr());
- exit(6);
+ options.getProgramName().c_str());
+ return (6);
}
RegistryKey sk1, sk2;
- if ( key1.openKey(S2U(options.getStartKey()), sk1) )
+ if ( key1.openKey(options.getStartKey(), sk1) )
{
fprintf(stdout, "%s: open start key of registry \"%s\" failed\n",
- options.getProgramName().getStr(), options.getRegName1().getStr());
- exit(7);
+ options.getProgramName().c_str(), options.getRegName1().c_str());
+ return (7);
}
- if ( key2.openKey(S2U(options.getStartKey()), sk2) )
+ if ( key2.openKey(options.getStartKey(), sk2) )
{
fprintf(stdout, "%s: open start key of registry \"%s\" failed\n",
- options.getProgramName().getStr(), options.getRegName2().getStr());
- exit(8);
+ options.getProgramName().c_str(), options.getRegName2().c_str());
+ return (8);
}
key1 = sk1;
key2 = sk2;
}
- sal_uInt32 nError = compareKeys(key1, key2);
+ sal_uInt32 nError = compareKeys(options, key1, key2);
if ( nError )
{
if ( options.unoTypeCheck() )
{
fprintf(stdout, "%s: registries are incompatible: %lu differences!\n",
- options.getProgramName().getStr(),
+ options.getProgramName().c_str(),
sal::static_int_cast< unsigned long >(nError));
- } else
+ }
+ else
{
fprintf(stdout, "%s: registries contain %lu differences!\n",
- options.getProgramName().getStr(),
+ options.getProgramName().c_str(),
sal::static_int_cast< unsigned long >(nError));
}
- } else
+ }
+ else
{
if ( options.unoTypeCheck() )
{
fprintf(stdout, "%s: registries are compatible!\n",
- options.getProgramName().getStr());
- } else
+ options.getProgramName().c_str());
+ }
+ else
{
fprintf(stdout, "%s: registries are equal!\n",
- options.getProgramName().getStr());
+ options.getProgramName().c_str());
}
}
@@ -2384,18 +2077,17 @@ int _cdecl main( int argc, char * argv[] )
if ( reg1.close() )
{
fprintf(stdout, "%s: closing registry \"%s\" failed\n",
- options.getProgramName().getStr(), options.getRegName1().getStr());
- exit(9);
+ options.getProgramName().c_str(), options.getRegName1().c_str());
+ return (9);
}
if ( reg2.close() )
{
fprintf(stdout, "%s: closing registry \"%s\" failed\n",
- options.getProgramName().getStr(), options.getRegName2().getStr());
- exit(10);
+ options.getProgramName().c_str(), options.getRegName2().c_str());
+ return (10);
}
- return nError > 0 ? 11 : 0;
+ return ((nError > 0) ? 11 : 0);
}
-
-/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ \ No newline at end of file
diff --git a/registry/tools/regmerge.cxx b/registry/tools/regmerge.cxx
index 81568a282128..9e25bc56f396 100644
--- a/registry/tools/regmerge.cxx
+++ b/registry/tools/regmerge.cxx
@@ -29,70 +29,35 @@
// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_registry.hxx"
-#include <stdio.h>
-#include <string.h>
-
#include "registry/registry.hxx"
-#include <rtl/ustring.hxx>
-#include <rtl/alloc.h>
-#include <osl/process.h>
-#include <osl/diagnose.h>
-#include <osl/thread.h>
-#include <osl/file.hxx>
+#include "fileurl.hxx"
+#include "options.hxx"
-#ifdef SAL_UNX
-#define SEPARATOR '/'
-#else
-#define SEPARATOR '\\'
-#endif
+#include "rtl/ustring.hxx"
+#include "osl/diagnose.h"
-using namespace ::rtl;
-using namespace ::osl;
+#include <stdio.h>
+#include <string.h>
-sal_Bool isFileUrl(const OString& fileName)
-{
- if (fileName.indexOf("file://") == 0 )
- return sal_True;
- return sal_False;
-}
+using namespace rtl;
+using namespace registry::tools;
-OUString convertToFileUrl(const OString& fileName)
+class Options_Impl : public Options
{
- if ( isFileUrl(fileName) )
- {
- return OStringToOUString(fileName, osl_getThreadTextEncoding());
- }
+ bool m_bVerbose;
- OUString uUrlFileName;
- OUString uFileName(fileName.getStr(), fileName.getLength(), osl_getThreadTextEncoding());
- if ( fileName.indexOf('.') == 0 || fileName.indexOf(SEPARATOR) < 0 )
- {
- OUString uWorkingDir;
- if (osl_getProcessWorkingDir(&uWorkingDir.pData) != osl_Process_E_None)
- {
- OSL_ASSERT(false);
- }
- if (FileBase::getAbsoluteFileURL(uWorkingDir, uFileName, uUrlFileName)
- != FileBase::E_None)
- {
- OSL_ASSERT(false);
- }
- } else
- {
- if (FileBase::getFileURLFromSystemPath(uFileName, uUrlFileName)
- != FileBase::E_None)
- {
- OSL_ASSERT(false);
- }
- }
-
- return uUrlFileName;
-}
+public:
+ explicit Options_Impl (char const * program)
+ : Options(program), m_bVerbose(false)
+ {}
+ bool isVerbose() const { return m_bVerbose; }
-int realargc;
-char* realargv[2048];
+protected:
+ virtual void printUsage_Impl() const;
+ virtual bool initOptions_Impl(std::vector< std::string > & rArgs);
+};
-static void dumpHelp()
+void Options_Impl::printUsage_Impl() const
{
fprintf(stderr, "using: regmerge [-v|--verbose] mergefile mergeKeyName regfile_1 ... regfile_n\n");
fprintf(stderr, " regmerge @regcmds\nOptions:\n");
@@ -104,181 +69,114 @@ static void dumpHelp()
fprintf(stderr, " regfile_1..n : specifies one or more registry files which are merged.\n");
}
-static bool checkCommandFile(char* cmdfile)
+bool Options_Impl::initOptions_Impl (std::vector< std::string > & rArgs)
{
- FILE *commandfile;
- char option[256];
- bool bVerbose = false;
-
- commandfile = fopen(cmdfile+1, "r");
- if( commandfile == NULL )
+ std::vector< std::string >::iterator first = rArgs.begin(), last = rArgs.end();
+ if ((first != last) && ((*first)[0] == '-'))
{
- fprintf(stderr, "ERROR: Can't open command file \"%s\"\n", cmdfile);
- } else
- {
- while ( fscanf(commandfile, "%s", option) != EOF )
+ std::string option(*first);
+ if ((option.compare("-v") == 0) || (option.compare("--verbose") == 0))
{
- if (option[0]== '@')
- {
- bool bRet = checkCommandFile(option);
- // ensure that the option will not be overwritten
- if ( !bRet )
- bVerbose = bRet;
- } else {
- if (option[0]== '-') {
- if (strncmp(option, "-v", 2) == 0 ||
- strncmp(option, "--verbose", 9) == 0)
- {
- bVerbose = true;
- } else {
- fprintf(stderr, "ERROR: unknown option \"%s\"\n", option);
- dumpHelp();
- exit(-1);
- }
- }else
- {
- realargv[realargc]= strdup(option);
- realargc++;
- }
- }
- if (realargc == 2047)
- {
- fprintf(stderr, "ERROR: more than 2048 arguments.\n");
- break;
- }
+ m_bVerbose = true;
}
- fclose(commandfile);
- }
-
- return bVerbose;
-}
-
-static bool checkCommandArgs(int argc, char **argv)
-{
- bool bVerbose = false;
-
- realargc = 0;
-
- for (int i=0; i<argc; i++)
- {
- if (argv[i][0]== '@')
+ else if ((option.compare("-h") == 0) || (option.compare("-?") == 0))
{
- bool bRet = checkCommandFile(argv[i]);
- // ensure that the option will not be overwritten
- if ( !bRet )
- bVerbose = bRet;
- } else {
- if (argv[i][0]== '-') {
- if (strncmp(argv[i], "-v", 2) == 0 ||
- strncmp(argv[i], "--verbose", 9) == 0)
- {
- bVerbose = true;
- } else {
- fprintf(stderr, "ERROR: unknown option \"%s\"\n", argv[i]);
- dumpHelp();
- exit(-1);
- }
- } else
- {
- realargv[realargc]= strdup(argv[i]);
- realargc++;
- }
+ return printUsage();
}
+ else
+ {
+ return badOption("unknown", option.c_str());
+ }
+ (void) rArgs.erase(first);
}
-
- return bVerbose;
-}
-
-static void cleanCommandArgs()
-{
- for (int i=0; i<realargc; i++)
- {
- free(realargv[i]);
- }
+ return true;
}
-
-
#if (defined UNX) || (defined OS2)
int main( int argc, char * argv[] )
#else
int _cdecl main( int argc, char * argv[] )
#endif
{
- bool bVerbose = checkCommandArgs(argc, argv);
+ Options_Impl options(argv[0]);
- if (realargc < 4)
+ std::vector< std::string > args;
+ for (int i = 1; i < argc; i++)
{
- dumpHelp();
- cleanCommandArgs();
- exit(1);
+ if (!Options::checkArgument(args, argv[i], strlen(argv[i])))
+ {
+ options.printUsage();
+ return (1);
+ }
+ }
+ if (!options.initOptions(args))
+ {
+ return (1);
+ }
+ if (args.size() < 3)
+ {
+ options.printUsage();
+ return (1);
}
-
- ::rtl::OUString regName( convertToFileUrl(realargv[1]) );
Registry reg;
+ OUString regName( convertToFileUrl(args[0].c_str(), args[0].size()) );
if (reg.open(regName, REG_READWRITE) != REG_NO_ERROR)
{
if (reg.create(regName) != REG_NO_ERROR)
{
- if (bVerbose)
- fprintf(stderr, "open registry \"%s\" failed\n", realargv[1]);
- cleanCommandArgs();
- exit(-1);
+ if (options.isVerbose())
+ fprintf(stderr, "open registry \"%s\" failed\n", args[0].c_str());
+ return (-1);
}
}
RegistryKey rootKey;
- if (reg.openRootKey(rootKey) == REG_NO_ERROR)
+ if (reg.openRootKey(rootKey) != REG_NO_ERROR)
+ {
+ if (options.isVerbose())
+ fprintf(stderr, "open root key of registry \"%s\" failed\n", args[0].c_str());
+ return (-4);
+ }
+
+ OUString mergeKeyName( OUString::createFromAscii(args[1].c_str()) );
+ for (size_t i = 2; i < args.size(); i++)
{
- ::rtl::OUString mergeKeyName( ::rtl::OUString::createFromAscii(realargv[2]) );
- ::rtl::OUString targetRegName;
- for (int i = 3; i < realargc; i++)
+ OUString targetRegName( convertToFileUrl(args[i].c_str(), args[i].size()) );
+ RegError _ret = reg.mergeKey(rootKey, mergeKeyName, targetRegName, sal_False, options.isVerbose());
+ if (_ret != REG_NO_ERROR)
{
- targetRegName = convertToFileUrl(realargv[i]);
- RegError _ret = reg.mergeKey(rootKey, mergeKeyName, targetRegName, sal_False, bVerbose);
- if (_ret != REG_NO_ERROR)
+ if (_ret == REG_MERGE_CONFLICT)
{
- if (_ret == REG_MERGE_CONFLICT)
- {
- if (bVerbose)
- fprintf(stderr, "merging registry \"%s\" under key \"%s\" in registry \"%s\".\n",
- realargv[i], realargv[2], realargv[1]);
- } else
- {
- if (bVerbose)
- fprintf(stderr, "ERROR: merging registry \"%s\" under key \"%s\" in registry \"%s\" failed.\n",
- realargv[i], realargv[2], realargv[1]);
- exit(-2);
- }
- } else
- {
- if (bVerbose)
+ if (options.isVerbose())
fprintf(stderr, "merging registry \"%s\" under key \"%s\" in registry \"%s\".\n",
- realargv[i], realargv[2], realargv[1]);
+ args[i].c_str(), args[1].c_str(), args[0].c_str());
+ }
+ else
+ {
+ if (options.isVerbose())
+ fprintf(stderr, "ERROR: merging registry \"%s\" under key \"%s\" in registry \"%s\" failed.\n",
+ args[i].c_str(), args[1].c_str(), args[0].c_str());
+ return (-2);
}
}
-
- rootKey.releaseKey();
- } else
- {
- if (bVerbose)
- fprintf(stderr, "open root key of registry \"%s\" failed\n",
- realargv[1]);
- exit(-4);
+ else
+ {
+ if (options.isVerbose())
+ fprintf(stderr, "merging registry \"%s\" under key \"%s\" in registry \"%s\".\n",
+ args[i].c_str(), args[1].c_str(), args[0].c_str());
+ }
}
+ rootKey.releaseKey();
if (reg.close() != REG_NO_ERROR)
{
- if (bVerbose)
- fprintf(stderr, "closing registry \"%s\" failed\n", realargv[1]);
- cleanCommandArgs();
- exit(-5);
+ if (options.isVerbose())
+ fprintf(stderr, "closing registry \"%s\" failed\n", args[0].c_str());
+ return (-5);
}
- cleanCommandArgs();
return(0);
}
-
-/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ \ No newline at end of file
diff --git a/registry/tools/regview.cxx b/registry/tools/regview.cxx
index 88c1632de867..482d62b44f9b 100644
--- a/registry/tools/regview.cxx
+++ b/registry/tools/regview.cxx
@@ -29,65 +29,16 @@
// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_registry.hxx"
-#include <stdio.h>
-
#include "registry/registry.h"
-#include <rtl/ustring.hxx>
-#include <rtl/alloc.h>
-#include <osl/process.h>
-#include <osl/diagnose.h>
-#include <osl/thread.h>
-#include <osl/file.hxx>
-
-#ifdef SAL_UNX
-#define SEPARATOR '/'
-#else
-#define SEPARATOR '\\'
-#endif
-
-using namespace ::rtl;
-using namespace ::osl;
-
-sal_Bool isFileUrl(const OString& fileName)
-{
- if (fileName.indexOf("file://") == 0 )
- return sal_True;
- return sal_False;
-}
+#include "fileurl.hxx"
-OUString convertToFileUrl(const OString& fileName)
-{
- if ( isFileUrl(fileName) )
- {
- return OStringToOUString(fileName, osl_getThreadTextEncoding());
- }
+#include "rtl/ustring.hxx"
- OUString uUrlFileName;
- OUString uFileName(fileName.getStr(), fileName.getLength(), osl_getThreadTextEncoding());
- if ( fileName.indexOf('.') == 0 || fileName.indexOf(SEPARATOR) < 0 )
- {
- OUString uWorkingDir;
- if (osl_getProcessWorkingDir(&uWorkingDir.pData) != osl_Process_E_None)
- {
- OSL_ASSERT(false);
- }
- if (FileBase::getAbsoluteFileURL(uWorkingDir, uFileName, uUrlFileName)
- != FileBase::E_None)
- {
- OSL_ASSERT(false);
- }
- } else
- {
- if (FileBase::getFileURLFromSystemPath(uFileName, uUrlFileName)
- != FileBase::E_None)
- {
- OSL_ASSERT(false);
- }
- }
-
- return uUrlFileName;
-}
+#include <stdio.h>
+#include <string.h>
+using rtl::OUString;
+using namespace registry::tools;
#if (defined UNX) || (defined OS2)
int main( int argc, char * argv[] )
@@ -104,7 +55,7 @@ int _cdecl main( int argc, char * argv[] )
exit(1);
}
- OUString regName( convertToFileUrl(argv[1]) );
+ OUString regName( convertToFileUrl(argv[1], strlen(argv[1])) );
if (reg_openRegistry(regName.pData, &hReg, REG_READONLY))
{
fprintf(stderr, "open registry \"%s\" failed\n", argv[1]);
@@ -128,12 +79,14 @@ int _cdecl main( int argc, char * argv[] )
fprintf(stderr, "closing key \"%s\" of registry \"%s\" failed\n",
argv[2], argv[1]);
}
- } else
+ }
+ else
{
fprintf(stderr, "key \"%s\" not exists in registry \"%s\"\n",
argv[2], argv[1]);
}
- } else
+ }
+ else
{
if (reg_dumpRegistry(hRootKey))
{
@@ -145,7 +98,8 @@ int _cdecl main( int argc, char * argv[] )
{
fprintf(stderr, "closing root key of registry \"%s\" failed\n", argv[1]);
}
- } else
+ }
+ else
{
fprintf(stderr, "open root key of registry \"%s\" failed\n", argv[1]);
}