00001
00020 #include "choices.h"
00021 #include "structures.h"
00022 #include "tordvars.h"
00023 #include "callcpp.h"
00024 #include "danerror.h"
00025 #include "host.h"
00026
00027
00028
00029
00031 #define CHOICEBLOCK 100
00032
00035 makestructure (newchoice, oldchoice, printchoice, A_CHOICE,
00036 freechoice, CHOICEBLOCK, "A_CHOICE", choicecount)
00038
00039
00040
00048 CHOICES append_choice(CHOICES ratings,
00049 const char *string,
00050 float rating,
00051 float certainty,
00052 INT8 config) {
00053 A_CHOICE *this_choice;
00054
00055 this_choice = new_choice (string, rating, certainty, config, NO_PERM);
00056 ratings = push_last (ratings, (LIST) this_choice);
00057 return (ratings);
00058 }
00059
00060
00064 CHOICES copy_choices(CHOICES choices) {
00065 CHOICES l;
00066 CHOICES result = NIL;
00067
00068 iterate_list(l, choices) {
00069 result = push (result,
00070 (LIST) new_choice (class_string (first (l)),
00071 class_probability (first (l)),
00072 class_certainty (first (l)),
00073 class_config (first (l)),
00074 class_permuter (first (l))));
00075 }
00076 return (reverse_d (result));
00077 }
00078
00079
00083 void free_choice(void *arg) {
00084 A_CHOICE *this_choice;
00085 LIST choice = (LIST) arg;
00086
00087 this_choice = (A_CHOICE *) choice;
00088 if (this_choice) {
00089 if (this_choice->string)
00090 strfree (this_choice->string);
00091 oldchoice(this_choice);
00092 }
00093 }
00094
00095
00099 A_CHOICE *new_choice(const char *string,
00100 float rating,
00101 float certainty,
00102 INT8 config,
00103 char permuter) {
00104 A_CHOICE *this_choice;
00105
00106 this_choice = newchoice ();
00107 this_choice->string = strsave (string);
00108 this_choice->rating = rating;
00109 this_choice->certainty = certainty;
00110 this_choice->config = config;
00111 this_choice->permuter = permuter;
00112 return (this_choice);
00113 }
00114
00115
00119 void print_choices(
00120 const char *label,
00121 CHOICES rating) {
00122 int first_one = TRUE;
00123 char str[CHARS_PER_LINE];
00124 int len;
00125
00126 cprintf ("%-20s\n", label);
00127 if (rating == NIL)
00128 cprintf (" No rating ");
00129
00130 iterate(rating) {
00131
00132 if (first_one && show_bold) {
00133 cprintf ("|");
00134 len = sprintf (str, " %s ", best_string (rating));
00135 print_bold(str);
00136 while (len++ < 8)
00137 cprintf (" ");
00138 }
00139 else {
00140 cprintf ("| %-7s", best_string (rating));
00141 }
00142
00143 cprintf ("%5.2lf ", best_probability (rating));
00144
00145 cprintf ("%5.2lf", best_certainty (rating));
00146 first_one = FALSE;
00147 }
00148 cprintf ("\n");
00149 }