]> git.cworth.org Git - mnemon/blobdiff - main.c
Break mnemon up into a main program and a mnemon "library"
[mnemon] / main.c
diff --git a/main.c b/main.c
new file mode 100644 (file)
index 0000000..643f49d
--- /dev/null
+++ b/main.c
@@ -0,0 +1,83 @@
+/* mnemon - A memory training program
+ * 
+ * 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 3, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA."
+ */
+
+/* for asprintf */
+#define _GNU_SOURCE
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdarg.h>
+#include <stdint.h>
+#include <math.h>
+
+#include <sys/types.h>
+#include <sys/time.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#include <dirent.h>
+#include <errno.h>
+#include <string.h>
+#include <assert.h>
+
+#include <readline/readline.h>
+#include <readline/history.h>
+
+#include "mnemon.h"
+
+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;
+}