2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
6 * These libraries and programs are free software; you can
7 * redistribute them and/or modify them under the terms of the GNU
8 * Lesser General Public License as published by the Free Software
9 * Foundation; either version 2 of the License, or (at your option)
12 * These libraries and programs are distributed in the hope that
13 * they will be useful, but WITHOUT ANY WARRANTY; without even the
14 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU Lesser General Public License for more
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these libraries and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
23 /****************************<+>*************************************
24 ********************************************************************
28 ** $TOG: EnvControl.c /main/21 1999/01/28 17:59:53 mgreess $
30 ** Project: DtSvc Runtime Library
32 ** Description: Get/Set the client's shell environment
34 **(c) Copyright 1992,1993,1994 by Hewlett-Packard Company
35 **(c) Copyright 1993,1994 International Business Machines Corp.
36 **(c) Copyright 1993,1994 Sun Microsystems, Inc.
37 **(c) Copyright 1993,1994 Unix System Labs, Inc., a subsidiary of Novell, Inc.
39 ********************************************************************
40 ****************************<+>*************************************/
43 #define X_INCLUDE_STRING_H
44 #define XOS_USE_XT_LOCKING
45 #include <X11/Xos_r.h>
46 #include <X11/Intrinsic.h>
47 #include <X11/Xatom.h>
49 #include <Dt/DtNlUtils.h>
50 #include "EnvControlP.h"
51 #include "EnvControlI.h"
52 #include "DtSvcLock.h"
54 extern char **environ;
57 * We assume that the following fields of these static structures
58 * are initialized at runtime to NULL pointers.
60 static struct environStruct _postDtEnvironment;
61 static struct environStruct _preDtEnvironment;
63 /* envBitVector is used to determine whether an environment
64 * variable has been put to the environment by the application.
65 * The flag values are in EnvControlI.h.
67 static unsigned int envBitVector = 0;
69 static void _EnvAdd (char *, char *, unsigned int);
72 /****************************************************************
73 * NOTES on an application's environ(5):
75 * The environment variable is an array of NULL-terminated strings.
76 * char **environ is defined in crt.o and is publicly extern-ed to
77 * all applications. There is one such variable per UN*X application.
79 * To deference an environment string, as in the debugger, use:
81 * environ[0] -- environ[n-1], where n is the number of
88 * You must manually malloc() space to keep a specific environment string
91 * putenv() is useless at NULLing out an environment variable. It will
92 * create a new value and will replace an existing value; however,
93 * in terms of getting rid of an environment variable, putenv() will only
94 * replace it with a NULL string ("") rather than freeing the space
95 * for it and NULLing the pointer. Afterwards, getenv() will return
96 * the NULL string rather than a NULL pointer, and hence give "incorrect"
97 * information to an application querying for a non-set environment
100 * E.g., there's a big difference between the following pairs
107 * XBMLANGPATH=<null pointer>
109 * The first will cause XmGetPixmap() to look nowhere for an icon image;
110 * the second will cause a lookup in all the default locations, which
113 * Bottom line is that you have to NULL out an unneeded environ manually.
115 * The environment array is able to be jerked any which way you'd like,
116 * using direct string/pointer manipulations. However, for safety:
117 * make a local copy of **environ.
119 ********************************************************************/
124 * Common suffixes for icon pixmap and icon bitmap paths. Each array must end
125 * with a null pointer. Note: the unusual string concatenation is necessary
126 * in order to prevent expansion of SCCS id keywords.
129 static const char *iconPmSuffixes[] = {
136 static const char *iconBmSuffixes[] = {
145 * makeDefaultIconPath
147 * Construct the icon pixmap or bitmap search path by constructing the values
148 * from the home directory, and then appending the system default path. The
149 * output is of the form "var=value", suitable for passing to putenv().
153 * outbuf A pointer to the memory to receive the output value. This
154 * must be large enough to accommodate the largest anticipated
155 * environment variable; no bounds checking is done!
159 * varname The environment variable name.
160 * basedefault The default value to be appended to the end.
161 * suffixes An array of suffixes used in constructing the path elements in
162 * the user's home directory. Must have a trailing NULL pointer.
167 const char *basedefault,
168 const char **suffixes)
170 char *fmt = "%s/.dt/icons/%s:";
173 int bytes_needed, fmt_bytes, homedir_bytes;
175 bytes_needed = strlen(varname) + strlen(basedefault) + 2;
177 homedir = getenv("HOME");
180 homedir_bytes = strlen(homedir);
181 fmt_bytes = strlen(fmt);
182 for ( ; *suffixes ; ++suffixes)
183 bytes_needed += (homedir_bytes + fmt_bytes + strlen(*suffixes));
186 outbuf = XtMalloc(bytes_needed);
187 (void)sprintf(outbuf, "%s=", varname);
190 char *temp = XtMalloc(bytes_needed);
192 for ( ; *suffixes ; ++suffixes)
194 (void)sprintf(temp, fmt, homedir, *suffixes);
195 (void)strcat(outbuf, temp);
198 if (temp) XtFree(temp);
200 (void)strcat(outbuf, basedefault);
207 * Construct a default value for XMICONSEARCHPATH into outbuf.
210 makeDefaultIconPmPath(void)
212 static char *defaultIconPmPath = NULL;
214 if (NULL == defaultIconPmPath)
216 makeDefaultIconPath(PM_PATH_ENVIRON, DTPMSYSDEFAULT, iconPmSuffixes);
218 return XtNewString(defaultIconPmPath);
223 * Construct a default value for XMICONBMSEARCHPATH into outbuf.
226 makeDefaultIconBmPath(void)
228 static char *defaultIconBmPath = NULL;
230 if (NULL == defaultIconBmPath)
232 makeDefaultIconPath(BM_PATH_ENVIRON, DTBMSYSDEFAULT, iconBmSuffixes);
234 return XtNewString(defaultIconBmPath);
238 /*****************************<->*************************************
240 * _DtEnvSessionManager ()
245 * Sets the SESSION_MANAGER environment variable if not already set.
255 *****************************<->***********************************/
257 _DtEnvSessionManager(void)
259 #define SESSION_MANAGER "SESSION_MANAGER"
260 char *session_manager = getenv(SESSION_MANAGER);
261 if (NULL == session_manager)
266 display = XOpenDisplay(NULL);
269 sm_atom = XInternAtom(display, SESSION_MANAGER, True);
273 unsigned long nitems, leftover;
276 if (Success == XGetWindowProperty(
277 display, XDefaultRootWindow(display),
278 sm_atom, 0L, 256, False, XA_STRING,
279 &actual_type, &actual_format,
281 (unsigned char **) &session_manager))
283 if (NULL != session_manager && None != actual_format)
286 envstr = (char*) malloc(
287 strlen(SESSION_MANAGER) +
288 strlen(session_manager) + 2);
294 XtFree(session_manager);
298 XCloseDisplay(display);
303 /*****************************<->*************************************
305 * _DtEnvControl ( int mode )
310 * Gets/Sets the application's environment
314 * mode - the command to the function; e.g., to set the
315 * DT environment, to restore the originial env., etc.
319 * Returns a success code--usually just the value of the original
320 * mode parameter. If an error occurs, returns DT_ENV_NO_OP.
322 *****************************<->***********************************/
327 static int environSetup = 0;
330 char *ptr; /* used for indexing into the $PATH */
331 int returnValue = DT_ENV_NO_OP;
338 if (!environSetup) /* first time through */
341 * Make sure the SESSION_MANAGER variable is set.
343 _DtEnvSessionManager();
346 * Set up DT environment in the application
347 * environment, while stashing the old environment
348 * in the _preDtEnvironment structure
350 * Note: this code will not check for duplicate
351 * environment values--it will append or prepend
352 * the DT environment values regardless of what's
353 * in the current environment.
357 * PATH = /opt/dt/bin : originalPath
361 * XBMLANGPATH = originalPath : dtPath
364 * Note: Of all the environmental vars, ONLY $PATH
365 * is jammed with the DT value first.
367 * Check for NULL environment strings before the sprintf
372 * Get the application's original environment
373 * to save it in the _preDtEnvironment structure
375 * We save in the _preDtEnvironment structure
376 * only existing (non-NULL getenv()) values.
381 * Prepend BIN_PATH_STRING to the PATH component.
383 tempString = getenv(BIN_PATH_ENVIRON);
386 * First, ensure that BIN_PATH_STRING isn't already there.
388 if (!tempString || !(strstr(tempString, BIN_PATH_STRING)))
393 * No existing PATH environment variable.
394 * Just create the new DT environment.
397 strlen(BIN_PATH_ENVIRON) + strlen(BIN_PATH_STRING) +2;
399 _postDtEnvironment.binPath = XtMalloc(bytes_needed);
400 sprintf(_postDtEnvironment.binPath,
408 * Save the existing PATH.
411 strlen(BIN_PATH_ENVIRON) + strlen(tempString) + 2;
413 _preDtEnvironment.binPath = XtMalloc(bytes_needed);
414 sprintf(_preDtEnvironment.binPath,
421 strlen(BIN_PATH_ENVIRON) +
422 strlen(BIN_PATH_STRING) + 4;
424 _postDtEnvironment.binPath = XtMalloc(bytes_needed);
426 if ((ptr = strstr(tempString, "/usr/openwin/bin")))
427 #elif defined(CSRG_BASED)
428 if ((ptr = strstr(tempString, "/usr/X11R6/bin")))
429 #elif defined(__linux__)
430 if ((ptr = strstr(tempString, "/usr/bin")))
432 if ((ptr = strstr(tempString, "/usr/bin/X11")))
436 * Shorten the string in tempString
437 * to the initial segment, up to the
438 * initial slash in "/usr/bin/X11"
440 if (ptr != tempString)
443 * then put our dt string just ahead of
444 * "/usr/bin/X11" in the new PATH
447 sprintf(_postDtEnvironment.binPath,
457 * Turns out that "/usr/bin/X11"
458 * is at the front of the PATH, so...
460 sprintf(_postDtEnvironment.binPath,
468 else if (ptr = strstr(tempString, "/usr/bin"))
471 * Shorten the string in tempString
472 * to the initial segment, up to the
473 * initial slash in "/usr/bin"
475 if (ptr != tempString)
478 * then put our dt string just ahead of
479 * "/usr/bin" in the new PATH
483 sprintf(_postDtEnvironment.binPath,
493 * Turns out that "/usr/bin"
494 * is at the front of the PATH, so...
496 sprintf(_postDtEnvironment.binPath,
506 * Put our dt string on the front of the PATH
508 sprintf(_postDtEnvironment.binPath,
516 _EnvAdd (BIN_PATH_ENVIRON,
517 _postDtEnvironment.binPath,
522 tempString = getenv(PM_PATH_ENVIRON);
526 strlen(PM_PATH_ENVIRON) + strlen(tempString) + 2;
528 _preDtEnvironment.pmPath = XtMalloc(bytes_needed);
529 sprintf(_preDtEnvironment.pmPath,
536 /* it doesn't exist, so generate a default value */
537 _postDtEnvironment.pmPath = makeDefaultIconPmPath();
538 _EnvAdd(PM_PATH_ENVIRON, _postDtEnvironment.pmPath,
543 tempString = getenv(BM_PATH_ENVIRON);
547 strlen(BM_PATH_ENVIRON) + strlen(tempString) + 2;
549 _preDtEnvironment.bmPath = XtMalloc(bytes_needed);
550 sprintf(_preDtEnvironment.bmPath,
557 /* it doesn't exist, so generate a default value */
558 _postDtEnvironment.bmPath = makeDefaultIconBmPath();
559 _EnvAdd(BM_PATH_ENVIRON, _postDtEnvironment.bmPath,
564 /* Do the admin for the NLSPATH env variable */
565 tempString = getenv(NLS_PATH_ENVIRON);
568 /* If it doesn't exist, set it to the CDE default */
570 strlen(NLS_PATH_ENVIRON) + strlen(NLS_PATH_STRING) + 2;
572 _postDtEnvironment.nlsPath = XtMalloc(bytes_needed);
573 sprintf(_postDtEnvironment.nlsPath,
580 /* If it does exist, store it away so it can be
581 * restored afterwards.....
584 strlen(NLS_PATH_ENVIRON) + strlen(tempString) + 2;
586 _preDtEnvironment.nlsPath = XtMalloc(bytes_needed);
587 sprintf(_preDtEnvironment.nlsPath,
592 /* ... then append the CDE default to the existing
596 strlen(NLS_PATH_ENVIRON) +
598 strlen(NLS_PATH_STRING) + 3;
600 _postDtEnvironment.nlsPath = XtMalloc(bytes_needed);
601 sprintf(_postDtEnvironment.nlsPath,
608 _EnvAdd(NLS_PATH_ENVIRON, _postDtEnvironment.nlsPath,
612 tempString = getenv(SYSTEM_APPL_PATH_ENVIRON);
616 strlen(SYSTEM_APPL_PATH_ENVIRON) +
617 strlen(SYSTEM_APPL_PATH_STRING) + 2;
619 _postDtEnvironment.sysApplPath = XtMalloc(bytes_needed);
620 sprintf(_postDtEnvironment.sysApplPath,
622 SYSTEM_APPL_PATH_ENVIRON,
623 SYSTEM_APPL_PATH_STRING);
628 strlen(SYSTEM_APPL_PATH_ENVIRON) + strlen(tempString) + 2;
630 _preDtEnvironment.sysApplPath = XtMalloc(bytes_needed);
631 sprintf(_preDtEnvironment.sysApplPath,
633 SYSTEM_APPL_PATH_ENVIRON,
637 strlen(SYSTEM_APPL_PATH_ENVIRON) +
639 strlen(SYSTEM_APPL_PATH_STRING) + 3;
641 _postDtEnvironment.sysApplPath = XtMalloc(bytes_needed);
642 sprintf(_postDtEnvironment.sysApplPath,
644 SYSTEM_APPL_PATH_ENVIRON,
646 SYSTEM_APPL_PATH_STRING);
649 _EnvAdd (SYSTEM_APPL_PATH_ENVIRON,
650 _postDtEnvironment.sysApplPath,
654 returnValue = DT_ENV_SET;
656 else /* we've already been here -- do nothing */
658 returnValue = DT_ENV_NO_OP;
662 case DT_ENV_RESTORE_PRE_DT:
665 if (_preDtEnvironment.nlsPath) {
666 _EnvAdd (NLS_PATH_ENVIRON,
667 _preDtEnvironment.nlsPath,
671 _DtEnvRemove(NLS_PATH_ENVIRON, 0);
672 envBitVector &= ~BV_NLSPATH;
675 if (_preDtEnvironment.sysApplPath) {
676 _EnvAdd (SYSTEM_APPL_PATH_ENVIRON,
677 _preDtEnvironment.sysApplPath,
681 _DtEnvRemove(SYSTEM_APPL_PATH_ENVIRON, 0);
682 envBitVector &= ~BV_SYSAPPLPATH;
685 if (_preDtEnvironment.pmPath) {
686 _EnvAdd (PM_PATH_ENVIRON,
687 _preDtEnvironment.pmPath,
691 _DtEnvRemove(PM_PATH_ENVIRON, 0);
692 envBitVector &= ~BV_PMPATH;
695 if (_preDtEnvironment.bmPath) {
696 _EnvAdd (BM_PATH_ENVIRON,
697 _preDtEnvironment.bmPath,
701 _DtEnvRemove(BM_PATH_ENVIRON, 0);
702 envBitVector &= ~BV_BMPATH;
705 returnValue = DT_ENV_RESTORE_PRE_DT;
709 returnValue = DT_ENV_NO_OP;
713 case DT_ENV_RESTORE_POST_DT:
717 if (_postDtEnvironment.nlsPath) {
718 _EnvAdd (NLS_PATH_ENVIRON,
719 _postDtEnvironment.nlsPath,
723 if (_postDtEnvironment.pmPath) {
724 _EnvAdd (PM_PATH_ENVIRON,
725 _postDtEnvironment.pmPath,
729 if (_postDtEnvironment.bmPath) {
730 _EnvAdd (BM_PATH_ENVIRON,
731 _postDtEnvironment.bmPath,
735 if (_postDtEnvironment.sysApplPath) {
736 _EnvAdd (SYSTEM_APPL_PATH_ENVIRON,
737 _postDtEnvironment.sysApplPath,
741 returnValue = DT_ENV_RESTORE_POST_DT;
745 returnValue = DT_ENV_NO_OP;
754 _DtSvcProcessUnlock();
759 printf("DT environment set:\n");
760 printf("-------------------------------\n");
763 case DT_ENV_RESTORE_PRE_DT:
764 printf("Pre-DT environment restored:\n");
765 printf("-------------------------------\n");
768 case DT_ENV_RESTORE_POST_DT:
769 printf("Post-DT environment restored:\n");
770 printf("-------------------------------\n");
774 printf("No change from last invocation:\n");
775 printf("-------------------------------\n");
779 tempString = getenv(BIN_PATH_ENVIRON);
780 printf("%s=|%s|\n", BIN_PATH_ENVIRON, tempString);
781 tempString = getenv(SYSTEM_APPL_PATH_ENVIRON);
782 printf("%s=|%s|\n", SYSTEM_APPL_PATH_ENVIRON, tempString);
783 tempString = getenv(NLS_PATH_ENVIRON);
784 printf("%s=|%s|\n", NLS_PATH_ENVIRON, tempString);
785 tempString = getenv(PM_PATH_ENVIRON);
786 printf("%s=|%s|\n", PM_PATH_ENVIRON, tempString);
787 tempString = getenv(BM_PATH_ENVIRON);
788 printf("%s=|%s|\n", BM_PATH_ENVIRON, tempString);
791 return (returnValue);
793 } /* END OF FUNCTION _DtEnvControl */
795 /*****************************<->*************************************
797 * _EnvAdd(char * str)
802 * Adds the given string to the application's environment
803 * If the existing environment variable string was allocated
804 * by this application, the space is freed.
808 * envVar The environment variable. E.g. NLSPATH
809 * envVarSetting The environment variable setting.
810 * E.g. NLSPATH=/usr/lib/nls
811 * bv_flag The constant denoting which environment variable
814 *****************************<->***********************************/
818 char * envVarSetting,
823 if (envBitVector & bv_flag) {
824 #if defined(CSRG_BASED) || defined(__linux__)
825 setenv(envVar, envVarSetting + strlen(envVar) + 1, 1);
829 size_t envVarLen = strlen(envVar);
832 /* if we have previously put this environment variable out to the
833 * environment, we can retrieve it and reuse it rather than letting
834 * it disappear into the ether
837 for ( i = 0; environ[i] ; i++ )
839 if ( environ[i][0] == envVar[0]
840 && ( strlen(environ[i]) >= envVarLen )
841 && ( environ[i][envVarLen] == '=' )
842 && !strncmp(envVar,environ[i],envVarLen))
852 envPtr = strdup(envVarSetting);
853 strcpy(envPtr,envVarSetting);
858 /* This should never happen */
859 putenv(strdup(envVarSetting));
861 #endif /* linux || CSRG_BASED */
864 putenv(strdup(envVarSetting));
866 envBitVector |= bv_flag;
867 _DtSvcProcessUnlock();
870 /*****************************<->*************************************
879 * Removes the given string from the application's environment
880 * Uses the char **extern environment string array.
884 * str - the name of the variable to remove (e.g., "NLSPATH")
885 * length - the length of the variable--we compute it dynamically.
889 * Returns a success code--"0" if the variable is found and removed.
890 * "1" if the variable isn't found.
892 *****************************<->***********************************/
898 char **pEnviron, **pEnviron2 = environ;
902 int count = 0; /* count is the number of items in the */
904 int index; /* index will range from 0 to count - 1 */
907 if (!(len = strlen(str)))
910 pEnviron = pEnviron2;
921 pEnviron = pEnviron2;
924 for (index = 0; index < count; index++)
927 && ( strlen(p) >= len )
929 && !strncmp(p, str, len))
931 #if defined(__linux__) || defined(CSRG_BASED)
933 It seems much safer to let libc worry about this
934 rather than try to do it ourselves.
940 freeMe = pEnviron2[index];
942 /* just move the last one into the gap - any
943 * putenv destroyed the initial lexical ordering
947 pEnviron2[index] = pEnviron2[count - 1];
948 pEnviron2[count - 1] = NULL;
951 #endif /* linux || CSRG_BASED */
966 p = (char **)(environ);
981 /*************************************<->*************************************
983 * _AddToPath (sPath, sDir)
988 * Append a directory to a directory path.
992 * sPath - the old path (must be a pointer to malloc'ed memory)
993 * sDir - the directory to add to the path
998 * A pointer to the new path if successful.
999 * NULL on memory allocation failures.
1003 * This functions adds sDir to the path of directories already in
1004 * sPath. Each directory is separated by a colon (':'). The function
1005 * is designed to work off the heap. sPath should be a pointer into
1006 * the heap on entry, or NULL. If sPath is NULL, then new memory is
1007 * allocated and returned. If sPath is not NULL, the storage for sPath
1008 * is reallocated to include space for the new string. In this case,
1009 * the pointer returned may point to a different value than sPath
1010 * that was passed in. If the pointer returned is different than sPath,
1011 * then sPath is invalid and should be reassigned.
1013 *************************************<->***********************************/
1023 sNew = XtRealloc (sPath, strlen(sPath) + 1 + strlen(sDir) + 1);
1027 sNew = XtMalloc (1 + strlen(sDir) + 1);
1031 strcat (sNew, sDir);
1037 /*************************************<->*************************************
1039 * _DtWsmSetBackdropSearchPath(screen, backdropPath, useMultiColorIcons)
1044 * Append the specified directories to DTICONSEARCHPATH environment
1045 * variable. This must be done before any icon lookup by XmGetPixmap.
1046 * Each directory in backdropPath is modified so the backdrop file
1047 * names can be matched (%B, %M, etc.).
1049 * _DtEnvControl( DT_ENV_RESTORE_PRE_DT ) will restore the original
1054 * screen - screen of display
1055 * backdropPath - a colon-separated list of directories
1056 * useMultiColorIcons - True if color backdrops are desired.
1060 * Returns a success code: success: DT_ENV_SET
1061 * failure: DT_ENV_NO_OP
1063 *************************************<->***********************************/
1065 _DtWsmSetBackdropSearchPath (
1068 Boolean useMultiColorIcons)
1074 char *bm_pm_fmt = "%s/%%B.bm:%s/%%B.pm:%s/%%B";
1075 char *pm_bm_fmt = "%s/%%B.pm:%s/%%B.bm:%s/%%B";
1076 int fmtlen = strlen(pm_bm_fmt);
1077 int returnValue = DT_ENV_NO_OP;
1079 _Xstrtokparams strtok_buf;
1081 /* for creating the name=value string */
1082 char postDtEnvironmentStringBuf[MAX_ENV_STRING];
1083 char *postDtEnvironmentString;
1085 if (backdropPath == NULL) return (returnValue);
1087 sOldEnv = getenv(PM_PATH_ENVIRON);
1091 _DtSvcProcessLock();
1095 * The user has no existing value for this
1096 * environment variable. Don't save it.
1097 * Just create the new DT environment.
1100 /* make a copy that we can modify locally */
1101 sBackDirs = strdup(backdropPath);
1102 strcpy (sBackDirs, backdropPath);
1105 * Initialize path string
1107 if (useMultiColorIcons)
1108 _postDtEnvironment.pmPath = makeDefaultIconPmPath();
1110 _postDtEnvironment.pmPath = makeDefaultIconBmPath();
1112 /* get first directory */
1113 sNext = _XStrtok(sBackDirs, ":", strtok_buf);
1115 /* process each directory individually */
1116 while (sNext != NULL)
1118 bytes_needed = (3 * (strlen(sNext) + fmtlen));
1119 if (bytes_needed >= MAX_ENV_STRING)
1120 postDtEnvironmentString = XtMalloc(bytes_needed);
1122 postDtEnvironmentString = postDtEnvironmentStringBuf;
1124 if (useMultiColorIcons)
1125 sprintf(postDtEnvironmentString, pm_bm_fmt, sNext, sNext, sNext);
1127 sprintf(postDtEnvironmentString, bm_pm_fmt, sNext, sNext, sNext);
1129 _postDtEnvironment.pmPath =
1130 _AddToPath(_postDtEnvironment.pmPath, postDtEnvironmentString);
1132 if (postDtEnvironmentString != postDtEnvironmentStringBuf)
1134 if (postDtEnvironmentString) XtFree(postDtEnvironmentString);
1135 postDtEnvironmentString = NULL;
1138 /* get next directory */
1139 sNext = _XStrtok(NULL, ":", strtok_buf);
1147 * Save the old path if not previously saved
1149 if (!_preDtEnvironment.pmPath)
1151 bytes_needed = strlen(PM_PATH_ENVIRON) + strlen(sOldEnv) + 2;
1152 _preDtEnvironment.pmPath = XtMalloc(bytes_needed);
1153 sprintf(_preDtEnvironment.pmPath,"%s=%s", PM_PATH_ENVIRON, sOldEnv);
1156 /* make a copy that we can modify locally */
1157 sBackDirs = strdup(backdropPath);
1158 strcpy (sBackDirs, backdropPath);
1161 * Initialize path environment string
1163 bytes_needed = strlen(PM_PATH_ENVIRON) + strlen(sOldEnv) + 2;
1164 _postDtEnvironment.pmPath = XtMalloc(bytes_needed);
1165 sprintf(_postDtEnvironment.pmPath, "%s=%s", PM_PATH_ENVIRON, sOldEnv);
1167 /* get first directory */
1168 sNext = _XStrtok(sBackDirs, ":", strtok_buf);
1170 /* process each directory individually */
1171 while (sNext != NULL)
1173 bytes_needed = (3 * (strlen(sNext) + fmtlen));
1174 if (bytes_needed >= MAX_ENV_STRING)
1175 postDtEnvironmentString = XtMalloc(bytes_needed);
1177 postDtEnvironmentString = postDtEnvironmentStringBuf;
1179 if (useMultiColorIcons)
1180 sprintf(postDtEnvironmentString, pm_bm_fmt, sNext, sNext, sNext);
1182 sprintf(postDtEnvironmentString, bm_pm_fmt, sNext, sNext, sNext);
1184 _postDtEnvironment.pmPath =
1185 _AddToPath(_postDtEnvironment.pmPath, postDtEnvironmentString);
1187 if (postDtEnvironmentString != postDtEnvironmentStringBuf)
1189 XtFree(postDtEnvironmentString);
1190 postDtEnvironmentString = NULL;
1193 /* get next directory */
1194 sNext = _XStrtok(NULL, ":", strtok_buf);
1200 putenv(strdup(_postDtEnvironment.pmPath));
1201 envBitVector |= BV_PMPATH;
1205 * Now do the same thing for the bitmap lookup path
1207 sOldEnv = getenv(BM_PATH_ENVIRON);
1211 * The user has no existing value for this
1212 * environment variable. Don't save it.
1213 * Just create the new DT environment.
1216 /* make a copy that we can modify locally */
1217 sBackDirs = strdup(backdropPath);
1218 strcpy (sBackDirs, backdropPath);
1221 * Initialize path string
1223 _postDtEnvironment.bmPath = makeDefaultIconBmPath();
1225 /* get first directory */
1226 sNext = _XStrtok(sBackDirs, ":", strtok_buf);
1228 /* process each directory individually */
1229 while (sNext != NULL)
1231 bytes_needed = (3 * (strlen(sNext) + fmtlen));
1232 if (bytes_needed >= MAX_ENV_STRING)
1233 postDtEnvironmentString = XtMalloc(bytes_needed);
1235 postDtEnvironmentString = postDtEnvironmentStringBuf;
1237 sprintf(postDtEnvironmentString, bm_pm_fmt, sNext, sNext, sNext);
1239 _postDtEnvironment.bmPath =
1240 _AddToPath(_postDtEnvironment.bmPath, postDtEnvironmentString);
1242 if (postDtEnvironmentString != postDtEnvironmentStringBuf)
1244 if (postDtEnvironmentString) XtFree(postDtEnvironmentString);
1245 postDtEnvironmentString = NULL;
1248 /* get next directory */
1249 sNext = _XStrtok(NULL, ":", strtok_buf);
1257 * Save the old path if not previously saved
1259 if (!_preDtEnvironment.bmPath)
1261 bytes_needed = strlen(BM_PATH_ENVIRON) + strlen(sOldEnv) + 2;
1262 _preDtEnvironment.pmPath = XtMalloc(bytes_needed);
1263 sprintf(_preDtEnvironment.pmPath,"%s=%s", BM_PATH_ENVIRON, sOldEnv);
1266 /* make a copy that we can modify locally */
1267 sBackDirs = strdup(backdropPath);
1268 strcpy (sBackDirs, backdropPath);
1271 * Initialize path environment string
1273 bytes_needed = strlen(BM_PATH_ENVIRON) + strlen(sOldEnv) + 2;
1274 _postDtEnvironment.bmPath = XtMalloc(bytes_needed);
1275 sprintf(_postDtEnvironment.bmPath, "%s=%s", BM_PATH_ENVIRON, sOldEnv);
1277 /* get first directory */
1278 sNext = _XStrtok(sBackDirs, ":", strtok_buf);
1280 /* process each directory individually */
1281 while (sNext != NULL)
1283 bytes_needed = (3 * (strlen(sNext) + fmtlen));
1284 if (bytes_needed >= MAX_ENV_STRING)
1285 postDtEnvironmentString = XtMalloc(bytes_needed);
1287 postDtEnvironmentString = postDtEnvironmentStringBuf;
1289 sprintf(postDtEnvironmentString, bm_pm_fmt, sNext, sNext, sNext);
1291 _postDtEnvironment.bmPath =
1292 _AddToPath(_postDtEnvironment.bmPath, postDtEnvironmentString);
1294 if (postDtEnvironmentString != postDtEnvironmentStringBuf)
1296 XtFree(postDtEnvironmentString);
1297 postDtEnvironmentString = NULL;
1300 /* get next directory */
1301 sNext = _XStrtok(NULL, ":", strtok_buf);
1307 putenv(strdup(_postDtEnvironment.bmPath));
1308 envBitVector |= BV_BMPATH;
1310 _DtSvcProcessUnlock();
1311 returnValue = DT_ENV_SET;
1312 return (returnValue);
1314 } /* END OF FUNCTION _DtWsmSetBackdropSearchPath */
1316 /********************* eof *************************/