~ubuntu-branches/ubuntu/warty/swish-e/warty

« back to all changes in this revision

Viewing changes to src/check.c

  • Committer: Bazaar Package Importer
  • Author(s): Ludovic Drolez
  • Date: 2004-03-11 08:41:07 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20040311084107-7vp0mu82blq1qjvo
Tags: 2.4.1-3
Oops ! A comment was not removed to disable interactive compilation.
Closes: Bug#237332

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
**
19
19
** fixed non-int subscripting pointed out by "gcc -Wall"
20
20
** SRE 2/22/00
 
21
**
 
22
** 2001-03-08 rasc   rewritten and enhanced suffix routines
 
23
**
21
24
*/
22
25
 
23
26
#include "swish.h"
24
27
#include "check.h"
25
28
#include "hash.h"
26
 
#include "string.h"
 
29
#include "swstring.h"
27
30
#include "mem.h"
28
31
 
29
32
/* Check if a file with a particular suffix should be indexed
36
39
** please let me know...
37
40
*/
38
41
 
39
 
int isokword(word)
40
 
      char *word;
41
 
{
42
 
        int i, same, hasnumber, hasvowel, hascons,
43
 
                numberrow, vowelrow, consrow, wordlen;
44
 
        char lastchar;
45
 
        
46
 
        if (word[0] == '\0')
47
 
                return 0;
48
 
        
49
 
        if (isstopword(word))
50
 
                return 0;
51
 
        wordlen = strlen(word);
52
 
        if ((wordlen < minwordlimit) || (wordlen > maxwordlimit))
53
 
                return 0;
54
 
        
55
 
        lastchar = '\0';
56
 
        same = 0;
57
 
        hasnumber = hasvowel = hascons = 0;
58
 
        numberrow = vowelrow = consrow = 0;
59
 
        for (i = 0; word[i] != '\0'; i++) {
60
 
                if (word[i] == lastchar) {
61
 
                        same++;
62
 
                        if (same > IGNORESAME)
63
 
                                return 0;
64
 
                }
65
 
                else
66
 
                        same = 0;
67
 
                if (isdigit((int)word[i])) {
68
 
                        hasnumber = 1;
69
 
                        numberrow++;
70
 
                        if (numberrow > IGNOREROWN)
71
 
                                return 0;
72
 
                        vowelrow = 0;
73
 
                        consrow = 0;
74
 
                }
75
 
                else if (isvowel(word[i])) {
76
 
                        hasvowel = 1;
77
 
                        vowelrow++;
78
 
                        if (vowelrow > IGNOREROWV)
79
 
                                return 0;
80
 
                        numberrow = 0;
81
 
                        consrow = 0;
82
 
                }
83
 
                else if (!ispunct((int)word[i])) {
84
 
                        hascons = 1;
85
 
                        consrow++;
86
 
                        if (consrow > IGNOREROWC)
87
 
                                return 0;
88
 
                        numberrow = 0;
89
 
                        vowelrow = 0;
90
 
                }
91
 
                lastchar = word[i];
92
 
        }
93
 
        
94
 
        if (IGNOREALLV)
95
 
                if (hasvowel && !hascons)
96
 
                return 0;
97
 
        if (IGNOREALLC)
98
 
                if (hascons && !hasvowel)
99
 
                return 0;
100
 
        if (IGNOREALLN)
101
 
                if (hasnumber && !hasvowel && !hascons)
102
 
                return 0;
103
 
        
104
 
        return 1;
105
 
}
106
 
 
107
 
/* Does a word have valid characters?
108
 
*/
109
 
 
110
 
int hasokchars(word)
111
 
     char *word;
112
 
