/* Inserts dot completion into current cursor position in the command line. * Returns zero on success. */ static int insert_dot_completion(const wchar_t completion[]) { wchar_t *ptr; size_t len = wcslen(completion); ptr = realloc(input_stat.line, (input_stat.len + len + 1)*sizeof(wchar_t)); if(ptr == NULL) { return 1; } input_stat.dot_index = input_stat.index; input_stat.dot_len = len; if(input_stat.line == NULL) { ptr[0] = L'\0'; } input_stat.line = ptr; wcsins(input_stat.line, completion, input_stat.index + 1); input_stat.index += len; input_stat.curs_pos += len; input_stat.len += len; return 0; }
static int def_handler(wchar_t key) { void *p; wchar_t buf[2] = {key, L'\0'}; input_stat.history_search = HIST_NONE; if(input_stat.complete_continue && input_stat.line[input_stat.index - 1] == L'/' && key == '/') { stop_completion(); return 0; } stop_completion(); if(key != L'\r' && !iswprint(key)) return 0; p = realloc(input_stat.line, (input_stat.len + 2) * sizeof(wchar_t)); if(p == NULL) { leave_cmdline_mode(); return 0; } input_stat.line = (wchar_t *) p; if(input_stat.len == 0) input_stat.line[0] = L'\0'; input_stat.index++; wcsins(input_stat.line, buf, input_stat.index); input_stat.len++; input_stat.curs_pos += wcwidth(key); update_cmdline_size(); update_cmdline_text(); return 0; }