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 /* $TOG: InfoLibSearchPath.C /main/5 1998/08/17 10:33:55 mgreess $ */
25 * (c) Copyright 1996 Digital Equipment Corporation.
26 * (c) Copyright 1996 Hewlett-Packard Company.
27 * (c) Copyright 1996 International Business Machines Corp.
28 * (c) Copyright 1996 Sun Microsystems, Inc.
29 * (c) Copyright 1996 Novell, Inc.
30 * (c) Copyright 1996 FUJITSU LIMITED.
31 * (c) Copyright 1996 Hitachi.
34 #include "SearchPath.h"
39 extern Options * options;
41 /**********************************************************************
45 * this constructor creates DTINFOLIBSEARCHPATH in a three-step
48 * 1. gathers environment variables and defaults to create a
49 * colon-separated list of paths
50 * 2. normalizes the list into host:/path format
51 * 3. builds the final version of the path
53 * Hierarchy of search paths:
56 * System Administrator's configuration directory
61 **********************************************************************/
62 InfoLibSearchPath::InfoLibSearchPath
64 CDEEnvironment * user,
67 ) : SearchPath(user, envvar, sep)
69 CString oldSysAdmConfig = user->sysAdmConfig;
70 CString oldFactoryInstall = user->factoryInstall;
72 // Need to re-initialize the defaults.
73 user->sysAdmConfig = "/etc/dt";
74 user->factoryInstall = "/usr/dt";
76 if (user->DTINFOLIBSP()) {
77 if (user->DTUSERINFOLIBSP()) {
78 search_path = *user->DTUSERINFOLIBSP() + ",";
79 if (user->DTUSERAPPSP())
80 search_path += *user->DTUSERAPPSP() + ",";
81 if (!user->DTINFOLIBSP()->contains(user->OS()->LocalHost(),",",":") &&
83 !user->DTAPPSP()->contains(user->OS()->LocalHost(),",",":")))
84 search_path += user->SysAdmConfig() + ",";
85 search_path += *user->DTINFOLIBSP() + ",";
86 if (user->DTINFOLIBSP()->contains(user->OS()->LocalHost(),",",":") &&
88 user->DTAPPSP()->contains(user->SysAdmConfig(),",",","))
89 search_path.replace(user->OS()->LocalHost() + ":,","");
91 search_path += *user->DTAPPSP() + ",";
92 search_path += user->FactoryInstall();
95 if (user->DTUSERAPPSP())
96 search_path = *user->DTUSERAPPSP() + ",";
97 if (!user->DTINFOLIBSP()->contains(user->OS()->LocalHost(),",",":") &&
99 !user->DTAPPSP()->contains(user->OS()->LocalHost(),",",":")))
100 search_path += user->SysAdmConfig() + ",";
101 search_path += *user->DTINFOLIBSP() + ",";
102 if (user->DTINFOLIBSP()->contains(user->OS()->LocalHost(),",",":") &&
104 user->DTAPPSP()->contains(user->SysAdmConfig(),",",","))
105 search_path.replace(user->OS()->LocalHost() + ":,","");
107 search_path += *user->DTAPPSP() + ",";
108 search_path += user->FactoryInstall();
111 else if (user->DTUSERINFOLIBSP()) {
112 search_path = *user->DTUSERINFOLIBSP() + ",";
114 if (user->DTUSERAPPSP())
115 search_path += *user->DTUSERAPPSP() + ",";
117 search_path += user->SysAdmConfig() + ",";
119 search_path += *user->DTAPPSP() + ",";
120 search_path += user->FactoryInstall();
123 if (user->DTUSERAPPSP())
124 search_path = *user->DTUSERAPPSP() + ",";
126 search_path += user->SysAdmConfig() + ",";
128 search_path += *user->DTAPPSP() + ",";
129 search_path += user->FactoryInstall();
132 if (options->CheckingUser())
135 search_path = *user->DTAPPSP();
141 user->sysAdmConfig = oldSysAdmConfig;
142 user->factoryInstall = oldFactoryInstall;
146 /***********************************************************************
149 * Given a search path element (host name:path name pair), construct
150 * the appropriate path for this particular desktop subsystem:
152 * DTINFOLIBSEARCHPATH
154 * A path is constructed so that each host:/path pair is appended.
155 ***********************************************************************/
156 void InfoLibSearchPath::MakePath
161 CTokenizedString element(pair,":");
162 CString host_element = element.next();
163 CString path_element = element.next();
165 if (path_element.contains(user->HOME())) {
166 if (host_element == user->OS()->LocalHost()) {
167 CString infolibPath(path_element);
168 if (user->OS()->isDirectory(infolibPath + "/infolib")
169 || options->dontOptimize()) {
170 AddToPath (infolibPath + "/infolib/" + user->UserHostDir() +
172 AddToPath (infolibPath + "/infolib/%L/%I.dti");
176 CString dir(ConstructPath(path_element + "/infolib", &host_element));
177 if (user->OS()->isDirectory(dir) || options->dontOptimize()) {
178 AddToPath (dir + "/" + user->UserHostDir() + "/%I.dti");
179 AddToPath (dir + "/%I.dti");
184 if (host_element == user->OS()->LocalHost()) {
185 CString infolibPath(path_element);
186 if (validSearchPath(infolibPath)) {
187 infolibPath += "/infolib";
188 if (user->OS()->isDirectory(infolibPath)
189 || options->dontOptimize()) {
190 AddToPath (infolibPath + "/%L/%I.dti");
194 if (user->OS()->isDirectory(infolibPath) ||
195 options->dontOptimize()) {
196 AddToPath (infolibPath + "/%I.dti");
200 CString dir(ConstructPath(path_element, &host_element));
201 if (validSearchPath(dir)) {
203 if (user->OS()->isDirectory(dir) || options->dontOptimize()) {
204 AddToPath (dir + "/%L/%I.dti");
208 if (user->OS()->isDirectory(dir) || options->dontOptimize()) {
209 AddToPath (dir + "/%I.dti");
215 /*********************************************************************
218 * This member function verifies that the path in question is a
219 * standard CDE location, i.e. /etc/dt/appconfig or /usr/dt/appconfig
220 * so that the appropriate massaging can take place.
222 *********************************************************************/
223 int InfoLibSearchPath::validSearchPath
228 if (st == user->SysAdmConfig()) // ...,/etc/dt/appconfig,...
231 if (st == user->FactoryInstall()) // ...,/usr/dt/appconfig,...
234 // ...,/nfs/machine/etc/dt/appconfig,...
236 if (st.contains(user->SysAdmConfig(), "", Separator().data()))
239 // ...,/nfs/machine/usr/dt/appconfig,...
241 if (st.contains(user->FactoryInstall(),"",Separator().data()))
244 // If this is an APP-specified path, it also needs to be massaged.
245 // The elements in the APP paths were originally specified using
246 // host:/path, but were converted to /path for InfoLib searchpaths
247 // so use the comma as the leader and the trailer.
249 if (user->DTAPPSP() &&
250 user->DTAPPSP()->contains (st, ",", ","))
253 if (user->DTUSERAPPSP() &&
254 user->DTUSERAPPSP()->contains (st, ",", ","))