LCOV - code coverage report
Current view: top level - cpputools/source/regsingleton - regsingleton.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 63 0.0 %
Date: 2012-08-25 Functions: 0 3 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 0 -

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*
       3                 :            :  * This file is part of the LibreOffice project.
       4                 :            :  *
       5                 :            :  * This Source Code Form is subject to the terms of the Mozilla Public
       6                 :            :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7                 :            :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8                 :            :  *
       9                 :            :  * This file incorporates work covered by the following license notice:
      10                 :            :  *
      11                 :            :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12                 :            :  *   contributor license agreements. See the NOTICE file distributed
      13                 :            :  *   with this work for additional information regarding copyright
      14                 :            :  *   ownership. The ASF licenses this file to you under the Apache
      15                 :            :  *   License, Version 2.0 (the "License"); you may not use this file
      16                 :            :  *   except in compliance with the License. You may obtain a copy of
      17                 :            :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18                 :            :  */
      19                 :            : 
      20                 :            : #include <stdio.h>
      21                 :            : 
      22                 :            : #include "sal/main.h"
      23                 :            : #include <osl/diagnose.h>
      24                 :            : #include <osl/file.h>
      25                 :            : 
      26                 :            : #include <cppuhelper/bootstrap.hxx>
      27                 :            : 
      28                 :            : #include <com/sun/star/registry/XSimpleRegistry.hpp>
      29                 :            : 
      30                 :            : #define OUSTR(x) ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(x) )
      31                 :            : 
      32                 :            : 
      33                 :            : using namespace ::rtl;
      34                 :            : using namespace ::com::sun::star;
      35                 :            : using namespace ::com::sun::star::uno;
      36                 :            : 
      37                 :          0 : static void print_options() SAL_THROW(())
      38                 :            : {
      39                 :            :     printf(
      40                 :            :         "\nusage: regsingleton [-r|-ra] registry_file singleton_name[=service_name] ...\n\n"
      41                 :            :         "Inserts a singleton entry into rdb.\n"
      42                 :          0 :         "Option -r revokes given entries, -ra revokes all entries.\n" );
      43                 :          0 : }
      44                 :            : 
      45                 :            : //==================================================================================================
      46                 :          0 : SAL_IMPLEMENT_MAIN_WITH_ARGS(argc, argv)
      47                 :            : {
      48                 :          0 :     if (argc < 3)
      49                 :            :     {
      50                 :          0 :         print_options();
      51                 :          0 :         return 1;
      52                 :            :     }
      53                 :            : 
      54                 :          0 :     bool insert_entry = true;
      55                 :          0 :     bool remove_all = false;
      56                 :          0 :     int nPos = 1;
      57                 :          0 :     if ('-' == argv[ nPos ][ 0 ] && 'r' == argv[ nPos ][ 1 ])
      58                 :            :     {
      59                 :          0 :         if ('a' == argv[ nPos ][ 2 ] && '\0' == argv[ nPos ][ 3 ])
      60                 :            :         {
      61                 :          0 :             remove_all = true;
      62                 :            :         }
      63                 :          0 :         else if ('\0' != argv[ nPos ][ 2 ])
      64                 :            :         {
      65                 :          0 :             print_options();
      66                 :          0 :             return 1;
      67                 :            :         }
      68                 :          0 :         insert_entry = false;
      69                 :          0 :         ++nPos;
      70                 :            :     }
      71                 :            : 
      72                 :          0 :     OUString sys_path( OUString::createFromAscii( argv[ nPos ] ) );
      73                 :          0 :     OUString file_url;
      74                 :          0 :     oslFileError rc = osl_getFileURLFromSystemPath( sys_path.pData, &file_url.pData );
      75                 :          0 :     if (osl_File_E_None != rc)
      76                 :            :     {
      77                 :          0 :         fprintf( stderr, "\nerror: cannot make file url out of %s\n", argv[ nPos ] );
      78                 :          0 :         return 1;
      79                 :            :     }
      80                 :          0 :     ++nPos;
      81                 :            : 
      82                 :            :     try
      83                 :            :     {
      84                 :          0 :         Reference< registry::XSimpleRegistry > xSimReg( ::cppu::createSimpleRegistry() );
      85                 :          0 :         xSimReg->open( file_url, sal_False, sal_True );
      86                 :          0 :         Reference< registry::XRegistryKey > xRoot( xSimReg->getRootKey() );
      87                 :            : 
      88                 :          0 :         if (remove_all)
      89                 :            :         {
      90                 :            :             try
      91                 :            :             {
      92                 :          0 :                 xRoot->deleteKey( OUSTR("SINGLETONS") );
      93                 :            :             }
      94                 :          0 :             catch (registry::InvalidRegistryException & exc)
      95                 :            :             {
      96                 :            :                 OString cstr_msg(
      97                 :          0 :                     OUStringToOString( exc.Message, RTL_TEXTENCODING_ASCII_US ) );
      98                 :            :                 fprintf(
      99                 :            :                     stderr, "\nwarning: removing all singletons failed: %s\n",
     100                 :          0 :                     cstr_msg.getStr() );
     101                 :            :             }
     102                 :            :         }
     103                 :            :         else
     104                 :            :         {
     105                 :          0 :             Reference< registry::XRegistryKey > xKey( xRoot->openKey( OUSTR("SINGLETONS") ) );
     106                 :          0 :             if (! xKey.is())
     107                 :          0 :                 xKey = xRoot->createKey( OUSTR("SINGLETONS") );
     108                 :            : 
     109                 :          0 :             for ( ; nPos < argc; ++nPos )
     110                 :            :             {
     111                 :          0 :                 OUString singleton( OUString::createFromAscii( argv[ nPos ] ) );
     112                 :          0 :                 OUString service;
     113                 :          0 :                 sal_Int32 eq = singleton.indexOf( '=' );
     114                 :          0 :                 if (eq >= 0)
     115                 :            :                 {
     116                 :          0 :                     service = singleton.copy( eq +1 );
     117                 :          0 :                     singleton = singleton.copy( 0, eq );
     118                 :            :                 }
     119                 :            : 
     120                 :          0 :                 if (insert_entry)
     121                 :            :                 {
     122                 :          0 :                     if (!service.isEmpty())
     123                 :            :                     {
     124                 :          0 :                         Reference< registry::XRegistryKey > xEntry( xKey->openKey( singleton ) );
     125                 :          0 :                         if (! xEntry.is())
     126                 :          0 :                             xEntry = xKey->createKey( singleton );
     127                 :          0 :                         xEntry->setStringValue( service );
     128                 :            :                     }
     129                 :            :                     else
     130                 :            :                     {
     131                 :          0 :                         OString entry( OUStringToOString( singleton, RTL_TEXTENCODING_ASCII_US ) );
     132                 :            :                         fprintf(
     133                 :            :                             stderr, "\nwarning: no service name given for singleton %s!\n",
     134                 :          0 :                             entry.getStr() );
     135                 :            :                     }
     136                 :            :                 }
     137                 :            :                 else
     138                 :            :                 {
     139                 :            :                     try
     140                 :            :                     {
     141                 :          0 :                         xKey->deleteKey( singleton );
     142                 :            :                     }
     143                 :          0 :                     catch (registry::InvalidRegistryException & exc)
     144                 :            :                     {
     145                 :            :                         OString cstr_singleton(
     146                 :          0 :                             OUStringToOString( singleton, RTL_TEXTENCODING_ASCII_US ) );
     147                 :            :                         OString cstr_msg(
     148                 :          0 :                             OUStringToOString( exc.Message, RTL_TEXTENCODING_ASCII_US ) );
     149                 :            :                         fprintf(
     150                 :            :                             stderr, "\nwarning: singleton %s is not registered: %s\n",
     151                 :          0 :                             cstr_singleton.getStr(), cstr_msg.getStr() );
     152                 :            :                     }
     153                 :            :                 }
     154                 :          0 :             }
     155                 :            :         }
     156                 :            : 
     157                 :          0 :         return 0;
     158                 :            :     }
     159                 :          0 :     catch (Exception & rExc)
     160                 :            :     {
     161                 :          0 :         OString msg( OUStringToOString( rExc.Message, RTL_TEXTENCODING_ASCII_US ) );
     162                 :          0 :         fprintf( stderr, "\nerror: %s\n", msg.getStr() );
     163                 :          0 :         return 1;
     164                 :          0 :     }
     165                 :            : }
     166                 :            : 
     167                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10