summaryrefslogtreecommitdiff
path: root/textproc/wordnet/files/patch-lib__wnutil.c
blob: 688c4ba37dbf8463b23cfb220c383a1cbcdd4466 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
--- lib/wnutil.c	Fri May  6 13:17:39 2005
+++ lib/wnutil.c	Mon Mar 16 22:52:04 2020
@@ -15,5 +15,6 @@
 #ifdef __unix__
 #ifndef __MACH__
-#include <malloc.h>
+#include <stdlib.h>
+#include <stdint.h>
 #endif
 #endif
@@ -25,5 +25,6 @@
 #include "wn.h"
 
-static int do_init();
+static int do_init(void);
+static const char *SetSearchdir(void);
 
 static char msgbuf[256];	/* buffer for constructing error messages */
@@ -37,5 +37,5 @@
 /* Initialization functions */
 
-static void closefps();
+static void closefps(void);
 
 int wninit(void)
@@ -46,7 +46,6 @@
 
     if (!done) {
-	if (env = getenv("WNDBVERSION")) {
-	    wnrelease = strdup(env);	/* set release */
-	    assert(wnrelease);
+	if ((env = getenv("WNDBVERSION"))) {
+	    wnrelease = env;	/* set release */
 	}
 	openerr = do_init();
@@ -68,7 +67,6 @@
     closefps();
 
-    if (env = getenv("WNDBVERSION")) {
-	wnrelease = strdup(env);	/* set release */
-	assert(wnrelease);
+    if ((env = getenv("WNDBVERSION"))) {
+	wnrelease = env;	/* set release */
     openerr = do_init();

@@ -90,8 +89,12 @@
     if (OpenDB) {
 	for (i = 1; i < NUMPARTS + 1; i++) {
-	    if (datafps[i] != NULL)
-		fclose(datafps[i]); datafps[i] = NULL;
-	    if (indexfps[i] != NULL)
-		fclose(indexfps[i]); indexfps[i] = NULL;
+	    if (datafps[i] != NULL) {
+		fclose(datafps[i]);
+		datafps[i] = NULL;
+	    }
+	    if (indexfps[i] != NULL) {
+		fclose(indexfps[i]);
+		indexfps[i] = NULL;
+	    }
 	}
 	if (sensefp != NULL) {
@@ -248,4 +246,20 @@
 }
 
+char *strtolower2(const char *from, char *to)
+{
+
+    char *t = to;
+
+    do {
+	if(*from >= 'A' && *from <= 'Z')
+	    *t = *from++ + 32;
+	else if(*from == '(')
+	    *t = '\0';
+	else
+	    *t = *from++;
+    } while (*t++);
+    return(to);
+}
+
 /* Convert string passed to lower case */
 
@@ -276,11 +290,24 @@
 /* Return pointer code for pointer type characer passed. */
 
-int getptrtype(char *ptrstr)
+unsigned short
+getptrtype(const char *ptrstr, char **end)
 {
-    register int i;
+    unsigned short i;
+    const char *ptype, *pstr;
     for(i = 1; i <= MAXPTR; i++) {
-	if(!strcmp(ptrstr, ptrtyp[i]))
+	ptype = ptrtyp[i];
+	pstr = ptrstr;
+	while (*pstr == *ptype && *ptype) {
+	    pstr++;
+	    ptype++;
+	}
+	if (*ptype == '\0' &&
+	    (*pstr == '\n' || *pstr == ' ' || *pstr == '\0')) {
+	    if (end)
+		*end = __DECONST(char *, pstr);
 	    return(i);
+	}
     }
+    fprintf(stderr, "Could not find the type of %s\n", ptrstr);
     return(0);
 }
@@ -288,5 +315,6 @@
 /* Return part of speech code for string passed */
 
-int getpos(char *s)
+int
+getpos(const char *s)
 {
     switch (*s) {
@@ -310,5 +338,6 @@
 /* Return synset type code for string passed. */
 
-int getsstype(char *s)
+int
+getsstype(const char *s)
 {
     switch (*s) {
@@ -332,5 +361,6 @@
 /* Pass in string for POS, return corresponding integer value */
 
-int StrToPos(char *str)
+int
+StrToPos(const char *str)
 {
     if (!strcmp(str, "noun"))
@@ -389,5 +419,6 @@
 /* Return synset for sense key passed. */
 
-SynsetPtr GetSynsetForSense(char *sensekey)
+SynsetPtr
+GetSynsetForSense(const char *sensekey)
 {
     long offset;
@@ -405,7 +436,8 @@
 /* Find offset of sense key in data file */
 
-long GetDataOffset(char *sensekey)
+long
+GetDataOffset(const char *sensekey)
 {
-    char *line;
+    const char *line;
 
     /* Pass in encoded sense string, return byte offset of corresponding
@@ -426,5 +458,6 @@
 /* Find polysemy count for sense key passed. */
 
-int GetPolyCount(char *sensekey)
+int
+GetPolyCount(const char *sensekey)
 {
     IndexPtr idx;
@@ -443,5 +476,6 @@
 
 /* Return word part of sense key */
-char *GetWORD(char *sensekey)
+const char *
+GetWORD(const char *sensekey)
 {
     static char word[100];
@@ -457,5 +491,6 @@
 /* Return POS code for sense key passed. */
 
-int GetPOS(char *sensekey)
+int
+GetPOS(const char *sensekey)
 {
     int pos;
@@ -470,5 +505,6 @@
 /* Reconstruct synset from synset pointer and return ptr to buffer */
 
-char *FmtSynset(SynsetPtr synptr, int defn)
+const char *
+FmtSynset(SynsetPtr synptr, int defn)
 {
     int i;
@@ -542,27 +578,8 @@
 }
 
-/* Search for string and/or baseform of word in database and return
-   index structure for word if found in database. */
-
-IndexPtr GetValidIndexPointer(char *word, int pos)
-{
-    IndexPtr idx;
-    char *morphword;
-
-    idx = getindex(word, pos);
-
-    if (idx == NULL) {
-	if ((morphword = morphstr(word, pos)) != NULL)
-	    while (morphword) {
-		if ((idx = getindex(morphword, pos)) != NULL) break;
-		morphword = morphstr(NULL, pos);
-	    }
-    }
-    return (idx);
-}
-
 /* Return sense number in database for word and lexsn passed. */
 
-int GetWNSense(char *word, char *lexsn)
+int
+GetWNSense(const char *word, const char *lexsn)
 {
     SnsIndexPtr snsidx;
@@ -578,7 +595,8 @@
 /* Return parsed sense index entry for sense key passed. */
 
-SnsIndexPtr GetSenseIndex(char *sensekey)
+SnsIndexPtr
+GetSenseIndex(const char *sensekey)
 {
-    char *line;
+    const char *line;
     char buf[256], loc[9];
     SnsIndexPtr snsidx = NULL;
@@ -608,5 +626,6 @@
 int GetTagcnt(IndexPtr idx, int sense) 
 {
-    char *sensekey, *line;
+    char *sensekey;
+    const char *line;
     char buf[256];
     int snum, cnt = 0;
@@ -632,10 +651,11 @@
 }
 
-char *GetOffsetForKey(unsigned int key)
+const char *
+GetOffsetForKey(unsigned int key)
 {
     unsigned int rkey;
     char ckey[7];
     static char loc[11] = "";
-    char *line;
+    const char *line;
     char searchdir[256], tmpbuf[256];
 
@@ -657,10 +677,10 @@
 }
 
-
-unsigned int GetKeyForOffset(char *loc)
+unsigned int
+GetKeyForOffset(const char *loc)
 {
     unsigned int key;
     char rloc[11] = "";
-    char *line;
+    const char *line;
     char searchdir[256], tmpbuf[256];
 
@@ -681,8 +701,9 @@
 }
 
-char *SetSearchdir()
+const char *
+SetSearchdir(void)
 {
-    static char searchdir[256];
-    char *env;
+    char *searchdir;
+    const char *env;
 
     /* Find base directory for database.  If set, use WNSEARCHDIR.
@@ -690,14 +711,17 @@
 
     if ((env = getenv("WNSEARCHDIR")) != NULL)
-	strcpy(searchdir, env);
-    else if ((env = getenv("WNHOME")) != NULL)
+	return(env);
+    else if ((env = getenv("WNHOME")) != NULL) {
+	searchdir = malloc(strlen(env) + sizeof(DICTDIR));
 	sprintf(searchdir, "%s%s", env, DICTDIR);
-    else
-	strcpy(searchdir, DEFAULTPATH);
-
-    return(searchdir);
+	return(searchdir);
+    } else
+	return(DEFAULTPATH);
 }
 
-int default_display_message(char *msg)
+#ifndef __GNUC__
+#	define __unused
+#endif
+int default_display_message(const char *msg __unused)
 {
     return(-1);
@@ -727,3 +751,2 @@
    return (loc - strstr_stringstart);
 }
-