1 /* $XConsortium: IconSearchPath.C /main/3 1995/11/03 12:31:13 rswiston $ */
2 /*******************************************************************
3 ** (c) Copyright Hewlett-Packard Company, 1990, 1991, 1992, 1993.
4 ** All rights are reserved. Copying or other reproduction of this
5 ** program except for archival purposes is prohibited without prior
6 ** written consent of Hewlett-Packard Company.
7 ********************************************************************
8 ****************************<+>*************************************/
10 #include "SearchPath.h"
15 extern Options * options;
17 /**********************************************************************
21 * This constructor creates DTICONSEARCHPATH in a three-step
24 * 1. gathers environment variables and defaults to create a
25 * colon-separated list of paths
26 * 2. normalizes the list into host:/path format
27 * 3. builds the final version of the path
29 * Hierarchy of search paths:
31 * User's home directory
32 * System Administrator's configuration directory
36 **********************************************************************/
37 IconSearchPath::IconSearchPath
39 CDEEnvironment * user,
44 ) : SearchPath(user,envvar,sep),
48 if (user->DTICONSP()) {
49 if (user->DTUSERICONSP()) {
50 search_path = *user->DTUSERICONSP() + ",";
51 if (user->DTUSERAPPSP())
52 search_path += *user->DTUSERAPPSP() + ",";
53 search_path += user->HOME() + ",";
54 if (!user->DTICONSP()->contains(user->OS()->LocalHost(),",",":") &&
55 !user->DTAPPSP()->contains(user->OS()->LocalHost(),",",":"))
56 search_path += user->SysAdmConfig() + ",";
57 search_path += *user->DTICONSP() + ",";
58 if (user->DTICONSP()->contains(user->OS()->LocalHost(),",",":") &&
59 user->DTAPPSP()->contains(user->SysAdmConfig(),",",","))
60 search_path.replace(user->OS()->LocalHost() + ":,","");
62 search_path += *user->DTAPPSP() + ",";
63 search_path += user->SysAdmConfig() + "," +
64 user->FactoryInstall();
67 if (user->DTUSERAPPSP())
68 search_path = *user->DTUSERAPPSP() + ",";
69 search_path += user->HOME() + ",";
70 if (!user->DTICONSP()->contains(user->OS()->LocalHost(),",",":") &&
71 !user->DTAPPSP()->contains(user->OS()->LocalHost(),",",":"))
72 search_path += user->SysAdmConfig() + ",";
73 search_path += *user->DTICONSP() + ",";
74 if (user->DTICONSP()->contains(user->OS()->LocalHost(),",",":") &&
75 user->DTAPPSP()->contains(user->SysAdmConfig(),",",","))
76 search_path.replace(user->OS()->LocalHost() + ":,","");
78 search_path += *user->DTAPPSP() + ",";
79 search_path += user->SysAdmConfig() + "," +
80 user->FactoryInstall();
83 else if (user->DTUSERICONSP()) {
84 search_path = *user->DTUSERICONSP() + ",";
85 if (user->DTUSERAPPSP())
86 search_path += *user->DTUSERAPPSP() + ",";
87 search_path += *user->DTAPPSP();
90 if (user->DTUSERAPPSP())
91 search_path = *user->DTUSERAPPSP() + ",";
92 search_path += *user->DTAPPSP();
95 // NormalizePath should remove duplicates
98 if (options->CheckingUser())
99 search_path = *user->DTAPPSP();
106 /************************************************************************
107 * MakeIconSearchPath()
109 * Given a search path element (host name:path name pair), construct
110 * the appropriate path for this particular desktop subsystem:
114 * A path is constructed so that each host:/path pair is appended.
115 ************************************************************************/
116 void IconSearchPath::MakePath
121 CTokenizedString element(pair,":");
122 CString host_element = element.next();
123 CString path_element = element.next();
125 if (path_element.contains(user->HOME())) {
126 if (host_element == user->OS()->LocalHost()) {
127 if (user->OS()->isDirectory(path_element + "/icons")
128 || options->dontOptimize()) {
129 AddToPath (path_element + "/icons/%B%M" + first);
130 AddToPath (path_element + "/icons/%B%M" + second);
131 AddToPath (path_element + "/icons/%B");
135 CString dir(ConstructPath(path_element + "/icons", &host_element));
136 if (user->OS()->isDirectory(dir) || options->dontOptimize()) {
137 AddToPath (dir + "/%B%M" + first);
138 AddToPath (dir + "/%B%M" + second);
139 AddToPath (dir + "/%B");
144 if (host_element == user->OS()->LocalHost()) {
145 CString dirname(path_element);
146 if (validSearchPath(dirname)) {
148 if (user->OS()->isDirectory (dirname)
149 || options->dontOptimize()) {
150 AddToPath (dirname + "/%L/%B%M" + first);
151 AddToPath (dirname + "/%L/%B%M" + second);
152 AddToPath (dirname + "/%L/%B");
156 if (user->OS()->isDirectory (dirname) || options->dontOptimize()) {
157 AddToPath (dirname + "/%B%M" + first);
158 AddToPath (dirname + "/%B%M" + second);
159 AddToPath (dirname + "/%B");
163 CString dir = ConstructPath(path_element, &host_element);
164 if (validSearchPath(dir)) {
166 if (user->OS()->isDirectory (dir) || options->dontOptimize()) {
167 AddToPath (dir + "/%L/%B%M" + first);
168 AddToPath (dir + "/%L/%B%M" + second);
169 AddToPath (dir + "/%L/%B");
173 if (user->OS()->isDirectory(dir) || options->dontOptimize()) {
174 AddToPath (dir + "/%B%M" + first);
175 AddToPath (dir + "/%B%M" + second);
176 AddToPath (dir + "/%B");
182 /*********************************************************************
185 * This member function verifies that the path in question is a
186 * standard CDE location, i.e. /etc/dt/appconfig or /usr/dt/appconfig
187 * so that the appropriate massaging can take place.
189 *********************************************************************/
190 int IconSearchPath::validSearchPath
195 if (st == user->SysAdmConfig()) // ...,/etc/dt/appconfig,...
198 if (st == user->FactoryInstall()) // ...,/usr/dt/appconfig,...
201 // ...,/nfs/machine/etc/dt/appconfig,...
203 if (st.contains(user->SysAdmConfig(),"",Separator().data()))
206 // ...,/nfs/machine/usr/dt/appconfig,...
208 if (st.contains(user->FactoryInstall(),"",Separator().data()))
211 // If this is an APP-specified path, it also needs to be massaged.
212 // The elements in the APP paths were originally specified using
213 // host:/path, but were converted to /path for Icon searchpaths
214 // so use the comma as the leader and the trailer.
216 if (user->DTAPPSP() &&
217 user->DTAPPSP()->contains (st, ",", ","))
220 if (user->DTUSERAPPSP() &&
221 user->DTUSERAPPSP()->contains (st, ",", ","))