summaryrefslogtreecommitdiff
path: root/sal
diff options
context:
space:
mode:
authorKay Ramme <kr@openoffice.org>2001-06-15 12:58:08 +0000
committerKay Ramme <kr@openoffice.org>2001-06-15 12:58:08 +0000
commita6f532e523c154bde258d54f3b977f75dd991681 (patch)
tree5b7c92c95a613fc64f81d9eb62fe47ffa0a197b8 /sal
parent56da097501600ee6e02527741e71e148c9a897cc (diff)
added macro expansion
Diffstat (limited to 'sal')
-rw-r--r--sal/rtl/source/bootstrap.cxx61
-rw-r--r--sal/rtl/source/cmdargs.cxx16
-rw-r--r--sal/rtl/source/macro.hxx80
-rw-r--r--sal/rtl/source/makefile.mk6
-rw-r--r--sal/test/bootstrap31
-rwxr-xr-xsal/test/bootstrap.bat26
-rw-r--r--sal/test/bootstraptest.ini8
-rw-r--r--sal/test/makefile.mk9
8 files changed, 212 insertions, 25 deletions
diff --git a/sal/rtl/source/bootstrap.cxx b/sal/rtl/source/bootstrap.cxx
index 2075ca6ba234..1974089636a4 100644
--- a/sal/rtl/source/bootstrap.cxx
+++ b/sal/rtl/source/bootstrap.cxx
@@ -2,9 +2,9 @@
*
* $RCSfile: bootstrap.cxx,v $
*
- * $Revision: 1.2 $
+ * $Revision: 1.3 $
*
- * last change: $Author: jbu $ $Date: 2001-05-17 10:06:08 $
+ * last change: $Author: kr $ $Date: 2001-06-15 13:53:53 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -71,6 +71,8 @@
#include <rtl/ustrbuf.hxx>
#include <rtl/byteseq.hxx>
+#include "macro.hxx"
+
// I need C++ for static variables and for lists (stl) !
// If we don't want C++, we need another solution for static vars !
using namespace ::rtl;
@@ -309,6 +311,43 @@ static void getFromDefault( rtl_uString **ppValue, rtl_uString *pName, rtl_uStri
}
}
+static void getFlatArg(rtl_uString * pName, rtl_uString ** ppValue, rtl_uString * pDefault)
+{
+ static const OUString sysUserConfig(RTL_CONSTASCII_USTRINGPARAM("SYSUSERCONFIG"));
+ static const OUString sysUserHome(RTL_CONSTASCII_USTRINGPARAM("SYSUSERHOME"));
+
+ // we have build ins:
+ if(!rtl_ustr_compare_WithLength(pName->buffer, pName->length, sysUserConfig.pData->buffer, sysUserConfig.pData->length))
+ {
+ oslSecurity security = osl_getCurrentSecurity();
+ osl_getConfigDir(security, ppValue);
+ osl_freeSecurityHandle(security);
+ }
+ else if(!rtl_ustr_compare_WithLength(pName->buffer, pName->length, sysUserHome.pData->buffer, sysUserHome.pData->length))
+ {
+ oslSecurity security = osl_getCurrentSecurity();
+ osl_getHomeDir(security, ppValue);
+ osl_freeSecurityHandle(security);
+ }
+ else
+ {
+ getFromCommandLineArgs( ppValue, pName );
+ if( ! *ppValue )
+ {
+ getFromIniFile( ppValue, pName );
+ if( ! *ppValue )
+ {
+ getFromEnvironment( ppValue, pName );
+ if( ! *ppValue && pDefault )
+ {
+ rtl_uString_assign( ppValue , pDefault );
+ }
+ }
+ }
+ }
+}
+
+
extern "C"
{
void SAL_CALL rtl_bootstrap_setIniFileName( rtl_uString *pName )
@@ -328,18 +367,12 @@ sal_Bool SAL_CALL rtl_bootstrap_get( rtl_uString *pName, rtl_uString **ppValue ,
*ppValue = 0;
}
- getFromCommandLineArgs( ppValue, pName );
- if( ! *ppValue )
- {
- getFromIniFile( ppValue, pName );
- if( ! *ppValue )
- {
- getFromEnvironment( ppValue, pName );
- if( ! *ppValue && pDefault )
- {
- rtl_uString_assign( ppValue , pDefault );
- }
- }
+ getFlatArg(pName, ppValue, pDefault);
+
+ if(*ppValue) {
+ OUString result = expandMacros(OUString(*ppValue));
+
+ rtl_uString_assign(ppValue, result.pData );
}
if( ! *ppValue )
diff --git a/sal/rtl/source/cmdargs.cxx b/sal/rtl/source/cmdargs.cxx
index 62e99aa54221..84aac80631af 100644
--- a/sal/rtl/source/cmdargs.cxx
+++ b/sal/rtl/source/cmdargs.cxx
@@ -2,9 +2,9 @@
*
* $RCSfile: cmdargs.cxx,v $
*
- * $Revision: 1.2 $
+ * $Revision: 1.3 $
*
- * last change: $Author: jbu $ $Date: 2001-05-18 15:30:59 $
+ * last change: $Author: kr $ $Date: 2001-06-15 13:53:53 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -62,8 +62,11 @@
#include <rtl/process.h>
#include <rtl/ustring.hxx>
+#include "macro.hxx"
-::rtl::OUString *g_pCommandArgs = 0;
+using namespace ::rtl;
+
+OUString *g_pCommandArgs = 0;
sal_Int32 g_nCommandArgCount = -1;
struct rtl_CmdArgs_ArgHolder
@@ -111,6 +114,7 @@ void impl_rtl_initCommandArgs()
}
+
extern "C"
{
oslProcessError SAL_CALL rtl_getAppCommandArg(sal_uInt32 nArg, rtl_uString **strCommandArg)
@@ -121,8 +125,10 @@ extern "C"
oslProcessError err = osl_Process_E_None;
if( nArg < g_nCommandArgCount )
{
- rtl_uString_assign( strCommandArg, g_pCommandArgs[nArg].pData );
- }
+ OUString expandedArg = expandMacros(g_pCommandArgs[nArg]);
+
+ rtl_uString_assign( strCommandArg, expandedArg.pData );
+ }
else
{
err = osl_Process_E_NotFound;
diff --git a/sal/rtl/source/macro.hxx b/sal/rtl/source/macro.hxx
new file mode 100644
index 000000000000..1502e22d5c42
--- /dev/null
+++ b/sal/rtl/source/macro.hxx
@@ -0,0 +1,80 @@
+/*************************************************************************
+ *
+ * $RCSfile: macro.hxx,v $
+ *
+ * $Revision: 1.1 $
+ *
+ * last change: $Author: kr $ $Date: 2001-06-15 13:53:53 $
+ *
+ * The Contents of this file are made available subject to the terms of
+ * either of the following licenses
+ *
+ * - GNU Lesser General Public License Version 2.1
+ * - Sun Industry Standards Source License Version 1.1
+ *
+ * Sun Microsystems Inc., October, 2000
+ *
+ * GNU Lesser General Public License Version 2.1
+ * =============================================
+ * Copyright 2000 by Sun Microsystems, Inc.
+ * 901 San Antonio Road, Palo Alto, CA 94303, USA
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ *
+ * Sun Industry Standards Source License Version 1.1
+ * =================================================
+ * The contents of this file are subject to the Sun Industry Standards
+ * Source License Version 1.1 (the "License"); You may not use this file
+ * except in compliance with the License. You may obtain a copy of the
+ * License at http://www.openoffice.org/license.html.
+ *
+ * Software provided under this License is provided on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+ * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+ * See the License for the specific provisions governing your rights and
+ * obligations concerning the Software.
+ *
+ * The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+ *
+ * Copyright: 2000 by Sun Microsystems, Inc.
+ *
+ * All Rights Reserved.
+ *
+ * Contributor(s): _______________________________________
+ *
+ *
+ ************************************************************************/
+
+#ifndef _RTL_MACRO_HXX
+#define _RTL_MACRO_HXX
+
+#include <rtl/ustring.hxx>
+
+/*
+ Expand macros via rtl_bootstrap_get.
+ see
+ http://udk.openoffice.org/common/man/spec/uno_default_bootstrapping.html
+ for details.
+*/
+::rtl::OUString SAL_CALL expandMacros(const ::rtl::OUString & argstr);
+
+#endif
+
+
+
+
+
diff --git a/sal/rtl/source/makefile.mk b/sal/rtl/source/makefile.mk
index 578f1d058aeb..1ef7c9b98309 100644
--- a/sal/rtl/source/makefile.mk
+++ b/sal/rtl/source/makefile.mk
@@ -2,9 +2,9 @@
#
# $RCSfile: makefile.mk,v $
#
-# $Revision: 1.6 $
+# $Revision: 1.7 $
#
-# last change: $Author: jl $ $Date: 2001-06-07 10:03:23 $
+# last change: $Author: kr $ $Date: 2001-06-15 13:53:53 $
#
# The Contents of this file are made available subject to the terms of
# either of the following licenses
@@ -98,6 +98,7 @@ SLOFILES= $(SLO)$/alloc.obj \
$(SLO)$/uri.obj \
$(SLO)$/bootstrap.obj \
$(SLO)$/cmdargs.obj \
+ $(SLO)$/macro.obj \
$(SLO)$/unload.obj
#.IF "$(UPDATER)"=="YES"
@@ -119,6 +120,7 @@ OBJFILES= $(OBJ)$/alloc.obj \
$(OBJ)$/uri.obj \
$(OBJ)$/bootstrap.obj \
$(OBJ)$/cmdargs.obj \
+ $(OBJ)$/macro.obj \
$(OBJ)$/unload.obj
#.ENDIF
diff --git a/sal/test/bootstrap b/sal/test/bootstrap
index 35529cf340c7..98c20494f2b9 100644
--- a/sal/test/bootstrap
+++ b/sal/test/bootstrap
@@ -15,4 +15,33 @@ echo 4
echo 5
./testbootstrap default -env:MYBOOTSTRAPTESTVALUE2=1 -env:INIFILENAME=
-echo bootstrap test finished \ No newline at end of file
+echo
+echo "macro tests"
+echo
+
+# simple macro expansion
+./testbootstrap _first_second_third_ -env:FIRST=first -env:SECOND=second -env:THIRD=third -env:MYBOOTSTRAPTESTVALUE='_${FIRST}_${SECOND}_${THIRD}_'
+
+# simple quoting
+./testbootstrap '_${FIRST}_${SECOND}_${THIRD}_' -env:FIRST=first -env:SECOND=second -env:THIRD=third -env:MYBOOTSTRAPTESTVALUE='_\$\{FIRST\}_\$\{SECOND\}_\$\{THIRD\}_'
+
+# simple ini access
+./testbootstrap TheKeysValue -env:'MYBOOTSTRAPTESTVALUE=${./bootstraptest.ini:TheSection:TheKey}'
+
+# ini access with simple macro expansion
+./testbootstrap TheKeysValue -env:ININAME=./bootstraptest.ini -env:SECTIONNAME=TheSection -env:KEYNAME=TheKey \
+ -env:'MYBOOTSTRAPTESTVALUE=${$ININAME:$SECTIONNAME:$KEYNAME}'
+
+# ini access with complex macro expansion
+./testbootstrap TheKeysValue -env:ININAME=./bootstraptest.ini \
+ -env:'MYBOOTSTRAPTESTVALUE=${$ININAME:${$ININAME:SecondSection:IndirectSection}:${$ININAME:SecondSection:IndirectKey}}'
+
+# test no infinit recursion
+./testbootstrap "***RECURSION DETECTED***" -env:'MYBOOTSTRAPTESTVALUE=$MYBOOTSTRAPTESTVALUE'
+
+# test unicode
+./testbootstrap AAABBBCCC000 -env:'MYBOOTSTRAPTESTVALUE=\u0041\u0041\u0041\u0042\u0042\u0042\u0043\u0043\u0043\u0030\u0030\u0030'
+
+echo
+echo "bootstrap test finished"
+echo
diff --git a/sal/test/bootstrap.bat b/sal/test/bootstrap.bat
index d0061e596919..af6554b5a7fa 100755
--- a/sal/test/bootstrap.bat
+++ b/sal/test/bootstrap.bat
@@ -15,4 +15,30 @@ rem simply ignore the file ....
echo 5
.\testbootstrap default -env:MYBOOTSTRAPTESTVALUE2=1 -env:INIFILENAME=
+echo
+echo "macro tests"
+echo
+
+rem simple macro expansion
+.\testbootstrap _first_second_third_ -env:FIRST=first -env:SECOND=second -env:THIRD=third -env:MYBOOTSTRAPTESTVALUE=_${FIRST}_${SECOND}_${THIRD}_
+
+rem simple quoting
+.\testbootstrap _${FIRST}_${SECOND}_${THIRD}_ -env:FIRST=first -env:SECOND=second -env:THIRD=third -env:MYBOOTSTRAPTESTVALUE=_\$\{FIRST\}_\$\{SECOND\}_\$\{THIRD\}_
+
+rem simple ini access
+.\testbootstrap TheKeysValue -env:MYBOOTSTRAPTESTVALUE=${./bootstraptest.ini:TheSection:TheKey}
+
+rem ini access with simple macro expansion
+.\testbootstrap TheKeysValue -env:ININAME=./bootstraptest.ini -env:SECTIONNAME=TheSection -env:KEYNAME=TheKey -env:MYBOOTSTRAPTESTVALUE=${$ININAME:$SECTIONNAME:$KEYNAME}
+
+rem ini access with complex macro expansion
+.\testbootstrap TheKeysValue -env:ININAME=./bootstraptest.ini -env:MYBOOTSTRAPTESTVALUE=${$ININAME:${$ININAME:SecondSection:IndirectSection}:${$ININAME:SecondSection:IndirectKey}}
+
+rem test no infinit recursion
+.\testbootstrap "***RECURSION DETECTED***" -env:MYBOOTSTRAPTESTVALUE=$MYBOOTSTRAPTESTVALUE
+
+rem test unicode
+.\testbootstrap AAABBBCCC000 -env:MYBOOTSTRAPTESTVALUE=\u0041\u0041\u0041\u0042\u0042\u0042\u0043\u0043\u0043\u0030\u0030\u0030
+
+
@echo bootstrap test finished \ No newline at end of file
diff --git a/sal/test/bootstraptest.ini b/sal/test/bootstraptest.ini
new file mode 100644
index 000000000000..3980d98a2221
--- /dev/null
+++ b/sal/test/bootstraptest.ini
@@ -0,0 +1,8 @@
+[TheSection]
+TheKey=TheKeysValue
+
+[SecondSection]
+IndirectSection=TheSection
+IndirectKey=TheKey
+
+
diff --git a/sal/test/makefile.mk b/sal/test/makefile.mk
index 15e9db4b8e58..cba38d877ccd 100644
--- a/sal/test/makefile.mk
+++ b/sal/test/makefile.mk
@@ -2,9 +2,9 @@
#
# $RCSfile: makefile.mk,v $
#
-# $Revision: 1.4 $
+# $Revision: 1.5 $
#
-# last change: $Author: jbu $ $Date: 2001-05-17 09:14:17 $
+# last change: $Author: kr $ $Date: 2001-06-15 13:53:54 $
#
# The Contents of this file are made available subject to the terms of
# either of the following licenses
@@ -108,7 +108,7 @@ APP2STDLIBS = $(SALLIB)
# --- Targets ------------------------------------------------------
.IF "$(depend)" == ""
-ALL : $(BIN)$/$(BOOTSTRAPSCRIPT) $(BIN)$/$(BOOTSTRAPINI) ALLTAR
+ALL : $(BIN)$/$(BOOTSTRAPSCRIPT) $(BIN)$/$(BOOTSTRAPINI) $(BIN)$/bootstraptest.ini ALLTAR
.ELSE
ALL: ALLDEP
.ENDIF
@@ -125,6 +125,9 @@ $(BIN)$/$(BOOTSTRAPSCRIPT) : $(BOOTSTRAPSCRIPT)
$(BIN)$/$(BOOTSTRAPINI) : testbootstrap.ini
$(MY_SCRIPTCAT) testbootstrap.ini > $@
+$(BIN)$/bootstraptest.ini : bootstraptest.ini
+ $(MY_SCRIPTCAT) bootstraptest.ini > $@
+
# --- SO2-Filter-Datei ---
$(MISC)$/tsl$(UPD)$(DLLPOSTFIX).flt:
@echo ------------------------------