for (i = 0; i < words->maxnbwords; i++) {
if (words->status[i] != none) {
if (mode) {
- set_color ((words->status[i] == correct) ? wgreen : wred);
+ switch (words->status[i]) {
+ case correct:
+ set_color (wgreen);
+ break;
+ case incorrect:
+ set_color (wred);
+ break;
+ default:
+ set_color (white);
+ break;
+ }
mvaddstr (yoffset + 2 + n, xoffset, words->tab[i]);
set_color (white);
} else {
free (words);
}
-spelling_e _checkdict (char *word, char *dict)
-{
- spelling_e ret = incorrect;
- FILE *fd = fopen (dict, "r");
- if (fd) {
- while (!feof (fd)) {
- char str[128] = {0};
- fscanf (fd, "%s", str);
- if (strcmp (word, str) == 0) {
- ret = correct;
- break;
- }
- }
- fclose (fd);
- } else {
- ret = correct;
- }
- return ret;
-}
-
-void checkspelling (word_t *words, play_t *play, play_t *turn, char *dict)
+void findwords (word_t *words, play_t *play, play_t *turn)
{
int i, j;
if (((letter == ' ') || (i == play->xsize - 1)) && (accountable)) {
if (nbletters > 1) {
words->tab[n][nbletters] = '\0';
- words->status[n] = _checkdict (words->tab[n], dict);
+ words->status[n] = notchecked;
}
n++;
}
if (((letter == ' ') || (i == play->xsize - 1)) && (accountable)) {
if (nbletters > 1) {
words->tab[n][nbletters] = '\0';
- words->status[n] = _checkdict (words->tab[n], dict);
+ words->status[n] = notchecked;
}
n++;
}
}
}
+void checkspelling (word_t *words, char *dict)
+{
+ int i = 0;
+ FILE *fd = fopen (dict, "r");
+ if (fd) {
+ char str[128] = {0};
+ while (fscanf (fd, "%s", str) > 0) {
+ int stop = 1;
+ for (i = 0; i < words->maxnbwords; i++) {
+ if (words->status[i] == notchecked) {
+ if (strcmp (words->tab[i], str) == 0) {
+ words->status[i] = correct;
+ } else {
+ stop = 0;
+ }
+ }
+ }
+ if (stop) {
+ break;
+ }
+ }
+ fclose (fd);
+ for (i = 0; i < words->maxnbwords; i++) {
+ if (words->status[i] == notchecked) {
+ words->status[i] = incorrect;
+ }
+ }
+ }
+}
+
/* vim: set ts=4 sw=4 et: */
void freeword (word_t *words);
-void checkspelling (word_t *words, play_t *play, play_t *turn, char *dict);
+void findwords (word_t *words, play_t *play, play_t *turn);
+
+void checkspelling (word_t *words, char *dict);
#endif /* __FUNCTION_H__ */
valuewindow (bag, xvaluewin, yvaluewin, 10, highlight);
scorewindow (nbpoints, xscorewin, yscorewin);
- checkspelling (words, play, turn[n], dict);
+ findwords (words, play, turn[n]);
+ checkspelling (words, dict);
spellwindow (words, xspellwin, yspellwin, 1);
int ch = getch ();
spellwindow (words, xspellwin, yspellwin, 0);