Add GNU LGPL headers to all .c .C and .h files
[oweals/cde.git] / cde / lib / DtSearch / vstfunct.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 /*
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
61 #define PROGNAME        "VSTFUNCT"
62
63 static struct or_swordrec Swordbuf;
64 static struct or_lwordrec Lwordbuf;
65
66
67 /************************/
68 /*                      */
69 /*      find_keyword    */
70 /*                      */
71 /************************/
72 /* Sets vista "curr record" to correct word record.
73  * Usually performed prior to vista read or write function.
74  * CALLER MUST CHECK DB_STATUS.
75  */
76 void            find_keyword (char *cur_word, int vista_num)
77 {
78     static size_t   len;
79     static long     keyfield;
80
81     len = strlen (cur_word);
82     if (len < sizeof (Swordbuf.or_swordkey))
83         keyfield = OR_SWORDKEY;
84     else if (len < sizeof (Lwordbuf.or_lwordkey))
85         keyfield = OR_LWORDKEY;
86     else
87         keyfield = OR_HWORDKEY;
88     KEYFIND (PROGNAME "24", keyfield, cur_word, vista_num);
89     return;
90 }  /* find_keyword() */
91
92
93
94 /********************************/
95 /*                              */
96 /*         read_wordstr         */
97 /*                              */
98 /********************************/
99 /* Performs vista RECREAD on curr word record.
100  * CALLER SHOULD CHECK DB_STATUS.
101  */
102 void            read_wordstr (struct or_hwordrec * glob_word, int vista_num)
103 {
104     static size_t   len;
105
106     len = strlen (glob_word->or_hwordkey);
107     if (len < sizeof (Swordbuf.or_swordkey)) {
108         RECREAD (PROGNAME "61", &Swordbuf, vista_num);
109         if (db_status != S_OKAY)
110             return;
111         strncpy (glob_word->or_hwordkey, Swordbuf.or_swordkey,
112             DtSrMAXWIDTH_HWORD);
113         glob_word->or_hwordkey[DtSrMAXWIDTH_HWORD - 1] = 0;
114         glob_word->or_hwoffset =        ntohl (Swordbuf.or_swoffset);
115         glob_word->or_hwfree =          ntohl (Swordbuf.or_swfree);
116         glob_word->or_hwaddrs =         ntohl (Swordbuf.or_swaddrs);
117     }
118     else if (len < sizeof (Lwordbuf.or_lwordkey)) {
119         RECREAD (PROGNAME "69", &Lwordbuf, vista_num);
120         if (db_status != S_OKAY)
121             return;
122         strncpy (glob_word->or_hwordkey, Lwordbuf.or_lwordkey,
123             DtSrMAXWIDTH_HWORD);
124         glob_word->or_hwordkey[DtSrMAXWIDTH_HWORD - 1] = 0;
125         glob_word->or_hwoffset =        ntohl (Lwordbuf.or_lwoffset);
126         glob_word->or_hwfree =          ntohl (Lwordbuf.or_lwfree);
127         glob_word->or_hwaddrs =         ntohl (Lwordbuf.or_lwaddrs);
128     }
129     else {
130         RECREAD (PROGNAME "78", glob_word, vista_num);
131         glob_word->or_hwordkey[DtSrMAXWIDTH_HWORD - 1] = 0;
132         NTOHL (glob_word->or_hwoffset);
133         NTOHL (glob_word->or_hwfree);
134         NTOHL (glob_word->or_hwaddrs);
135     }
136     return;
137 }  /* read_wordstr() */
138
139
140 /********************************/
141 /*                              */
142 /*         write_wordstr        */
143 /*                              */
144 /********************************/
145 /* performs vista RECWRITE on curr word record.
146  * CALLER MUST CHECK DB_STATUS.
147  */
148 void            write_wordstr (struct or_hwordrec * glob_word, int vista_num)
149 {
150     static size_t   len;
151
152     len = strlen (glob_word->or_hwordkey);
153
154     if (len < sizeof (Swordbuf.or_swordkey)) {
155         strcpy (Swordbuf.or_swordkey, glob_word->or_hwordkey);
156         Swordbuf.or_swoffset =  htonl (glob_word->or_hwoffset);
157         Swordbuf.or_swfree =    htonl (glob_word->or_hwfree);
158         Swordbuf.or_swaddrs =   htonl (glob_word->or_hwaddrs);
159         RECWRITE (PROGNAME "102", &Swordbuf, vista_num);
160     }
161     else if (len < sizeof (Lwordbuf.or_lwordkey)) {
162         strcpy (Lwordbuf.or_lwordkey, glob_word->or_hwordkey);
163         Lwordbuf.or_lwoffset =  htonl (glob_word->or_hwoffset);
164         Lwordbuf.or_lwfree =    htonl (glob_word->or_hwfree);
165         Lwordbuf.or_lwaddrs =   htonl (glob_word->or_hwaddrs);
166         RECWRITE (PROGNAME "111", &Lwordbuf,
167             vista_num);
168     }
169     else {
170         if (len >= DtSrMAXWIDTH_HWORD) {
171             printf ("\n" PROGNAME "124 Program Error Abort, "
172                 "word too long:\n  '%s'\n",
173                 glob_word->or_hwordkey);
174             DtSearchExit (24);
175         }
176         HTONL (glob_word->or_hwoffset);
177         HTONL (glob_word->or_hwfree);
178         HTONL (glob_word->or_hwaddrs);
179         RECWRITE (PROGNAME "115", glob_word, vista_num);
180         NTOHL (glob_word->or_hwoffset);
181         NTOHL (glob_word->or_hwfree);
182         NTOHL (glob_word->or_hwaddrs);
183     }
184     return;
185 }  /* write_wordstr() */
186
187
188 /****************************************/
189 /*                                      */
190 /*           fillnew_wordrec            */
191 /*                                      */
192 /****************************************/
193 /* The input record is always a word in a 'huge' structure.
194  * This function performs vista FILLNEW on that word,
195  * but into correct sized word rec.
196  * Formerly this function was called put_new_word().
197  * CALLER MUST CHECK DB_STATUS.
198  */
199 void            fillnew_wordrec (struct or_hwordrec * glob_word, int vista_num)
200 {
201     static size_t   len;
202
203     len = strlen (glob_word->or_hwordkey);
204     if (len < sizeof (Swordbuf.or_swordkey)) {
205         strcpy (Swordbuf.or_swordkey, glob_word->or_hwordkey);
206         Swordbuf.or_swoffset =  htonl (glob_word->or_hwoffset);
207         Swordbuf.or_swfree =    htonl (glob_word->or_hwfree);
208         Swordbuf.or_swaddrs =   htonl (glob_word->or_hwaddrs);
209         FILLNEW (PROGNAME "137", OR_SWORDREC, &Swordbuf, vista_num);
210     }
211     else if (len < sizeof (Lwordbuf.or_lwordkey)) {
212         strcpy (Lwordbuf.or_lwordkey, glob_word->or_hwordkey);
213         Lwordbuf.or_lwoffset =  htonl (glob_word->or_hwoffset);
214         Lwordbuf.or_lwfree =    htonl (glob_word->or_hwfree);
215         Lwordbuf.or_lwaddrs =   htonl (glob_word->or_hwaddrs);
216         FILLNEW (PROGNAME "147", OR_LWORDREC, &Lwordbuf, vista_num);
217     }
218     else {
219         if (len >= DtSrMAXWIDTH_HWORD) {
220             printf ("\n" PROGNAME "168 Program Error Abort, "
221                 "word too long:\n  '%s'\n",
222                 glob_word->or_hwordkey);
223             DtSearchExit (68);
224         }
225         HTONL (glob_word->or_hwoffset);
226         HTONL (glob_word->or_hwfree);
227         HTONL (glob_word->or_hwaddrs);
228         FILLNEW (PROGNAME "151", OR_HWORDREC, glob_word, vista_num);
229         NTOHL (glob_word->or_hwoffset);
230         NTOHL (glob_word->or_hwfree);
231         NTOHL (glob_word->or_hwaddrs);
232     }
233     return;
234 }  /* fillnew_wordrec() */
235
236 /********************* VSTFUNCT.C **********************************/