1 /* $TOG: InfoLibSearchPath.C /main/5 1998/08/17 10:33:55 mgreess $
3 * (c) Copyright 1996 Digital Equipment Corporation.
4 * (c) Copyright 1996 Hewlett-Packard Company.
5 * (c) Copyright 1996 International Business Machines Corp.
6 * (c) Copyright 1996 Sun Microsystems, Inc.
7 * (c) Copyright 1996 Novell, Inc.
8 * (c) Copyright 1996 FUJITSU LIMITED.
9 * (c) Copyright 1996 Hitachi.
12 #include "SearchPath.h"
17 extern Options * options;
19 /**********************************************************************
23 * this constructor creates DTINFOLIBSEARCHPATH in a three-step
26 * 1. gathers environment variables and defaults to create a
27 * colon-separated list of paths
28 * 2. normalizes the list into host:/path format
29 * 3. builds the final version of the path
31 * Hierarchy of search paths:
34 * System Administrator's configuration directory
39 **********************************************************************/
40 InfoLibSearchPath::InfoLibSearchPath
42 CDEEnvironment * user,
45 ) : SearchPath(user, envvar, sep)
47 CString oldSysAdmConfig = user->sysAdmConfig;
48 CString oldFactoryInstall = user->factoryInstall;
50 // Need to re-initialize the defaults.
51 user->sysAdmConfig = "/etc/dt";
52 user->factoryInstall = "/usr/dt";
54 if (user->DTINFOLIBSP()) {
55 if (user->DTUSERINFOLIBSP()) {
56 search_path = *user->DTUSERINFOLIBSP() + ",";
57 if (user->DTUSERAPPSP())
58 search_path += *user->DTUSERAPPSP() + ",";
59 if (!user->DTINFOLIBSP()->contains(user->OS()->LocalHost(),",",":") &&
61 !user->DTAPPSP()->contains(user->OS()->LocalHost(),",",":")))
62 search_path += user->SysAdmConfig() + ",";
63 search_path += *user->DTINFOLIBSP() + ",";
64 if (user->DTINFOLIBSP()->contains(user->OS()->LocalHost(),",",":") &&
66 user->DTAPPSP()->contains(user->SysAdmConfig(),",",","))
67 search_path.replace(user->OS()->LocalHost() + ":,","");
69 search_path += *user->DTAPPSP() + ",";
70 search_path += user->FactoryInstall();
73 if (user->DTUSERAPPSP())
74 search_path = *user->DTUSERAPPSP() + ",";
75 if (!user->DTINFOLIBSP()->contains(user->OS()->LocalHost(),",",":") &&
77 !user->DTAPPSP()->contains(user->OS()->LocalHost(),",",":")))
78 search_path += user->SysAdmConfig() + ",";
79 search_path += *user->DTINFOLIBSP() + ",";
80 if (user->DTINFOLIBSP()->contains(user->OS()->LocalHost(),",",":") &&
82 user->DTAPPSP()->contains(user->SysAdmConfig(),",",","))
83 search_path.replace(user->OS()->LocalHost() + ":,","");
85 search_path += *user->DTAPPSP() + ",";
86 search_path += user->FactoryInstall();
89 else if (user->DTUSERINFOLIBSP()) {
90 search_path = *user->DTUSERINFOLIBSP() + ",";
92 if (user->DTUSERAPPSP())
93 search_path += *user->DTUSERAPPSP() + ",";
95 search_path += user->SysAdmConfig() + ",";
97 search_path += *user->DTAPPSP() + ",";
98 search_path += user->FactoryInstall();
101 if (user->DTUSERAPPSP())
102 search_path = *user->DTUSERAPPSP() + ",";
104 search_path += user->SysAdmConfig() + ",";
106 search_path += *user->DTAPPSP() + ",";
107 search_path += user->FactoryInstall();
110 if (options->CheckingUser())
113 search_path = *user->DTAPPSP();
119 user->sysAdmConfig = oldSysAdmConfig;
120 user->factoryInstall = oldFactoryInstall;
124 /***********************************************************************
127 * Given a search path element (host name:path name pair), construct
128 * the appropriate path for this particular desktop subsystem:
130 * DTINFOLIBSEARCHPATH
132 * A path is constructed so that each host:/path pair is appended.
133 ***********************************************************************/
134 void InfoLibSearchPath::MakePath
139 CTokenizedString element(pair,":");
140 CString host_element = element.next();
141 CString path_element = element.next();
143 if (path_element.contains(user->HOME())) {
144 if (host_element == user->OS()->LocalHost()) {
145 CString infolibPath(path_element);
146 if (user->OS()->isDirectory(infolibPath + "/infolib")
147 || options->dontOptimize()) {
148 AddToPath (infolibPath + "/infolib/" + user->UserHostDir() +
150 AddToPath (infolibPath + "/infolib/%L/%I.dti");
154 CString dir(ConstructPath(path_element + "/infolib", &host_element));
155 if (user->OS()->isDirectory(dir) || options->dontOptimize()) {
156 AddToPath (dir + "/" + user->UserHostDir() + "/%I.dti");
157 AddToPath (dir + "/%I.dti");
162 if (host_element == user->OS()->LocalHost()) {
163 CString infolibPath(path_element);
164 if (validSearchPath(infolibPath)) {
165 infolibPath += "/infolib";
166 if (user->OS()->isDirectory(infolibPath)
167 || options->dontOptimize()) {
168 AddToPath (infolibPath + "/%L/%I.dti");
172 if (user->OS()->isDirectory(infolibPath) ||
173 options->dontOptimize()) {
174 AddToPath (infolibPath + "/%I.dti");
178 CString dir(ConstructPath(path_element, &host_element));
179 if (validSearchPath(dir)) {
181 if (user->OS()->isDirectory(dir) || options->dontOptimize()) {
182 AddToPath (dir + "/%L/%I.dti");
186 if (user->OS()->isDirectory(dir) || options->dontOptimize()) {
187 AddToPath (dir + "/%I.dti");
193 /*********************************************************************
196 * This member function verifies that the path in question is a
197 * standard CDE location, i.e. /etc/dt/appconfig or /usr/dt/appconfig
198 * so that the appropriate massaging can take place.
200 *********************************************************************/
201 int InfoLibSearchPath::validSearchPath
206 if (st == user->SysAdmConfig()) // ...,/etc/dt/appconfig,...
209 if (st == user->FactoryInstall()) // ...,/usr/dt/appconfig,...
212 // ...,/nfs/machine/etc/dt/appconfig,...
214 if (st.contains(user->SysAdmConfig(), "", Separator().data()))
217 // ...,/nfs/machine/usr/dt/appconfig,...
219 if (st.contains(user->FactoryInstall(),"",Separator().data()))
222 // If this is an APP-specified path, it also needs to be massaged.
223 // The elements in the APP paths were originally specified using
224 // host:/path, but were converted to /path for InfoLib searchpaths
225 // so use the comma as the leader and the trailer.
227 if (user->DTAPPSP() &&
228 user->DTAPPSP()->contains (st, ",", ","))
231 if (user->DTUSERAPPSP() &&
232 user->DTUSERAPPSP()->contains (st, ",", ","))