From 30dbbad54422aaf3544f9701a27933b3acbcc092 Mon Sep 17 00:00:00 2001 From: James Booth Date: Wed, 2 May 2012 02:14:29 +0100 Subject: Refactored history --- history.c | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/history.c b/history.c index a7b570f8..a98a47fd 100644 --- a/history.c +++ b/history.c @@ -29,6 +29,8 @@ static PHistory history; +void _stringify_input(char *inp, int size, char *string); + void history_init(void) { history = p_history_new(MAX_HISTORY); @@ -42,24 +44,26 @@ void history_append(char *inp) char * history_previous(char *inp, int *size) { char inp_str[*size + 1]; - int i; - for (i = 0; i < *size; i++) { - inp_str[i] = inp[i]; - } - inp_str[*size] = '\0'; - + _stringify_input(inp, *size, inp_str); + return p_history_previous(history, inp_str); } char *history_next(char *inp, int *size) { char inp_str[*size + 1]; - int i; - for (i = 0; i < *size; i++) { - inp_str[i] = inp[i]; - } - inp_str[*size] = '\0'; + _stringify_input(inp, *size, inp_str); return p_history_next(history, inp_str); } +void _stringify_input(char *inp, int size, char *string) +{ + int i; + for (i = 0; i < size; i++) { + string[i] = inp[i]; + } + string[size] = '\0'; +} + + -- cgit 1.4.1-2-gfad0