merge the formfield patch from ooo-build
[ooovba.git] / sal / rtl / source / cmdargs.cxx
blobd762372aeff49535e04fbaa94e3ae52378e09ae7
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: cmdargs.cxx,v $
10 * $Revision: 1.11 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sal.hxx"
34 #include <osl/mutex.hxx>
35 #include <rtl/process.h>
36 #include <rtl/ustring.hxx>
38 namespace {
40 rtl_uString ** g_ppCommandArgs = 0;
41 sal_uInt32 g_nCommandArgCount = 0;
43 struct ArgHolder
45 ~ArgHolder();
48 ArgHolder::~ArgHolder()
50 while (g_nCommandArgCount > 0)
51 rtl_uString_release (g_ppCommandArgs[--g_nCommandArgCount]);
53 rtl_freeMemory (g_ppCommandArgs);
54 g_ppCommandArgs = 0;
57 // The destructor of this static ArgHolder is "activated" by the assignments to
58 // g_ppCommandArgs and g_nCommandArgCount in init():
59 ArgHolder argHolder;
61 void init()
63 osl::MutexGuard guard( osl::Mutex::getGlobalMutex() );
64 if (!g_ppCommandArgs)
66 sal_Int32 i, n = osl_getCommandArgCount();
68 g_ppCommandArgs =
69 (rtl_uString**)rtl_allocateZeroMemory (n * sizeof(rtl_uString*));
70 for (i = 0; i < n; i++)
72 rtl_uString * pArg = 0;
73 osl_getCommandArg (i, &pArg);
74 if (('-' == pArg->buffer[0] || '/' == pArg->buffer[0]) &&
75 'e' == pArg->buffer[1] &&
76 'n' == pArg->buffer[2] &&
77 'v' == pArg->buffer[3] &&
78 ':' == pArg->buffer[4] &&
79 rtl_ustr_indexOfChar (&(pArg->buffer[5]), '=') >= 0 )
81 // ignore.
82 rtl_uString_release (pArg);
84 else
86 // assign.
87 g_ppCommandArgs[g_nCommandArgCount++] = pArg;
95 oslProcessError SAL_CALL rtl_getAppCommandArg (
96 sal_uInt32 nArg, rtl_uString **ppCommandArg)
98 init();
99 oslProcessError result = osl_Process_E_NotFound;
100 if( nArg < g_nCommandArgCount )
102 rtl_uString_assign( ppCommandArg, g_ppCommandArgs[nArg] );
103 result = osl_Process_E_None;
105 return (result);
108 sal_uInt32 SAL_CALL rtl_getAppCommandArgCount (void)
110 init();
111 return g_nCommandArgCount;