2 * Copyright © 2006 Carl Worth
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2, or (at your option)
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software Foundation,
16 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA."
27 #include <sys/types.h>
35 #include <readline/readline.h>
36 #include <readline/history.h>
38 #define ASSERT_NOT_REACHED \
40 static const int NOT_REACHED = 0; \
41 assert (NOT_REACHED); \
46 typedef struct _item {
60 CATEGORY_ORDER_RANDOM,
61 CATEGORY_ORDER_SEQUENTIAL
70 typedef struct _category {
76 /* Support sequential introduction of items from bin 0 */
77 category_order_t order;
78 /* Support categories where responses are timed (0.0 == disable). */
81 /* Support challenges of non-text types (image, audio, etc.) */
82 challenge_type_t challenge_type;
85 typedef struct _mnemon {
90 category_t *categories;
103 xmalloc (size_t size)
109 fprintf (stderr, "Error: out of memory\n");
117 xrealloc (void *ptr, size_t size)
121 ret = realloc (ptr, size);
123 fprintf (stderr, "Error: out of memory\n");
131 xstrdup (const char *s)
137 fprintf (stderr, "Error: out of memory\n");
145 xstrndup (const char *s, size_t n)
149 ret = strndup (s, n);
151 fprintf (stderr, "Error: out of memory\n");
159 xasprintf (char **strp, const char *fmt, ...)
165 ret = vasprintf (strp, fmt, ap);
169 fprintf (stderr, "Error: out of memory\n");
175 item_init (item_t *item,
177 const char *challenge,
178 const char *response)
182 item->challenge = xmalloc (strlen (challenge) + 1 +
183 strlen (response) + 1);
184 item->response = item->challenge + strlen (challenge) + 1;
186 strcpy (item->challenge, challenge);
187 strcpy (item->response, response);
191 item_fini (item_t *item)
193 /* item->response shares allocation with item->challenge, so
194 * doesn't require a separate call to free */
195 free (item->challenge);
199 category_init (category_t *category,
202 category->name = xstrdup (name);
204 category->items_size = 0;
205 category->num_items = 0;
206 category->items = NULL;
207 category->order = CATEGORY_ORDER_RANDOM;
208 category->time_limit = 0.0;
209 category->bin_zero_head = 0;
210 category->challenge_type = CHALLENGE_TYPE_TEXT;
214 category_fini (category_t *category)
218 for (i = 0; i < category->num_items; i++)
219 item_fini (&category->items[i]);
221 free (category->items);
223 free (category->name);
227 category_grow (category_t *category)
229 if (category->items_size)
230 category->items_size *= 2;
232 category->items_size = 1;
234 category->items = xrealloc (category->items,
235 category->items_size * sizeof (item_t));
239 category_add_item (category_t *category,
241 const char *challenge,
242 const char *response)
246 if (category->num_items == category->items_size)
247 category_grow (category);
249 item = &category->items[category->num_items++];
251 item_init (item, score, challenge, response);
257 category_next_bin_zero_item (category_t *category)
259 int *i = &category->bin_zero_head;
261 for ( ; *i < category->num_items; *i = *i + 1)
262 if (category->items[*i].score == 0)
263 return &category->items[*i];
269 category_print (category_t *category,
275 fprintf (file, "order = %s\n\n",
276 category->order == CATEGORY_ORDER_RANDOM ? "random" : "sequential");
277 fprintf (file, "time = %f\n\n",
278 category->time_limit);
280 fprintf (file, "challenge = ");
281 switch (category->challenge_type) {
282 case CHALLENGE_TYPE_TEXT:
283 fprintf (file, "text");
285 case CHALLENGE_TYPE_IMAGE:
286 fprintf (file, "image");
288 case CHALLENGE_TYPE_AUDIO:
289 fprintf (file, "audio");
292 fprintf (file, "\n\n");
294 for (i = 0; i < category->num_items; i++) {
295 item = &category->items[i];
297 fprintf (file, "\n");
298 fprintf (file, "%d\n%s\n%s\n",
306 bin_init (bin_t *bin,
317 bin_fini (bin_t *bin)
323 bin_grow (bin_t *bin)
326 bin->items_size *= 2;
330 bin->items = xrealloc (bin->items,
331 bin->items_size * sizeof (item_t*));
335 bin_add_item (bin_t *bin,
338 assert (item->score == bin->score);
340 if (bin->num_items == bin->items_size)
343 bin->items[bin->num_items++] = item;
347 bin_remove_item (bin_t *bin,
350 /* Replace the current item with the last item, (no need to shift
351 * any more than that since we don't care about the order of the
352 * items within a bin). */
355 bin->items[item_index] = bin->items[bin->num_items];
358 /* Find the index for an item within a bin.
360 * XXX: This is currently a linear search, so is a potential
361 * performance problem.
364 bin_item_index (bin_t *bin,
369 for (i = 0; i < bin->num_items; i++)
370 if (bin->items[i] == item)
376 typedef int (item_match_predicate_t) (void *closure, item_t *item);
378 /* Return the number of items in the bin from the given category (or
379 * from all categories if category == NULL) */
381 bin_num_items_matching (bin_t *bin,
382 item_match_predicate_t *predicate,
385 int i, num_items = 0;
387 if (predicate == NULL)
388 return bin->num_items;
390 for (i = 0; i < bin->num_items; i++)
391 if ((predicate) (closure, bin->items[i]))
398 mnemon_init (mnemon_t *mnemon)
402 home = getenv ("HOME");
406 xasprintf (&mnemon->dir_name, "%s/.mnemon", getenv ("HOME"));
408 mnemon->categories_size = 0;
409 mnemon->num_categories = 0;
410 mnemon->categories = NULL;
412 mnemon->bins_size = 0;
413 mnemon->num_bins = 0;
416 mnemon->to_introduce = 10;
417 mnemon->to_master = 10;
418 mnemon->unlearned = 0;
419 mnemon->mastered = -1;
423 mnemon_fini (mnemon_t *mnemon)
427 for (i = 0; i < mnemon->num_bins; i++)
428 bin_fini (&mnemon->bins[i]);
431 for (i = 0; i < mnemon->num_categories; i++)
432 category_fini (&mnemon->categories[i]);
433 free (mnemon->categories);
435 free (mnemon->dir_name);
439 mnemon_categories_grow (mnemon_t *mnemon)
441 if (mnemon->categories_size)
442 mnemon->categories_size *= 2;
444 mnemon->categories_size = 1;
446 mnemon->categories = xrealloc (mnemon->categories,
447 mnemon->categories_size * sizeof (category_t));
450 /* Get a category by name if it exists */
452 mnemon_get_category_if_exists (mnemon_t *mnemon,
457 for (i = 0; i < mnemon->num_categories; i++)
458 if (strcmp (mnemon->categories[i].name, name) == 0)
459 return &mnemon->categories[i];
464 /* Get a category by name, creating new one if necessary. */
466 mnemon_get_category (mnemon_t *mnemon,
469 category_t *category;
471 category = mnemon_get_category_if_exists (mnemon, name);
475 mnemon_categories_grow (mnemon);
477 category = &mnemon->categories[mnemon->num_categories++];
479 category_init (category, name);
485 mnemon_bins_grow (mnemon_t *mnemon)
487 if (mnemon->bins_size)
488 mnemon->bins_size *= 2;
490 mnemon->bins_size = 1;
492 mnemon->bins = xrealloc (mnemon->bins,
493 mnemon->bins_size * sizeof (bin_t));
497 mnemon_get_bin (mnemon_t *mnemon,
503 for (i = 0; i < mnemon->num_bins; i++)
504 if (mnemon->bins[i].score == score)
505 return &mnemon->bins[i];
506 else if (mnemon->bins[i].score > score)
509 if (mnemon->num_bins == mnemon->bins_size)
510 mnemon_bins_grow (mnemon);
512 bin = &mnemon->bins[i];
514 /* Make room to insert new bin at its sorted location. */
515 if (i < mnemon->num_bins)
516 memmove (bin + 1, bin, (mnemon->num_bins - i) * sizeof (bin_t));
519 bin_init (bin, score);
525 mnemon_remove_bin (mnemon_t *mnemon,
528 int i = bin - mnemon->bins;
532 memmove (bin, bin + 1, (mnemon->num_bins - i) * sizeof (bin_t));
539 int len = strlen (s);
542 if (s[len - 1] == '\n')
547 trim_space (char *string)
552 while (*s && isspace (*s))
557 s = string + strlen (string) - 1;
558 while (s > string && isspace (*s)) {
567 mnemon_load_category (mnemon_t *mnemon,
571 char *line = NULL, *end;
572 size_t line_size = 0;
576 category_t *category;
579 path = xmalloc (strlen (mnemon->dir_name) + 1 + strlen (name) + 1);
580 sprintf (path, "%s/%s", mnemon->dir_name, name);
582 file = fopen (path, "r");
584 fprintf (stderr, "Error: Failed to open %s: %s\n",
585 path, strerror (errno));
589 category = mnemon_get_category (mnemon, name);
591 #define READ_LINE do { \
592 bytes_read = getline (&line, &line_size, file); \
593 if (bytes_read == -1) \
601 char *name, *equal, *value;
603 /* Ignore blank lines */
608 /* An initial digit means we hit an item. Trigger the
609 * spaghetti machine. */
610 if ((*line >= '0' && *line <= '9') || *line == '-')
613 equal = strchr (line, '=');
615 fprintf (stderr, "Malformed option, (expected name=value): \"%s\" at %s:%d\n",
616 line, path, line_count);
624 name = trim_space (name);
625 value = trim_space (value);
627 if (strcmp (name, "order") == 0) {
628 if (strcmp (value, "sequential") == 0) {
629 category->order = CATEGORY_ORDER_SEQUENTIAL;
630 } else if (strcmp (value, "random") == 0) {
631 category->order = CATEGORY_ORDER_RANDOM;
633 fprintf (stderr, "Unknown value for \"order\" option \"%s\" at %s:%d\n",
634 value, path, line_count);
637 } else if (strcmp (name, "time") == 0) {
640 limit = strtod (value, &end);
641 while (isspace (*end))
644 category->time_limit = limit;
646 fprintf (stderr, "Failed to parse time value: %s at %s:%d\n",
647 value, path, line_count);
650 } else if (strcmp (name, "challenge") == 0) {
651 if (strcmp (value, "text") == 0) {
652 category->challenge_type = CHALLENGE_TYPE_TEXT;
653 } else if (strcmp (value, "image") == 0) {
654 category->challenge_type = CHALLENGE_TYPE_IMAGE;
655 } else if (strcmp (value, "audio") == 0) {
656 category->challenge_type = CHALLENGE_TYPE_AUDIO;
658 fprintf (stderr, "Unknown value for \"challenge\" option \"%s\" at %s:%d\n",
659 value, path, line_count);
663 fprintf (stderr, "Unknown option %s at %s:%d\n",
664 name, path, line_count);
672 char *challenge, *response;
674 /* Ignore blank lines */
679 /* Read bin number */
681 score = strtol (line, &end, 10);
683 fprintf (stderr, "Failed to parse bin number from \"%s\" at %s:%d\n",
684 line, path, line_count);
690 challenge = strdup (line);
696 category_add_item (category, score, challenge, response);
706 /* Resize category items to fit exactly. */
707 category->items_size = category->num_items;
708 category->items = xrealloc (category->items, category->items_size * sizeof (item_t));
710 /* Now that the category is completely loaded, with stable
711 * pointers to every item, we can add each item to its appropriate
713 for (i = 0; i < category->num_items; i++) {
714 item_t *item = &category->items[i];
715 bin_t *bin = mnemon_get_bin (mnemon, item->score);
717 bin_add_item (bin, item);
722 mnemon_load (mnemon_t *mnemon)
725 struct dirent *dirent;
727 dir = opendir (mnemon->dir_name);
729 fprintf (stderr, "Error: Failed to open directory %s: %s\n",
730 mnemon->dir_name, strerror (errno));
735 dirent = readdir (dir);
739 if (dirent->d_type == DT_REG) {
740 /* Ignore files matching *~, (yes, this shouldn't be
741 * hard-coded in such an ad-hoc way, but there you go. */
742 if (dirent->d_name[strlen(dirent->d_name)-1] != '~')
743 mnemon_load_category (mnemon, dirent->d_name);
751 mnemon_save (mnemon_t *mnemon)
754 char *filename, *lock_filename;
756 category_t *category;
758 for (i = 0; i < mnemon->num_categories; i++) {
759 category = &mnemon->categories[i];
761 xasprintf (&filename, "%s/%s",
762 mnemon->dir_name, category->name);
763 xasprintf (&lock_filename, "%s/.#%s",
764 mnemon->dir_name, category->name);
766 file = fopen (lock_filename, "w");
768 fprintf (stderr, "Error: Failed to open %s for writing: %s\n",
769 lock_filename, strerror (errno));
773 category_print (category, file);
775 fsync (fileno (file));
778 err = rename (lock_filename, filename);
780 fprintf (stderr, "Error: Failed to rename %s to %s: %s\n",
781 lock_filename, filename, strerror (errno));
786 free (lock_filename);
790 /* Return a uniformly-distributed pseudo-random integer within the
793 * 0 <= result < num_values
796 rand_within (int num_values)
798 return (int) (num_values * (rand() / (RAND_MAX + 1.0)));
801 /* Return an exponentially-distributed pseudo-random integer within
804 * 0 <= result < num_values
806 * The distribution is such that each successively larger value will
807 * occur with a probability of half of the previous value.
810 rand_within_exponential (int num_values)
813 static uint32_t mask = 0;
817 /* Optimize the constant case. */
827 while (mask > RAND_MAX)
834 if (ones == num_values)
842 /* Find the category to which an item belongs. */
844 mnemon_item_category (mnemon_t *mnemon,
847 category_t *category;
850 for (i = 0; i < mnemon->num_categories; i++) {
851 category = &mnemon->categories[i];
852 item_index = item - category->items;
853 if (item_index >= 0 && item_index < category->num_items)
860 typedef struct _item_in_category_closure
863 category_t *category;
864 } item_in_category_closure_t;
867 mnemon_item_in_category (void *closure, item_t *item)
869 item_in_category_closure_t *iicc = closure;
870 mnemon_t *mnemon = iicc->mnemon;
871 category_t *category = iicc->category;
873 return (mnemon_item_category (mnemon, item) == category);
876 typedef struct _item_in_category_of_length_closure
879 category_t *category;
881 } item_in_category_of_length_closure_t;
884 mnemon_item_in_category_of_length (void *closure, item_t *item)
886 item_in_category_of_length_closure_t *iicolc = closure;
887 mnemon_t *mnemon = iicolc->mnemon;
888 category_t *category = iicolc->category;
889 int length = iicolc->length;
891 if (mnemon_item_category (mnemon, item) != category)
894 return strlen (item->challenge) == length;
898 mnemon_select_item (mnemon_t *mnemon,
901 category_t **category_ret)
903 int bin_index, item_index;
906 category_t *category;
908 bin_index = rand_within_exponential (mnemon->num_bins);
909 bin = &mnemon->bins[bin_index];
911 /* The most intuitive understanding of the to_introduce counter is
912 * that it's tracking never-before-learned items as they are
913 * pulled from the bin with score 0. But that bin can become
914 * empty. So the refined rule is that we decrement to_introduce
915 * whenever we pull from the lowest-indexed bin with a
916 * non-negative score. */
917 if (mnemon->to_introduce && bin->score >=0 &&
918 (bin_index == 0 || mnemon->bins[bin_index-1].score < 0))
920 mnemon->to_introduce--;
923 item_index = rand_within (bin->num_items);
925 item = bin->items[item_index];
926 category = mnemon_item_category (mnemon, item);
928 if (bin->score == 0) {
929 if (category->order == CATEGORY_ORDER_SEQUENTIAL) {
930 item = category_next_bin_zero_item (category);
932 item_index = bin_item_index (bin, item);
937 *item_index_ret = item_index;
938 *category_ret = category;
942 #define HISTOGRAM_ROW_FORMAT "%3d: %3d"
943 #define HISTOGRAM_BAR_WIDTH 63
946 print_histogram_bar (double size,
949 int units_per_cell = (int) ceil (max / HISTOGRAM_BAR_WIDTH);
950 static char const *boxes[8] = {
955 while (size > units_per_cell) {
957 size -= units_per_cell;
960 size /= units_per_cell;
964 else if (size > 6.5/8.0)
966 else if (size > 5.5/8.0)
968 else if (size > 4.5/8.0)
970 else if (size > 3.5/8.0)
972 else if (size > 2.5/8.0)
974 else if (size > 1.5/8.0)
976 else if (size > 0.5/8.0)
983 mnemon_print_histogram (mnemon_t *mnemon,
984 const char *category_name,
987 int i, last_score, max;
988 category_t *category = NULL;
991 item_match_predicate_t *predicate = NULL;
992 void *closure = NULL;
993 item_in_category_closure_t item_in_category;
994 item_in_category_of_length_closure_t item_in_category_of_length;
996 if (mnemon->num_bins == 0)
1000 category = mnemon_get_category_if_exists (mnemon, category_name);
1003 predicate = mnemon_item_in_category_of_length;
1004 item_in_category_of_length.mnemon = mnemon;
1005 item_in_category_of_length.category = category;
1006 item_in_category_of_length.length = length;
1007 closure = &item_in_category_of_length;
1009 predicate = mnemon_item_in_category;
1010 item_in_category.mnemon = mnemon;
1011 item_in_category.category = category;
1012 closure = &item_in_category;
1017 for (i = 0; i < mnemon->num_bins; i++) {
1018 num_items = bin_num_items_matching (&mnemon->bins[i],
1019 predicate, closure);
1020 if (i == 0 || num_items > max)
1024 for (i = 0; i < mnemon->num_bins; i++) {
1025 bin = &mnemon->bins[i];
1027 while (bin->score - last_score > 1)
1028 printf (HISTOGRAM_ROW_FORMAT "\n", ++last_score, 0);
1029 num_items = bin_num_items_matching (bin,
1030 predicate, closure);
1031 printf (HISTOGRAM_ROW_FORMAT " ", bin->score, num_items);
1032 print_histogram_bar (num_items, max);
1033 last_score = bin->score;
1038 mnemon_handle_command (mnemon_t *mnemon,
1039 const char *command)
1043 switch (command[0]) {
1046 char *category = NULL;
1050 arg += strspn (arg, " \t");
1051 len = strcspn (arg, " \t");
1053 category = xstrndup (arg, len);
1055 arg += strspn (arg, " \t");
1057 length = atoi (arg);
1059 mnemon_print_histogram (mnemon, category, length);
1063 printf ("Unknown command: %s\n", command);
1069 mnemon_handle_response (mnemon_t *mnemon,
1073 const char *response,
1074 double response_time,
1079 correct = (strcmp (response, item->response) == 0);
1081 bin_remove_item (bin, item_index);
1083 /* If the bin is now empty, we must remove it. Also if we just
1084 * picked the last word we'll ever pick from the bin with
1085 * score 0, then we can remove that as well. */
1086 if (bin->num_items == 0 ||
1087 (bin->score == 0 && mnemon->to_introduce == 0))
1089 mnemon_remove_bin (mnemon, bin);
1093 (time_limit == 0.0 || response_time < time_limit))
1096 mnemon->to_master--;
1097 /* We reserve an item score of 0 for an item that has
1098 * never been asked. */
1099 if (item->score == 0) {
1101 mnemon->unlearned--;
1102 mnemon->to_master--;
1103 printf ("You got it!");
1104 } else if (item->score < 0) {
1105 printf ("Yes---just give me %d more.",
1107 } else if (item->score == 1) {
1108 printf ("On your first try, no less!");
1110 printf ("Masterful (%dx).", item->score);
1114 printf (" %s is the correct answer.",
1117 printf ("Correct, but not quite quick enough (%0.2f seconds---needed %0.2f seconds)\n",
1118 response_time, time_limit);
1119 /* Penalize an incorrect response by forcing the score
1121 if (item->score >= 0) {
1122 if (item->score > 0)
1123 printf (" Oops, you knew that, right? (%dx)\n ",
1125 mnemon->unlearned++;
1126 /* We add three here, (rather than just 2 to track the
1127 * change in the item's score below), as an extra
1128 * penalty. If the user is forgetting stuff learned
1129 * previously, then more time should be spent on mastering
1130 * than learning new items. */
1131 mnemon->to_master += item->score + 3;
1132 /* We go to -2 to force a little extra reinforcement
1133 * when re-learning an item, (otherwise, it will often
1134 * get asked again immediately where it is easy to get
1135 * a correct response without any learning). */
1139 mnemon->to_master++;
1144 if (mnemon->to_introduce)
1145 printf ("%d to come. ", mnemon->to_introduce);
1146 if (mnemon->unlearned)
1147 printf ("%d still unlearned. ", mnemon->unlearned);
1148 if (mnemon->to_introduce == 0 && mnemon->to_master > 0)
1149 printf ("%d items to master", mnemon->to_master);
1152 bin = mnemon_get_bin (mnemon, item->score);
1154 bin_add_item (bin, item);
1158 mnemon_show_challenge (mnemon_t *mnemon,
1159 challenge_type_t challenge_type,
1160 const char *challenge)
1162 const char *program;
1165 if (challenge_type == CHALLENGE_TYPE_TEXT) {
1166 printf ("%s\n", challenge);
1170 /* XXX: Yes, shelling out to system is total cheese. The planned
1171 * fix here is to bring graphical display in process, (or at least
1172 * have a custom external program that accepts image filenames on
1175 switch (challenge_type) {
1176 case CHALLENGE_TYPE_TEXT:
1179 case CHALLENGE_TYPE_IMAGE:
1180 program = "xli -gamma 2.2";
1182 case CHALLENGE_TYPE_AUDIO:
1187 xasprintf (&command, "%s %s/%s >/dev/null 2>&1 &",
1196 mnemon_hide_challenge (mnemon_t *mnemon, challenge_type_t challenge_type)
1200 if (challenge_type != CHALLENGE_TYPE_IMAGE)
1203 /* XXX: And this is just embarrassing (obviously wrong in several
1204 * ways). Hopefully I'll amend away any commit that includes this.
1206 xasprintf (&command, "killall xli");
1212 mnemon_do_challenges (mnemon_t *mnemon)
1217 category_t *category;
1221 /* Count the number of items with negative scores. */
1222 mnemon->unlearned = 0;
1223 for (i = 0; i < mnemon->num_bins; i++) {
1224 bin = &mnemon->bins[i];
1225 if (bin->score >= 0)
1227 mnemon->unlearned += bin->num_items;
1230 mnemon->to_introduce -= mnemon->unlearned;
1231 if (mnemon->to_introduce < 0)
1232 mnemon->to_introduce = 0;
1234 /* Get rid of bin with score of 0 if we aren't going to be
1235 * introducing anything from it. */
1236 if (mnemon->to_introduce == 0) {
1237 bin = mnemon_get_bin (mnemon, 0);
1238 mnemon_remove_bin (mnemon, bin);
1241 if (mnemon->unlearned) {
1242 printf ("You've got %d items to learn already. ", mnemon->unlearned);
1243 if (mnemon->to_introduce)
1244 printf ("I'll introduce %d more as we go.", mnemon->to_introduce);
1247 printf ("Introducing %d new items.\n", mnemon->to_introduce);
1252 struct timeval start, end;
1254 mnemon_select_item (mnemon, &bin, &item_index, &category);
1255 item = bin->items[item_index];
1258 if (category->time_limit > 0.0) {
1259 response = readline ("The next one is timed. Press enter when ready:");
1263 mnemon_show_challenge (mnemon, category->challenge_type,
1266 gettimeofday (&start, NULL);
1267 response = readline ("> ");
1268 gettimeofday (&end, NULL);
1270 mnemon_hide_challenge (mnemon, category->challenge_type);
1272 /* Terminate on EOF */
1273 if (response == NULL) {
1278 if (response[0] == '/') {
1279 mnemon_handle_command (mnemon, response + 1);
1286 mnemon_handle_response (mnemon, bin, item_index,
1288 (end.tv_sec + end.tv_usec / 1e6) -
1289 (start.tv_sec + start.tv_usec / 1e6),
1290 category->time_limit);
1293 /* Replay audio challenges for reinforcement. */
1294 if (category->challenge_type == CHALLENGE_TYPE_AUDIO) {
1295 mnemon_show_challenge (mnemon, category->challenge_type,
1299 } while (mnemon->to_introduce ||
1300 mnemon->unlearned ||
1301 mnemon->to_master > 0);
1305 main (int argc, char *argv[])
1310 srand (time (NULL));
1312 mnemon_init (&mnemon);
1314 mnemon_load (&mnemon);
1316 mnemon_do_challenges (&mnemon);
1318 mnemon_save (&mnemon);
1320 mnemon_fini (&mnemon);
1322 mnemon_init (&mnemon);
1323 mnemon_load (&mnemon);
1325 printf ("Great job.\nHere are your current results:\n");
1326 mnemon_print_histogram (&mnemon, NULL, 0);
1327 response = readline ("Press enter to quit.\n");
1330 mnemon_fini (&mnemon);