OpenIndiana and Solaris port
[oweals/cde.git] / cde / programs / dtinfo / DtMmdb / oliasdb / c_api_bookcase.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_bookcase.cc /main/5 1996/07/18 16:00:51 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_server* oserver_ptr;
30 extern OLIAS_DB* mmdb_ptr;
31
32
33 ///////////////////////////////////////////////////////////////
34
35 int
36 DtMmdbGetBookCaseByName(int infolib_descriptor, const char* name)
37 {
38    mtry {
39       info_lib* x = mmdb_ptr -> getInfoLib(infolib_descriptor);
40
41       if ( x == 0 ) return -1;
42
43       info_base* base = x -> get_info_base(name);
44
45       if ( base == 0 ) 
46          return -1;
47       else
48          return base -> index_id();
49    }
50
51    mcatch (mmdbException &,e)
52    {
53       return -1;
54    } end_try;
55    return -1;
56 }
57
58 int
59 DtMmdbGetBookCaseByIndex(int infolib_descriptor, int index)
60 {
61    mtry {
62       info_lib* x = mmdb_ptr -> getInfoLib(infolib_descriptor);
63
64       if ( x == 0 ) return -1;
65
66       if ( 0 <= index && index < x -> num_of_bases() ) {
67
68          info_base* base;
69
70          long ind = x -> first();
71          for ( int i=0; i<index; i++ )
72             x -> next(ind);
73
74          base = (*x)(ind);
75
76          if ( base == 0 ) 
77             return -1;
78          else
79             return base -> index_id();
80
81       } else
82         return -1;
83    }
84    mcatch (mmdbException &,e)
85    {
86       return -1;
87    } end_try;
88    return -1;
89 }
90
91 int
92 DtMmdbGetBookCaseByLoc(int infolib_descriptor, const char* locator)
93 {
94    mtry {
95       info_lib* x = mmdb_ptr -> getInfoLib(infolib_descriptor);
96
97       if ( x == 0 ) return -1;
98
99       //info_base* base = oserver_ptr -> get_infobase(locator, olias_server::LOC);
100       info_base* base = x -> getInfobaseByComponent(locator, info_lib::LOC);
101
102       if ( base == 0 ) 
103             return -1;
104       else
105             return base -> index_id();
106       
107    }
108    mcatch (mmdbException &,e)
109    {
110       return -1;
111    } end_try;
112
113    return -1;
114 }
115
116 int*
117 DtMmdbGetBookCaseByLocs(int infolib_descriptor, const char** locators, 
118         int* count_ptr)
119 {
120
121     mtry {
122       info_lib* x = mmdb_ptr -> getInfoLib(infolib_descriptor);
123
124       if ( x == 0 ) return 0;
125
126       int count = 0;
127       while ( locators[count] )
128          count++;
129
130       info_base** bases = 
131          x -> getInfobasesByComponent((char**)locators, count, info_lib::LOC);
132
133       count = 0;
134       while ( bases[count] )
135          count++;
136
137       int* ds = (int*) malloc(sizeof(int)*(count+1));
138
139       for ( int i=0; i<count; i++ )
140          ds[i] = bases[i] -> index_id();
141
142       delete bases;
143
144       if (count_ptr) *count_ptr = count;
145
146       return ds;
147
148    }
149    mcatch (mmdbException &,e)
150    {
151       if (count_ptr) *count_ptr = 0;
152       return 0;
153    } end_try;
154
155    return 0;
156 }
157
158
159 DtMmdbBookCaseInfo* 
160 DtMmdbBookCaseGetInfo(int bookcase_descriptor)
161 {
162    mtry {
163         info_base* x = getBookCase(bookcase_descriptor);
164   
165         if ( x == 0 ) return 0;
166   
167         DtMmdbBookCaseInfo *y =
168             (DtMmdbBookCaseInfo*)malloc(sizeof(DtMmdbBookCaseInfo));
169   
170         if ( y == 0 ) return 0;
171
172         y -> name = x -> get_base_name();
173         y -> num_books = x -> num_of_docs();
174
175         return y;
176
177    }
178    mcatch (mmdbException &,e)
179    {
180       return 0;
181    } end_try;
182
183    return 0;
184 }
185
186 void DtMmdbBookCaseFreeInfo(DtMmdbBookCaseInfo* x)
187 {
188    free((void*)x);
189 }
190