LCOV - code coverage report
Current view: top level - registry/tools - regmerge.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 0 70 0.0 %
Date: 2015-06-13 12:38:46 Functions: 0 7 0.0 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.11