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 /* $XConsortium: HelpSearchPath.C /main/3 1995/11/03 12:30:59 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 DTHELPSEARCHPATH 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 HelpSearchPath::HelpSearchPath
61 CDEEnvironment * user,
64 ) : SearchPath(user, envvar, sep)
66 if (user->DTHELPSP()) {
67 if (user->DTUSERHELPSP()) {
68 search_path = *user->DTUSERHELPSP() + ",";
69 if (user->DTUSERAPPSP())
70 search_path += *user->DTUSERAPPSP() + ",";
71 search_path += user->HOME() + ",";
72 if (!user->DTHELPSP()->contains(user->OS()->LocalHost(),",",":") &&
73 !user->DTAPPSP()->contains(user->OS()->LocalHost(),",",":"))
74 search_path += user->SysAdmConfig() + ",";
75 search_path += *user->DTHELPSP() + ",";
76 if (user->DTHELPSP()->contains(user->OS()->LocalHost(),",",":") &&
77 user->DTAPPSP()->contains(user->SysAdmConfig(),",",","))
78 search_path.replace(user->OS()->LocalHost() + ":,","");
80 search_path += *user->DTAPPSP() + ",";
81 search_path += user->FactoryInstall();
84 if (user->DTUSERAPPSP())
85 search_path = *user->DTUSERAPPSP() + ",";
86 search_path += user->HOME() + ",";
87 if (!user->DTHELPSP()->contains(user->OS()->LocalHost(),",",":") &&
88 !user->DTAPPSP()->contains(user->OS()->LocalHost(),",",":"))
89 search_path += user->SysAdmConfig() + ",";
90 search_path += *user->DTHELPSP() + ",";
91 if (user->DTHELPSP()->contains(user->OS()->LocalHost(),",",":") &&
92 user->DTAPPSP()->contains(user->SysAdmConfig(),",",","))
93 search_path.replace(user->OS()->LocalHost() + ":,","");
95 search_path += *user->DTAPPSP() + ",";
96 search_path += user->FactoryInstall();
99 else if (user->DTUSERHELPSP()) {
100 search_path = *user->DTUSERHELPSP() + ",";
101 if (user->DTUSERAPPSP())
102 search_path += *user->DTUSERAPPSP() + ",";
103 search_path += *user->DTAPPSP();
106 if (user->DTUSERAPPSP())
107 search_path = *user->DTUSERAPPSP() + ",";
108 search_path += *user->DTAPPSP();
111 if (options->CheckingUser())
112 search_path = *user->DTAPPSP();
118 AddToPath ("/etc/vhelp/%T/%L/%H");
119 AddToPath ("/etc/vhelp/%T/%H");
120 AddToPath ("/etc/vhelp/%T/%L/%H.hv");
121 AddToPath ("/etc/vhelp/%T/%H.hv");
122 AddToPath ("/etc/vhelp/%T/C/%H");
123 AddToPath ("/etc/vhelp/%T/C/%H.hv");
124 AddToPath ("/usr/vhelp/%T/%L/%H");
125 AddToPath ("/usr/vhelp/%T/%H");
126 AddToPath ("/usr/vhelp/%T/%L/%H.hv");
127 AddToPath ("/usr/vhelp/%T/%H.hv");
128 AddToPath ("/usr/vhelp/%T/C/%H");
129 AddToPath ("/usr/vhelp/%T/C/%H.hv");
134 /***********************************************************************
137 * Given a search path element (host name:path name pair), construct
138 * the appropriate path for this particular desktop subsystem:
142 * A path is constructed so that each host:/path pair is appended.
143 ***********************************************************************/
144 void HelpSearchPath::MakePath
149 CTokenizedString element(pair,":");
150 CString host_element = element.next();
151 CString path_element = element.next();
153 if (path_element.contains(user->HOME())) {
154 if (host_element == user->OS()->LocalHost()) {
155 CString helpPath(path_element);
156 if (user->OS()->isDirectory(helpPath + "/help")
157 || options->dontOptimize()) {
158 AddToPath (helpPath + "/help/" + user->UserHostDir() + "/%H");
159 AddToPath (helpPath + "/help/" + user->UserHostDir() + "/%H.sdl");
160 AddToPath (helpPath + "/help/" + user->UserHostDir() + "/%H.hv");
161 AddToPath (helpPath + "/help/%H");
162 AddToPath (helpPath + "/help/%H.sdl");
163 AddToPath (helpPath + "/help/%H.hv");
167 CString dir(ConstructPath(path_element + "/help", &host_element));
168 if (user->OS()->isDirectory(dir) || options->dontOptimize()) {
169 AddToPath (dir + "/" + user->UserHostDir() + "/%H");
170 AddToPath (dir + "/" + user->UserHostDir() + "/%H.sdl");
171 AddToPath (dir + "/" + user->UserHostDir() + "/%H.hv");
172 AddToPath (dir + "/%H");
173 AddToPath (dir + "/%H.sdl");
174 AddToPath (dir + "/%H.hv");
179 if (host_element == user->OS()->LocalHost()) {
180 CString helpPath(path_element);
181 if (validSearchPath(helpPath)) {
183 if (user->OS()->isDirectory(helpPath)
184 || options->dontOptimize()) {
185 AddToPath (helpPath + "/%L/%H");
186 AddToPath (helpPath + "/%L/%H.sdl");
187 AddToPath (helpPath + "/%L/%H.hv");
191 if (user->OS()->isDirectory(helpPath) || options->dontOptimize()) {
192 AddToPath (helpPath + "/%H");
193 AddToPath (helpPath + "/%H.sdl");
194 AddToPath (helpPath + "/%H.hv");
198 CString dir(ConstructPath(path_element, &host_element));
199 if (validSearchPath(dir)) {
201 if (user->OS()->isDirectory(dir) || options->dontOptimize()) {
202 AddToPath (dir + "/%L/%H");
203 AddToPath (dir + "/%L/%H.sdl");
204 AddToPath (dir + "/%L/%H.hv");
208 if (user->OS()->isDirectory(dir) || options->dontOptimize()) {
209 AddToPath (dir + "/%H");
210 AddToPath (dir + "/%H.sdl");
211 AddToPath (dir + "/%H.hv");
217 /*********************************************************************
220 * This member function verifies that the path in question is a
221 * standard CDE location, i.e. /etc/dt/appconfig or /usr/dt/appconfig
222 * so that the appropriate massaging can take place.
224 *********************************************************************/
225 int HelpSearchPath::validSearchPath
230 if (st == user->SysAdmConfig()) // ...,/etc/dt/appconfig,...
233 if (st == user->FactoryInstall()) // ...,/usr/dt/appconfig,...
236 // ...,/nfs/machine/etc/dt/appconfig,...
238 if (st.contains(user->SysAdmConfig(), "", Separator().data()))
241 // ...,/nfs/machine/usr/dt/appconfig,...
243 if (st.contains(user->FactoryInstall(),"",Separator().data()))
246 // If this is an APP-specified path, it also needs to be massaged.
247 // The elements in the APP paths were originally specified using
248 // host:/path, but were converted to /path for Help searchpaths
249 // so use the comma as the leader and the trailer.
251 if (user->DTAPPSP() &&
252 user->DTAPPSP()->contains (st, ",", ","))
255 if (user->DTUSERAPPSP() &&
256 user->DTUSERAPPSP()->contains (st, ",", ","))