Disable all code related to libXp
[oweals/cde.git] / cde / programs / dtinfo / DtMmdb / object / compressed_pstring.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 /*
24  * $XConsortium: compressed_pstring.cc /main/4 1996/06/11 17:23:44 cde-hal $
25  *
26  * Copyright (c) 1992 HAL Computer Systems International, Ltd.
27  * All rights reserved.  Unpublished -- rights reserved under
28  * the Copyright Laws of the United States.  USE OF A COPYRIGHT
29  * NOTICE IS PRECAUTIONARY ONLY AND DOES NOT IMPLY PUBLICATION
30  * OR DISCLOSURE.
31  * 
32  * THIS SOFTWARE CONTAINS CONFIDENTIAL INFORMATION AND TRADE
33  * SECRETS OF HAL COMPUTER SYSTEMS INTERNATIONAL, LTD.  USE,
34  * DISCLOSURE, OR REPRODUCTION IS PROHIBITED WITHOUT THE
35  * PRIOR EXPRESS WRITTEN PERMISSION OF HAL COMPUTER SYSTEMS
36  * INTERNATIONAL, LTD.
37  * 
38  *                         RESTRICTED RIGHTS LEGEND
39  * Use, duplication, or disclosure by the Government is subject
40  * to the restrictions as set forth in subparagraph (c)(l)(ii)
41  * of the Rights in Technical Data and Computer Software clause
42  * at DFARS 252.227-7013.
43  *
44  *          HAL COMPUTER SYSTEMS INTERNATIONAL, LTD.
45  *                  1315 Dell Avenue
46  *                  Campbell, CA  95008
47  * 
48  */
49
50
51 #include "object/compressed_pstring.h"
52
53 #ifdef C_API
54 buffer* compressed_pstring::working_buffer_ptr;
55 buffer* compressed_pstring::v_cp_io_buf_ptr;
56 #define working_buffer (*working_buffer_ptr)
57 #define v_cp_io_buf (*v_cp_io_buf_ptr)
58 // for pstring's buffer
59 #define v_io_buf (*v_io_buf_ptr) 
60 #else
61 buffer compressed_pstring::working_buffer(LBUFSIZ);
62 buffer compressed_pstring::v_cp_io_buf(LBUFSIZ);
63 #endif
64
65
66 compressed_pstring::compressed_pstring(c_code_t c_id) : 
67    pstring(c_id), agent(0), v_uncompressed_sz(0)
68 {
69 }
70
71 compressed_pstring::~compressed_pstring()
72 {
73 }
74
75 MMDB_BODIES(compressed_pstring)
76
77 char* compressed_pstring::get(buffer& string_buffer)
78 {
79 //MESSAGE(cerr, "compressed_pstring::get()");
80 //debug(cerr, v_uncompressed_sz);
81
82
83    string_buffer.reset();
84    string_buffer.expand_chunk(v_uncompressed_sz+1);
85
86    pstring::get(working_buffer);
87
88 // use cached version of compression agent
89 //debug(cerr, compress_agent_id);
90
91    if ( (storage_ptr -> my_oid()).ccode() ==  MEM_STORAGE_CODE )
92       agent = (compress_agent_handler*)
93         (new handler(DICT_AGENT_CODE, storage_ptr));
94    else
95       agent = new compress_agent_handler(compress_agent_id, storage_ptr);
96
97    (*agent) -> decompress(working_buffer, string_buffer);
98
99    delete agent;
100
101    string_buffer.get_base()[v_uncompressed_sz] = 0;
102
103 //MESSAGE(cerr, "compressed_pstring::get() done");
104    return string_buffer.get_base();
105 }
106
107 io_status compressed_pstring::asciiIn(istream& in) 
108 {
109    compress_agent_id.asciiIn(in);       // compress agent oid part
110 //debug(cerr, compress_agent_id);
111    return this -> _asciiIn(in);
112 }
113
114 io_status compressed_pstring::asciiIn(const char* buf, int size, const oid_t& id) 
115 {
116    compress_agent_id.become(id);        // compress agent oid part
117    return this -> _asciiIn(buf, size);
118 }
119
120 io_status compressed_pstring::asciiIn(const char* buf, int size) 
121 {
122    return pstring::asciiIn(buf, size);
123 }
124
125 io_status compressed_pstring::_asciiIn(istream& in) 
126 {
127 // use cached version of compression agent
128
129    if ( (storage_ptr -> my_oid()).ccode() ==  MEM_STORAGE_CODE )
130       agent = (compress_agent_handler*)
131         (new handler(DICT_AGENT_CODE, storage_ptr));
132    else
133       agent = new compress_agent_handler(compress_agent_id, storage_ptr);
134
135    pstring::_asciiIn(in);
136
137    _compress();
138
139    return done;
140 }
141
142 io_status compressed_pstring::_asciiIn(const char* buf, int size) 
143 {
144 // use cached version of compression agent
145    if ( (storage_ptr -> my_oid()).ccode() == MEM_STORAGE_CODE )
146       agent = (compress_agent_handler*)
147         (new handler(DICT_AGENT_CODE, storage_ptr));
148    else
149       agent = new compress_agent_handler(compress_agent_id, storage_ptr);
150
151    pstring::asciiIn(buf, size);         // uncompress data part
152
153    _compress();
154
155    return done;
156 }
157
158 void compressed_pstring::_compress() 
159 {
160    v_uncompressed_sz = v_io_buf.content_sz();
161
162    if ( v_uncompressed_sz > 0 ) {
163
164       working_buffer.reset();
165
166       (*agent) -> compress(v_io_buf, working_buffer);
167
168 //debug(cerr, v_uncompressed_sz);
169 //debug(cerr, working_buffer.content_sz());
170
171       pstring::update(working_buffer.get_base(),  working_buffer.content_sz());
172    }
173
174    set_mode(UPDATE, true);
175
176    delete agent;
177
178 }
179
180 int compressed_pstring::size() const
181 {
182    return v_uncompressed_sz;
183 }
184
185 int compressed_pstring::cdr_sizeof()
186 {
187    return pstring::cdr_sizeof() + sizeof(v_uncompressed_sz) + 
188           compress_agent_id.cdr_sizeof(); 
189 }
190
191 io_status compressed_pstring::cdrOut(buffer& buf)
192 {
193 //MESSAGE(cerr, "compressed_pstring: cdrOut()");
194 //debug(cerr, compress_agent_id);
195
196    pstring::cdrOut(buf);
197    buf.put(v_uncompressed_sz);
198    return compress_agent_id.cdrOut(buf);
199 }
200
201 io_status compressed_pstring::cdrIn(buffer& buf)
202 {
203    pstring::cdrIn(buf);
204    buf.get(v_uncompressed_sz);
205    return compress_agent_id.cdrIn(buf);
206 }
207
208 HANDLER_BODIES(compressed_pstring)