{
113
 
        int i;
114
 
        /* Jose Ruiz 06/00
115
 
        ** Obsolete. Let's use the lookuptable
116
 
        int i, j;
117
 
        char c;
118
 
        c = word[strlen(word) - 1];
119
 
        for (i = j = 0; beginchars[i] != '\0'; i++)
120
 
                if (word[0] == beginchars[i])
121
 
                j++;
122
 
        if (!j)
123
 
                return 0;
124
 
        */
125
 
        if(!begincharslookuptable[(int)((unsigned char)word[0])]) return 0;
126
 
 
127
 
        /* Jose Ruiz 06/00
128
 
        ** Obsolete. Let's use the lookuptable
129
 
        for (i = j = 0; endchars[i] != '\0'; i++)
130
 
                if (c == endchars[i])
131
 
                j++;
132
 
        if (!j)
133
 
                return 0;
134
 
        */
135
 
        if(!endcharslookuptable[(int)((unsigned char)word[strlen(word)-1])]) return 0;
136
 
 
137
 
        /* Jose Ruiz 06/00
138
 
        ** Obsolete. Let's use the lookuptable
139
 
        for (i = 0; word[i] != '\0'; i++)
140
 
                for (j = 0; wordchars[j] != '\0'; j++)
141
 
                if (word[i] == wordchars[j])
142
 
                return 1;
143
 
        */
144
 
        for (i = 0; word[i] != '\0'; i++)
145
 
                if(iswordchar(word[i]))
146
 
                return 1;
147
 
 
148
 
        return 0;
149
 
}
150
 
 
151
 
/* Is a letter a vowel?
152
 
*/
153
 
/* Obsolete - Now is a macro that uses a lookuptable  
154
 
int isvowel(char c)
155
 
{
156
 
        if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u' ||
157
 
            c == 'A' || c == 'E' || c == 'I' || c == 'O' || c == 'U')
158
 
          return 1;
159
 
        return 0;
160
 
}
161
 
*/
 
42
int     isokword(sw, word, indexf)
 
43
     SWISH  *sw;
 
44
     char   *word;
 
45
     IndexFILE *indexf;
 
46
{
 
47
    int     i,
 
48
            same,
 
49
            hasnumber,
 
50
            hasvowel,
 
51
            hascons,
 
52
            numberrow,
 
53
            vowelrow,
 
54
            consrow,
 
55
            wordlen;
 
56
    char    lastchar;
 
57
 
 
58
    if (word[0] == '\0')
 
59
        return 0;
 
60
 
 
61
    if ( is_word_in_hash_table( indexf->header.hashstoplist, word ) )
 
62
        return 0;
 
63
 
 
64
    wordlen = strlen(word);
 
65
    if ((wordlen < indexf->header.minwordlimit) || (wordlen > indexf->header.maxwordlimit))
 
66
        return 0;
 
67
 
 
68
    lastchar = '\0';
 
69
    same = 0;
 
70
    hasnumber = hasvowel = hascons = 0;
 
71
    numberrow = vowelrow = consrow = 0;
 
72
 
 
73
    for (i = 0; word[i] != '\0'; i++)
 
74
    {
 
75
        /* Max number of times a char can repeat in a word */
 
76
        if (word[i] == lastchar)
 
77
        {
 
78
            same++;
 
79
            if (same > IGNORESAME)
 
80
                return 0;
 
81
        }
 
82
        else
 
83
            same = 0;
 
84
 
 
85
        /* Max number of consecutive digits */
 
86
        if (isdigit((int) ( (unsigned char) word[i])))
 
87
        {
 
88
            hasnumber = 1;
 
89
            numberrow++;
 
90
            if (numberrow > IGNOREROWN)
 
91
                return 0;
 
92
            vowelrow = 0;
 
93
            consrow = 0;
 
94
        }
 
95
 
 
96
        /* maximum number of consecutive vowels a word can have */
 
97
        else if (isvowel(sw, word[i]))
 
98
        {
 
99
            hasvowel = 1;
 
100
            vowelrow++;
 
101
            if (vowelrow > IGNOREROWV)
 
102
                return 0;
 
103
            numberrow = 0;
 
104
            consrow = 0;
 
105
        }
 
106
 
 
107
        /* maximum number of consecutive consonants a word can have */
 
108
        else if (!ispunct((int) ( (unsigned char) word[i])))
 
109
        {
 
110
            hascons = 1;
 
111
            consrow++;
 
112
            if (consrow > IGNOREROWC)
 
113
                return 0;
 
114
            numberrow = 0;
 
115
            vowelrow = 0;
 
116
        }
 
117
        lastchar = word[i];
 
118
    }
 
119
 
 
120
    /* If IGNOREALLV is 1, words containing all vowels won't be indexed. */
 
121
    if (IGNOREALLV)
 
122
        if (hasvowel && !hascons)
 
123
            return 0;
 
124
 
 
125
    /* If IGNOREALLC is 1, words containing all consonants won't be indexed */
 
126
    if (IGNOREALLC)
 
127
        if (hascons && !hasvowel)
 
128
            return 0;
 
129
 
 
130
    /* If IGNOREALLN is 1, words containing all digits won't be indexed */
 
131
    if (IGNOREALLN)
 
132
        if (hasnumber && !hasvowel && !hascons)
 
133
            return 0;
 
134
 
 
135
    return 1;
 
136
}
162
137
 
