vstfunct.c 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  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. /*
  24. * COMPONENT_NAME: austext
  25. *
  26. * FUNCTIONS: fillnew_wordrec
  27. * find_keyword
  28. * read_wordstr
  29. * write_wordstr
  30. *
  31. * ORIGINS: 27
  32. *
  33. *
  34. * (C) COPYRIGHT International Business Machines Corp. 1993,1995
  35. * All Rights Reserved
  36. * Licensed Materials - Property of IBM
  37. * US Government Users Restricted Rights - Use, duplication or
  38. * disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  39. */
  40. /********************* VSTFUNCT.C **********************************
  41. * $XConsortium: vstfunct.c /main/6 1996/08/12 13:20:01 cde-ibm $
  42. * Performs vista KEYFIND, RECREAD, RECWRITE, and FILLNEW functions
  43. * on word database files without caller having to know
  44. * whether word is short, long, or huge.
  45. * Remember: all word lengths are 1 byte shorter than the field size,
  46. * plus 1 byte for the terminating \0.
  47. *
  48. * $Log$
  49. * Revision 2.2 1995/10/26 14:12:32 miker
  50. * Added prolog.
  51. *
  52. * Revision 2.1 1995/09/22 22:23:13 miker
  53. * Freeze DtSearch 0.1, AusText 2.1.8
  54. *
  55. * Revision 1.3 1995/09/05 19:34:07 miker
  56. * Minor name changes for DtSearch.
  57. */
  58. #include "SearchP.h"
  59. #include "vista.h"
  60. #define PROGNAME "VSTFUNCT"
  61. static struct or_swordrec Swordbuf;
  62. static struct or_lwordrec Lwordbuf;
  63. /************************/
  64. /* */
  65. /* find_keyword */
  66. /* */
  67. /************************/
  68. /* Sets vista "curr record" to correct word record.
  69. * Usually performed prior to vista read or write function.
  70. * CALLER MUST CHECK DB_STATUS.
  71. */
  72. void find_keyword (char *cur_word, int vista_num)
  73. {
  74. static size_t len;
  75. static long keyfield;
  76. len = strlen (cur_word);
  77. if (len < sizeof (Swordbuf.or_swordkey))
  78. keyfield = OR_SWORDKEY;
  79. else if (len < sizeof (Lwordbuf.or_lwordkey))
  80. keyfield = OR_LWORDKEY;
  81. else
  82. keyfield = OR_HWORDKEY;
  83. KEYFIND (PROGNAME "24", keyfield, cur_word, vista_num);
  84. return;
  85. } /* find_keyword() */
  86. /********************************/
  87. /* */
  88. /* read_wordstr */
  89. /* */
  90. /********************************/
  91. /* Performs vista RECREAD on curr word record.
  92. * CALLER SHOULD CHECK DB_STATUS.
  93. */
  94. void read_wordstr (struct or_hwordrec * glob_word, int vista_num)
  95. {
  96. static size_t len;
  97. len = strlen (glob_word->or_hwordkey);
  98. if (len < sizeof (Swordbuf.or_swordkey)) {
  99. RECREAD (PROGNAME "61", &Swordbuf, vista_num);
  100. if (db_status != S_OKAY)
  101. return;
  102. strncpy (glob_word->or_hwordkey, Swordbuf.or_swordkey,
  103. DtSrMAXWIDTH_HWORD);
  104. glob_word->or_hwordkey[DtSrMAXWIDTH_HWORD - 1] = 0;
  105. glob_word->or_hwoffset = ntohl (Swordbuf.or_swoffset);
  106. glob_word->or_hwfree = ntohl (Swordbuf.or_swfree);
  107. glob_word->or_hwaddrs = ntohl (Swordbuf.or_swaddrs);
  108. }
  109. else if (len < sizeof (Lwordbuf.or_lwordkey)) {
  110. RECREAD (PROGNAME "69", &Lwordbuf, vista_num);
  111. if (db_status != S_OKAY)
  112. return;
  113. strncpy (glob_word->or_hwordkey, Lwordbuf.or_lwordkey,
  114. DtSrMAXWIDTH_HWORD);
  115. glob_word->or_hwordkey[DtSrMAXWIDTH_HWORD - 1] = 0;
  116. glob_word->or_hwoffset = ntohl (Lwordbuf.or_lwoffset);
  117. glob_word->or_hwfree = ntohl (Lwordbuf.or_lwfree);
  118. glob_word->or_hwaddrs = ntohl (Lwordbuf.or_lwaddrs);
  119. }
  120. else {
  121. RECREAD (PROGNAME "78", glob_word, vista_num);
  122. glob_word->or_hwordkey[DtSrMAXWIDTH_HWORD - 1] = 0;
  123. NTOHL (glob_word->or_hwoffset);
  124. NTOHL (glob_word->or_hwfree);
  125. NTOHL (glob_word->or_hwaddrs);
  126. }
  127. return;
  128. } /* read_wordstr() */
  129. /********************************/
  130. /* */
  131. /* write_wordstr */
  132. /* */
  133. /********************************/
  134. /* performs vista RECWRITE on curr word record.
  135. * CALLER MUST CHECK DB_STATUS.
  136. */
  137. void write_wordstr (struct or_hwordrec * glob_word, int vista_num)
  138. {
  139. static size_t len;
  140. len = strlen (glob_word->or_hwordkey);
  141. if (len < sizeof (Swordbuf.or_swordkey)) {
  142. strcpy (Swordbuf.or_swordkey, glob_word->or_hwordkey);
  143. Swordbuf.or_swoffset = htonl (glob_word->or_hwoffset);
  144. Swordbuf.or_swfree = htonl (glob_word->or_hwfree);
  145. Swordbuf.or_swaddrs = htonl (glob_word->or_hwaddrs);
  146. RECWRITE (PROGNAME "102", &Swordbuf, vista_num);
  147. }
  148. else if (len < sizeof (Lwordbuf.or_lwordkey)) {
  149. strcpy (Lwordbuf.or_lwordkey, glob_word->or_hwordkey);
  150. Lwordbuf.or_lwoffset = htonl (glob_word->or_hwoffset);
  151. Lwordbuf.or_lwfree = htonl (glob_word->or_hwfree);
  152. Lwordbuf.or_lwaddrs = htonl (glob_word->or_hwaddrs);
  153. RECWRITE (PROGNAME "111", &Lwordbuf,
  154. vista_num);
  155. }
  156. else {
  157. if (len >= DtSrMAXWIDTH_HWORD) {
  158. printf ("\n" PROGNAME "124 Program Error Abort, "
  159. "word too long:\n '%s'\n",
  160. glob_word->or_hwordkey);
  161. DtSearchExit (24);
  162. }
  163. HTONL (glob_word->or_hwoffset);
  164. HTONL (glob_word->or_hwfree);
  165. HTONL (glob_word->or_hwaddrs);
  166. RECWRITE (PROGNAME "115", glob_word, vista_num);
  167. NTOHL (glob_word->or_hwoffset);
  168. NTOHL (glob_word->or_hwfree);
  169. NTOHL (glob_word->or_hwaddrs);
  170. }
  171. return;
  172. } /* write_wordstr() */
  173. /****************************************/
  174. /* */
  175. /* fillnew_wordrec */
  176. /* */
  177. /****************************************/
  178. /* The input record is always a word in a 'huge' structure.
  179. * This function performs vista FILLNEW on that word,
  180. * but into correct sized word rec.
  181. * Formerly this function was called put_new_word().
  182. * CALLER MUST CHECK DB_STATUS.
  183. */
  184. void fillnew_wordrec (struct or_hwordrec * glob_word, int vista_num)
  185. {
  186. static size_t len;
  187. len = strlen (glob_word->or_hwordkey);
  188. if (len < sizeof (Swordbuf.or_swordkey)) {
  189. strcpy (Swordbuf.or_swordkey, glob_word->or_hwordkey);
  190. Swordbuf.or_swoffset = htonl (glob_word->or_hwoffset);
  191. Swordbuf.or_swfree = htonl (glob_word->or_hwfree);
  192. Swordbuf.or_swaddrs = htonl (glob_word->or_hwaddrs);
  193. FILLNEW (PROGNAME "137", OR_SWORDREC, &Swordbuf, vista_num);
  194. }
  195. else if (len < sizeof (Lwordbuf.or_lwordkey)) {
  196. strcpy (Lwordbuf.or_lwordkey, glob_word->or_hwordkey);
  197. Lwordbuf.or_lwoffset = htonl (glob_word->or_hwoffset);
  198. Lwordbuf.or_lwfree = htonl (glob_word->or_hwfree);
  199. Lwordbuf.or_lwaddrs = htonl (glob_word->or_hwaddrs);
  200. FILLNEW (PROGNAME "147", OR_LWORDREC, &Lwordbuf, vista_num);
  201. }
  202. else {
  203. if (len >= DtSrMAXWIDTH_HWORD) {
  204. printf ("\n" PROGNAME "168 Program Error Abort, "
  205. "word too long:\n '%s'\n",
  206. glob_word->or_hwordkey);
  207. DtSearchExit (68);
  208. }
  209. HTONL (glob_word->or_hwoffset);
  210. HTONL (glob_word->or_hwfree);
  211. HTONL (glob_word->or_hwaddrs);
  212. FILLNEW (PROGNAME "151", OR_HWORDREC, glob_word, vista_num);
  213. NTOHL (glob_word->or_hwoffset);
  214. NTOHL (glob_word->or_hwfree);
  215. NTOHL (glob_word->or_hwaddrs);
  216. }
  217. return;
  218. } /* fillnew_wordrec() */
  219. /********************* VSTFUNCT.C **********************************/