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: ManSearchPath.C /main/3 1995/11/03 12:31:46 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"
36 extern Options * options;
38 ManSearchPath::ManSearchPath
40 CDEEnvironment * user,
43 ) : SearchPath(user, envvar, sep)
45 if (user->DTMANPATH())
46 search_path = user->FactoryManPath() + "," + *user->DTMANPATH();
48 search_path = user->FactoryManPath();
50 // add OS manpath now so duplicate path elements can be removed by Normalize
51 // Normalize should recognize both ':' and ',' as separators.
53 if (!user->OS()->MANPATH().isNull())
54 search_path += ":" + user->OS()->MANPATH();
61 /************************************************************************
64 * Given a search path element (host name:path name pair), construct
65 * the appropriate path for this particular desktop subsystem:
69 * A path is constructed so that each host:/path pair is appended.
70 ************************************************************************/
71 void ManSearchPath::MakePath
76 CTokenizedString element(pair,":");
77 CString host_element = element.next();
78 CString path_element = element.next();
80 if (host_element == user->OS()->LocalHost()) {
81 if (user->OS()->isDirectory(path_element) || options->dontOptimize())
82 AddToPath (path_element);
85 CString dirname(ConstructPath(path_element, &host_element));
86 if (user->OS()->isDirectory(dirname) || options->dontOptimize())
91 #if defined(__FreeBSD__)
92 /*****************************************************************
95 * Check whether to leave MANPATH unmodified (or unset)
98 int ManSearchPath::useSystemPath()
100 if (user->OS()->getEnvironmentVariable("MANPATH").isNull()) {
108 /*****************************************************************
111 * Export the variable value to the rest of the session.
113 *****************************************************************/
114 void ManSearchPath::ExportPath()
116 if (!useSystemPath()) {
117 CString env(GetEnvVar());
118 user->OS()->shell()->putToEnv(env,
119 final_search_path.data());
124 void ManSearchPath::Print()
126 printf("%s:\n", GetEnvVar());
127 CString sp(GetSearchPath());
128 if (!useSystemPath() && !sp.isNull()) {
129 CTokenizedString path (sp,Separator().data());
130 CString subpath = path.next();
131 while (!subpath.isNull()) {
132 printf("\t%s\n",subpath.data());
133 subpath = path.next();
139 #if defined(linux) || defined(CSRG_BASED) || defined(sun)
140 std::ostream & operator<<
143 const ManSearchPath & sp
149 const ManSearchPath & sp
153 #if defined(linux) || defined(CSRG_BASED) || defined(sun)
154 os << sp.GetEnvVar() << std::endl;
156 os << sp.GetEnvVar() << endl;