OpenIndiana and Solaris port
[oweals/cde.git] / cde / programs / dtinfo / DtMmdb / oliasdb / olias_funcs.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: olias_funcs.cc /main/5 1996/07/18 14:48:42 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 #include "oliasdb/olias_funcs.h"
52 #include "oliasdb/asciiIn_filters.h"
53 #include "oliasdb/olias_consts.h"
54 #include "oliasdb/node_hd.h"
55 #include "oliasdb/doc_hd.h"
56 #include "oliasdb/dlp_hd.h"
57
58
59 /*
60 #define BB_STRING "%%BoundingBox:"
61 int bb_string_leng = strlen(BB_STRING);
62 */
63
64
65 /////////////////////////////////////////////////
66 // load sgml node data. This will cluster them. 
67 /////////////////////////////////////////////////
68
69 //extern char base_str[PATHSIZ];
70
71 struct map_record {
72    char* col_name;
73    c_code_t instance_class_code;
74    handler* collection_hd;
75 };
76
77 struct map_record set_map[]=
78
79    {(char*)"loc", LOCATOR_CODE, 0},
80    {(char*)"toc", TOC_CODE, 0 },
81    {(char*)"doc", DOC_CODE, 0 },
82    {(char*)"graphic", GRAPHIC_CODE, 0 },
83 //   {(char*)"stylesheet", STYLESHEET_CODE, 0 },
84 }; 
85
86 struct map_record list_map[]=
87
88    {(char*)"dlp", DLP_CODE, 0},
89 }; 
90
91 //#define SET_MAP_SZ 5
92 #define SET_MAP_SZ 4
93 #define LIST_MAP_SZ 1
94
95 /////////////////////////////////////////////////
96 // load mixed stream of infobase data from stdin.
97 /////////////////////////////////////////////////
98 void insert_to_collection(c_code_t ccode, istream& in)
99 {
100     enum coll_type { VOID, SET, LIST };
101
102     coll_type obj_type = VOID;
103
104     abs_storage* store = 0;
105 //  handler* hd = 0;
106
107     int i;
108     for ( i = 0; i<SET_MAP_SZ ; i++ ) {
109       if ( set_map[i].instance_class_code == ccode ) {
110          obj_type = SET;
111          store = set_map[i].collection_hd -> its_store();
112 //       hd = set_map[i].collection_hd;
113          break;
114       }
115     }
116
117     if ( obj_type == VOID ) 
118     for ( i = 0; i<LIST_MAP_SZ ; i++ ) {
119        if ( list_map[i].instance_class_code == ccode ) {
120          obj_type = LIST;
121           store = list_map[i].collection_hd -> its_store();
122 //        hd = set_map[i].collection_hd;
123           break;
124        }
125     }
126
127     if ( store == 0 ) {
128        throw(stringException(form("unknown class code %d", ccode)));
129     }
130
131     handler* root_hd_ptr = new handler(ccode, store);
132
133     (*root_hd_ptr) ->asciiIn(in);
134     root_hd_ptr -> commit();
135
136     switch ( obj_type ) {
137        case SET:
138          (*(cset_handlerPtr)(set_map[i].collection_hd)) ->
139              insert_object(*root_hd_ptr);
140          break;
141        case LIST:
142          (*(dl_list_handlerPtr)(list_map[i].collection_hd)) -> 
143               insert_as_tail(*(dl_list_cell_handler*)root_hd_ptr);
144          break;
145        default:
146          cerr << "bad ccode = " << ccode << "\n";
147          throw(stringException("bad ccode"));
148    }
149
150    delete root_hd_ptr;
151
152 }
153
154 static char locator[LBUFSIZ];
155
156 void sgml_content_load(info_base* x, istream& in)
157 {
158    in.getline(locator, LBUFSIZ);
159
160    char* locator_string = strchr(locator, '\t') + 1;
161    if ( locator_string == (char*)1 )
162       throw(formatException("bad sgml data format"));
163
164    node_smart_ptr y(x, locator_string);
165
166    if ( y.update_data(in) == false ) 
167       throw(formatException("can't update sgml data"));
168    
169 }
170
171 void _connectNodeToDoc(info_base* x_base);
172
173 int _load_mixed_objects_from_cin(info_base* base_ptr)
174 {
175    return _load_mixed_objects(base_ptr, cin);
176 }
177
178 int _load_mixed_objects(info_base* base_ptr, istream& in)
179 {
180    int i;
181    for ( i = 0; i<SET_MAP_SZ ; i++ ) {
182       cset_handlerPtr x = base_ptr -> get_set(set_map[i].col_name);
183
184       if (x==0)
185          throw(stringException("null cset_handler pointer"));
186
187       (*x) -> batch_index_begin();
188       set_map[i].collection_hd = x;
189    }
190
191    for ( i = 0; i<LIST_MAP_SZ ; i++ ) {
192       dl_list_handlerPtr x = base_ptr -> get_list(list_map[i].col_name);
193
194       if (x==0)
195          throw(stringException("null cset_handler pointer"));
196
197       (*x) -> batch_index_begin();
198       list_map[i].collection_hd = x;
199    }
200
201    
202    char ccode_buf[LBUFSIZ];
203    int ccode;
204
205    while ( in.getline(ccode_buf, LBUFSIZ) ) {
206       sscanf(ccode_buf, "%u", &ccode);
207 //debug(cerr, ccode);
208
209       if ( ccode == SGML_CONTENT_CODE )
210          sgml_content_load(base_ptr, in);
211       else
212          insert_to_collection(ccode, in);
213    }
214
215    for ( i = 0; i<SET_MAP_SZ ; i++ ) {
216       cset_handlerPtr x = (cset_handlerPtr)(set_map[i].collection_hd);
217       (*x) -> batch_index_end();
218    }
219
220    for ( i = 0; i<LIST_MAP_SZ ; i++ ) {
221       dl_list_handlerPtr x = (dl_list_handlerPtr)(list_map[i].collection_hd);
222       (*x) -> batch_index_end();
223    }
224
225    return 0;
226 }
227
228 int load_mixed_objects_from_cin(info_base* base_ptr)
229 {
230    return load_mixed_objects(base_ptr, cin);
231 }
232
233 int load_mixed_objects(info_base* base_ptr, istream& in)
234 {
235    _load_mixed_objects(base_ptr, in);
236    _connectNodeToDoc(base_ptr);
237    return 0;
238 }
239
240 void _connectNodeToDoc(info_base* x_base)
241 {
242    int docs = x_base -> num_of_docs();
243
244    doc_smart_ptr* doc = 0;
245
246    node_smart_ptr* first_node = 0, *node = 0;
247    dlp_smart_ptr* x = 0, *dlp_cell = 0;
248
249    for ( int i=0; i<docs; i++ ) {
250       doc = new doc_smart_ptr(x_base, i+1);
251 /*
252 debug(cerr, doc -> its_oid());
253 debug(cerr, doc -> long_title());
254 */
255
256       first_node = new node_smart_ptr(x_base, doc -> locator_id());
257
258       dlp_cell = new dlp_smart_ptr(x_base, first_node -> its_oid());
259
260       while ( dlp_cell ) {
261
262          
263 //debug(cerr, dlp_cell -> node_id());
264
265          node = new node_smart_ptr(x_base, dlp_cell -> node_id());
266 //debug(cerr, node -> doc_id());
267          node -> update_doc_id(doc -> its_oid());
268 //debug(cerr, node -> doc_id());
269          delete node;
270    
271          x = dlp_cell -> next();
272
273          delete dlp_cell;
274
275          dlp_cell = x;
276       }
277
278       delete doc;
279       delete first_node;
280    }
281 }
282
283
284 void connectNodeToDoc(info_lib* x_lib)
285 {
286    if ( x_lib == 0 )
287       throw(stringException("connectNodeToDoc: can't find infolib"));
288
289    info_base* x_base = 0;
290
291    long ind = x_lib -> first();
292
293    while ( ind ) {
294       x_base = (*x_lib)(ind);
295
296       if ( x_base == 0 )
297          throw(stringException("connectNodeToDoc: null base pointer"));
298
299       _connectNodeToDoc(x_base);
300
301       x_lib -> next(ind);
302    };
303 }
304
305
306