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 librararies 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 publically 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()
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()
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()
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"))
428 if (ptr = strstr(tempString, "/usr/bin/X11"))
432 * Shorten the string in tempString
433 * to the initial segment, up to the
434 * initial slash in "/usr/bin/X11"
436 if (ptr != tempString)
439 * then put our dt string just ahead of
440 * "/usr/bin/X11" in the new PATH
443 sprintf(_postDtEnvironment.binPath,
453 * Turns out that "/usr/bin/X11"
454 * is at the front of the PATH, so...
456 sprintf(_postDtEnvironment.binPath,
464 else if (ptr = strstr(tempString, "/usr/bin"))
467 * Shorten the string in tempString
468 * to the initial segment, up to the
469 * initial slash in "/usr/bin"
471 if (ptr != tempString)
474 * then put our dt string just ahead of
475 * "/usr/bin" in the new PATH
479 sprintf(_postDtEnvironment.binPath,
489 * Turns out that "/usr/bin"
490 * is at the front of the PATH, so...
492 sprintf(_postDtEnvironment.binPath,
502 * Put our dt string on the front of the PATH
504 sprintf(_postDtEnvironment.binPath,
512 _EnvAdd (BIN_PATH_ENVIRON,
513 _postDtEnvironment.binPath,
518 tempString = getenv(PM_PATH_ENVIRON);
522 strlen(PM_PATH_ENVIRON) + strlen(tempString) + 2;
524 _preDtEnvironment.pmPath = XtMalloc(bytes_needed);
525 sprintf(_preDtEnvironment.pmPath,
532 /* it doesn't exist, so generate a default value */
533 _postDtEnvironment.pmPath = makeDefaultIconPmPath();
534 _EnvAdd(PM_PATH_ENVIRON, _postDtEnvironment.pmPath,
539 tempString = getenv(BM_PATH_ENVIRON);
543 strlen(BM_PATH_ENVIRON) + strlen(tempString) + 2;
545 _preDtEnvironment.bmPath = XtMalloc(bytes_needed);
546 sprintf(_preDtEnvironment.bmPath,
553 /* it doesn't exist, so generate a default value */
554 _postDtEnvironment.bmPath = makeDefaultIconBmPath();
555 _EnvAdd(BM_PATH_ENVIRON, _postDtEnvironment.bmPath,
560 /* Do the admin for the NLSPATH env variable */
561 tempString = getenv(NLS_PATH_ENVIRON);
564 /* If it doesn't exist, set it to the CDE default */
566 strlen(NLS_PATH_ENVIRON) + strlen(NLS_PATH_STRING) + 2;
568 _postDtEnvironment.nlsPath = XtMalloc(bytes_needed);
569 sprintf(_postDtEnvironment.nlsPath,
576 /* If it does exist, store it away so it can be
577 * restored afterwards.....
580 strlen(NLS_PATH_ENVIRON) + strlen(tempString) + 2;
582 _preDtEnvironment.nlsPath = XtMalloc(bytes_needed);
583 sprintf(_preDtEnvironment.nlsPath,
588 /* ... then append the CDE default to the existing
592 strlen(NLS_PATH_ENVIRON) +
594 strlen(NLS_PATH_STRING) + 3;
596 _postDtEnvironment.nlsPath = XtMalloc(bytes_needed);
597 sprintf(_postDtEnvironment.nlsPath,
604 _EnvAdd(NLS_PATH_ENVIRON, _postDtEnvironment.nlsPath,
608 tempString = getenv(SYSTEM_APPL_PATH_ENVIRON);
612 strlen(SYSTEM_APPL_PATH_ENVIRON) +
613 strlen(SYSTEM_APPL_PATH_STRING) + 2;
615 _postDtEnvironment.sysApplPath = XtMalloc(bytes_needed);
616 sprintf(_postDtEnvironment.sysApplPath,
618 SYSTEM_APPL_PATH_ENVIRON,
619 SYSTEM_APPL_PATH_STRING);
624 strlen(SYSTEM_APPL_PATH_ENVIRON) + strlen(tempString) + 2;
626 _preDtEnvironment.sysApplPath = XtMalloc(bytes_needed);
627 sprintf(_preDtEnvironment.sysApplPath,
629 SYSTEM_APPL_PATH_ENVIRON,
633 strlen(SYSTEM_APPL_PATH_ENVIRON) +
635 strlen(SYSTEM_APPL_PATH_STRING) + 3;
637 _postDtEnvironment.sysApplPath = XtMalloc(bytes_needed);
638 sprintf(_postDtEnvironment.sysApplPath,
640 SYSTEM_APPL_PATH_ENVIRON,
642 SYSTEM_APPL_PATH_STRING);
645 _EnvAdd (SYSTEM_APPL_PATH_ENVIRON,
646 _postDtEnvironment.sysApplPath,
650 returnValue = DT_ENV_SET;
652 else /* we've already been here -- do nothing */
654 returnValue = DT_ENV_NO_OP;
658 case DT_ENV_RESTORE_PRE_DT:
661 if (_preDtEnvironment.nlsPath) {
662 _EnvAdd (NLS_PATH_ENVIRON,
663 _preDtEnvironment.nlsPath,
667 _DtEnvRemove(NLS_PATH_ENVIRON, 0);
668 envBitVector &= ~BV_NLSPATH;
671 if (_preDtEnvironment.sysApplPath) {
672 _EnvAdd (SYSTEM_APPL_PATH_ENVIRON,
673 _preDtEnvironment.sysApplPath,
677 _DtEnvRemove(SYSTEM_APPL_PATH_ENVIRON, 0);
678 envBitVector &= ~BV_SYSAPPLPATH;
681 if (_preDtEnvironment.pmPath) {
682 _EnvAdd (PM_PATH_ENVIRON,
683 _preDtEnvironment.pmPath,
687 _DtEnvRemove(PM_PATH_ENVIRON, 0);
688 envBitVector &= ~BV_PMPATH;
691 if (_preDtEnvironment.bmPath) {
692 _EnvAdd (BM_PATH_ENVIRON,
693 _preDtEnvironment.bmPath,
697 _DtEnvRemove(BM_PATH_ENVIRON, 0);
698 envBitVector &= ~BV_BMPATH;
701 returnValue = DT_ENV_RESTORE_PRE_DT;
705 returnValue = DT_ENV_NO_OP;
709 case DT_ENV_RESTORE_POST_DT:
713 if (_postDtEnvironment.nlsPath) {
714 _EnvAdd (NLS_PATH_ENVIRON,
715 _postDtEnvironment.nlsPath,
719 if (_postDtEnvironment.pmPath) {
720 _EnvAdd (PM_PATH_ENVIRON,
721 _postDtEnvironment.pmPath,
725 if (_postDtEnvironment.bmPath) {
726 _EnvAdd (BM_PATH_ENVIRON,
727 _postDtEnvironment.bmPath,
731 if (_postDtEnvironment.sysApplPath) {
732 _EnvAdd (SYSTEM_APPL_PATH_ENVIRON,
733 _postDtEnvironment.sysApplPath,
737 returnValue = DT_ENV_RESTORE_POST_DT;
741 returnValue = DT_ENV_NO_OP;
750 _DtSvcProcessUnlock();
755 printf("DT environment set:\n");
756 printf("-------------------------------\n");
759 case DT_ENV_RESTORE_PRE_DT:
760 printf("Pre-DT environment restored:\n");
761 printf("-------------------------------\n");
764 case DT_ENV_RESTORE_POST_DT:
765 printf("Post-DT environment restored:\n");
766 printf("-------------------------------\n");
770 printf("No change from last invocation:\n");
771 printf("-------------------------------\n");
775 tempString = getenv(BIN_PATH_ENVIRON);
776 printf("%s=|%s|\n", BIN_PATH_ENVIRON, tempString);
777 tempString = getenv(SYSTEM_APPL_PATH_ENVIRON);
778 printf("%s=|%s|\n", SYSTEM_APPL_PATH_ENVIRON, tempString);
779 tempString = getenv(NLS_PATH_ENVIRON);
780 printf("%s=|%s|\n", NLS_PATH_ENVIRON, tempString);
781 tempString = getenv(PM_PATH_ENVIRON);
782 printf("%s=|%s|\n", PM_PATH_ENVIRON, tempString);
783 tempString = getenv(BM_PATH_ENVIRON);
784 printf("%s=|%s|\n", BM_PATH_ENVIRON, tempString);
787 return (returnValue);
789 } /* END OF FUNCTION _DtEnvControl */
791 /*****************************<->*************************************
793 * _EnvAdd(char * str)
798 * Adds the given string to the application's environment
799 * If the existing environment variable string was allocated
800 * by this application, the space is freed.
804 * envVar The environment variable. E.g. NLSPATH
805 * envVarSetting The environment variable setting.
806 * E.g. NLSPATH=/usr/lib/nls
807 * bv_flag The constant denoting which environment variable
810 *****************************<->***********************************/
814 char * envVarSetting,
819 if (envBitVector & bv_flag) {
821 size_t envVarLen = strlen(envVar);
824 /* if we have previously put this environment variable out to the
825 * environment, we can retrieve it and reuse it rather than letting
826 * it disappear into the ether
829 for ( i = 0; environ[i] ; i++ )
831 if ( environ[i][0] == envVar[0]
832 && ( strlen(environ[i]) >= envVarLen )
833 && ( environ[i][envVarLen] == '=' )
834 && !strncmp(envVar,environ[i],envVarLen))
844 envPtr = strdup(envVarSetting);
845 strcpy(envPtr,envVarSetting);
850 /* This should never happen */
851 putenv(strdup(envVarSetting));
855 putenv(strdup(envVarSetting));
857 envBitVector |= bv_flag;
858 _DtSvcProcessUnlock();
861 /*****************************<->*************************************
870 * Removes the given string from the application's environment
871 * Uses the char **extern environment string array.
875 * str - the name of the variable to remove (e.g., "NLSPATH")
876 * length - the length of the variable--we compute it dynamically.
880 * Returns a success code--"0" if the variable is found and removed.
881 * "1" if the variable isn't found.
883 *****************************<->***********************************/
889 char **pEnviron, **pEnviron2 = environ;
893 int count = 0; /* count is the number of items in the */
895 int index; /* index will range from 0 to count - 1 */
898 if (!(len = strlen(str)))
901 pEnviron = pEnviron2;
912 pEnviron = pEnviron2;
915 for (index = 0; index < count; index++)
918 && ( strlen(p) >= len )
920 && !strncmp(p, str, len))
922 freeMe = pEnviron2[index];
924 /* just move the last one into the gap - any
925 * putenv destroyed the initial lexical ordering
929 pEnviron2[index] = pEnviron2[count - 1];
930 pEnviron2[count - 1] = NULL;
947 p = (char **)(environ);
962 /*************************************<->*************************************
964 * _AddToPath (sPath, sDir)
969 * Append a directory to a directory path.
973 * sPath - the old path (must be a pointer to malloc'ed memory)
974 * sDir - the directory to add to the path
979 * A pointer to the new path if successful.
980 * NULL on memory allocation failures.
984 * This functions adds sDir to the path of directories already in
985 * sPath. Each directory is separated by a colon (':'). The function
986 * is designed to work off the heap. sPath should be a pointer into
987 * the heap on entry, or NULL. If sPath is NULL, then new memory is
988 * allocated and returned. If sPath is not NULL, the storage for sPath
989 * is reallocated to include space for the new string. In this case,
990 * the pointer returned may point to a different value than sPath
991 * that was passed in. If the pointer returned is different than sPath,
992 * then sPath is invalid and should be reassigned.
994 *************************************<->***********************************/
1004 sNew = XtRealloc (sPath, 1+strlen(sPath)+1+strlen(sDir));
1008 sNew = XtMalloc (1+strlen(sPath)+1+strlen(sDir));
1012 strcat (sNew, sDir);
1018 /*************************************<->*************************************
1020 * _DtWsmSetBackdropSearchPath(screen, backdropPath, useMultiColorIcons)
1025 * Append the specified directories to DTICONSEARCHPATH environment
1026 * variable. This must be done before any icon lookup by XmGetPixmap.
1027 * Each directory in backdropPath is modified so the backdrop file
1028 * names can be matched (%B, %M, etc.).
1030 * _DtEnvControl( DT_ENV_RESTORE_PRE_DT ) will restore the original
1035 * screen - screen of display
1036 * backdropPath - a colon-separated list of directories
1037 * useMultiColorIcons - True if color backdrops are desired.
1041 * Returns a success code: success: DT_ENV_SET
1042 * failure: DT_ENV_NO_OP
1044 *************************************<->***********************************/
1046 _DtWsmSetBackdropSearchPath (
1049 Boolean useMultiColorIcons)
1055 char *bm_pm_fmt = "%s/%%B.bm:%s/%%B.pm:%s/%%B";
1056 char *pm_bm_fmt = "%s/%%B.pm:%s/%%B.bm:%s/%%B";
1057 int fmtlen = strlen(pm_bm_fmt);
1058 int returnValue = DT_ENV_NO_OP;
1060 _Xstrtokparams strtok_buf;
1062 /* for creating the name=value string */
1063 char postDtEnvironmentStringBuf[MAX_ENV_STRING];
1064 char *postDtEnvironmentString;
1066 if (backdropPath == NULL) return (returnValue);
1068 sOldEnv = getenv(PM_PATH_ENVIRON);
1072 _DtSvcProcessLock();
1076 * The user has no existing value for this
1077 * environment variable. Don't save it.
1078 * Just create the new DT environment.
1081 /* make a copy that we can modify locally */
1082 sBackDirs = strdup(backdropPath);
1083 strcpy (sBackDirs, backdropPath);
1086 * Initialize path string
1088 if (useMultiColorIcons)
1089 _postDtEnvironment.pmPath = makeDefaultIconPmPath();
1091 _postDtEnvironment.pmPath = makeDefaultIconBmPath();
1093 /* get first directory */
1094 sNext = _XStrtok(sBackDirs, ":", strtok_buf);
1096 /* process each directory individually */
1097 while (sNext != NULL)
1099 bytes_needed = (3 * (strlen(sNext) + fmtlen));
1100 if (bytes_needed >= MAX_ENV_STRING)
1101 postDtEnvironmentString = XtMalloc(bytes_needed);
1103 postDtEnvironmentString = postDtEnvironmentStringBuf;
1105 if (useMultiColorIcons)
1106 sprintf(postDtEnvironmentString, pm_bm_fmt, sNext, sNext, sNext);
1108 sprintf(postDtEnvironmentString, bm_pm_fmt, sNext, sNext, sNext);
1110 _postDtEnvironment.pmPath =
1111 _AddToPath(_postDtEnvironment.pmPath, postDtEnvironmentString);
1113 if (postDtEnvironmentString != postDtEnvironmentStringBuf)
1115 if (postDtEnvironmentString) XtFree(postDtEnvironmentString);
1116 postDtEnvironmentString = NULL;
1119 /* get next directory */
1120 sNext = _XStrtok(NULL, ":", strtok_buf);
1128 * Save the old path if not previously saved
1130 if (!_preDtEnvironment.pmPath)
1132 bytes_needed = strlen(PM_PATH_ENVIRON) + strlen(sOldEnv) + 2;
1133 _preDtEnvironment.pmPath = XtMalloc(bytes_needed);
1134 sprintf(_preDtEnvironment.pmPath,"%s=%s", PM_PATH_ENVIRON, sOldEnv);
1137 /* make a copy that we can modify locally */
1138 sBackDirs = strdup(backdropPath);
1139 strcpy (sBackDirs, backdropPath);
1142 * Initialize path environment string
1144 bytes_needed = strlen(PM_PATH_ENVIRON) + strlen(sOldEnv) + 2;
1145 _postDtEnvironment.pmPath = XtMalloc(bytes_needed);
1146 sprintf(_postDtEnvironment.pmPath, "%s=%s", PM_PATH_ENVIRON, sOldEnv);
1148 /* get first directory */
1149 sNext = _XStrtok(sBackDirs, ":", strtok_buf);
1151 /* process each directory individually */
1152 while (sNext != NULL)
1154 bytes_needed = (3 * (strlen(sNext) + fmtlen));
1155 if (bytes_needed >= MAX_ENV_STRING)
1156 postDtEnvironmentString = XtMalloc(bytes_needed);
1158 postDtEnvironmentString = postDtEnvironmentStringBuf;
1160 if (useMultiColorIcons)
1161 sprintf(postDtEnvironmentString, pm_bm_fmt, sNext, sNext, sNext);
1163 sprintf(postDtEnvironmentString, bm_pm_fmt, sNext, sNext, sNext);
1165 _postDtEnvironment.pmPath =
1166 _AddToPath(_postDtEnvironment.pmPath, postDtEnvironmentString);
1168 if (postDtEnvironmentString != postDtEnvironmentStringBuf)
1170 if (postDtEnvironmentString) XtFree(postDtEnvironmentString);
1171 postDtEnvironmentString = NULL;
1174 /* get next directory */
1175 sNext = _XStrtok(NULL, ":", strtok_buf);
1181 putenv(strdup(_postDtEnvironment.pmPath));
1182 envBitVector |= BV_PMPATH;
1186 * Now do the same thing for the bitmap lookup path
1188 sOldEnv = getenv(BM_PATH_ENVIRON);
1192 * The user has no existing value for this
1193 * environment variable. Don't save it.
1194 * Just create the new DT environment.
1197 /* make a copy that we can modify locally */
1198 sBackDirs = strdup(backdropPath);
1199 strcpy (sBackDirs, backdropPath);
1202 * Initialize path string
1204 _postDtEnvironment.bmPath = makeDefaultIconBmPath();
1206 /* get first directory */
1207 sNext = _XStrtok(sBackDirs, ":", strtok_buf);
1209 /* process each directory individually */
1210 while (sNext != NULL)
1212 bytes_needed = (3 * (strlen(sNext) + fmtlen));
1213 if (bytes_needed >= MAX_ENV_STRING)
1214 postDtEnvironmentString = XtMalloc(bytes_needed);
1216 postDtEnvironmentString = postDtEnvironmentStringBuf;
1218 sprintf(postDtEnvironmentString, bm_pm_fmt, sNext, sNext, sNext);
1220 _postDtEnvironment.bmPath =
1221 _AddToPath(_postDtEnvironment.bmPath, postDtEnvironmentString);
1223 if (postDtEnvironmentString != postDtEnvironmentStringBuf)
1225 if (postDtEnvironmentString) XtFree(postDtEnvironmentString);
1226 postDtEnvironmentString = NULL;
1229 /* get next directory */
1230 sNext = _XStrtok(NULL, ":", strtok_buf);
1238 * Save the old path if not previously saved
1240 if (!_preDtEnvironment.bmPath)
1242 bytes_needed = strlen(BM_PATH_ENVIRON) + strlen(sOldEnv) + 2;
1243 _preDtEnvironment.pmPath = XtMalloc(bytes_needed);
1244 sprintf(_preDtEnvironment.pmPath,"%s=%s", BM_PATH_ENVIRON, sOldEnv);
1247 /* make a copy that we can modify locally */
1248 sBackDirs = strdup(backdropPath);
1249 strcpy (sBackDirs, backdropPath);
1252 * Initialize path environment string
1254 bytes_needed = strlen(BM_PATH_ENVIRON) + strlen(sOldEnv) + 2;
1255 _postDtEnvironment.bmPath = XtMalloc(bytes_needed);
1256 sprintf(_postDtEnvironment.bmPath, "%s=%s", BM_PATH_ENVIRON, sOldEnv);
1258 /* get first directory */
1259 sNext = _XStrtok(sBackDirs, ":", strtok_buf);
1261 /* process each directory individually */
1262 while (sNext != NULL)
1264 bytes_needed = (3 * (strlen(sNext) + fmtlen));
1265 if (bytes_needed >= MAX_ENV_STRING)
1266 postDtEnvironmentString = XtMalloc(bytes_needed);
1268 postDtEnvironmentString = postDtEnvironmentStringBuf;
1270 sprintf(postDtEnvironmentString, bm_pm_fmt, sNext, sNext, sNext);
1272 _postDtEnvironment.bmPath =
1273 _AddToPath(_postDtEnvironment.bmPath, postDtEnvironmentString);
1275 if (postDtEnvironmentString != postDtEnvironmentStringBuf)
1277 if (postDtEnvironmentString) XtFree(postDtEnvironmentString);
1278 postDtEnvironmentString = NULL;
1281 /* get next directory */
1282 sNext = _XStrtok(NULL, ":", strtok_buf);
1288 putenv(strdup(_postDtEnvironment.bmPath));
1289 envBitVector |= BV_BMPATH;
1291 _DtSvcProcessUnlock();
1292 returnValue = DT_ENV_SET;
1293 return (returnValue);
1295 } /* END OF FUNCTION _DtWsmSetBackdropSearchPath */
1297 /********************* eof *************************/