LCOV - code coverage report
Current view: top level - sal/rtl - cmdargs.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 36 36 100.0 %
Date: 2015-06-13 12:38:46 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        1912 : ArgHolder::~ArgHolder()
      35             : {
      36        6957 :     while (g_nCommandArgCount > 0)
      37        3133 :         rtl_uString_release (g_ppCommandArgs[--g_nCommandArgCount]);
      38             : 
      39        1912 :     rtl_freeMemory (g_ppCommandArgs);
      40        1912 :     g_ppCommandArgs = 0;
      41        1912 : }
      42             : 
      43             : // The destructor of this static ArgHolder is "activated" by the assignments to
      44             : // g_ppCommandArgs and g_nCommandArgCount in init():
      45        1912 : ArgHolder argHolder;
      46             : 
      47        6068 : void init()
      48             : {
      49        6068 :     osl::MutexGuard guard( osl::Mutex::getGlobalMutex() );
      50        6068 :     if (!g_ppCommandArgs)
      51             :     {
      52         667 :         sal_Int32 i, n = osl_getCommandArgCount();
      53             : 
      54             :         g_ppCommandArgs =
      55         667 :             static_cast<rtl_uString**>(rtl_allocateZeroMemory (n * sizeof(rtl_uString*)));
      56        5402 :         for (i = 0; i < n; i++)
      57             :         {
      58        4735 :             rtl_uString * pArg = 0;
      59        4735 :             osl_getCommandArg (i, &pArg);
      60       15799 :             if (('-' == pArg->buffer[0] || '/' == pArg->buffer[0]) &&
      61        5954 :                  'e' == pArg->buffer[1] &&
      62        3204 :                  'n' == pArg->buffer[2] &&
      63        3204 :                  'v' == pArg->buffer[3] &&
      64        7939 :                  ':' == pArg->buffer[4] &&
      65        1602 :                 rtl_ustr_indexOfChar (&(pArg->buffer[5]), '=') >= 0 )
      66             :             {
      67             :                 // ignore.
      68        1602 :                 rtl_uString_release (pArg);
      69             :             }
      70             :             else
      71             :             {
      72             :                 // assign.
      73        3133 :                 g_ppCommandArgs[g_nCommandArgCount++] = pArg;
      74             :             }
      75             :         }
      76        6068 :     }
      77        6068 : }
      78             : 
      79             : }
      80             : 
      81        3910 : oslProcessError SAL_CALL rtl_getAppCommandArg (
      82             :     sal_uInt32 nArg, rtl_uString **ppCommandArg)
      83             : {
      84        3910 :     init();
      85        3910 :     oslProcessError result = osl_Process_E_NotFound;
      86        3910 :     if( nArg < g_nCommandArgCount )
      87             :     {
      88        3910 :          rtl_uString_assign( ppCommandArg, g_ppCommandArgs[nArg] );
      89        3910 :         result = osl_Process_E_None;
      90             :     }
      91        3910 :     return result;
      92             : }
      93             : 
      94        2158 : sal_uInt32 SAL_CALL rtl_getAppCommandArgCount()
      95             : {
      96        2158 :     init();
      97        2158 :     return g_nCommandArgCount;
      98        5736 : }
      99             : 
     100             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11