X-Git-Url: https://git.cworth.org/git?p=mnemon;a=blobdiff_plain;f=mnemon.c;h=a27efd4f106042f3ae14be7a626f04b7eadc2b34;hp=0dc45380760d3d3592a9c875a11b343f100d50eb;hb=HEAD;hpb=33d0169d3bd989486de8e97f58002c1544a8211e diff --git a/mnemon.c b/mnemon.c index 0dc4538..a27efd4 100644 --- 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) @@ -337,7 +321,7 @@ mnemon_init (mnemon_t *mnemon) void mnemon_fini (mnemon_t *mnemon) { - int i; + unsigned int i; for (i = 0; i < mnemon->num_bins; i++) bin_fini (&mnemon->bins[i]); @@ -367,7 +351,7 @@ category_t * mnemon_get_category_if_exists (mnemon_t *mnemon, const char *name) { - int i; + unsigned int i; for (i = 0; i < mnemon->num_categories; i++) if (strcmp (mnemon->categories[i].name, name) == 0) @@ -412,7 +396,7 @@ static bin_t * mnemon_get_bin (mnemon_t *mnemon, int score) { - int i; + unsigned int i; bin_t *bin; for (i = 0; i < mnemon->num_bins; i++) @@ -494,7 +478,7 @@ mnemon_load_category (mnemon_t *mnemon, int line_count = 0; char *path; category_t *category; - int i; + unsigned int i; struct stat st; path = xmalloc (strlen (mnemon->dir_name) + 1 + strlen (name) + 1); @@ -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; @@ -686,7 +658,8 @@ mnemon_load (mnemon_t *mnemon) void mnemon_save (mnemon_t *mnemon) { - int i, err; + unsigned int i; + int err; char *filename, *lock_filename; FILE *file; category_t *category; @@ -780,12 +753,12 @@ mnemon_item_category (mnemon_t *mnemon, item_t *item) { category_t *category; - int i, item_index; + unsigned int i, item_index; for (i = 0; i < mnemon->num_categories; i++) { category = &mnemon->categories[i]; item_index = item - category->items; - if (item_index >= 0 && item_index < category->num_items) + if (item_index < category->num_items) return category; }