File: check.c

package info (click to toggle)
swish-e 1.1-1
  • links: PTS
  • area: main
  • in suites: hamm, potato, slink
  • size: 380 kB
  • ctags: 340
  • sloc: ansic: 4,540; makefile: 77; sh: 12
file content (206 lines) | stat: -rwxr-xr-x 4,206 bytes parent folder | download | duplicates (2)
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
/*
** Copyright (C) 1995, Enterprise Integration Technologies Corp.        
** All Rights Reserved.
** Kevin Hughes, kevinh@eit.com 
** 3/11/94
*/

#include "swish.h"
#include "check.h"

/* Check if a file with a particular suffix should be indexed
** according to the settings in the configuration file.
*/

int isoksuffix(filename, rulelist)
     char *filename;
     struct swline *rulelist;
{
	int badfile;
	char *c, suffix[MAXSUFFIXLEN], checksuffix[MAXSUFFIXLEN];
	struct swline *tmplist;

	tmplist = rulelist;
        if (tmplist == NULL)
                return 1;
	if ((c = (char *) strrchr(filename, '.')) == NULL)
		return 0;

	badfile = 1;
	strcpy(checksuffix, c + 1);
        while (tmplist != NULL) {
		if ((c = (char *) strrchr(tmplist->line, '.')) == NULL)
			strcpy(suffix, tmplist->line);
		else
			strcpy(suffix, c + 1);
                if (lstrstr(suffix, checksuffix) && strlen(suffix) ==
		strlen(checksuffix))
                        badfile = 0;
                tmplist = tmplist->next;
        }
	return !(badfile);
}

/* Check if a particular title should be ignored
** according to the settings in the configuration file.
*/

int isoktitle(title)
     char *title;
{
        int badfile;
        struct swline *tmplist;

        badfile = 0;
        tmplist = titconlist;
        while (tmplist != NULL) {
                if (lstrstr(title, tmplist->line)) {
                        badfile = 1;
                        break;
                }
                tmplist = tmplist->next;
        }
        if (badfile)
                return 0;
        else
                return 1;
}

/* Should a word be indexed? Consults the stopword hash list
** and checks if the word is of a reasonable length...
** If you have any good rules that can work with most languages,
** please let me know...
*/

int isokword(word)
      char *word;
{
        int i, same, hasnumber, hasvowel, hascons,
		numberrow, vowelrow, consrow;
	char lastchar;

	if (word[0] == '\0')
		return 0;

        if (isstopword(word))
                return 0;
        if (strlen(word) < MINWORDLIMIT || strlen(word) > MAXWORDLIMIT)
                return 0;

	lastchar = ':';
	same = 0;
	hasnumber = hasvowel = hascons = 0;
	numberrow = vowelrow = consrow = 0;
	for (i = 0; word[i] != '\0'; i++) {
		if (word[i] == lastchar) {
			same++;
			if (same > IGNORESAME)
				return 0;
		}
		else
			same = 0;
		if (isdigit(word[i])) {
			hasnumber = 1;
			numberrow++;
			if (numberrow > IGNOREROWN)
				return 0;
			vowelrow = 0;
			consrow = 0;
		}
		else if (isvowel(word[i])) {
			hasvowel = 1;
			vowelrow++;
			if (vowelrow > IGNOREROWV)
				return 0;
			numberrow = 0;
			consrow = 0;
		}
		else if (!ispunct(word[i])) {
			hascons = 1;
			consrow++;
			if (consrow > IGNOREROWC)
				return 0;
			numberrow = 0;
			vowelrow = 0;
		}
		lastchar = word[i];
	}

	if (IGNOREALLV)
		if (hasvowel && !hascons)
			return 0;
	if (IGNOREALLC)
		if (hascons && !hasvowel)
			return 0;
	if (IGNOREALLN)
		if (hasnumber && !hasvowel && !hascons)
			return 0;

	return 1;
}

/* Does a word have valid characters?
*/

int hasokchars(word)
     char *word;
{
	int i, j;
	char c;

	c = word[strlen(word) - 1];
	for (i = j = 0; BEGINCHARS[i] != '\0'; i++)
		if (word[0] == BEGINCHARS[i])
			j++;
	if (!j)
		return 0;
	for (i = j = 0; ENDCHARS[i] != '\0'; i++)
		if (c == ENDCHARS[i])
			j++;
	if (!j)
		return 0;
	for (i = 0; word[i] != '\0'; i++)
		for (j = 0; WORDCHARS[j] != '\0'; j++)
			if (word[i] == WORDCHARS[j])
				return 1;
	return 0;
}

/* Is a letter a vowel?
*/

int isvowel(c)
     char c;
{
	if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u')
		return 1;
	return 0;
}

/* This checks is a filename has one of the following suffixes:
** "htm", "HTM", "html", "HTML", "shtml", "SHTML".
*/

int ishtml(filename)
     char *filename;
{
	char *c, suffix[MAXSUFFIXLEN];

	c = (char *) strrchr(filename, '.');

	if (c == NULL)
		return 0;
	strcpy(suffix, c + 1);
	if (suffix[0] == '\0')
		return 0;

	if (!strncmp(suffix, "htm", 3))
		return 1;
	else if (!strncmp(suffix, "HTM", 3))
		return 1;
	else if (!strncmp(suffix, "shtml", 5))
		return 1;
	else if (!strncmp(suffix, "SHTML", 5))
		return 1;
	return 0;
}