]> git.cworth.org Git - mnemon/blobdiff - mnemon.c
More cleanup of "unsigned vs. signed" integer comparison.
[mnemon] / mnemon.c
index 0dc45380760d3d3592a9c875a11b343f100d50eb..ac31422cba7c4eb2f8757e9ed07425250d07ef78 100644 (file)
--- a/mnemon.c
+++ b/mnemon.c
@@ -139,14 +139,14 @@ category_init (category_t *category,
     category->order = CATEGORY_ORDER_RANDOM;
     category->time_limit = 0.0;
     category->bin_zero_head = 0;
-    category->challenge_type = CHALLENGE_TYPE_TEXT;
+    category->challenge_type = xstrdup("");
     category->repeat = 0;
 }
 
 static void
 category_fini (category_t *category)
 {
-    int i;
+    unsigned int i;
 
     for (i = 0; i < category->num_items; i++)
        item_fini (&category->items[i]);
@@ -154,6 +154,8 @@ category_fini (category_t *category)
     free (category->items);
 
     free (category->name);
+
+    free (category->challenge_type);
 }
 
 static void
@@ -189,7 +191,7 @@ category_add_item (category_t       *category,
 static item_t *
 category_next_bin_zero_item (category_t        *category)
 {
-    int *i = &category->bin_zero_head;
+    unsigned int *i = &category->bin_zero_head;
 
     for ( ; *i < category->num_items; *i = *i + 1)
        if (category->items[*i].score == 0)
@@ -202,7 +204,7 @@ static void
 category_print (category_t     *category,
                FILE            *file)
 {
-    int i;
+    unsigned int i;
     item_t *item;
 
     fprintf (file, "order = %s\n\n",
@@ -210,25 +212,7 @@ category_print (category_t *category,
     fprintf (file, "time = %f\n\n",
             category->time_limit);
 
-    fprintf (file, "challenge = ");
-    switch (category->challenge_type) {
-    case CHALLENGE_TYPE_TEXT:
-       fprintf (file, "text");
-       break;
-    case CHALLENGE_TYPE_IMAGE:
-       fprintf (file, "image");
-       break;
-    case CHALLENGE_TYPE_AUDIO:
-       fprintf (file, "audio");
-       break;
-    case CHALLENGE_TYPE_MIDI:
-       fprintf (file, "midi");
-       break;
-    case CHALLENGE_TYPE_TEXT_TO_SPEECH:
-       fprintf (file, "text-to-speech");
-       break;
-    }
-    fprintf (file, "\n\n");
+    fprintf (file, "challenge = %s\n\n", category->challenge_type);
 
     fprintf (file, "repeat = %d\n\n", category->repeat);
 
@@ -305,7 +289,7 @@ static int
 bin_item_index (bin_t  *bin,
                item_t  *item)
 {
-    int i;
+    unsigned int i;
 
     for (i = 0; i < bin->num_items; i++)
        if (bin->items[i] == item)
@@ -575,21 +559,9 @@ mnemon_load_category (mnemon_t             *mnemon,
                exit (1);
            }
        } else if (strcmp (name, "challenge") == 0) {
-           if (strcmp (value, "text") == 0) {
-               category->challenge_type = CHALLENGE_TYPE_TEXT;
-           } else if (strcmp (value, "image") == 0) {
-               category->challenge_type = CHALLENGE_TYPE_IMAGE;
-           } else if (strcmp (value, "audio") == 0) {
-               category->challenge_type = CHALLENGE_TYPE_AUDIO;
-           } else if (strcmp (value, "midi") == 0) {
-               category->challenge_type = CHALLENGE_TYPE_MIDI;
-           } else if (strcmp (value, "text-to-speech") == 0) {
-               category->challenge_type = CHALLENGE_TYPE_TEXT_TO_SPEECH;
-           } else {
-               fprintf (stderr, "Unknown value for \"challenge\" option \"%s\" at %s:%d\n",
-                        value, path, line_count);
-               exit (1);
-           }
+           /* XXX: Need to switch to talloc here. */
+           free (category->challenge_type);
+           category->challenge_type = xstrdup (value);
        } else if (strcmp (name, "repeat") == 0) {
            if (strcmp (value, "0") == 0) 
                category->repeat = 0;