Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : :
30 : : #include <osl/mutex.hxx>
31 : : #include <rtl/process.h>
32 : : #include <rtl/ustring.hxx>
33 : :
34 : : namespace {
35 : :
36 : : rtl_uString ** g_ppCommandArgs = 0;
37 : : sal_uInt32 g_nCommandArgCount = 0;
38 : :
39 : : struct ArgHolder
40 : : {
41 : : ~ArgHolder();
42 : : };
43 : :
44 : 3013 : ArgHolder::~ArgHolder()
45 : : {
46 [ + + ]: 5973 : while (g_nCommandArgCount > 0)
47 : 2960 : rtl_uString_release (g_ppCommandArgs[--g_nCommandArgCount]);
48 : :
49 : 3013 : rtl_freeMemory (g_ppCommandArgs);
50 : 3013 : g_ppCommandArgs = 0;
51 : 3013 : }
52 : :
53 : : // The destructor of this static ArgHolder is "activated" by the assignments to
54 : : // g_ppCommandArgs and g_nCommandArgCount in init():
55 : 3013 : ArgHolder argHolder;
56 : :
57 : 10497 : void init()
58 : : {
59 [ + - ][ + - ]: 10497 : osl::MutexGuard guard( osl::Mutex::getGlobalMutex() );
60 [ + + ]: 10497 : if (!g_ppCommandArgs)
61 : : {
62 [ + - ]: 593 : sal_Int32 i, n = osl_getCommandArgCount();
63 : :
64 : : g_ppCommandArgs =
65 : 593 : (rtl_uString**)rtl_allocateZeroMemory (n * sizeof(rtl_uString*));
66 [ + + ]: 4790 : for (i = 0; i < n; i++)
67 : : {
68 : 4197 : rtl_uString * pArg = 0;
69 [ + - ]: 4197 : osl_getCommandArg (i, &pArg);
70 [ + + ][ + + ]: 5434 : if (('-' == pArg->buffer[0] || '/' == pArg->buffer[0]) &&
[ + + ][ + - ]
[ + - ]
[ + - + - ]
[ + + ]
71 : 3453 : 'e' == pArg->buffer[1] &&
72 : 1237 : 'n' == pArg->buffer[2] &&
73 : 1237 : 'v' == pArg->buffer[3] &&
74 : 1237 : ':' == pArg->buffer[4] &&
75 : 1237 : rtl_ustr_indexOfChar (&(pArg->buffer[5]), '=') >= 0 )
76 : : {
77 : : // ignore.
78 : 1237 : rtl_uString_release (pArg);
79 : : }
80 : : else
81 : : {
82 : : // assign.
83 : 2960 : g_ppCommandArgs[g_nCommandArgCount++] = pArg;
84 : : }
85 : : }
86 [ + - ]: 10497 : }
87 : 10497 : }
88 : :
89 : : }
90 : :
91 : 6674 : oslProcessError SAL_CALL rtl_getAppCommandArg (
92 : : sal_uInt32 nArg, rtl_uString **ppCommandArg)
93 : : {
94 : 6674 : init();
95 : 6674 : oslProcessError result = osl_Process_E_NotFound;
96 [ + - ]: 6674 : if( nArg < g_nCommandArgCount )
97 : : {
98 : 6674 : rtl_uString_assign( ppCommandArg, g_ppCommandArgs[nArg] );
99 : 6674 : result = osl_Process_E_None;
100 : : }
101 : 6674 : return (result);
102 : : }
103 : :
104 : 3823 : sal_uInt32 SAL_CALL rtl_getAppCommandArgCount()
105 : : {
106 : 3823 : init();
107 : 3823 : return g_nCommandArgCount;
108 [ + - ][ + - ]: 9039 : }
109 : :
110 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|