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.
55 #include "api/info_base.h"
56 #include "compression/abs_agent.h"
58 info_base::info_base(object_dict& obj_dict,
59 char** set_name_list, char** list_name_list,
60 const char* base_dir, const char* base_nm,
61 const char* base_ds, const char* base_uid,
62 const char* base_locale,
66 set_name_list, list_name_list,
67 base_dir, base_nm, base_ds, base_uid
71 debug(cerr, base_dir);
75 int len = MIN(strlen(base_locale), PATHSIZ - 1);
77 *((char *) memcpy (info_base_locale, base_locale, len) + len) = '\0';
79 *info_base_locale = 0;
84 //////////////////////
86 //////////////////////
87 info_base_set_ptrs = new cset_handlerPtr[num_cset_ptrs];
89 for ( i=0; i<num_cset_ptrs; i++ ) {
91 nm = form("%s.%s", base_nm, info_base_set_names[i]);
94 info_base_set_ptrs[i] = (cset_handler*)
95 (f_obj_dict -> get_handler(nm));
99 info_base_set_ptrs[i] = 0;
104 //////////////////////
106 //////////////////////
107 info_base_list_ptrs = new dl_list_handlerPtr[num_list_ptrs];
109 for ( i=0; i<num_list_ptrs; i++ ) {
111 nm = form("%s.%s", base_nm, info_base_list_names[i]);
114 info_base_list_ptrs[i] = (dl_list_handler*)
115 obj_dict.get_handler(nm);
119 info_base_list_ptrs[i] = 0;
124 MESSAGE(cerr, form("info base %s in %s available.", base_name, base_dir));
127 info_base::~info_base()
129 delete info_base_list_ptrs;
130 delete info_base_set_ptrs;
133 int info_base::get_set_pos(const char* set_nm)
135 for ( int i=0; i<num_cset_ptrs; i++ ) {
136 if ( strcmp(set_nm, info_base_set_names[i]) == 0 )
143 cset_handlerPtr info_base::get_set(const char* set_nm)
145 //MESSAGE(cerr, "in info_base::get_set()");
146 return get_set(get_set_pos(set_nm));
149 cset_handlerPtr info_base::get_set(int i)
151 if ( !INRANGE(i, 0, num_cset_ptrs-1) )
152 throw (boundaryException(0, num_cset_ptrs-1, i));
154 return info_base_set_ptrs[i];
161 int info_base::get_list_pos(const char* list_nm)
163 for ( int i=0; i<num_list_ptrs; i++ ) {
164 if ( strcmp(list_nm, info_base_list_names[i]) == 0 )
171 dl_list_handlerPtr info_base::get_list(const char* list_nm)
173 return ( get_list(get_list_pos(list_nm)) );
176 dl_list_handlerPtr info_base::get_list(int i)
178 if ( !INRANGE(i, 0, num_list_ptrs-1) ) {
179 throw(boundaryException(0, num_list_ptrs-1, i));
182 return info_base_list_ptrs[i];
185 int info_base::num_of_docs()
187 // the implementation is temp. It should take
188 // a hint as where to obtain the information.
189 // like from a set named so and so.
191 cset_handler* x = get_set("doc");
193 return (*x) -> count();
199 ////////////////////////////////////////////////////////////////////
201 ////////////////////////////////////////////////////////////////////
203 Iterator::Iterator( handler* x, c_code_t y) :
204 collection_hd(x), instance_c_code(y), ind(0)
208 Iterator::~Iterator()
212 Iterator::operator void*()
214 return ( ind == 0 ) ? 0 : (void*)1;
219 Iterator* info_base::first(char* col_nm, c_code_t code)
221 handler* x = get_set(col_nm);
224 x = get_list(col_nm);
228 throw(stringException("unknown collection name"));
231 page_storage *s = (page_storage*)(x -> its_store());
234 throw(stringException("collection has no store"));
237 if ( s -> my_oid().ccode() != PAGE_STORAGE_CODE ) {
238 throw(stringException("non page store no supported"));
241 Iterator* it = new Iterator(x, code);
243 it -> ind = s -> first_loc();
245 if ( managers::template_mgr -> peek_slot(s, it->ind) != code ) {
252 oid_t info_base::get_oid(const Iterator& it)
254 page_storage *s = (page_storage*)( it.collection_hd -> its_store() );
257 managers::template_mgr -> init_obj(s, it.ind, r);
259 throw(stringException("null root pointer"));
261 return r -> my_oid();
264 void info_base::next(Iterator& it)
266 page_storage *s = (page_storage*)( it.collection_hd -> its_store());
268 while ( s -> seek_loc( it.ind, positive, spointer_t::IS_OBJECT ) == true ) {
269 if ( managers::template_mgr -> peek_slot(s, it.ind) == it.instance_c_code ) {
277 int stdin_sgml_data_getchar(unsigned char* buf, int max_sz)
279 static int remain_chars = 0;
280 static int chars_to_read;
281 static char loc_buf[LBUFSIZ];
283 if ( remain_chars == 0 ) {
284 if ( fgets(loc_buf, LBUFSIZ, stdin) == NULL )
287 if ( fgets(loc_buf, LBUFSIZ, stdin) == NULL )
288 throw(stringException("no locator line"));
290 if ( fscanf(stdin, "%d", &remain_chars) != 1 )
291 throw(stringException("sgml_data_getchar(): fscanf() failed"));
293 if ( getc(stdin) != '\t' ) {
294 debug(cerr, remain_chars);
295 throw(stringException("'\\t' expected"));
300 chars_to_read = MIN(max_sz, remain_chars);
302 if ( (int)fread((char*)buf, 1, chars_to_read, stdin) != chars_to_read ) {
303 throw(stringException("sgml_data_getchar(): fread() failed"));
306 remain_chars -= chars_to_read;
308 if ( remain_chars == 0 ) {
309 if ( getc(stdin) != '\n' )
310 throw(stringException("'\\n' expected"));
314 for ( int i=0; i<chars_to_read; i++ ) {
319 debug(cerr, chars_to_read);
322 return chars_to_read;
325 int stdin_ps_data_getchar(unsigned char* buf, int max_sz)
327 return fread((char*)buf, 1, max_sz, stdin);
330 extern int sgmllex();
333 void info_base::build_dict(char* agent_name)
335 compress_agent_handler* x = (compress_agent_handler*)
336 (f_obj_dict -> get_handler(agent_name));
339 throw(stringException("info_base::build_dict(): unknown compress agent"));
341 if ( strstr(agent_name, ".sgml.") != NULL ) {
342 (*x) -> build_dict(sgmllex, stdin_sgml_data_getchar);
344 if ( strstr(agent_name, ".ps.") != NULL ) {
345 (*x) -> build_dict(pslex, stdin_ps_data_getchar);
347 throw(stringException("info_base::build_dict(): unknown compress target"));