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 /* $XConsortium: IconSearchPath.C /main/3 1995/11/03 12:31:13 rswiston $ */
24 /*******************************************************************
25 ** (c) Copyright Hewlett-Packard Company, 1990, 1991, 1992, 1993.
26 ** All rights are reserved. Copying or other reproduction of this
27 ** program except for archival purposes is prohibited without prior
28 ** written consent of Hewlett-Packard Company.
29 ********************************************************************
30 ****************************<+>*************************************/
32 #include "SearchPath.h"
37 extern Options * options;
39 /**********************************************************************
43 * This constructor creates DTICONSEARCHPATH in a three-step
46 * 1. gathers environment variables and defaults to create a
47 * colon-separated list of paths
48 * 2. normalizes the list into host:/path format
49 * 3. builds the final version of the path
51 * Hierarchy of search paths:
53 * User's home directory
54 * System Administrator's configuration directory
58 **********************************************************************/
59 IconSearchPath::IconSearchPath
61 CDEEnvironment * user,
66 ) : SearchPath(user,envvar,sep),
70 if (user->DTICONSP()) {
71 if (user->DTUSERICONSP()) {
72 search_path = *user->DTUSERICONSP() + ",";
73 if (user->DTUSERAPPSP())
74 search_path += *user->DTUSERAPPSP() + ",";
75 search_path += user->HOME() + ",";
76 if (!user->DTICONSP()->contains(user->OS()->LocalHost(),",",":") &&
77 !user->DTAPPSP()->contains(user->OS()->LocalHost(),",",":"))
78 search_path += user->SysAdmConfig() + ",";
79 search_path += *user->DTICONSP() + ",";
80 if (user->DTICONSP()->contains(user->OS()->LocalHost(),",",":") &&
81 user->DTAPPSP()->contains(user->SysAdmConfig(),",",","))
82 search_path.replace(user->OS()->LocalHost() + ":,","");
84 search_path += *user->DTAPPSP() + ",";
85 search_path += user->SysAdmConfig() + "," +
86 user->FactoryInstall();
89 if (user->DTUSERAPPSP())
90 search_path = *user->DTUSERAPPSP() + ",";
91 search_path += user->HOME() + ",";
92 if (!user->DTICONSP()->contains(user->OS()->LocalHost(),",",":") &&
93 !user->DTAPPSP()->contains(user->OS()->LocalHost(),",",":"))
94 search_path += user->SysAdmConfig() + ",";
95 search_path += *user->DTICONSP() + ",";
96 if (user->DTICONSP()->contains(user->OS()->LocalHost(),",",":") &&
97 user->DTAPPSP()->contains(user->SysAdmConfig(),",",","))
98 search_path.replace(user->OS()->LocalHost() + ":,","");
100 search_path += *user->DTAPPSP() + ",";
101 search_path += user->SysAdmConfig() + "," +
102 user->FactoryInstall();
105 else if (user->DTUSERICONSP()) {
106 search_path = *user->DTUSERICONSP() + ",";
107 if (user->DTUSERAPPSP())
108 search_path += *user->DTUSERAPPSP() + ",";
109 search_path += *user->DTAPPSP();
112 if (user->DTUSERAPPSP())
113 search_path = *user->DTUSERAPPSP() + ",";
114 search_path += *user->DTAPPSP();
117 // NormalizePath should remove duplicates
120 if (options->CheckingUser())
121 search_path = *user->DTAPPSP();
128 /************************************************************************
129 * MakeIconSearchPath()
131 * Given a search path element (host name:path name pair), construct
132 * the appropriate path for this particular desktop subsystem:
136 * A path is constructed so that each host:/path pair is appended.
137 ************************************************************************/
138 void IconSearchPath::MakePath
143 CTokenizedString element(pair,":");
144 CString host_element = element.next();
145 CString path_element = element.next();
147 if (path_element.contains(user->HOME())) {
148 if (host_element == user->OS()->LocalHost()) {
149 if (user->OS()->isDirectory(path_element + "/icons")
150 || options->dontOptimize()) {
151 AddToPath (path_element + "/icons/%B%M" + first);
152 AddToPath (path_element + "/icons/%B%M" + second);
153 AddToPath (path_element + "/icons/%B");
157 CString dir(ConstructPath(path_element + "/icons", &host_element));
158 if (user->OS()->isDirectory(dir) || options->dontOptimize()) {
159 AddToPath (dir + "/%B%M" + first);
160 AddToPath (dir + "/%B%M" + second);
161 AddToPath (dir + "/%B");
166 if (host_element == user->OS()->LocalHost()) {
167 CString dirname(path_element);
168 if (validSearchPath(dirname)) {
170 if (user->OS()->isDirectory (dirname)
171 || options->dontOptimize()) {
172 AddToPath (dirname + "/%L/%B%M" + first);
173 AddToPath (dirname + "/%L/%B%M" + second);
174 AddToPath (dirname + "/%L/%B");
178 if (user->OS()->isDirectory (dirname) || options->dontOptimize()) {
179 AddToPath (dirname + "/%B%M" + first);
180 AddToPath (dirname + "/%B%M" + second);
181 AddToPath (dirname + "/%B");
185 CString dir = ConstructPath(path_element, &host_element);
186 if (validSearchPath(dir)) {
188 if (user->OS()->isDirectory (dir) || options->dontOptimize()) {
189 AddToPath (dir + "/%L/%B%M" + first);
190 AddToPath (dir + "/%L/%B%M" + second);
191 AddToPath (dir + "/%L/%B");
195 if (user->OS()->isDirectory(dir) || options->dontOptimize()) {
196 AddToPath (dir + "/%B%M" + first);
197 AddToPath (dir + "/%B%M" + second);
198 AddToPath (dir + "/%B");
204 /*********************************************************************
207 * This member function verifies that the path in question is a
208 * standard CDE location, i.e. /etc/dt/appconfig or /usr/dt/appconfig
209 * so that the appropriate massaging can take place.
211 *********************************************************************/
212 int IconSearchPath::validSearchPath
217 if (st == user->SysAdmConfig()) // ...,/etc/dt/appconfig,...
220 if (st == user->FactoryInstall()) // ...,/usr/dt/appconfig,...
223 // ...,/nfs/machine/etc/dt/appconfig,...
225 if (st.contains(user->SysAdmConfig(),"",Separator().data()))
228 // ...,/nfs/machine/usr/dt/appconfig,...
230 if (st.contains(user->FactoryInstall(),"",Separator().data()))
233 // If this is an APP-specified path, it also needs to be massaged.
234 // The elements in the APP paths were originally specified using
235 // host:/path, but were converted to /path for Icon searchpaths
236 // so use the comma as the leader and the trailer.
238 if (user->DTAPPSP() &&
239 user->DTAPPSP()->contains (st, ",", ","))
242 if (user->DTUSERAPPSP() &&
243 user->DTUSERAPPSP()->contains (st, ",", ","))