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: AppSearchPath.C /main/2 1995/07/17 14:08:52 drk $ */
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 /**********************************************************************
41 * AppSearchPath - this constructor creates DTAPPSEARCHPATH in a three-
44 * 1. gathers environment variables and defaults
45 * to create a comma-separated list of paths
46 * 2. normalizes the list into host:/path format
47 * 3. builds the final version of the path
49 * Hierarchy of search paths:
51 * User's home directory
52 * System Administrator's configuration directory
56 **********************************************************************/
57 AppSearchPath::AppSearchPath
59 CDEEnvironment * user,
62 ) : SearchPath(user, envvar, sep)
64 if (user->DTAPPSP()) {
65 if (user->DTUSERAPPSP()) {
66 search_path = *user->DTUSERAPPSP() + "," +
68 if (!user->DTAPPSP()->contains(user->OS()->LocalHost(),",",":"))
69 search_path += user->SysAdmConfig() + ",";
70 search_path += *user->DTAPPSP() + "," +
71 user->FactoryInstall();
74 search_path = user->HOME() + ",";
75 if (!user->DTAPPSP()->contains(user->OS()->LocalHost(),",",":"))
76 search_path += user->SysAdmConfig() + ",";
77 search_path += *user->DTAPPSP() + "," +
78 user->FactoryInstall();
82 else if (user->DTUSERAPPSP())
83 search_path = *user->DTUSERAPPSP() + "," + user->DefaultSearchPath();
86 search_path = user->DefaultSearchPath();
88 if (options->CheckingUser())
89 search_path = user->DefaultSearchPath();
91 // Now convert the initial list to host:/path format
95 // Convert the host:/path list to a colon-separated list of
102 /************************************************************************
105 * Given a search path element (host name:path name pair), construct
106 * the appropriate path for this particular desktop subsystem:
110 * A path is constructed so that each host:/path pair is appended.
111 ************************************************************************/
112 void AppSearchPath::MakePath
117 CTokenizedString element(pair,":,");
118 CString host_element = element.next();
119 CString path_element = element.next();
121 if (host_element == user->OS()->LocalHost()) {
122 if (user->OS()->isDirectory(path_element) || options->dontOptimize())
123 AddToPath (path_element);
126 CString dir(ConstructPath(path_element, &host_element));
127 if (user->OS()->isDirectory(dir) || options->dontOptimize())
133 void AppSearchPath::FixUp()
135 if (!final_search_path.isNull()) {
136 CTokenizedString subpath(final_search_path,",");
137 CString dirname = subpath.next();
138 CString result_sp(dirname);
140 result_sp += "/appmanager";
141 if (!dirname.contains(user->HOME()))
142 result_sp += "/%L:" + dirname + "/appmanager/C";
143 dirname = subpath.next();
144 if (dirname.isNull())
146 result_sp += ":" + dirname;
148 final_search_path = result_sp;