OpenIndiana and Solaris port
[oweals/cde.git] / cde / programs / dtinfo / DtMmdb / oliasdb / c_api_infolib.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 /* $XConsortium: c_api_infolib.cc /main/5 1996/07/18 16:01:28 drk $ */
24
25 #include "oliasdb/c_api_common.h"
26
27 //extern void_ptr_array* infolib_array;
28 extern void_ptr_array* bookcase_array;
29 extern OLIAS_DB* mmdb_ptr;
30
31 //extern olias_server* oserver_ptr;
32       
33 void _assign_bookcase_index_id(info_lib* x)
34 {
35   long ind = x -> first();
36   info_base* base;
37   while (ind) {
38     base = (*x)(ind);
39
40 // no duplication check yet
41     int i = bookcase_array -> no_elmts();
42     bookcase_array -> insert(base, i);
43     bookcase_array -> reset_elmts(i+1);
44
45     base -> set_index_id(i);
46     x -> next(ind);
47   }
48 }
49
50 int 
51 DtMmdbOpenInfoLib(
52         const char* infolib_path,
53         const char* selected_base_name,
54         DtMmdbBool delayed_infolib_init
55                )
56 {
57    mtry {
58
59       mmdb_ptr = new OLIAS_DB;
60       info_lib* x = mmdb_ptr -> openInfoLib(infolib_path, selected_base_name);
61    
62
63       int i = x -> descriptor();
64 /*
65       int i = infolib_array -> no_elmts();
66       infolib_array -> insert(x, i);
67       infolib_array -> reset_elmts(i+1);
68 */
69
70       _assign_bookcase_index_id(x);
71    
72       return i;
73    }
74
75    mcatch (mmdbException &,e)
76    {
77       return -1;
78    } end_try;
79
80    return -1;
81 }
82
83 void DtMmdbCloseInfoLib(int infolib_descriptor)
84 {
85    delete mmdb_ptr;
86    mmdb_ptr = 0;
87
88    //infolib_array -> reset_vptr(0);
89 }
90
91
92 DtMmdbInfoLibInfo* 
93 DtMmdbInfoLibGetInfo(int infolib_descriptor)
94 {
95    mtry {
96         info_lib* x = mmdb_ptr -> getInfoLib(infolib_descriptor);
97    
98         if ( x == 0 ) return 0;
99    
100         DtMmdbInfoLibInfo *y = 
101             (DtMmdbInfoLibInfo*)malloc(sizeof(DtMmdbInfoLibInfo)); 
102    
103         if ( y == 0 ) return 0;
104    
105         y -> path = x -> get_info_lib_path();
106         y -> name = x -> get_info_lib_name();
107         y -> num_bookcases = x -> num_of_bases();
108    
109         return y;
110    
111    }
112    mcatch (mmdbException &,e)
113    {
114       return 0;
115    } end_try;
116
117    return 0;
118 }
119
120 void DtMmdbInfoLibFreeInfo(DtMmdbInfoLibInfo* x)
121 {
122    free((void*)x);
123 }
124
125