Resolve many build warnings
[oweals/cde.git] / cde / programs / dtsearchpath / libCliSrv / TTFile.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: TTFile.C /main/2 1995/07/17 14:10:04 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 ****************************<+>*************************************/
31
32 #include "TTFile.h"
33 #include <Tt/tt_c.h>
34 #include <stdio.h>
35
36 TTFile::TTFile
37         (
38         const CString & host, 
39         const CString & path
40         ) : CString(), status(TT_OK)
41 {
42     char * temp = tt_host_file_netfile(host.data(), path.data());
43
44     if ((status = tt_ptr_error(temp)) != TT_OK)
45         Throw (TT_Exception(temp));
46
47     contents = tt_netfile_file(temp);
48     tt_free(temp);
49
50     if ((status = tt_ptr_error(contents)) != TT_OK)
51         Throw (TT_Exception(contents));
52 }
53
54 TTFile::TTFile
55         (
56         const TTFile & file
57         )
58 {
59     contents = new char [file.length() + 1];
60     strcpy(contents,file.data());
61     status = file.status;
62 }
63
64 TTFile::~TTFile()
65 {
66     if (contents)
67         tt_free(contents);
68 }
69
70 #ifndef HAS_EXCEPTIONS
71 void TTFile::TT_Exception
72         (
73         char *     str
74         )
75 {
76 #ifdef IOSTREAMSWORKS
77     cerr << tt_status_message(tt_pointer_error(str)) << endl;
78 #else
79     fprintf(stderr, "%s\n", tt_status_message(tt_pointer_error(str)));
80 #endif
81 }
82 #endif
83
84 TTFile & TTFile::operator=
85         (
86         const TTFile & file
87         )
88 {
89     if (file != *this) {
90         delete [] contents;
91         contents = new char [file.length() + 1];
92         strcpy(contents,file.data());
93         status = file.status;
94     }
95     return *this;
96 }
97
98 #if defined(linux) || defined(CSRG_BASED)
99 std::ostream & operator<<
100         (
101         std::ostream & os,
102         TTFile &  file
103         )
104 #else
105 ostream & operator<<
106         (
107         ostream & os,
108         TTFile &  file
109         )
110 #endif
111 {
112     if (file.ttFileOpFailed())
113 #if defined(linux) || defined(CSRG_BASED)
114         return os << "Error in filename mapping; status = " 
115                   << file.getStatus() << std::endl;
116 #else
117         return os << "Error in filename mapping; status = " 
118                   << file.getStatus() << endl;
119 #endif
120     else
121 #if defined(linux) || defined(CSRG_BASED)
122         return os << file.data() << std::endl;
123 #else
124         return os << file.data() << endl;
125 #endif
126 }