1 |
adcroft |
1.1 |
/* |
2 |
|
|
** Copyright (C) 1995, 1996, 1997, 1998 Hewlett-Packard Company |
3 |
|
|
** Originally by Kevin Hughes, kev@kevcom.com, 3/11/94 |
4 |
|
|
** |
5 |
|
|
** This program and library is free software; you can redistribute it and/or |
6 |
|
|
** modify it under the terms of the GNU (Library) General Public License |
7 |
|
|
** as published by the Free Software Foundation; either version 2 |
8 |
|
|
** of the License, or any later version. |
9 |
|
|
** |
10 |
|
|
** This program is distributed in the hope that it will be useful, |
11 |
|
|
** but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 |
|
|
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 |
|
|
** GNU (Library) General Public License for more details. |
14 |
|
|
** |
15 |
|
|
** You should have received a copy of the GNU (Library) General Public License |
16 |
|
|
** along with this program; if not, write to the Free Software |
17 |
|
|
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
18 |
|
|
** |
19 |
|
|
** 1998-07-04 addfilter ( R. Scherg) |
20 |
|
|
** 2001-02-28 rasc -- addfilter removed here |
21 |
|
|
** |
22 |
|
|
*/ |
23 |
|
|
|
24 |
|
|
#include "swish.h" |
25 |
|
|
#include "list.h" |
26 |
|
|
#include "mem.h" |
27 |
|
|
#include "metanames.h" |
28 |
|
|
#include "string.h" |
29 |
|
|
|
30 |
|
|
|
31 |
|
|
struct swline *addswline(struct swline *rp, char *line) |
32 |
|
|
{ |
33 |
|
|
struct swline *newnode; |
34 |
|
|
|
35 |
|
|
newnode = (struct swline *) emalloc(sizeof(struct swline)); |
36 |
|
|
newnode->line = (char *) estrdup(line); |
37 |
|
|
newnode->next = NULL; |
38 |
|
|
|
39 |
|
|
if (rp == NULL) |
40 |
|
|
rp = newnode; |
41 |
|
|
else |
42 |
|
|
rp->nodep->next = newnode; |
43 |
|
|
|
44 |
|
|
rp->nodep = newnode; |
45 |
|
|
|
46 |
|
|
return rp; |
47 |
|
|
} |
48 |
|
|
|
49 |
|
|
struct swline *dupswline(struct swline *rp) |
50 |
|
|
{ |
51 |
|
|
struct swline *tmp=NULL, *tmp2=NULL; |
52 |
|
|
struct swline *newnode; |
53 |
|
|
while(rp) |
54 |
|
|
{ |
55 |
|
|
newnode = (struct swline *) emalloc(sizeof(struct swline)); |
56 |
|
|
newnode->line = (char *) estrdup(rp->line); |
57 |
|
|
newnode->next = NULL; |
58 |
|
|
|
59 |
|
|
if(!tmp) |
60 |
|
|
tmp = newnode; |
61 |
|
|
else |
62 |
|
|
tmp2->next=newnode; |
63 |
|
|
tmp2 = newnode; |
64 |
|
|
rp=rp->next; |
65 |
|
|
} |
66 |
|
|
return tmp; |
67 |
|
|
} |
68 |
|
|
|
69 |
|
|
IndexFILE *addindexfile(IndexFILE *rp, char *line) |
70 |
|
|
{ |
71 |
|
|
IndexFILE *newnode; |
72 |
|
|
|
73 |
|
|
newnode = (IndexFILE *) emalloc(sizeof(IndexFILE)); |
74 |
|
|
memset( newnode, 0, sizeof(IndexFILE) ); |
75 |
|
|
|
76 |
|
|
newnode->line = (char *) estrdup(line); |
77 |
|
|
|
78 |
|
|
|
79 |
|
|
init_header(&newnode->header); |
80 |
|
|
|
81 |
|
|
newnode->next = NULL; |
82 |
|
|
|
83 |
|
|
|
84 |
|
|
/* Add default meta names -- these will be replaced if reading from an index file */ |
85 |
|
|
add_default_metanames(newnode); |
86 |
|
|
|
87 |
|
|
if (rp == NULL) |
88 |
|
|
rp = newnode; |
89 |
|
|
else |
90 |
|
|
rp->nodep->next = newnode; |
91 |
|
|
|
92 |
|
|
rp->nodep = newnode; |
93 |
|
|
|
94 |
|
|
return rp; |
95 |
|
|
} |
96 |
|
|
|
97 |
|
|
|
98 |
|
|
void freeswline(struct swline *tmplist) |
99 |
|
|
{ |
100 |
|
|
struct swline *tmplist2; |
101 |
|
|
|
102 |
|
|
while (tmplist) { |
103 |
|
|
tmplist2 = tmplist->next; |
104 |
|
|
efree(tmplist->line); |
105 |
|
|
efree(tmplist); |
106 |
|
|
tmplist = tmplist2; |
107 |
|
|
} |
108 |
|
|
} |
109 |
|
|
|
110 |
|
|
|
111 |
|
|
void freeindexfile(IndexFILE *tmplist) |
112 |
|
|
{ |
113 |
|
|
IndexFILE *tmplist2; |
114 |
|
|
|
115 |
|
|
while (tmplist) { |
116 |
|
|
tmplist2 = tmplist->next; |
117 |
|
|
efree(tmplist->line); |
118 |
|
|
efree(tmplist); |
119 |
|
|
tmplist = tmplist2; |
120 |
|
|
} |
121 |
|
|
} |
122 |
|
|
|
123 |
|
|
|
124 |
|
|
void init_header(INDEXDATAHEADER *header) |
125 |
|
|
{ |
126 |
|
|
|
127 |
|
|
header->lenwordchars=header->lenbeginchars=header->lenendchars=header->lenignorelastchar=header->lenignorefirstchar=header->lenbumpposchars=MAXCHARDEFINED; |
128 |
|
|
|
129 |
|
|
header->wordchars = (char *)emalloc(header->lenwordchars + 1); |
130 |
|
|
header->wordchars = SafeStrCopy(header->wordchars,WORDCHARS,&header->lenwordchars); |
131 |
|
|
sortstring(header->wordchars); /* Sort chars and remove dups */ |
132 |
|
|
makelookuptable(header->wordchars,header->wordcharslookuptable); |
133 |
|
|
|
134 |
|
|
header->beginchars = (char *)emalloc(header->lenbeginchars + 1); |
135 |
|
|
header->beginchars = SafeStrCopy(header->beginchars,BEGINCHARS,&header->lenbeginchars); |
136 |
|
|
sortstring(header->beginchars); /* Sort chars and remove dups */ |
137 |
|
|
makelookuptable(header->beginchars,header->begincharslookuptable); |
138 |
|
|
|
139 |
|
|
header->endchars = (char *)emalloc(header->lenendchars + 1); |
140 |
|
|
header->endchars = SafeStrCopy(header->endchars,ENDCHARS,&header->lenendchars); |
141 |
|
|
sortstring(header->endchars); /* Sort chars and remove dups */ |
142 |
|
|
makelookuptable(header->endchars,header->endcharslookuptable); |
143 |
|
|
|
144 |
|
|
header->ignorelastchar = (char *)emalloc(header->lenignorelastchar + 1); |
145 |
|
|
header->ignorelastchar = SafeStrCopy(header->ignorelastchar,IGNORELASTCHAR,&header->lenignorelastchar); |
146 |
|
|
sortstring(header->ignorelastchar); /* Sort chars and remove dups */ |
147 |
|
|
makelookuptable(header->ignorelastchar,header->ignorelastcharlookuptable); |
148 |
|
|
|
149 |
|
|
header->ignorefirstchar = (char *)emalloc(header->lenignorefirstchar + 1); |
150 |
|
|
header->ignorefirstchar = SafeStrCopy(header->ignorefirstchar,IGNOREFIRSTCHAR,&header->lenignorefirstchar); |
151 |
|
|
sortstring(header->ignorefirstchar); /* Sort chars and remove dups */ |
152 |
|
|
makelookuptable(header->ignorefirstchar,header->ignorefirstcharlookuptable); |
153 |
|
|
|
154 |
|
|
|
155 |
|
|
header->bumpposchars = (char *)emalloc(header->lenbumpposchars + 1); |
156 |
|
|
header->bumpposchars[0]='\0'; |
157 |
|
|
|
158 |
|
|
header->lenindexedon=header->lensavedasheader=header->lenindexn=header->lenindexd=header->lenindexp=header->lenindexa=MAXSTRLEN; |
159 |
|
|
header->indexn = (char *)emalloc(header->lenindexn + 1);header->indexn[0]='\0'; |
160 |
|
|
header->indexd = (char *)emalloc(header->lenindexd + 1);header->indexd[0]='\0'; |
161 |
|
|
header->indexp = (char *)emalloc(header->lenindexp + 1);header->indexp[0]='\0'; |
162 |
|
|
header->indexa = (char *)emalloc(header->lenindexa + 1);header->indexa[0]='\0'; |
163 |
|
|
header->savedasheader = (char *)emalloc(header->lensavedasheader + 1);header->savedasheader[0]='\0'; |
164 |
|
|
header->indexedon = (char *)emalloc(header->lenindexedon + 1);header->indexedon[0]='\0'; |
165 |
|
|
|
166 |
|
|
header->ignoreTotalWordCountWhenRanking = 1; |
167 |
|
|
header->minwordlimit = MINWORDLIMIT; |
168 |
|
|
header->maxwordlimit = MAXWORDLIMIT; |
169 |
|
|
|
170 |
|
|
makelookuptable("",header->bumpposcharslookuptable); |
171 |
|
|
|
172 |
|
|
BuildTranslateChars(header->translatecharslookuptable,(unsigned char *)"",(unsigned char *)""); |
173 |
|
|
|
174 |
|
|
|
175 |
|
|
/* this is to ignore numbers */ |
176 |
|
|
header->numberchars_used_flag = 0; /* not used by default*/ |
177 |
|
|
} |
178 |
|
|
|
179 |
|
|
|
180 |
|
|
void free_header(INDEXDATAHEADER *header) |
181 |
|
|
{ |
182 |
|
|
if(header->lenwordchars) efree(header->wordchars); |
183 |
|
|
if(header->lenbeginchars) efree(header->beginchars); |
184 |
|
|
if(header->lenendchars) efree(header->endchars); |
185 |
|
|
if(header->lenignorefirstchar) efree(header->ignorefirstchar); |
186 |
|
|
if(header->lenignorelastchar) efree(header->ignorelastchar); |
187 |
|
|
if(header->lenindexn) efree(header->indexn); |
188 |
|
|
if(header->lenindexa) efree(header->indexa); |
189 |
|
|
if(header->lenindexp) efree(header->indexp); |
190 |
|
|
if(header->lenindexd) efree(header->indexd); |
191 |
|
|
if(header->lenindexedon) efree(header->indexedon); |
192 |
|
|
if(header->lensavedasheader) efree(header->savedasheader); |
193 |
|
|
if(header->lenbumpposchars) efree(header->bumpposchars); |
194 |
|
|
|
195 |
|
|
|
196 |
|
|
/* ??? temporary until metas and props are seperated */ |
197 |
|
|
if ( header->propIDX_to_metaID ) |
198 |
|
|
efree( header->propIDX_to_metaID ); |
199 |
|
|
|
200 |
|
|
if ( header->metaID_to_PropIDX ) |
201 |
|
|
efree( header->metaID_to_PropIDX ); |
202 |
|
|
|
203 |
|
|
#ifndef USE_BTREE |
204 |
|
|
if ( header->TotalWordsPerFile ) |
205 |
|
|
efree( header->TotalWordsPerFile ); |
206 |
|
|
#endif |
207 |
|
|
|
208 |
|
|
} |
209 |
|
|
|
210 |
|
|
|
211 |
|
|
/* 2001/04Jose Ruiz |
212 |
|
|
Splits a swline struct by char c */ |
213 |
|
|
void splitswline(struct swline *rp, int c) |
214 |
|
|
{ |
215 |
|
|
struct swline *temp; |
216 |
|
|
char *p; |
217 |
|
|
for(p=rp->line;(p=strrchr(rp->line,c));) |
218 |
|
|
{ |
219 |
|
|
*p='\0'; |
220 |
|
|
p++; |
221 |
|
|
if(*p) |
222 |
|
|
{ |
223 |
|
|
temp=(struct swline *)emalloc(sizeof(struct swline)); |
224 |
|
|
temp->next=rp->next; |
225 |
|
|
temp->line=(char *)estrdup(p); |
226 |
|
|
rp->next=temp; |
227 |
|
|
} |
228 |
|
|
} |
229 |
|
|
} |
230 |
|
|
|