163
138
 
164
139
/*
165
 
 -- Check, if a filter is needed to retrieve information from a file
166
 
 -- Returns NULL or path to filter prog according conf file.
167
 
 -- 1999-08-07 rasc
 
140
  -- Determine document type by checking the file extension
 
141
  -- of the filename
 
142
  -- Return: doctype
 
143
  -- 2001-03-08 rasc   rewritten (optimize and match also
 
144
  --                   e.g. ".htm", ".htm.de" or ".html.gz")
168
145
*/
169
146
 
170
 
char *hasfilter (char *filename, struct filter *filterlist)
171
 
 
172
 
{
173
 
   struct filter *fl;
174
 
   char *c, *checksuffix;
175
 
   int  lchecksuffix;
176
 
 
177
 
 
178
 
   fl = filterlist;
179
 
 
180
 
   if (! fl) return (char *)NULL;;
181
 
   if (! (c = (char *)strrchr(filename, '.')) ) return (char *) NULL;
182
 
   
183
 
   lchecksuffix = strlen(c);
184
 
   checksuffix=(char *) emalloc(lchecksuffix + 1);
185
 
   strcpy(checksuffix, c);
186
 
 
187
 
   while (fl != NULL) {
188
 
        if (lstrstr(fl->suffix, checksuffix)
189
 
            && strlen(fl->suffix) == lchecksuffix) {
190
 
                efree(checksuffix);
191
 
                return fl->prog;
192
 
        }
193
 
        fl = fl->next;
194
 
   }
195
 
 
196
 
   efree(checksuffix);
197
 
   return (char *)NULL;
198
 
}
199
 
 
200
 
 
 
147
int     getdoctype(char *filename, struct IndexContents *indexcontents)
 
148
{
 
149
    struct swline *swl;
 
150
    char   *s,
 
151
           *fe;
 
152
 
 
153
 
 
154
    if (!indexcontents)
 
155
        return NODOCTYPE;
 
156
 
 
157
    /* basically do a right to left compare */
 
158
    fe = (filename + strlen(filename));
 
159
    while (indexcontents)
 
160
    {
 
161
        swl = indexcontents->patt;
 
162
 
 
163
        while (swl)
 
164
        {
 
165
            s = fe - strlen(swl->line);
 
166
            if (s >= filename)
 
167
            {                   /* no negative overflow! */
 
168
                if (!strcasecmp(swl->line, s))
 
169
                {
 
170
                    return indexcontents->DocType;;
 
171
                }
 
172
            }
 
173
            swl = swl->next;
 
174
        }
 
175
 
 
176
        indexcontents = indexcontents->next;
 
177
    }
 
178
 
 
179
    return NODOCTYPE;
 
180
}
 
181
 
 
182
 
 
183
 
 
184
 
 
185
 
 
186
struct StoreDescription *hasdescription(int doctype, struct StoreDescription *sd)
 
187
{
 
188
    while (sd)
 
189
    {
 
190
        if (sd->DocType == doctype)
 
191
            return sd;
 
192
        sd = sd->next;
 
193
    }
 
194
    return NULL;
 
195
}