X-Git-Url: https://git.cworth.org/git?p=mnemon;a=blobdiff_plain;f=mnemon.c;h=f869993061de67ad9332bbe3b77a8753ab882310;hp=7f0526d8766beb410fd5a02caf6555817dba6f49;hb=e213a74c688dc475578348ac5e0e438055d11311;hpb=10d0f1e757ef8c22bf8c1d921b624296a25ab238 diff --git a/mnemon.c b/mnemon.c index 7f0526d..f869993 100644 --- a/mnemon.c +++ b/mnemon.c @@ -1,9 +1,10 @@ -/* - * Copyright © 2006 Carl Worth +/* mnemon - A memory training library + * + * Copyright © 2006,2011 Carl Worth * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) + * the Free Software Foundation; either version 3, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, @@ -16,6 +17,8 @@ * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA." */ +#include "mnemon.h" + /* for asprintf */ #define _GNU_SOURCE #include @@ -42,6 +45,8 @@ do { \ assert (NOT_REACHED); \ } while (0) +#define unused(foo) foo __attribute__((unused)) + typedef int bool_t; typedef struct _item { @@ -50,12 +55,12 @@ typedef struct _item { char *response; } item_t; -typedef struct _bin { +struct _bin { int score; int items_size; int num_items; item_t **items; -} bin_t; +}; typedef enum { CATEGORY_ORDER_RANDOM, @@ -70,7 +75,7 @@ typedef enum { CHALLENGE_TYPE_TEXT_TO_SPEECH } challenge_type_t; -typedef struct _category { +struct _category { char *name; int items_size; int num_items; @@ -85,24 +90,7 @@ typedef struct _category { challenge_type_t challenge_type; /* Whether to repeat afterwards (for a little extra reinforcement) */ bool_t repeat; -} category_t; - -typedef struct _mnemon { - char *dir_name; - - int categories_size; - int num_categories; - category_t *categories; - - int bins_size; - int num_bins; - bin_t *bins; - - int to_introduce; - int to_master; - int unlearned; - int mastered; -} mnemon_t; +}; static void * xmalloc (size_t size) @@ -408,7 +396,7 @@ bin_num_items_matching (bin_t *bin, return num_items; } -static void +void mnemon_init (mnemon_t *mnemon) { char *home; @@ -433,7 +421,7 @@ mnemon_init (mnemon_t *mnemon) mnemon->mastered = -1; } -static void +void mnemon_fini (mnemon_t *mnemon) { int i; @@ -577,7 +565,7 @@ trim_space (char *string) return string; } -static void +void mnemon_load_category (mnemon_t *mnemon, const char *name) { @@ -748,7 +736,7 @@ mnemon_load_category (mnemon_t *mnemon, } } -static void +void mnemon_load (mnemon_t *mnemon) { DIR *dir; @@ -777,7 +765,7 @@ mnemon_load (mnemon_t *mnemon) closedir (dir); } -static void +void mnemon_save (mnemon_t *mnemon) { int i, err; @@ -916,7 +904,7 @@ mnemon_item_in_category_of_length (void *closure, item_t *item) item_in_category_of_length_closure_t *iicolc = closure; mnemon_t *mnemon = iicolc->mnemon; category_t *category = iicolc->category; - int length = iicolc->length; + unsigned int length = iicolc->length; if (mnemon_item_category (mnemon, item) != category) return 0; @@ -1009,7 +997,7 @@ print_histogram_bar (double size, printf ("\n"); } -static void +void mnemon_print_histogram (mnemon_t *mnemon, const char *category_name, int length) @@ -1236,7 +1224,8 @@ mnemon_show_challenge (mnemon_t *mnemon, } static void -mnemon_hide_challenge (mnemon_t *mnemon, challenge_type_t challenge_type) +mnemon_hide_challenge (unused (mnemon_t *mnemon), + challenge_type_t challenge_type) { char * command; @@ -1251,7 +1240,7 @@ mnemon_hide_challenge (mnemon_t *mnemon, challenge_type_t challenge_type) free (command); } -static void +void mnemon_do_challenges (mnemon_t *mnemon) { bin_t *bin; @@ -1345,46 +1334,3 @@ mnemon_do_challenges (mnemon_t *mnemon) mnemon->unlearned || mnemon->to_master > 0); } - -int -main (int argc, char *argv[]) -{ - mnemon_t mnemon; - char *response; - - void _load_categories() - { - if (argc > 1) { - int i; - for (i = 1; i < argc; i++) - mnemon_load_category (&mnemon, argv[i]); - } else { - mnemon_load (&mnemon); - } - } - - srand (time (NULL)); - - mnemon_init (&mnemon); - - _load_categories (); - - mnemon_do_challenges (&mnemon); - - mnemon_save (&mnemon); - - mnemon_fini (&mnemon); - - mnemon_init (&mnemon); - - _load_categories (); - - printf ("Great job.\nHere are your current results:\n"); - mnemon_print_histogram (&mnemon, NULL, 0); - response = readline ("Press enter to quit.\n"); - free (response); - - mnemon_fini (&mnemon); - - return 0; -}