diff options
author | Daniel Boelzle <dbo@openoffice.org> | 2002-09-11 07:24:34 +0000 |
---|---|---|
committer | Daniel Boelzle <dbo@openoffice.org> | 2002-09-11 07:24:34 +0000 |
commit | 78282f558eb832847ee01916125d6050768a1c95 (patch) | |
tree | 69ec15ec266bc7dbb991cea4891bb2416858b6b2 /cpputools/source/regsingleton | |
parent | #103028# (diff) | |
download | core-78282f558eb832847ee01916125d6050768a1c95.tar.gz core-78282f558eb832847ee01916125d6050768a1c95.zip |
#103151# added options -r, -ra
Diffstat (limited to 'cpputools/source/regsingleton')
-rw-r--r-- | cpputools/source/regsingleton/makefile.mk | 10 | ||||
-rw-r--r-- | cpputools/source/regsingleton/regsingleton.cxx | 114 |
2 files changed, 100 insertions, 24 deletions
diff --git a/cpputools/source/regsingleton/makefile.mk b/cpputools/source/regsingleton/makefile.mk index 966a5f6fd3af..03521d375dd4 100644 --- a/cpputools/source/regsingleton/makefile.mk +++ b/cpputools/source/regsingleton/makefile.mk @@ -2,9 +2,9 @@ # # $RCSfile: makefile.mk,v $ # -# $Revision: 1.1 $ +# $Revision: 1.2 $ # -# last change: $Author: dbo $ $Date: 2002-09-10 09:39:15 $ +# last change: $Author: dbo $ $Date: 2002-09-11 08:24:34 $ # # The Contents of this file are made available subject to the terms of # either of the following licenses @@ -110,5 +110,11 @@ APP1STDLIBS= \ $(CPPULIB) \ $(CPPUHELPERLIB) +.IF "$(debug)" != "" +.IF "$(COM)" == "MSC" +CFLAGS += -Ob0 +.ENDIF +.ENDIF + .INCLUDE : target.mk diff --git a/cpputools/source/regsingleton/regsingleton.cxx b/cpputools/source/regsingleton/regsingleton.cxx index 3f4d5704aca7..bb2c7cb2fe69 100644 --- a/cpputools/source/regsingleton/regsingleton.cxx +++ b/cpputools/source/regsingleton/regsingleton.cxx @@ -2,9 +2,9 @@ * * $RCSfile: regsingleton.cxx,v $ * - * $Revision: 1.1 $ + * $Revision: 1.2 $ * - * last change: $Author: dbo $ $Date: 2002-09-10 09:39:15 $ + * last change: $Author: dbo $ $Date: 2002-09-11 08:24:34 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -75,53 +75,123 @@ using namespace ::rtl; using namespace ::com::sun::star; using namespace ::com::sun::star::uno; +static void print_options() SAL_THROW( () ) +{ + printf( + "\nusage: regsingleton [-r|-ra] registry_file singleton_name[=service_name] ...\n\n" + "Inserts a singleton entry into rdb.\n" + "Option -r revokes given entries, -ra revokes all entries.\n" ); +} //================================================================================================== extern "C" int SAL_CALL main( int argc, char const * argv [] ) { if (argc < 3) { - fprintf( - stderr, "\nusage: regsingleton registry_file singleton_name1=service_name1 ...\n" ); + print_options(); return 1; } - OUString sys_path( OUString::createFromAscii( argv[ 1 ] ) ); + bool insert_entry = true; + bool remove_all = false; + int nPos = 1; + if ('-' == argv[ nPos ][ 0 ] && 'r' == argv[ nPos ][ 1 ]) + { + if ('a' == argv[ nPos ][ 2 ] && '\0' == argv[ nPos ][ 3 ]) + { + remove_all = true; + } + else if ('\0' != argv[ nPos ][ 2 ]) + { + print_options(); + return 1; + } + insert_entry = false; + ++nPos; + } + + OUString sys_path( OUString::createFromAscii( argv[ nPos ] ) ); OUString file_url; oslFileError rc = osl_getFileURLFromSystemPath( sys_path.pData, &file_url.pData ); if (osl_File_E_None != rc) { - fprintf( stderr, "\nerror: cannot make file url out of %s\n", argv[ 1 ] ); + fprintf( stderr, "\nerror: cannot make file url out of %s\n", argv[ nPos ] ); return 1; } + ++nPos; try { Reference< registry::XSimpleRegistry > xSimReg( ::cppu::createSimpleRegistry() ); xSimReg->open( file_url, sal_False, sal_True ); Reference< registry::XRegistryKey > xRoot( xSimReg->getRootKey() ); - Reference< registry::XRegistryKey > xKey( xRoot->openKey( OUSTR("SINGLETONS") ) ); - if (! xKey.is()) - xKey = xRoot->createKey( OUSTR("SINGLETONS") ); - for ( int nPos = 2; nPos < argc; ++nPos ) + if (remove_all) { - OUString singleton( OUString::createFromAscii( argv[ nPos ] ) ); - sal_Int32 eq = singleton.indexOf( '=' ); - if (eq < 0) + try + { + xRoot->deleteKey( OUSTR("SINGLETONS") ); + } + catch (registry::InvalidRegistryException & exc) { - OString entry( OUStringToOString( singleton, RTL_TEXTENCODING_ASCII_US ) ); - fprintf( stderr, "skipping %s: no service name given!\n", entry.getStr() ); + OString cstr_msg( + OUStringToOString( exc.Message, RTL_TEXTENCODING_ASCII_US ) ); + fprintf( + stderr, "\nwarning: removing all singletons failed: %s\n", + cstr_msg.getStr() ); } - else + } + else + { + Reference< registry::XRegistryKey > xKey( xRoot->openKey( OUSTR("SINGLETONS") ) ); + if (! xKey.is()) + xKey = xRoot->createKey( OUSTR("SINGLETONS") ); + + for ( ; nPos < argc; ++nPos ) { - OUString service( singleton.copy( eq +1 ) ); - singleton = singleton.copy( 0, eq ); + OUString singleton( OUString::createFromAscii( argv[ nPos ] ) ); + OUString service; + sal_Int32 eq = singleton.indexOf( '=' ); + if (eq >= 0) + { + service = singleton.copy( eq +1 ); + singleton = singleton.copy( 0, eq ); + } - Reference< registry::XRegistryKey > xEntry( xKey->openKey( singleton ) ); - if (! xEntry.is()) - xEntry = xKey->createKey( singleton ); - xEntry->setStringValue( service ); + if (insert_entry) + { + if (service.getLength()) + { + Reference< registry::XRegistryKey > xEntry( xKey->openKey( singleton ) ); + if (! xEntry.is()) + xEntry = xKey->createKey( singleton ); + xEntry->setStringValue( service ); + } + else + { + OString entry( OUStringToOString( singleton, RTL_TEXTENCODING_ASCII_US ) ); + fprintf( + stderr, "\nwarning: no service name given for singleton %s!\n", + entry.getStr() ); + } + } + else + { + try + { + xKey->deleteKey( singleton ); + } + catch (registry::InvalidRegistryException & exc) + { + OString cstr_singleton( + OUStringToOString( singleton, RTL_TEXTENCODING_ASCII_US ) ); + OString cstr_msg( + OUStringToOString( exc.Message, RTL_TEXTENCODING_ASCII_US ) ); + fprintf( + stderr, "\nwarning: singleton %s is not registered: %s\n", + cstr_singleton.getStr(), cstr_msg.getStr() ); + } + } } } |