OpenIndiana and Solaris port
[oweals/cde.git] / cde / programs / dtinfo / DtMmdb / oliasdb / c_api_section.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_section.cc /main/3 1996/06/11 17:27:53 cde-hal $
24
25 #include "oliasdb/c_api_common.h"
26
27 const char* 
28 DtMmdbSectionGetLoc(DtMmdbInfoRequest* request)
29 {
30    mtry {
31       info_base* x = getBookCase(request -> bookcase_descriptor);
32       if ( x == 0 ) return 0;
33    
34       oid_t * id = getPrimiaryOid(request); 
35    
36       if ( id == 0 ) return 0;
37    
38       node_smart_ptr y(x, *id);
39    
40       return y.locator();
41    }
42
43    mcatch (mmdbException &,e)
44    {
45      return 0;
46    } end_try;
47      return 0;
48 }
49
50 static node_smart_ptr* 
51 getSectionUsingLocAndProid(DtMmdbInfoRequest* request)
52 {
53    mtry {
54       info_base* x = getBookCase(request -> bookcase_descriptor);
55       if ( x == 0 ) return 0;
56
57       const char* str = getLocator(request);
58
59       if ( str ) {
60          return new node_smart_ptr(x, str);
61       }
62
63       oid_t * id = getPrimiaryOid(request);
64
65       if ( id == 0 ) return 0;
66
67       return new node_smart_ptr(x, *id);
68    }
69
70    mcatch (mmdbException &,e)
71    {
72      return 0;
73    } end_try;
74      return 0;
75 }
76
77 const char* 
78 DtMmdbSectionGetLongTitle(
79         DtMmdbInfoRequest* request,
80         unsigned int* title_length
81                          )
82 {
83    mtry {
84       node_smart_ptr* x = getSectionUsingLocAndProid(request);
85
86       if ( x == 0 ) return 0;
87
88 #ifdef DEBUG
89       fprintf(stderr, " mmdb_oid = ");
90       (*x).its_oid().asciiOut(cerr); cerr << "\n";
91       cerr.flush();
92 #endif
93
94       const char* y = x -> long_title();
95
96       if ( title_length ) *title_length = strlen(y);
97       delete x;
98       return y;
99    }
100
101    mcatch (mmdbException &,e)
102    {
103      return 0;
104    } end_try;
105      return 0;
106 }
107
108 const char* 
109 DtMmdbSectionGetShortTitle(
110         DtMmdbInfoRequest* request,
111         unsigned int* title_length
112                           )
113 {
114    mtry {
115       node_smart_ptr* x = getSectionUsingLocAndProid(request);
116
117       if ( x == 0 ) return 0;
118       const char* y = x -> short_title();
119
120       if ( title_length ) *title_length = strlen(y);
121       delete x;
122       return y;
123    }
124
125    mcatch (mmdbException &,e)
126    {
127      return 0;
128    } end_try;
129      return 0;
130 }
131
132 const char* 
133 DtMmdbSectionGetData
134         (
135         DtMmdbInfoRequest* request,
136         unsigned int* data_length
137         )
138 {
139    mtry {
140       node_smart_ptr* x = getSectionUsingLocAndProid(request);
141
142       if ( x == 0 ) return 0;
143       const char* y = x -> data();
144
145       if ( data_length ) *data_length = strlen(y);
146       delete x;
147       return y;
148    }
149
150    mcatch (mmdbException &,e)
151    {
152      return 0;
153    } end_try;
154      return 0;
155 }
156
157 int DtMmdbSectionGetDataSize(DtMmdbInfoRequest* request)
158 {
159    mtry {
160       node_smart_ptr* x = getSectionUsingLocAndProid(request);
161
162       if ( x == 0 ) return -1;
163
164       int y = x -> data_size();
165
166       delete x;
167       return y;
168    }
169
170    mcatch (mmdbException &,e)
171    {
172      return -1;
173    } end_try;
174
175      return -1;
176 }
177         
178 const char* DtMmdbSectionGetTocLoc(DtMmdbInfoRequest* request)
179 {
180    mtry {
181       node_smart_ptr* x = getSectionUsingLocAndProid(request);
182
183       if ( x == 0 ) return 0;
184       const char* y = x -> toc_node_loc();
185
186       delete x;
187       return y;
188    }
189
190    mcatch (mmdbException &,e)
191    {
192      return 0;
193    } end_try;
194
195      return 0;
196 }
197
198 DtMmdbHandle* 
199 DtMmdbSectionGetBookId(DtMmdbInfoRequest* request)
200 {
201    mtry {
202       node_smart_ptr* x = getSectionUsingLocAndProid(request);
203
204       if ( x == 0 ) return 0;
205
206       DtMmdbHandle *z = newDtMmdbHandle(x -> doc_id());
207
208       delete x;
209       return z;
210    }
211
212    mcatch (mmdbException &,e)
213    {
214      return 0;
215    } end_try;
216      return 0;
217 }
218
219 DtMmdbHandle* 
220 DtMmdbSectionGetStyleSheetId(DtMmdbInfoRequest* request)
221 {
222    mtry {
223       node_smart_ptr* x = getSectionUsingLocAndProid(request);
224
225       if ( x == 0 ) return 0;
226
227       DtMmdbHandle *z = newDtMmdbHandle(x -> stylesheet_id());
228
229       delete x;
230       return z;
231    }
232
233    mcatch (mmdbException &,e)
234    {
235      return 0;
236    } end_try;
237      return 0;
238 }
239