c_api_bookcase.C 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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_bookcase.cc /main/5 1996/07/18 16:00:51 drk $ */
  24. #include "oliasdb/c_api_common.h"
  25. //extern void_ptr_array* infolib_array;
  26. extern void_ptr_array* bookcase_array;
  27. //extern olias_server* oserver_ptr;
  28. extern OLIAS_DB* mmdb_ptr;
  29. ///////////////////////////////////////////////////////////////
  30. int
  31. DtMmdbGetBookCaseByName(int infolib_descriptor, const char* name)
  32. {
  33. mtry {
  34. info_lib* x = mmdb_ptr -> getInfoLib(infolib_descriptor);
  35. if ( x == 0 ) return -1;
  36. info_base* base = x -> get_info_base(name);
  37. if ( base == 0 )
  38. return -1;
  39. else
  40. return base -> index_id();
  41. }
  42. mcatch (mmdbException &,e)
  43. {
  44. return -1;
  45. } end_try;
  46. return -1;
  47. }
  48. int
  49. DtMmdbGetBookCaseByIndex(int infolib_descriptor, int index)
  50. {
  51. mtry {
  52. info_lib* x = mmdb_ptr -> getInfoLib(infolib_descriptor);
  53. if ( x == 0 ) return -1;
  54. if ( 0 <= index && index < x -> num_of_bases() ) {
  55. info_base* base;
  56. long ind = x -> first();
  57. for ( int i=0; i<index; i++ )
  58. x -> next(ind);
  59. base = (*x)(ind);
  60. if ( base == 0 )
  61. return -1;
  62. else
  63. return base -> index_id();
  64. } else
  65. return -1;
  66. }
  67. mcatch (mmdbException &,e)
  68. {
  69. return -1;
  70. } end_try;
  71. return -1;
  72. }
  73. int
  74. DtMmdbGetBookCaseByLoc(int infolib_descriptor, const char* locator)
  75. {
  76. mtry {
  77. info_lib* x = mmdb_ptr -> getInfoLib(infolib_descriptor);
  78. if ( x == 0 ) return -1;
  79. //info_base* base = oserver_ptr -> get_infobase(locator, olias_server::LOC);
  80. info_base* base = x -> getInfobaseByComponent(locator, info_lib::LOC);
  81. if ( base == 0 )
  82. return -1;
  83. else
  84. return base -> index_id();
  85. }
  86. mcatch (mmdbException &,e)
  87. {
  88. return -1;
  89. } end_try;
  90. return -1;
  91. }
  92. int*
  93. DtMmdbGetBookCaseByLocs(int infolib_descriptor, const char** locators,
  94. int* count_ptr)
  95. {
  96. mtry {
  97. info_lib* x = mmdb_ptr -> getInfoLib(infolib_descriptor);
  98. if ( x == 0 ) return 0;
  99. int count = 0;
  100. while ( locators[count] )
  101. count++;
  102. info_base** bases =
  103. x -> getInfobasesByComponent((char**)locators, count, info_lib::LOC);
  104. count = 0;
  105. while ( bases[count] )
  106. count++;
  107. int* ds = (int*) malloc(sizeof(int)*(count+1));
  108. for ( int i=0; i<count; i++ )
  109. ds[i] = bases[i] -> index_id();
  110. delete [] bases;
  111. if (count_ptr) *count_ptr = count;
  112. return ds;
  113. }
  114. mcatch (mmdbException &,e)
  115. {
  116. if (count_ptr) *count_ptr = 0;
  117. return 0;
  118. } end_try;
  119. return 0;
  120. }
  121. DtMmdbBookCaseInfo*
  122. DtMmdbBookCaseGetInfo(int bookcase_descriptor)
  123. {
  124. mtry {
  125. info_base* x = getBookCase(bookcase_descriptor);
  126. if ( x == 0 ) return 0;
  127. DtMmdbBookCaseInfo *y =
  128. (DtMmdbBookCaseInfo*)malloc(sizeof(DtMmdbBookCaseInfo));
  129. if ( y == 0 ) return 0;
  130. y -> name = x -> get_base_name();
  131. y -> num_books = x -> num_of_docs();
  132. return y;
  133. }
  134. mcatch (mmdbException &,e)
  135. {
  136. return 0;
  137. } end_try;
  138. return 0;
  139. }
  140. void DtMmdbBookCaseFreeInfo(DtMmdbBookCaseInfo* x)
  141. {
  142. free((void*)x);
  143. }