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

Generated by: LCOV version 1.10