about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-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';
+}
+
+