static void restore_user_input(void) { input_stat.cmd_pos = -1; free(input_stat.line); input_stat.line = my_wcsdup(input_stat.line_buf); input_stat.len = wcslen(input_stat.line); update_cmdline(); }
static void complete_next(const hist_t *hist, size_t len) { if(hist_is_empty(hist)) { return; } if(input_stat.history_search != HIST_SEARCH) { if(input_stat.cmd_pos <= 0) { restore_user_input(); return; } input_stat.cmd_pos--; } else { int pos = input_stat.cmd_pos; int len = input_stat.hist_search_len; while(--pos >= 0) { wchar_t *const buf = to_wide(hist->items[pos]); if(wcsncmp(input_stat.line, buf, len) == 0) { free(buf); break; } free(buf); } if(pos < 0) { restore_user_input(); return; } input_stat.cmd_pos = pos; } (void)replace_input_line(hist->items[input_stat.cmd_pos]); update_cmdline(); if(input_stat.cmd_pos > len - 1) { input_stat.cmd_pos = len - 1; } }
static void complete_prev(const hist_t *hist, size_t len) { if(hist_is_empty(hist)) { return; } if(input_stat.history_search != HIST_SEARCH) { if(input_stat.cmd_pos == hist->pos) return; input_stat.cmd_pos++; } else { int pos = input_stat.cmd_pos; int len = input_stat.hist_search_len; while(++pos <= hist->pos) { wchar_t *buf; buf = to_wide(hist->items[pos]); if(wcsncmp(input_stat.line, buf, len) == 0) { free(buf); break; } free(buf); } if(pos > hist->pos) return; input_stat.cmd_pos = pos; } (void)replace_input_line(hist->items[input_stat.cmd_pos]); update_cmdline(); if(input_stat.cmd_pos > len - 1) { input_stat.cmd_pos = len - 1; } }