Browse Source

dictionary file location

master
alistair 4 years ago
parent
commit
2dab9d5895
  1. 1
      Makefile
  2. 25
      main.c

1
Makefile

@ -8,6 +8,7 @@ debug: main.c
install: default install: default
cp banagram /usr/bin/banagram cp banagram /usr/bin/banagram
cp -n words /usr/share/dict/banawords
uninstall: uninstall:
rm /usr/bin/banagram rm /usr/bin/banagram

25
main.c

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

Loading…
Cancel
Save