OpenIndiana and Solaris port
[oweals/cde.git] / cde / programs / dtinfo / DtMmdb / oliasdb / mark_base.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: mark_base.cc /main/7 1996/07/18 14:47:29 drk $
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
52 #include "oliasdb/mark_base.h"
53 #include "oliasdb/mark.h"
54 #include "utility/debug.h"
55 #include "misc/unique_id.h"
56
57 mark_base::mark_base(user_base::rw_flag_t rw) : 
58         user_base(MARK_SPEC, rw)
59 {
60 }
61
62
63 mark_base::mark_base( const char* base_dir, 
64                       const char* base_nm,
65                       const char* base_ds,
66                       user_base::rw_flag_t rw 
67                     ) : 
68         user_base(base_dir, base_nm, base_ds, MARK_SPEC, rw) 
69 {
70    if ( checking_status != SUCC ) 
71       return;
72
73    desc* ptr = first_desc_ptr;
74
75    if ( ptr == 0 ) 
76       throw(stringException("empty mark specification"));
77      
78    while ( ptr ) {
79      if ( strcmp( ptr -> get_type(), "container set") == 0 ) {
80         mark_set_hd = (cset_handler*)
81             (f_obj_dict -> get_handler(ptr -> get_nm()));
82         return;
83      }
84      ptr = ptr -> get_next_desc();
85    }
86
87    throw(stringException("can't find mark set description record"));
88 }
89
90 mark_base::~mark_base()
91 {
92 }
93
94 oid_list_handler* mark_base::get_mark_list(const char* node_locator)
95 {
96 #ifdef INTERCEPT_MARK_BASE_CALLS
97 MESSAGE(cerr, "mark_base::get_mark_list()");
98 debug(cerr, node_locator);
99 #endif
100
101    pstring* x = new pstring(node_locator, strlen(node_locator));
102    handler y(x, 0);
103
104    oid_list_handler*z = (*mark_set_hd) -> get_locs(y, 1);
105
106 #ifdef INTERCEPT_MARK_BASE_CALLS
107 if (z) 
108   debug(cerr, (*z) -> asciiOut(cerr));
109 #endif
110
111    return z;
112 }
113     
114 mmdb_pos_t mark_base::first()
115 {
116    page_storage *s = (page_storage*)((*mark_set_hd) -> get_store());
117
118    mmdb_pos_t ind = s -> first_loc();
119
120    if ( managers::template_mgr -> peek_slot(s, ind) != USER_MARK_CODE ) {
121       this -> next(ind);
122    }
123
124    return ind;
125 }
126    
127 oid_t mark_base::get_mark_oid(mmdb_pos_t& ind)
128 {
129    page_storage *s = (page_storage*)((*mark_set_hd) -> get_store());
130
131    root *r = 0;
132    managers::template_mgr -> init_obj(s, ind, r);
133
134    if (r==0)
135       throw(stringException("null root object pointer"));
136
137    oid_t x = r -> my_oid();
138    delete r;
139
140    return x;
141 }
142
143 void mark_base::next(mmdb_pos_t& ind)
144 {
145    page_storage *s = (page_storage*)((*mark_set_hd) -> get_store());
146
147    while ( s -> seek_loc( ind, positive, spointer_t::IS_OBJECT ) == true ) {
148      if ( managers::template_mgr -> peek_slot(s, ind) == USER_MARK_CODE ) {
149         return;
150      }
151    }
152
153    ind = 0;
154 }
155