static void print_variant_clauses (struct type *type, int field_num, struct type *outer_type, struct ui_file *stream, int show, int level) { int i; struct type *var_type, *par_type; struct type *discr_type; var_type = TYPE_FIELD_TYPE (type, field_num); discr_type = ada_variant_discrim_type (var_type, outer_type); if (TYPE_CODE (var_type) == TYPE_CODE_PTR) { var_type = TYPE_TARGET_TYPE (var_type); if (var_type == NULL || TYPE_CODE (var_type) != TYPE_CODE_UNION) return; } par_type = ada_find_parallel_type (var_type, "___XVU"); if (par_type != NULL) var_type = par_type; for (i = 0; i < TYPE_NFIELDS (var_type); i += 1) { fprintf_filtered (stream, "\n%*swhen ", level + 4, ""); print_choices (var_type, i, stream, discr_type); fprintf_filtered (stream, " =>"); if (print_record_field_types (TYPE_FIELD_TYPE (var_type, i), outer_type, stream, show, level + 4) <= 0) fprintf_filtered (stream, " null;"); } }
/********************************************************************** * classify_blob * * Classify the this blob if it is not already recorded in the match * table. Attempt to recognize this blob as a character. The recognition * rating (probability) for this blob will be stored as a part of the * blob. This value will also be returned to the caller. **********************************************************************/ CHOICES classify_blob(TBLOB *pblob, TBLOB *blob, TBLOB *nblob, TEXTROW *row, int fx, const char *string, C_COL color, STATE *this_state, STATE *best_state, INT32 pass, INT32 blob_index) { CHOICES rating; INT32 old_index; chars_classified++; /* Global value */ if (blob_skip) return (NIL); #ifndef GRAPHICS_DISABLED if (display_all_blobs) display_blob(blob, color); #endif rating = get_match (blob); if (rating == NIL) { if (pass) { old_index = blob_index; //?cast to int* blob_type = compare_states (best_state, this_state, (int *) &blob_index); blob_answer = word_answer[blob_index]; if (blob_answer < '!') fprintf (matcher_fp, "Bad compare states: best state=0x%x%x, this=0x%x%x, bits=" INT32FORMAT ", index=" INT32FORMAT ", outdex=" INT32FORMAT ", word=%s\n", best_state->part1, best_state->part2, this_state->part1, this_state->part2, bits_in_states, old_index, blob_index, word_answer); } else blob_type = 0; rating = /*(*blob_matchers [fx]) */ (CHOICES) call_matcher (pblob, blob, nblob, NULL, row); put_match(blob, rating); } #ifndef GRAPHICS_DISABLED if (display_ratings && string) print_choices(string, rating); if (blob_pause) window_wait(blob_window); #endif return (rating); }
t_list *enter_key(t_list *l) { t_list *tmp; tmp = l; while (tmp->highlighted != 1) tmp = tmp->nxt; tmp->selected = (tmp->selected == 1) ? 0 : 1; tputs(tgetstr("cl", NULL), 1, ft_outc); print_choices(l); print_bar(l); return (l); }
const struct choice * selected_choice(void) { char buf[6]; int key, selection = 0, visible_choices_count; int word_position; size_t cursor_position, length, query_length, scroll; cursor_position = query_length = strlen(query); filter_choices(); init_tty(); if (cursor_position >= (size_t)columns) scroll = cursor_position - columns + 1; else scroll = 0; visible_choices_count = print_choices(selection); print_query(query, query_length, cursor_position, scroll); tty_putp(cursor_normal); for (;;) { fflush(tty_out); memset(buf, 0, sizeof(buf)); key = get_key(buf, sizeof(buf), &length); switch (key) { case ENTER: if (visible_choices_count > 0) { restore_tty(); if (selection >= 0 && selection < (ssize_t)choices.length) return &choices.v[selection]; else return NULL; } break; case ALT_ENTER: restore_tty(); choices.v[choices.length].string = query; choices.v[choices.length].description = ""; return &choices.v[choices.length]; case DEL: if (cursor_position > 0) { for (length = 1; isu8cont(query[cursor_position - length]); length++); delete_between( query, query_length, cursor_position - length, cursor_position); cursor_position -= length; query_length -= length; filter_choices(); selection = 0; } break; case CTRL_D: if (cursor_position < query_length) { for (length = 1; isu8cont(query[cursor_position + length]); length++); delete_between( query, query_length, cursor_position, cursor_position + length); query_length -= length; filter_choices(); selection = 0; } break; case CTRL_U: delete_between( query, query_length, 0, cursor_position); query_length -= cursor_position; cursor_position = 0; filter_choices(); selection = 0; break; case CTRL_K: delete_between( query, query_length, cursor_position, query_length); query_length = cursor_position; filter_choices(); selection = 0; break; case CTRL_W: if (cursor_position == 0) break; for (word_position = cursor_position;;) { while (isu8cont(query[--word_position])); if (word_position < 1) break; if (query[word_position] != ' ' && query[word_position - 1] == ' ') break; } delete_between( query, query_length, word_position, cursor_position); query_length -= cursor_position - word_position; cursor_position = word_position; filter_choices(); selection = 0; break; case CTRL_A: cursor_position = 0; break; case CTRL_E: cursor_position = query_length; break; case DOWN: if (selection < visible_choices_count - 1) ++selection; break; case UP: if (selection > 0) --selection; break; case LEFT: while (cursor_position > 0 && isu8cont(query[--cursor_position])); break; case RIGHT: while (cursor_position < query_length && isu8cont(query[++cursor_position])); break; default: if (!isu8start(buf[0]) && !isprint(buf[0])) continue; if (query_size < query_length + length) { query_size = 2*query_length + length; if ((query = reallocarray(query, query_size, sizeof(char))) == NULL) err(1, NULL); } if (cursor_position < query_length) memmove(query + cursor_position + length, query + cursor_position, query_length - cursor_position); memcpy(query + cursor_position, buf, length); cursor_position += length; query_length += length; query[query_length] = '\0'; filter_choices(); selection = 0; break; } tty_putp(cursor_invisible); visible_choices_count = print_choices(selection); if (cursor_position >= scroll + columns) scroll = cursor_position - columns + 1; if (cursor_position < scroll) scroll = cursor_position; print_query(query, query_length, cursor_position, scroll); tty_putp(cursor_normal); } }
void ui() { int choice, len = 0; char* input = malloc(sizeof(char)*MAX_INPUT_STRING_LENGTH); char* res = malloc(sizeof(char)); int* array = calloc(20, sizeof(int)); print_choices(); printf("Write the number of the operation you want to do:\n"); scanf("%d", &choice); printf("Give the input string: (max size %d) ", MAX_INPUT_STRING_LENGTH); print_instructions(choice); scanf("%s", input); wavelet_tree* root = create_wavelet_tree(input); wavelet_tree* res_root; if (choice == 1) { char** strings = malloc(sizeof(char*)); strings[0] = input; iterator_state* state = initialize_iterator(strings, 1); single_iterate(state, &print_node, 0); free_iterator_state(state); free(strings); } else if (choice == 2) { res_root = s_to_bwt(input); print_wavelet_tree(res_root); } else if (choice == 3) { res = bwt_to_s(root); printf("%s\n", res); } else if (choice == 4) { res_root = reverse_bwt(input); print_wavelet_tree(res_root); } else if (choice == 5) { array = create_c_array(root,0,0,0,0); int len = strlen(determine_alphabet(input)); print_int_array(array, len); } else if (choice == 6) { bit_vector* runs = create_runs_vector(root,0); print_runs_vector(runs, strlen(input)+1); free_bit_vector(runs); } else if (choice == 7) { printf("Give the second input string: "); char* input2 = malloc(sizeof(char)*MAX_INPUT_STRING_LENGTH); scanf("%s", input2); char** strings = malloc(2 * sizeof(char*)); strings[0] = input; strings[1] = input2; parameter_struct* params = initialize_for_mums(strings, 0); iterator_state* state = iterate(params); mum_results* results = (mum_results*) params->ret_data; triplet* nodes = results->data; print_mums(input, results, state); mum_print_bit_vectors(input,input2, results, state); free(strings); free(results->data); free_iterator_state(state); } else if (choice == 8) { printf("Not supported yet\n"); } else if (choice == 9) { printf("%d\n", distinct_substrings(input)); } else if (choice == 10) { parameter_struct* params = initialize_for_max_repeats(input, 0); iterator_state* state = iterate(params); max_repeat_results* results = (max_repeat_results*) params->ret_data; //maximals_print_nodes(input); print_maximal_repeat_substrings(input, results, state); //compare_quick_sort() } else if (choice == 11) { printf("Give the second input string: "); char* input2 = malloc(sizeof(char)*MAX_INPUT_STRING_LENGTH); scanf("%s", input2); char** strings = malloc(2 * sizeof(char*)); strings[0] = input; strings[1] = input2; parameter_struct* params = initialize_for_mems(strings, 0); iterator_state* state = iterate(params); mem_results* results = (mem_results*) params->ret_data; triplet* nodes = results->data; print_mems(input, results, state); free(strings); free(results->data); free_iterator_state(state); }else { printf("Invalid choice\n"); } }