Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPredrag Stanar2018-11-30 19:17:48 +0000
committerSravan Kumar Lakkimsetti2020-06-08 10:45:03 +0000
commitf49d80cfb5265ec98888ac9f48b219ac16863cc4 (patch)
treeb0350f666402f94db1e00e9c7a60a0c7a721f172
parent23a2e4d841dbc7ababbea5cca4b8d9cdc640208f (diff)
downloadrt.equinox.framework-f49d80cfb5265ec98888ac9f48b219ac16863cc4.tar.gz
rt.equinox.framework-f49d80cfb5265ec98888ac9f48b219ac16863cc4.tar.xz
rt.equinox.framework-f49d80cfb5265ec98888ac9f48b219ac16863cc4.zip
Bug 102239 - Environment variable substitution in <launcher>.ini/eclipse.ini
Signed-off-by: Predrag Stanar <predrag.stanar@aucerna.com>
-rw-r--r--features/org.eclipse.equinox.executable.feature/library/eclipseConfig.c55
1 files changed, 54 insertions, 1 deletions
diff --git a/features/org.eclipse.equinox.executable.feature/library/eclipseConfig.c b/features/org.eclipse.equinox.executable.feature/library/eclipseConfig.c
index 172f20236..7111cdd02 100644
--- a/features/org.eclipse.equinox.executable.feature/library/eclipseConfig.c
+++ b/features/org.eclipse.equinox.executable.feature/library/eclipseConfig.c
@@ -38,6 +38,59 @@
#endif
+static const _TCHAR LHS[] = _T_ECLIPSE("$"); /* left-hand side marker */
+static const _TCHAR RHS[] = _T_ECLIPSE("$"); /* right-hand side marker */
+static const unsigned short LHS_LEN = (sizeof(LHS) - sizeof(_TCHAR)) / sizeof(_TCHAR);
+static const unsigned short RHS_LEN = (sizeof(RHS) - sizeof(_TCHAR)) / sizeof(_TCHAR);
+
+/* we use a function pointer to abstract out the logic from getenv()
+ to ease testing */
+_TCHAR * expandEnvVarsInternal(const _TCHAR * input, _TCHAR* (*resolve)(const _TCHAR *)) {
+ _TCHAR * result;
+ const _TCHAR * lhsOuterPos = _tcsstr(input, LHS);
+
+ if ((lhsOuterPos != NULL) && _tcslen(lhsOuterPos) > LHS_LEN) {
+ const _TCHAR * lhsInnerPos = lhsOuterPos + LHS_LEN - 1;
+ const _TCHAR * rhsInnerPos = _tcsstr(lhsInnerPos, RHS);
+
+ if (rhsInnerPos != NULL) {
+ const _TCHAR * value;
+ _TCHAR * var = (_TCHAR *) calloc((rhsInnerPos - lhsInnerPos), sizeof(_TCHAR));
+
+ _tcsncpy(var, lhsInnerPos + 1, (rhsInnerPos - lhsInnerPos - 1));
+ value = resolve(var);
+
+ free(var);
+
+ if (value != NULL) {
+ /* expand remaining of the original string */
+ _TCHAR * remaining = expandEnvVarsInternal(rhsInnerPos + RHS_LEN, resolve);
+
+ /* length of the beginning of the original string */
+ const unsigned int beginLen = lhsOuterPos - input;
+ size_t len = beginLen
+ + _tcslen(value) /* de-referenced variable */
+ + _tcslen(remaining) /* rest of the string (expanded vars) */
+ + 1; /* string terminator */
+
+ result = (_TCHAR *) calloc(len, sizeof(_TCHAR));
+ _tcsncpy(result, input, beginLen);
+ _tcscat(result, value);
+ _tcscat(result, remaining);
+
+ free(remaining);
+
+ return result;
+ }
+ }
+ }
+
+ /* nothing to expand, just return a copy of the original string */
+ result = _tcsdup(input);
+
+ return result;
+}
+
int readIniFile(_TCHAR* program, int *argc, _TCHAR ***argv)
{
_TCHAR* config_file = NULL;
@@ -153,7 +206,7 @@ int readConfigFile( _TCHAR * config_file, int *argc, _TCHAR ***argv )
if(argument[0] == _T_ECLIPSE('#'))
continue;
- arg = _tcsdup(argument);
+ arg = expandEnvVarsInternal(argument, _tgetenv);
length = _tcslen(arg);
/* basic whitespace trimming */

Back to the top