X-Git-Url: https://git.cworth.org/git?p=mnemon;a=blobdiff_plain;f=mnemon.c;h=7f0526d8766beb410fd5a02caf6555817dba6f49;hp=3dee0347e153c5e2a5c00f93d717f57605fd787d;hb=10d0f1e757ef8c22bf8c1d921b624296a25ab238;hpb=3c887fd06a0a6790db978d13df4cc73f6d5b75b0 diff --git a/mnemon.c b/mnemon.c index 3dee034..7f0526d 100644 --- a/mnemon.c +++ b/mnemon.c @@ -26,6 +26,7 @@ #include #include +#include #include #include #include @@ -588,6 +589,7 @@ mnemon_load_category (mnemon_t *mnemon, char *path; category_t *category; int i; + struct stat st; path = xmalloc (strlen (mnemon->dir_name) + 1 + strlen (name) + 1); sprintf (path, "%s/%s", mnemon->dir_name, name); @@ -599,6 +601,12 @@ mnemon_load_category (mnemon_t *mnemon, exit (1); } + fstat (fileno(file), &st); + if (! S_ISREG(st.st_mode)) { + fprintf (stderr, "Error: File %s is not a regular file.\n", path); + exit (1); + } + category = mnemon_get_category (mnemon, name); #define READ_LINE do { \ @@ -1344,11 +1352,22 @@ 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); - mnemon_load (&mnemon); + _load_categories (); mnemon_do_challenges (&mnemon); @@ -1357,7 +1376,8 @@ main (int argc, char *argv[]) mnemon_fini (&mnemon); mnemon_init (&mnemon); - mnemon_load (&mnemon); + + _load_categories (); printf ("Great job.\nHere are your current results:\n"); mnemon_print_histogram (&mnemon, NULL, 0);