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 85011 : ArgHolder::~ArgHolder()
35 : {
36 170025 : while (g_nCommandArgCount > 0)
37 3 : rtl_uString_release (g_ppCommandArgs[--g_nCommandArgCount]);
38 :
39 85011 : rtl_freeMemory (g_ppCommandArgs);
40 85011 : g_ppCommandArgs = 0;
41 85011 : }
42 :
43 : // The destructor of this static ArgHolder is "activated" by the assignments to
44 : // g_ppCommandArgs and g_nCommandArgCount in init():
45 85011 : ArgHolder argHolder;
46 :
47 11 : void init()
48 : {
49 11 : osl::MutexGuard guard( osl::Mutex::getGlobalMutex() );
50 11 : if (!g_ppCommandArgs)
51 : {
52 1 : sal_Int32 i, n = osl_getCommandArgCount();
53 :
54 : g_ppCommandArgs =
55 1 : (rtl_uString**)rtl_allocateZeroMemory (n * sizeof(rtl_uString*));
56 4 : for (i = 0; i < n; i++)
57 : {
58 3 : rtl_uString * pArg = 0;
59 3 : osl_getCommandArg (i, &pArg);
60 10 : if (('-' == pArg->buffer[0] || '/' == pArg->buffer[0]) &&
61 3 : 'e' == pArg->buffer[1] &&
62 0 : 'n' == pArg->buffer[2] &&
63 0 : 'v' == pArg->buffer[3] &&
64 3 : ':' == pArg->buffer[4] &&
65 0 : rtl_ustr_indexOfChar (&(pArg->buffer[5]), '=') >= 0 )
66 : {
67 : // ignore.
68 0 : rtl_uString_release (pArg);
69 : }
70 : else
71 : {
72 : // assign.
73 3 : g_ppCommandArgs[g_nCommandArgCount++] = pArg;
74 : }
75 : }
76 11 : }
77 11 : }
78 :
79 : }
80 :
81 8 : oslProcessError SAL_CALL rtl_getAppCommandArg (
82 : sal_uInt32 nArg, rtl_uString **ppCommandArg)
83 : {
84 8 : init();
85 8 : oslProcessError result = osl_Process_E_NotFound;
86 8 : if( nArg < g_nCommandArgCount )
87 : {
88 8 : rtl_uString_assign( ppCommandArg, g_ppCommandArgs[nArg] );
89 8 : result = osl_Process_E_None;
90 : }
91 8 : return (result);
92 : }
93 :
94 3 : sal_uInt32 SAL_CALL rtl_getAppCommandArgCount()
95 : {
96 3 : init();
97 3 : return g_nCommandArgCount;
98 255033 : }
99 :
100 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|