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