static void history_up(t_tokenline *tl) { int entry; if (tl->hist_step == -1) entry = history_previous(tl, tl->hist_end); else entry = history_previous(tl, tl->hist_step); if (entry == -1) return; line_clear(tl); set_line(tl, tl->hist_buf + entry); tl->hist_step = entry; }
static edit_status editor_history_previous (rp_input_line *line) { const char *entry = history_previous (line->history_id); if (entry) { if (!saved_command) { line->buffer[line->length] = '\0'; saved_command = xstrdup (line->buffer); PRINT_DEBUG (("saved current command line: \'%s\'\n", saved_command)); } free (line->buffer); line->buffer = xstrdup (entry); line->length = strlen (line->buffer); line->size = line->length + 1; line->position = line->length; PRINT_DEBUG (("entry: \'%s\'\n", line->buffer)); } else { PRINT_DEBUG (("- do nothing -\n")); return EDIT_NO_OP; } return EDIT_INSERT; }
static void history_show(t_tokenline *tl) { int entry, i; /* Skip the 'history' command itself. */ entry = history_previous(tl, tl->hist_end); for (entry = history_previous(tl, entry); entry != -1; entry = history_previous(tl, entry)) { tl->print(tl->user, tl->hist_buf + entry); /* Did we drop off the end of the buffer? */ for (i = entry; i < TL_MAX_HISTORY_SIZE; i++) { if (!tl->hist_buf[i]) break; } if (i == TL_MAX_HISTORY_SIZE) /* Yes we did */ tl->print(tl->user, tl->hist_buf); tl->print(tl->user, NL); } }