/***************************************************************************
 *                                                                         *
 *   Zabit: Content and attachment filter for qmail.                       *
 *   Version 0.7.1                                                         *
 *   http://www.enderunix.org/zabit                                        *
 *                                                                         *
 *   Copyright (C) 2004 by N.Ersen SISECI                                  *
 *   siseci@enderunix.org                                                  *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/

#include <stdio.h>
#include <string.h>

#include "zabit.h"

extern int searchbinary;

void readwordfile(char *wordfile)
{
	FILE *block;
	int i;
	char inpbuf[WORDSIZE];
	char *p2;
	char *p1;

	if (strlen(wordfile) > MAXFILENAMELEN - 1) {
		printf("Error: %s\n", wordfile);
		exit(ERRORTMP);
	}

	if ((block = fopen(wordfile, "r")) == NULL) {
		printf("Can't open word file: %s\n", WORD_LIST);
		exit(ERRORTMP);
	}

	i = 0;

	wordlist = (badwordlist *) calloc(sizeof(badwordlist), WORDLISTSIZE);

	while (!feof(block)) {
		fgets(inpbuf, WORDSIZE - 1, block);
		if (strlen(inpbuf) > 1)
			inpbuf[strlen(inpbuf) - 1] = '\0';
		if ((inpbuf[0] != '#') && (strlen(inpbuf) >= 5)) {
			p1 = (char *)strtok(inpbuf, "=");
			snprintf(wordlist[i].word, WORDSIZE - 1, "%s", p1);
			p2 = (char *)strtok(NULL, "=");
			if (p2 == NULL)
				wordlist[i++].count = 1;
			else
				wordlist[i++].count = abs(atoi(p2));
		}
		if (i > WORDLISTSIZE - 1) {
                        fprintf(stderr, "too many words, last processed line:\n%s\n", inpbuf);
                        break;
                }
	}
	fclose(block);
	entrycount = i;
	wordlist = (badwordlist *) realloc(wordlist, i * sizeof(badwordlist));
}


syntax highlighted by Code2HTML, v. 0.9.1