int main(int argc, char **argv) { int option; use_alternate_screen = getenv("VIM") == NULL; setlocale(LC_CTYPE, ""); while ((option = getopt(argc, argv, "dhoq:SvxX")) != -1) { switch (option) { case 'd': descriptions = 1; break; case 'o': /* * Only output description if descriptions are read and * displayed in the list of choices. */ output_description = descriptions; break; case 'q': if ((query = strdup(optarg)) == NULL) err(1, "strdup"); query_size = strlen(query) + 1; break; case 'S': sort = 0; break; case 'v': version(); case 'x': use_alternate_screen = 1; break; case 'X': use_alternate_screen = 0; break; default: usage(); } } argc -= optind; argv += optind; if (query == NULL) { query_size = 64; if ((query = calloc(query_size, sizeof(*query))) == NULL) err(1, "calloc"); } get_choices(); put_choice(selected_choice()); free_choices(); free(query); return EX_OK; }
/********************************************************************** * improve_one_blob * * Start with the current word of blobs and its classification. Find * the worst blobs and try to divide it up to improve the ratings. *********************************************************************/ CHOICES_LIST improve_one_blob(TWERD *word, CHOICES_LIST char_choices, int fx, INT32 *blob_number, SEAMS *seam_list, DANGERR *fixpt, STATE *this_state, STATE *correct_state, INT32 pass) { TBLOB *pblob; TBLOB *blob; INT16 x = 0; float rating_ceiling = MAX_FLOAT32; CHOICES answer; SEAM *seam; do { *blob_number = select_blob_to_split (char_choices, rating_ceiling); if (*blob_number == -1) return (NULL); seam = attempt_blob_chop (word, *blob_number, *seam_list); if (seam != NULL) break; /* Must split null blobs */ answer = (CHOICES) array_value (char_choices, *blob_number); if (answer == NIL) return (NULL); /* Try different blob */ rating_ceiling = best_probability (answer); } while (!blob_skip); /* Split OK */ for (blob = word->blobs, pblob = NULL; x < *blob_number; x++) { pblob = blob; blob = blob->next; } *seam_list = insert_seam (*seam_list, *blob_number, seam, blob, word->blobs); free_choices ((CHOICES) array_value (char_choices, *blob_number)); answer = classify_blob (pblob, blob, blob->next, NULL, fx, "improve 1:", Red, this_state, correct_state, pass, *blob_number); char_choices = array_insert (char_choices, *blob_number, answer); answer = classify_blob (blob, blob->next, blob->next->next, NULL, fx, "improve 2:", Yellow, this_state, correct_state, pass, *blob_number + 1); array_value (char_choices, *blob_number + 1) = (char *) answer; return (char_choices); }
/********************************************************************** * free_matrix * * Deallocate the memory taken up by a matrix of match ratings. *********************************************************************/ void free_matrix(MATRIX matrix) { int x; int y; int dimension = matrix_dimension (matrix); CHOICES matrix_cell; for (x = 0; x < dimension; x++) { for (y = 0; y < dimension; y++) { matrix_cell = matrix_get (matrix, x, y); if (matrix_cell != NOT_CLASSIFIED) free_choices(matrix_cell); } } memfree(matrix); }