olias_funcs.C 7.6 KB

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