Add GNU LGPL headers to all .c .C and .h files
[oweals/cde.git] / cde / programs / dtsearchpath / dtsp / ManSearchPath.C
1 /*
2  * CDE - Common Desktop Environment
3  *
4  * Copyright (c) 1993-2012, The Open Group. All rights reserved.
5  *
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)
10  * any later version.
11  *
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
16  * details.
17  *
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
22  */
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 ****************************<+>*************************************/
31
32 #include "SearchPath.h"
33 #include "TTFile.h"
34 #include "Options.h"
35
36 extern Options * options;
37
38 ManSearchPath::ManSearchPath
39         (
40         CDEEnvironment * user,
41         const char *     envvar,
42         const char *     sep
43         ) : SearchPath(user, envvar, sep)
44 {
45     if (user->DTMANPATH())
46         search_path = user->FactoryManPath() + "," + *user->DTMANPATH();
47     else
48         search_path = user->FactoryManPath();
49
50     // add OS manpath now so duplicate path elements can be removed by Normalize
51     // Normalize should recognize both ':' and ',' as separators.
52
53     if (!user->OS()->MANPATH().isNull())
54         search_path += ":" + user->OS()->MANPATH();
55
56     NormalizePath();
57     TraversePath();
58 }
59
60
61 /************************************************************************
62  *  MakePath()
63  *
64  *     Given a search path element (host name:path name pair), construct
65  *     the appropriate path for this particular desktop subsystem:
66  *
67  *     DTMANPATH
68  *
69  *     A path is constructed so that each host:/path pair is appended.
70  ************************************************************************/
71 void ManSearchPath::MakePath
72         (
73         const CString & pair
74         ) 
75 {
76     CTokenizedString element(pair,":");
77     CString host_element = element.next();
78     CString path_element = element.next();
79
80     if (host_element == user->OS()->LocalHost()) {
81         if (user->OS()->isDirectory(path_element) || options->dontOptimize())
82             AddToPath (path_element);
83     }
84     else {
85         CString dirname(ConstructPath(path_element, &host_element));
86         if (user->OS()->isDirectory(dirname) || options->dontOptimize())
87             AddToPath (dirname);
88     }
89 }
90
91
92 /*****************************************************************
93  *  ExportPath()
94  *
95  *         Export the variable value to the rest of the session.
96  *
97  *****************************************************************/
98 void ManSearchPath::ExportPath()
99 {
100     CString env(GetEnvVar());
101     user->OS()->shell()->putToEnv(env,
102                        final_search_path.data());
103 }
104
105
106 void ManSearchPath::Print()
107 {
108     printf("%s:\n", GetEnvVar());
109     CString sp(GetSearchPath());
110     if (!sp.isNull()) {
111         CTokenizedString path (sp,Separator().data());
112         CString subpath = path.next();
113         while (!subpath.isNull()) {
114             printf("\t%s\n",subpath.data());
115             subpath = path.next();
116         }
117         printf("\n");
118     }
119 }
120
121 ostream & operator<< 
122         (
123         ostream & os, 
124         const ManSearchPath & sp
125         )
126 {
127     os << sp.GetEnvVar() << endl;
128     sp.PrettyPrint(os);
129     return os;
130 }