LCOV - code coverage report
Current view: top level - sal/rtl - cmdargs.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 36 36 100.0 %
Date: 2014-11-03 Functions: 6 6 100.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             : #include <osl/mutex.hxx>
      21             : #include <rtl/process.h>
      22             : #include <rtl/ustring.hxx>
      23             : 
      24             : namespace {
      25             : 
      26             : rtl_uString ** g_ppCommandArgs = 0;
      27             : sal_uInt32     g_nCommandArgCount = 0;
      28             : 
      29             : struct ArgHolder
      30             : {
      31             :     ~ArgHolder();
      32             : };
      33             : 
      34        2842 : ArgHolder::~ArgHolder()
      35             : {
      36       11393 :     while (g_nCommandArgCount > 0)
      37        5709 :         rtl_uString_release (g_ppCommandArgs[--g_nCommandArgCount]);
      38             : 
      39        2842 :     rtl_freeMemory (g_ppCommandArgs);
      40        2842 :     g_ppCommandArgs = 0;
      41        2842 : }
      42             : 
      43             : // The destructor of this static ArgHolder is "activated" by the assignments to
      44             : // g_ppCommandArgs and g_nCommandArgCount in init():
      45        2842 : ArgHolder argHolder;
      46             : 
      47       10850 : void init()
      48             : {
      49       10850 :     osl::MutexGuard guard( osl::Mutex::getGlobalMutex() );
      50       10850 :     if (!g_ppCommandArgs)
      51             :     {
      52        1227 :         sal_Int32 i, n = osl_getCommandArgCount();
      53             : 
      54             :         g_ppCommandArgs =
      55        1227 :             (rtl_uString**)rtl_allocateZeroMemory (n * sizeof(rtl_uString*));
      56        9712 :         for (i = 0; i < n; i++)
      57             :         {
      58        8485 :             rtl_uString * pArg = 0;
      59        8485 :             osl_getCommandArg (i, &pArg);
      60       28465 :             if (('-' == pArg->buffer[0] || '/' == pArg->buffer[0]) &&
      61       10577 :                  'e' == pArg->buffer[1] &&
      62        5552 :                  'n' == pArg->buffer[2] &&
      63        5552 :                  'v' == pArg->buffer[3] &&
      64       14037 :                  ':' == pArg->buffer[4] &&
      65        2776 :                 rtl_ustr_indexOfChar (&(pArg->buffer[5]), '=') >= 0 )
      66             :             {
      67             :                 // ignore.
      68        2776 :                 rtl_uString_release (pArg);
      69             :             }
      70             :             else
      71             :             {
      72             :                 // assign.
      73        5709 :                 g_ppCommandArgs[g_nCommandArgCount++] = pArg;
      74             :             }
      75             :         }
      76       10850 :     }
      77       10850 : }
      78             : 
      79             : }
      80             : 
      81        7051 : oslProcessError SAL_CALL rtl_getAppCommandArg (
      82             :     sal_uInt32 nArg, rtl_uString **ppCommandArg)
      83             : {
      84        7051 :     init();
      85        7051 :     oslProcessError result = osl_Process_E_NotFound;
      86        7051 :     if( nArg < g_nCommandArgCount )
      87             :     {
      88        7051 :          rtl_uString_assign( ppCommandArg, g_ppCommandArgs[nArg] );
      89        7051 :         result = osl_Process_E_None;
      90             :     }
      91        7051 :     return (result);
      92             : }
      93             : 
      94        3799 : sal_uInt32 SAL_CALL rtl_getAppCommandArgCount()
      95             : {
      96        3799 :     init();
      97        3799 :     return g_nCommandArgCount;
      98        8526 : }
      99             : 
     100             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10