2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
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)
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
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
23 // $XConsortium: c_api_book.cc /main/4 1996/06/11 17:26:37 cde-hal $
25 #include "oliasdb/c_api_common.h"
28 getDocUsingPrOrSecOrSeq(DtMmdbInfoRequest* request)
31 info_base* x = getBookCase(request -> bookcase_descriptor);
32 if ( x == 0 ) return 0;
34 oid_t * id = getPrimiaryOid(request);
37 return new doc_smart_ptr(x, *id);
40 id = getSecondaryOid(request); // book id
43 return new doc_smart_ptr(*id, x);
46 int seq = getSeqNum(request); // seq number
48 if ( seq == -1 ) return 0;
50 // bookcase is treated 1 based internally. But 0-based externally.
51 return new doc_smart_ptr(x, seq+1);
54 catch (mmdbException &,e)
62 DtMmdbBookGetTocObjectId(DtMmdbInfoRequest* request)
65 doc_smart_ptr* x = getDocUsingPrOrSecOrSeq(request);
66 if ( x == 0 ) return 0;
68 DtMmdbHandle *z = newDtMmdbHandle(x -> locator_id());
74 catch (mmdbException &,e)
82 DtMmdbBookGetShortTitle(DtMmdbInfoRequest* request, unsigned int* length)
85 doc_smart_ptr* x = getDocUsingPrOrSecOrSeq(request);
86 if ( x == 0 ) return 0;
88 const char* z = x -> short_title();
90 if ( length ) *length = strlen(z);
96 catch (mmdbException &,e)
104 DtMmdbBookGetLongTitle(DtMmdbInfoRequest* request, unsigned int* length)
107 doc_smart_ptr* x = getDocUsingPrOrSecOrSeq(request);
108 if ( x == 0 ) return 0;
110 const char* z = x -> long_title();
112 if ( length ) *length = strlen(z);
118 catch (mmdbException &,e)
125 int DtMmdbBookGetSeqNum(DtMmdbInfoRequest* request)
128 doc_smart_ptr* x = getDocUsingPrOrSecOrSeq(request);
129 if ( x == 0 ) return 0;
131 int z = x -> seq_num();
137 catch (mmdbException &,e)
145 DtMmdbBookGetSeqLIcense(DtMmdbInfoRequest* request, unsigned int* length)
148 doc_smart_ptr* x = getDocUsingPrOrSecOrSeq(request);
149 if ( x == 0 ) return 0;
151 const char* z = x -> license_terms();
153 *length = x -> license_terms_size();
159 catch (mmdbException &,e)
166 DtMmdbHandle** DtMmdbBookGetTabList(DtMmdbInfoRequest* request, unsigned int* length)
169 doc_smart_ptr* x = getDocUsingPrOrSecOrSeq(request);
170 if ( x == 0 ) return 0;
172 short_list_handler* z = x -> tab_list();
174 if ( z == 0 ) return 0;
176 int count = (*z) -> count();
178 DtMmdbHandle** u = (DtMmdbHandle**)malloc(sizeof(DtMmdbHandle*)* (count+1));
180 if ( u == 0 ) return 0;
182 const char* desc = 0;
183 pstring_handler *p = 0;
185 for (int i=0; i<count; i++) {
186 p = (pstring_handler *)((*z)->get_component (i+1));
188 // The format is the title, a tab char, then the section oid.
191 while (*desc != '\0' && *desc != '\t') desc++;
198 oid_t w((char*)desc, true, false);
199 u[i] = newDtMmdbHandle(w);
207 if ( length ) *length = count;
214 catch (mmdbException &,e)