]> git.cworth.org Git - mnemon/blobdiff - mnemon.c
Eliminate some compiler warnings.
[mnemon] / mnemon.c
index 3dee0347e153c5e2a5c00f93d717f57605fd787d..5fa8ac9e418a8d6f6f1e143c92d6d4addd039f6b 100644 (file)
--- a/mnemon.c
+++ b/mnemon.c
@@ -26,6 +26,7 @@
 
 #include <sys/types.h>
 #include <sys/time.h>
+#include <sys/stat.h>
 #include <unistd.h>
 #include <dirent.h>
 #include <errno.h>
@@ -41,6 +42,8 @@ do {                                  \
     assert (NOT_REACHED);              \
 } while (0)
 
+#define unused(foo) foo __attribute__((unused))
+
 typedef int bool_t;
 
 typedef struct _item {
@@ -588,6 +591,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 +603,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 {                                 \
@@ -908,7 +918,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;
@@ -1228,7 +1238,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;
 
@@ -1344,11 +1355,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 +1379,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);