about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2012-05-02 02:14:29 +0100
committerJames Booth <boothj5@gmail.com>2012-05-02 02:14:29 +0100
commit30dbbad54422aaf3544f9701a27933b3acbcc092 (patch)
tree51eb351bb1b8ad96e7204b788021a8189e88cd80
parent5fe3b1ff7990954ec3822f7a41d8ac84df221186 (diff)
downloadprofani-tty-30dbbad54422aaf3544f9701a27933b3acbcc092.tar.gz
Refactored history
-rw-r--r--history.c26
1 files 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';
+}
+
+