/* * Add the sequence of characters given in sequence as the key mapping * for the given key symbol. */ void add_key_sequence(SCREEN *screen, char *sequence, int key_type) { key_entry_t *tmp_key; keymap_t *current; int length, j, key_ent; #ifdef DEBUG __CTRACE(__CTRACE_MISC, "add_key_sequence: add key sequence: %s(%s)\n", sequence, keyname(key_type)); #endif /* DEBUG */ current = screen->base_keymap; /* always start with * base keymap. */ length = (int) strlen(sequence); /* * OK - we really should never get a zero length string here, either * the terminfo entry is there and it has a value or we are not called * at all. Unfortunately, if someone assigns a terminfo string to the * ^@ value we get passed a null string which messes up our length. * So, if we get a null string then just insert a leaf value in * the 0th char position of the root keymap. Note that we are * totally screwed if someone terminates a multichar sequence * with ^@... oh well. */ if (length == 0) length = 1; for (j = 0; j < length - 1; j++) { /* add the entry to the struct */ tmp_key = add_new_key(current, sequence[j], KEYMAP_MULTI, 0); /* index into the key array - it's clearer if we stash this */ key_ent = current->mapping[(unsigned char) sequence[j]]; current->key[key_ent] = tmp_key; /* next key uses this map... */ current = current->key[key_ent]->value.next; } /* * This is the last key in the sequence (it may have been the * only one but that does not matter) this means it is a leaf * key and should have a symbol associated with it. */ tmp_key = add_new_key(current, sequence[length - 1], KEYMAP_LEAF, key_type); current->key[current->mapping[(int)sequence[length - 1]]] = tmp_key; }
char *word_user(char *filename, char *filename_user) //当添加一个词条后,必须重新开始,才能再次加入查找范围 { dict_elem_t *head_p; int total; int total_d; int total_user; dict_elem_t *elem_fund; total_d = get_elem_count(filename); total_user = get_elem_count(filename_user); if (total_user == -1) { total = total_d; head_p = malloc(total * sizeof(*head_p)); head_p = read_to_mem_from_txt(filename, head_p, total); } else { total = total_d + total_user; head_p = malloc(total * sizeof(*head_p)); head_p = read_to_mem_from_txt(filename, head_p, total_d); read_to_mem_from_txt(filename_user, &(head_p[total_d]), total_user); } shell_sort(head_p, 0, total-1); printf("\n\t\t\tWelcome enjoy this dictionary\n\n"); printf("input you word ,exit is quit... \n"); for (;;) { elem_fund = search(head_p, total); //退出,说明没找到,继续找 if (elem_fund == NULL) { add_new_key(filename_user); continue; } else if ((unsigned)elem_fund == 1) { distory(head_p, total); return (char *) 1; } else if ((unsigned)elem_fund == 2) { puts("error"); distory(head_p, total); return (char *) 2; } else { print_one_elem(elem_fund); } } }