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 librararies and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
24 * $XConsortium: info_base.C /main/5 1996/09/04 01:37:05 cde-hal $
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
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
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.
44 * HAL COMPUTER SYSTEMS INTERNATIONAL, LTD.
51 #include "api/info_base.h"
52 #include "compression/abs_agent.h"
54 info_base::info_base(object_dict& obj_dict,
55 char** set_name_list, char** list_name_list,
56 const char* base_dir, const char* base_nm,
57 const char* base_ds, const char* base_uid,
58 const char* base_locale,
62 set_name_list, list_name_list,
63 base_dir, base_nm, base_ds, base_uid
67 debug(cerr, base_dir);
72 strcpy(info_base_locale, base_locale);
74 *info_base_locale = 0;
78 //////////////////////
80 //////////////////////
81 info_base_set_ptrs = new cset_handlerPtr[num_cset_ptrs];
83 for ( int i=0; i<num_cset_ptrs; i++ ) {
85 nm = form("%s.%s", base_nm, info_base_set_names[i]);
88 info_base_set_ptrs[i] = (cset_handler*)
89 (f_obj_dict -> get_handler(nm));
93 info_base_set_ptrs[i] = 0;
98 //////////////////////
100 //////////////////////
101 info_base_list_ptrs = new dl_list_handlerPtr[num_list_ptrs];
103 for ( i=0; i<num_list_ptrs; i++ ) {
105 nm = form("%s.%s", base_nm, info_base_list_names[i]);
108 info_base_list_ptrs[i] = (dl_list_handler*)
109 obj_dict.get_handler(nm);
113 info_base_list_ptrs[i] = 0;
118 MESSAGE(cerr, form("info base %s in %s available.", base_name, base_dir));
121 info_base::~info_base()
123 delete info_base_list_ptrs;
124 delete info_base_set_ptrs;
127 int info_base::get_set_pos(const char* set_nm)
130 for ( int i=0; i<num_cset_ptrs; i++ ) {
131 if ( strcmp(set_nm, info_base_set_names[i]) == 0 )
138 cset_handlerPtr info_base::get_set(const char* set_nm)
140 //MESSAGE(cerr, "in info_base::get_set()");
141 return get_set(get_set_pos(set_nm));
144 cset_handlerPtr info_base::get_set(int i)
146 if ( !INRANGE(i, 0, num_cset_ptrs-1) )
147 throw (boundaryException(0, num_cset_ptrs-1, i));
149 return info_base_set_ptrs[i];
156 int info_base::get_list_pos(const char* list_nm)
158 for ( int i=0; i<num_list_ptrs; i++ ) {
159 if ( strcmp(list_nm, info_base_list_names[i]) == 0 )
166 dl_list_handlerPtr info_base::get_list(const char* list_nm)
168 return ( get_list(get_list_pos(list_nm)) );
171 dl_list_handlerPtr info_base::get_list(int i)
173 if ( !INRANGE(i, 0, num_list_ptrs-1) ) {
174 throw(boundaryException(0, num_list_ptrs-1, i));
177 return info_base_list_ptrs[i];
180 int info_base::num_of_docs()
182 // the implementation is temp. It should take
183 // a hint as where to obtain the information.
184 // like from a set named so and so.
186 cset_handler* x = get_set("doc");
188 return (*x) -> count();
194 ////////////////////////////////////////////////////////////////////
196 ////////////////////////////////////////////////////////////////////
198 iterator::iterator( handler* x, c_code_t y) :
199 collection_hd(x), instance_c_code(y), ind(0)
203 iterator::~iterator()
207 iterator::operator void*()
209 return ( ind == 0 ) ? 0 : (void*)1;
214 iterator* info_base::first(char* col_nm, c_code_t code)
216 handler* x = get_set(col_nm);
219 handler* x = get_list(col_nm);
223 throw(stringException("unknown collection name"));
226 page_storage *s = (page_storage*)(x -> its_store());
229 throw(stringException("collection has no store"));
232 if ( s -> my_oid().ccode() != PAGE_STORAGE_CODE ) {
233 throw(stringException("non page store no supported"));
236 iterator* it = new iterator(x, code);
238 it -> ind = s -> first_loc();
240 if ( managers::template_mgr -> peek_slot(s, it->ind) != code ) {
247 oid_t info_base::get_oid(const iterator& it)
249 page_storage *s = (page_storage*)( it.collection_hd -> its_store() );
252 managers::template_mgr -> init_obj(s, it.ind, r);
254 throw(stringException("null root pointer"));
256 return r -> my_oid();
259 void info_base::next(iterator& it)
261 page_storage *s = (page_storage*)( it.collection_hd -> its_store());
263 while ( s -> seek_loc( it.ind, positive, spointer_t::IS_OBJECT ) == true ) {
264 if ( managers::template_mgr -> peek_slot(s, it.ind) == it.instance_c_code ) {
272 int stdin_sgml_data_getchar(unsigned char* buf, int max_sz)
274 static int remain_chars = 0;
275 static int chars_to_read;
276 static char loc_buf[LBUFSIZ];
278 if ( remain_chars == 0 ) {
279 if ( fgets(loc_buf, LBUFSIZ, stdin) == NULL )
282 if ( fgets(loc_buf, LBUFSIZ, stdin) == NULL )
283 throw(stringException("no locator line"));
285 if ( fscanf(stdin, "%d", &remain_chars) != 1 )
286 throw(stringException("sgml_data_getchar(): fscanf() failed"));
288 if ( getc(stdin) != '\t' ) {
289 debug(cerr, remain_chars);
290 throw(stringException("'\\t' expected"));
295 chars_to_read = MIN(max_sz, remain_chars);
297 if ( fread((char*)buf, 1, chars_to_read, stdin) != chars_to_read ) {
298 throw(stringException("sgml_data_getchar(): fread() failed"));
301 remain_chars -= chars_to_read;
303 if ( remain_chars == 0 ) {
304 if ( getc(stdin) != '\n' )
305 throw(stringException("'\\n' expected"));
309 for ( int i=0; i<chars_to_read; i++ ) {
314 debug(cerr, chars_to_read);
317 return chars_to_read;
320 int stdin_ps_data_getchar(unsigned char* buf, int max_sz)
322 return fread((char*)buf, 1, max_sz, stdin);
325 extern int sgmllex();
328 void info_base::build_dict(char* agent_name)
330 compress_agent_handler* x = (compress_agent_handler*)
331 (f_obj_dict -> get_handler(agent_name));
334 throw(stringException("info_base::build_dict(): unknown compress agent"));
336 if ( strstr(agent_name, ".sgml.") != NULL ) {
337 (*x) -> build_dict(sgmllex, stdin_sgml_data_getchar);
339 if ( strstr(agent_name, ".ps.") != NULL ) {
340 (*x) -> build_dict(pslex, stdin_ps_data_getchar);
342 throw(stringException("info_base::build_dict(): unknown compress target"));