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)
40 #include "api/c/tt_c.h"
41 #include "util/tt_iostream.h"
42 #include "tttar_utils.h"
43 #include "tttar_spec.h"
46 * Lstar_spec::Lstar_spec()
51 _props = new Lstar_spec_prop_list();
55 * Lstar_spec::Lstar_spec() -
58 Lstar_spec( _Tt_string id, _Tt_string path )
62 _props = new Lstar_spec_prop_list();
66 * Lstar_spec::~Lstar_spec()
79 if (! this->_id.xdr(xdrs)) {
82 if (! this->_path.xdr(xdrs)) {
85 if (! this->_type.xdr(xdrs)) {
88 if (! this->_props.xdr(xdrs)) {
95 * Lstar_spec::read_self() - Read from ToolTalk everything we need to know
96 * about ourselves in order to archive ourself.
98 Tt_status Lstar_spec::
102 * Get the spec's type.
104 note_ptr_err( tt_spec_type( (char *)_id ));
105 if (IS_TT_ERR(err_noted)) {
108 _type = ptr_returned;
110 * Get how many properties are on the spec.
112 note_int_err( tt_spec_propnames_count( (char *)_id ));
113 if (IS_TT_ERR(err_noted)) {
116 int num_props = int_returned;
118 * Push the spec's properties onto our list in reverse order,
119 * to preserve the admittedly meaningless order they had.
121 for (int n = num_props - 1; n >= 0; n--) {
122 note_ptr_err( tt_spec_propname( (char *)_id, n ));
131 if (IS_TT_ERR(err_noted)) {
135 _Tt_string propname = ptr_returned;
136 Lstar_spec_prop_ptr prop_ptr;
138 prop_ptr = new Lstar_spec_prop( _id, propname );
139 this->_props->push( prop_ptr );
145 * Lstar_spec::write_self() - Recreate a spec like the one we are, returning
146 * the id of the spec created. The string returned must be freed
150 write_self( _Tt_string where, bool_t preserve__props, Tt_status *err )
152 char *spec_created = NULL;
155 if (this->_path.len() <= 0) {
160 * TO_DO: tt_spec_create() won't convert /./ to / in a path
161 * if the path doesn't exist.
163 if (this->_path.left(2) == "./") {
164 this->_path = this->_path.right( _path.len() - 2 );
167 * If the archived path is absolute, ignore <where>.
169 if (this->_path[0] == '/') {
172 path = where.cat( "/" ).cat( this->_path );
174 note_ptr_err( tt_spec_create( (char *)path ));
176 spec_created = ptr_returned;
177 if (IS_TT_ERR(err_noted)) {
180 note_err( tt_spec_type_set( spec_created, (char *)this->_type ));
182 if (IS_TT_ERR(err_noted)) {
185 Lstar_spec_prop_list_cursor prop_cursor( this->_props );
186 while (prop_cursor.next()) {
187 *err = prop_cursor->write_self( spec_created, preserve__props );
189 note_err( tt_spec_write( spec_created ));
195 * Lstar_spec::print()
198 print( FILE *fs ) const
200 fprintf( fs, "spec id: " );
201 this->_id.print( fs );
202 fprintf( fs, "\nspec type: " );
203 this->_type.print( fs );
204 fprintf( fs, "\nspec path: " );
205 this->_path.print( fs );
207 this->_props->print(Lstar_spec::do_print, fs );
211 implement_list_of(Lstar_spec_prop)
214 * Lstar_spec_prop::Lstar_spec_prop()
222 * Lstar_spec_prop::Lstar_spec_prop()
225 Lstar_spec_prop( _Tt_string id, _Tt_string propname )
227 _propname = propname;
228 _values = new _Tt_string_list();
230 * Get how many values are in the spec's property.
232 note_int_err( tt_spec_prop_count( (char *)id, (char *)propname ));
234 case TT_ERR_PROPNAME:
240 if (IS_TT_ERR(err_noted)) {
244 int num_values = int_returned;
246 * Push the property's values onto our list in reverse order,
247 * to preserve the order they had.
249 for (int n = num_values - 1; n >= 0; n--) {
251 unsigned char *value;
253 note_err( tt_spec_bprop( (char *)id, (char *)propname, n, &value, &len ));
255 case TT_ERR_PROPNAME:
263 if (IS_TT_ERR(err_noted)) {
267 _Tt_string val( value, len );
268 this->_values->push( val );
273 * Lstar_spec_prop::~Lstar_spec_prop()
281 * Lstar_spec_prop::xdr()
283 bool_t Lstar_spec_prop::
286 if (! this->_propname.xdr(xdrs)) {
289 if (! this->_values.xdr(xdrs)) {
296 * Lstar_spec_prop::write_self() - Write this prop onto the given spec.
298 Tt_status Lstar_spec_prop::
299 write_self( char *spec_id, bool_t preserve__props )
302 * If we're not root and this is a blessed property,
303 * do not attempt to write it.
304 * Insert link here to policy statement about prop names in tt_c.h.
306 if ( (_propname[0] == '_')
307 && ( (! preserve__props)
312 _Tt_string_list_cursor value_cursor( this->_values );
315 while (value_cursor.next()) {
316 val = (char *)(*value_cursor);
317 len = (*value_cursor).len();
318 note_err( tt_spec_bprop_add( spec_id, (char *)_propname,
319 (unsigned char *)val, len));
320 if (IS_TT_ERR(err_noted)) {
328 * Lstar_spec_prop::print()
330 void Lstar_spec_prop::
331 print( FILE *fs ) const
333 this->_propname.print( fs );
335 this->_values->print(_tt_string_print,fs);
340 do_print(const _Tt_ostream &os, const _Tt_object *obj)
342 ((Lstar_spec *)obj)->print(os.theFILE());
345 void Lstar_spec_prop::
346 do_print(FILE *fs, const _Tt_object *obj)
348 ((Lstar_spec_prop *)obj)->print(fs);