c_api_section.C 4.6 KB

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