PrefixResult *search_prefix(Node *graph, wchar_t *search_string) { Node *search_result_root = find_word_node(graph, search_string); DynArray *current_string = alloc_dyn_array(); PrefixResult *result = NULL; init_dyn_array(wchar_t *, current_string); while (*search_string != L'\0') { append_dyn_array_char(current_string, *search_string); search_string++; } if (get_permutations(search_result_root, current_string, &result) == 0) { clear_dyn_array(current_string); dealloc_dyn_array(current_string); return result; } else { return NULL; } }
int main(int argc, char **argv) { Node **head = malloc(sizeof(Node *)); Node *word_node; char **filenames = init_filenames(); char ch; char *indexfile = "index"; char *namefile = "filenames"; char *word; while((ch = getopt(argc, argv, "i:n:")) != -1) { switch (ch) { case 'i': indexfile = optarg; break; case 'n': namefile = optarg; break; default: fprintf(stderr, "Usage: indexfile [-i FILE] [-n FILE ] FILE...\n"); exit(1); } } if (argv[optind] == NULL) { // No word arguments were given. fprintf(stderr, "Usage: indexfile [-u FILE] [-n FILE] FILE...\n"); exit(1); } word = argv[optind]; read_list(namefile, indexfile, head, filenames); word_node = find_word_node(*head, word); if (word_node != NULL) { print_query(word_node, filenames); } else { // The word does not exist in the linked list. printf("indexfile %s: word not found\n", argv[optind]); } return 0; }