LCOV - code coverage report
Current view: top level - registry/tools - regmerge.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 33 70 47.1 %
Date: 2012-08-25 Functions: 5 7 71.4 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 44 166 26.5 %

           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                 :            : 
      21                 :            : #include "registry/registry.hxx"
      22                 :            : #include "fileurl.hxx"
      23                 :            : #include "options.hxx"
      24                 :            : 
      25                 :            : #include "rtl/ustring.hxx"
      26                 :            : #include "osl/diagnose.h"
      27                 :            : 
      28                 :            : #include <stdio.h>
      29                 :            : #include <string.h>
      30                 :            : 
      31                 :            : using namespace rtl;
      32                 :            : using namespace registry::tools;
      33                 :            : 
      34         [ -  + ]:         20 : class Options_Impl : public Options
      35                 :            : {
      36                 :            :     bool m_bVerbose;
      37                 :            : 
      38                 :            : public:
      39                 :         20 :     explicit Options_Impl (char const * program)
      40                 :         20 :         : Options(program), m_bVerbose(false)
      41                 :         20 :     {}
      42                 :      18948 :     bool isVerbose() const { return m_bVerbose; }
      43                 :            : 
      44                 :            : protected:
      45                 :            :     virtual void printUsage_Impl() const;
      46                 :            :     virtual bool initOptions_Impl(std::vector< std::string > & rArgs);
      47                 :            : };
      48                 :            : 
      49                 :          0 : void Options_Impl::printUsage_Impl() const
      50                 :            : {
      51                 :          0 :     fprintf(stderr, "using: regmerge [-v|--verbose] mergefile mergeKeyName regfile_1 ... regfile_n\n");
      52                 :          0 :     fprintf(stderr, "       regmerge @regcmds\nOptions:\n");
      53                 :          0 :     fprintf(stderr, "  -v, --verbose : verbose output on stdout.\n");
      54                 :          0 :     fprintf(stderr, "  mergefile     : specifies the merged registry file. If this file doesn't exists,\n");
      55                 :          0 :     fprintf(stderr, "                  it is created.\n");
      56                 :          0 :     fprintf(stderr, "  mergeKeyName  : specifies the merge key, everything is merged under this key.\n");
      57                 :          0 :     fprintf(stderr, "                  If this key doesn't exists, it is created.\n");
      58                 :          0 :     fprintf(stderr, "  regfile_1..n  : specifies one or more registry files which are merged.\n");
      59                 :          0 : }
      60                 :            : 
      61                 :         20 : bool Options_Impl::initOptions_Impl (std::vector< std::string > & rArgs)
      62                 :            : {
      63                 :         20 :     std::vector< std::string >::iterator first = rArgs.begin(), last = rArgs.end();
      64 [ +  - ][ +  - ]:         20 :     if ((first != last) && ((*first)[0] == '-'))
         [ +  - ][ -  + ]
         [ -  + ][ +  - ]
      65                 :            :     {
      66 [ #  # ][ #  # ]:          0 :         std::string option(*first);
      67 [ #  # ][ #  # ]:          0 :         if ((option.compare("-v") == 0) || (option.compare("--verbose") == 0))
         [ #  # ][ #  # ]
                 [ #  # ]
      68                 :            :         {
      69                 :          0 :             m_bVerbose = true;
      70                 :            :         }
      71 [ #  # ][ #  # ]:          0 :         else if ((option.compare("-h") == 0) || (option.compare("-?") == 0))
         [ #  # ][ #  # ]
                 [ #  # ]
      72                 :            :         {
      73         [ #  # ]:          0 :             return printUsage();
      74                 :            :         }
      75                 :            :         else
      76                 :            :         {
      77         [ #  # ]:          0 :             return badOption("unknown", option.c_str());
      78                 :            :         }
      79 [ #  # ][ #  # ]:          0 :         (void) rArgs.erase(first);
      80                 :            :     }
      81                 :         20 :     return true;
      82                 :            : }
      83                 :            : 
      84                 :            : #if (defined UNX)
      85                 :         20 : int main( int argc, char * argv[] )
      86                 :            : #else
      87                 :            : int __cdecl main( int argc, char * argv[] )
      88                 :            : #endif
      89                 :            : {
      90         [ +  - ]:         20 :     Options_Impl options(argv[0]);
      91                 :            : 
      92         [ +  - ]:         20 :     std::vector< std::string > args;
      93         [ +  + ]:         42 :     for (int i = 1; i < argc; i++)
      94                 :            :     {
      95 [ +  - ][ -  + ]:         22 :         if (!Options::checkArgument(args, argv[i], strlen(argv[i])))
      96                 :            :         {
      97         [ #  # ]:          0 :             options.printUsage();
      98                 :          0 :             return (1);
      99                 :            :         }
     100                 :            :     }
     101 [ +  - ][ -  + ]:         20 :     if (!options.initOptions(args))
     102                 :            :     {
     103                 :          0 :         return (1);
     104                 :            :     }
     105         [ -  + ]:         20 :     if (args.size() < 3)
     106                 :            :     {
     107         [ #  # ]:          0 :         options.printUsage();
     108                 :          0 :         return (1);
     109                 :            :     }
     110                 :            : 
     111         [ +  - ]:         20 :     Registry reg;
     112 [ +  - ][ +  - ]:         20 :     OUString regName( convertToFileUrl(args[0].c_str(), args[0].size()) );
                 [ +  - ]
     113 [ +  - ][ +  + ]:         20 :     if (reg.open(regName, REG_READWRITE) != REG_NO_ERROR)
     114                 :            :     {
     115 [ +  - ][ -  + ]:         15 :         if (reg.create(regName) != REG_NO_ERROR)
     116                 :            :         {
     117         [ #  # ]:          0 :             if (options.isVerbose())
     118 [ #  # ][ #  # ]:          0 :                 fprintf(stderr, "open registry \"%s\" failed\n", args[0].c_str());
     119                 :          0 :             return (-1);
     120                 :            :         }
     121                 :            :     }
     122                 :            : 
     123         [ +  - ]:         20 :     RegistryKey rootKey;
     124 [ +  - ][ -  + ]:         20 :     if (reg.openRootKey(rootKey) != REG_NO_ERROR)
     125                 :            :     {
     126         [ #  # ]:          0 :         if (options.isVerbose())
     127 [ #  # ][ #  # ]:          0 :             fprintf(stderr, "open root key of registry \"%s\" failed\n", args[0].c_str());
     128                 :          0 :         return (-4);
     129                 :            :     }
     130                 :            : 
     131         [ +  - ]:         20 :     OUString mergeKeyName( OUString::createFromAscii(args[1].c_str()) );
     132         [ +  + ]:       9494 :     for (size_t i = 2; i < args.size(); i++)
     133                 :            :     {
     134 [ +  - ][ +  - ]:       9474 :         OUString targetRegName( convertToFileUrl(args[i].c_str(), args[i].size()) );
                 [ +  - ]
     135         [ +  - ]:       9474 :         RegError _ret = reg.mergeKey(rootKey, mergeKeyName, targetRegName, sal_False, options.isVerbose());
     136         [ -  + ]:       9474 :         if (_ret != REG_NO_ERROR)
     137                 :            :         {
     138         [ #  # ]:          0 :             if (_ret == REG_MERGE_CONFLICT)
     139                 :            :             {
     140         [ #  # ]:          0 :                 if (options.isVerbose())
     141                 :            :                     fprintf(stderr, "merging registry \"%s\" under key \"%s\" in registry \"%s\".\n",
     142 [ #  # ][ #  # ]:          0 :                             args[i].c_str(), args[1].c_str(), args[0].c_str());
         [ #  # ][ #  # ]
     143                 :            :             }
     144                 :            :             else
     145                 :            :             {
     146         [ #  # ]:          0 :                 if (options.isVerbose())
     147                 :            :                     fprintf(stderr, "ERROR: merging registry \"%s\" under key \"%s\" in registry \"%s\" failed.\n",
     148 [ #  # ][ #  # ]:          0 :                             args[i].c_str(), args[1].c_str(), args[0].c_str());
         [ #  # ][ #  # ]
     149                 :          0 :                 return (-2);
     150                 :            :             }
     151                 :            :         }
     152                 :            :         else
     153                 :            :         {
     154         [ -  + ]:       9474 :             if (options.isVerbose())
     155                 :            :                 fprintf(stderr, "merging registry \"%s\" under key \"%s\" in registry \"%s\".\n",
     156 [ #  # ][ #  # ]:       9474 :                         args[i].c_str(), args[1].c_str(), args[0].c_str());
         [ #  # ][ #  # ]
     157                 :            :         }
     158         [ +  - ]:       9474 :     }
     159                 :            : 
     160         [ +  - ]:         20 :     rootKey.releaseKey();
     161 [ +  - ][ -  + ]:         20 :     if (reg.close() != REG_NO_ERROR)
     162                 :            :     {
     163         [ #  # ]:          0 :         if (options.isVerbose())
     164 [ #  # ][ #  # ]:          0 :             fprintf(stderr, "closing registry \"%s\" failed\n", args[0].c_str());
     165                 :          0 :         return (-5);
     166                 :            :     }
     167                 :            : 
     168 [ +  - ][ +  - ]:         20 :     return(0);
                 [ +  - ]
     169                 :            : }
     170                 :            : 
     171                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10