#include #include #include #include #include "database.h" void lowercase(char* string) { int index; for (index = 0; string[index] = tolower(string[index]); index++); } void main(int argc, char* argv[]) { word_record* master_wordlist; word_record* next_wordlist; int master_wordcount, index, argument; char* file_name; FileID fileID; if (argc < 3) { fprintf(stderr, "\tSyntax: %s [ ]+\n", argv[0]); exit(1); } if (open_database(argv[1], database_read) == 0) { fprintf(stderr, "\tUnable to open database %s\n", argv[1]); exit(1); } lowercase(argv[2]); master_wordcount = lookup_word(argv[2], &master_wordlist); for (argument = 3; argument < argc; argument++) { word_record* temp_wordlist; int wordcount, temp_wordlist_size = 0; int i, j; lowercase(argv[argument]); wordcount = lookup_word(argv[argument], &next_wordlist);; temp_wordlist = (word_record*)malloc( (master_wordcount < wordcount ? master_wordcount : wordcount) * sizeof(word_record)); for (i = 0; i < master_wordcount; i++) { for (j = 0; j < wordcount; j++) { if (master_wordlist[i].file == next_wordlist[j].file) { int newscore; temp_wordlist[temp_wordlist_size] = master_wordlist[i]; newscore = (master_wordlist[i].score + next_wordlist[j].score)/2; temp_wordlist[temp_wordlist_size].score = newscore; temp_wordlist_size++; } } } free(next_wordlist); free(master_wordlist); master_wordlist = temp_wordlist; master_wordcount = temp_wordlist_size; } printf("MATCHES: %i\n", master_wordcount); for (index=0; index