]> git.cworth.org Git - mnemon/blob - main.c
643f49d77407b134d37e1983933b0c6157312436
[mnemon] / main.c
1 /* mnemon - A memory training program
2  * 
3  * Copyright © 2006,2011 Carl Worth
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 3, or (at your option)
8  * any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software Foundation,
17  * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA."
18  */
19
20 /* for asprintf */
21 #define _GNU_SOURCE
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <stdarg.h>
25 #include <stdint.h>
26 #include <math.h>
27
28 #include <sys/types.h>
29 #include <sys/time.h>
30 #include <sys/stat.h>
31 #include <unistd.h>
32 #include <dirent.h>
33 #include <errno.h>
34 #include <string.h>
35 #include <assert.h>
36
37 #include <readline/readline.h>
38 #include <readline/history.h>
39
40 #include "mnemon.h"
41
42 int
43 main (int argc, char *argv[])
44 {
45     mnemon_t mnemon;
46     char *response;
47
48     void _load_categories()
49     {
50         if (argc > 1) {
51             int i;
52             for (i = 1; i < argc; i++)
53                 mnemon_load_category (&mnemon, argv[i]);
54         } else {
55             mnemon_load (&mnemon);
56         }
57     }
58
59     srand (time (NULL));
60
61     mnemon_init (&mnemon);
62
63     _load_categories ();
64
65     mnemon_do_challenges (&mnemon);
66
67     mnemon_save (&mnemon);
68
69     mnemon_fini (&mnemon);
70
71     mnemon_init (&mnemon);
72
73     _load_categories ();
74
75     printf ("Great job.\nHere are your current results:\n");
76     mnemon_print_histogram (&mnemon, NULL, 0);
77     response = readline ("Press enter to quit.\n");
78     free (response);
79
80     mnemon_fini (&mnemon);
81
82     return 0;
83 }