|
|
|
@ -4,6 +4,8 @@
@@ -4,6 +4,8 @@
|
|
|
|
|
#include <ctype.h> |
|
|
|
|
#include <stdbool.h> |
|
|
|
|
|
|
|
|
|
#define DICTFILE "/usr/share/dict/banawords" |
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Copyright 2020 Alistair Michael |
|
|
|
|
*
|
|
|
|
@ -60,10 +62,23 @@ int *count_char(char *word) {
@@ -60,10 +62,23 @@ int *count_char(char *word) {
|
|
|
|
|
} |
|
|
|
|
return counts; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
FILE *open_dict_file(char *filename) { |
|
|
|
|
FILE *wfile = fopen(filename, "r"); |
|
|
|
|
|
|
|
|
|
if (!wfile) { |
|
|
|
|
fprintf(stderr, "Unable to open dict\n"); |
|
|
|
|
exit(1); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return wfile; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// @param allowed: additional characters allowed in anagram match,
|
|
|
|
|
// set to NULL to allow matching any set of characters.
|
|
|
|
|
int get_minimum_match(char *word, int added, char *allowed) { |
|
|
|
|
FILE *wfile = fopen("words", "r"); |
|
|
|
|
FILE* wfile = open_dict_file(DICTFILE); |
|
|
|
|
|
|
|
|
|
char line[LINELENGTH]; |
|
|
|
|
int err; |
|
|
|
|
int len = strlen(word); |
|
|
|
@ -97,6 +112,10 @@ int get_minimum_match(char *word, int added, char *allowed) {
@@ -97,6 +112,10 @@ int get_minimum_match(char *word, int added, char *allowed) {
|
|
|
|
|
|
|
|
|
|
if (allowed) { |
|
|
|
|
max_letter_counts = count_char(allowed); |
|
|
|
|
if (!max_letter_counts) { |
|
|
|
|
return 1; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
for (int i = 0; i < 26; i++) { |
|
|
|
|
max_letter_counts[i] += orig_word_letter_counts[i]; |
|
|
|
|
} |
|
|
|
@ -150,9 +169,11 @@ int get_minimum_match(char *word, int added, char *allowed) {
@@ -150,9 +169,11 @@ int get_minimum_match(char *word, int added, char *allowed) {
|
|
|
|
|
return 0; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int get_exact_anag(char *word) { |
|
|
|
|
FILE *wfile = fopen("words", "r"); |
|
|
|
|
|
|
|
|
|
make_lowercase(word); |
|
|
|
|
FILE* wfile = open_dict_file(DICTFILE); |
|
|
|
|
|
|
|
|
|
char line[LINELENGTH]; |
|
|
|
|
int err; |
|
|
|
|