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 //%% (c) Copyright 1993, 1994 Hewlett-Packard Company
24 //%% (c) Copyright 1993, 1994 International Business Machines Corp.
25 //%% (c) Copyright 1993, 1994 Sun Microsystems, Inc.
26 //%% (c) Copyright 1993, 1994 Novell, Inc.
27 //%% $XConsortium: tttar_spec.C /main/3 1995/10/20 17:00:42 rswiston $
29 * tttar_spec.cc - Implementation of specs for Link Service/ToolTalk archiving
31 * Copyright (c) 1990 by Sun Microsystems, Inc.
35 #if defined(__osf__) || defined(linux) || defined(CSRG_BASED) || defined(sun)
39 #include "tt_options.h"
40 #if defined(OPT_BUG_USL)
44 #endif /* if defined(OPT_BUG_USL) */
49 #include "api/c/tt_c.h"
50 #include "util/tt_iostream.h"
51 #include "tttar_utils.h"
52 #include "tttar_spec.h"
55 * Lstar_spec::Lstar_spec()
60 _props = new Lstar_spec_prop_list();
64 * Lstar_spec::Lstar_spec() -
67 Lstar_spec( _Tt_string id, _Tt_string path )
71 _props = new Lstar_spec_prop_list();
75 * Lstar_spec::~Lstar_spec()
88 if (! this->_id.xdr(xdrs)) {
91 if (! this->_path.xdr(xdrs)) {
94 if (! this->_type.xdr(xdrs)) {
97 if (! this->_props.xdr(xdrs)) {
104 * Lstar_spec::read_self() - Read from ToolTalk everything we need to know
105 * about ourselves in order to archive ourself.
107 Tt_status Lstar_spec::
111 * Get the spec's type.
113 note_ptr_err( tt_spec_type( (char *)_id ));
114 if (IS_TT_ERR(err_noted)) {
117 _type = ptr_returned;
119 * Get how many properties are on the spec.
121 note_int_err( tt_spec_propnames_count( (char *)_id ));
122 if (IS_TT_ERR(err_noted)) {
125 int num_props = int_returned;
127 * Push the spec's properties onto our list in reverse order,
128 * to preserve the admittedly meaningless order they had.
130 for (int n = num_props - 1; n >= 0; n--) {
131 note_ptr_err( tt_spec_propname( (char *)_id, n ));
140 if (IS_TT_ERR(err_noted)) {
144 _Tt_string propname = ptr_returned;
145 Lstar_spec_prop_ptr prop_ptr;
147 prop_ptr = new Lstar_spec_prop( _id, propname );
148 this->_props->push( prop_ptr );
154 * Lstar_spec::write_self() - Recreate a spec like the one we are, returning
155 * the id of the spec created. The string returned must be freed
159 write_self( _Tt_string where, bool_t preserve__props, Tt_status *err )
161 char *spec_created = NULL;
164 if (this->_path.len() <= 0) {
169 * TO_DO: tt_spec_create() won't convert /./ to / in a path
170 * if the path doesn't exist.
172 if (this->_path.left(2) == "./") {
173 this->_path = this->_path.right( _path.len() - 2 );
176 * If the archived path is absolute, ignore <where>.
178 if (this->_path[0] == '/') {
181 path = where.cat( "/" ).cat( this->_path );
183 note_ptr_err( tt_spec_create( (char *)path ));
185 spec_created = ptr_returned;
186 if (IS_TT_ERR(err_noted)) {
189 note_err( tt_spec_type_set( spec_created, (char *)this->_type ));
191 if (IS_TT_ERR(err_noted)) {
194 Lstar_spec_prop_list_cursor prop_cursor( this->_props );
195 while (prop_cursor.next()) {
196 *err = prop_cursor->write_self( spec_created, preserve__props );
198 note_err( tt_spec_write( spec_created ));
204 * Lstar_spec::print()
207 print( FILE *fs ) const
209 fprintf( fs, "spec id: " );
210 this->_id.print( fs );
211 fprintf( fs, "\nspec type: " );
212 this->_type.print( fs );
213 fprintf( fs, "\nspec path: " );
214 this->_path.print( fs );
216 this->_props->print(Lstar_spec::do_print, fs );
220 implement_list_of(Lstar_spec_prop)
223 * Lstar_spec_prop::Lstar_spec_prop()
231 * Lstar_spec_prop::Lstar_spec_prop()
234 Lstar_spec_prop( _Tt_string id, _Tt_string propname )
236 _propname = propname;
237 _values = new _Tt_string_list();
239 * Get how many values are in the spec's property.
241 note_int_err( tt_spec_prop_count( (char *)id, (char *)propname ));
243 case TT_ERR_PROPNAME:
249 if (IS_TT_ERR(err_noted)) {
253 int num_values = int_returned;
255 * Push the property's values onto our list in reverse order,
256 * to preserve the order they had.
258 for (int n = num_values - 1; n >= 0; n--) {
260 unsigned char *value;
262 note_err( tt_spec_bprop( (char *)id, (char *)propname, n, &value, &len ));
264 case TT_ERR_PROPNAME:
272 if (IS_TT_ERR(err_noted)) {
276 _Tt_string val( value, len );
277 this->_values->push( val );
282 * Lstar_spec_prop::~Lstar_spec_prop()
290 * Lstar_spec_prop::xdr()
292 bool_t Lstar_spec_prop::
295 if (! this->_propname.xdr(xdrs)) {
298 if (! this->_values.xdr(xdrs)) {
305 * Lstar_spec_prop::write_self() - Write this prop onto the given spec.
307 Tt_status Lstar_spec_prop::
308 write_self( char *spec_id, bool_t preserve__props )
311 * If we're not root and this is a blessed property,
312 * do not attempt to write it.
313 * Insert link here to policy statement about prop names in tt_c.h.
315 if ( (_propname[0] == '_')
316 && ( (! preserve__props)
321 _Tt_string_list_cursor value_cursor( this->_values );
324 while (value_cursor.next()) {
325 val = (char *)(*value_cursor);
326 len = (*value_cursor).len();
327 note_err( tt_spec_bprop_add( spec_id, (char *)_propname,
328 (unsigned char *)val, len));
329 if (IS_TT_ERR(err_noted)) {
337 * Lstar_spec_prop::print()
339 void Lstar_spec_prop::
340 print( FILE *fs ) const
342 this->_propname.print( fs );
344 this->_values->print(_tt_string_print,fs);
349 do_print(const _Tt_ostream &os, const _Tt_object *obj)
351 ((Lstar_spec *)obj)->print(os.theFILE());
354 void Lstar_spec_prop::
355 do_print(FILE *fs, const _Tt_object *obj)
357 ((Lstar_spec_prop *)obj)->print(fs);