]> pd.if.org Git - pd_readline/blobdiff - history.c
More work.
[pd_readline] / history.c
index f8a0d256d81c6b29b3a0ac7d4eb99c7508734088..dd70ed5797bfeb7196526333eb9e18b433708633 100644 (file)
--- a/history.c
+++ b/history.c
@@ -6,6 +6,11 @@
 /*  "Share and enjoy...."  ;)                          */  
 /*  See the UNLICENSE file for details.                */ 
 
+#include <string.h>   
+#include <stdio.h> 
+#include <stdlib.h> 
+#include <malloc.h>
+#include "pd_readline.h"  
 
 
 /*  Helper function, to let us see if a file */ 
@@ -36,9 +41,13 @@ char hist[20][80];
 
 
 
-/* Read the file into the array of strings.  */ 
-void readhistory(char *fname) 
+/* Read the file into the array of strings.                */ 
+buf readhistory(char *fname) 
 { 
+       
+   /*  Create a history buffer.  */ 
+   buf h;      
+       
    int retval = fexists(fname); 
         
    int i; 
@@ -48,18 +57,35 @@ void readhistory(char *fname)
          /* append new commands to it. */ 
          FILE *fptr;  
          fptr = fopen(fname, "rw"); 
-                          
+               
+      char line[80] ; 
+                                          
          for(i=0; i<20; i++)  
-         {  
-               chop(fgets(hist[i], 80, fptr) );  
+         { 
+               fgets(line, 80, fptr);                   
+               chop(line) ;   
+               memcpy(hist[i], line, 80) ;   
+               puts(hist[i]); 
          }
          
    }  /* retval == 0  */          
        
        else puts("Error! File does not exist. \n");  
        
+       /* Read the most recent command into histbuf */ 
+       /* and set the index to 19.                  */
+       /*  
+           h.index = 19; 
+        h.array = hist[h.index] ;  
+    */
+       
+       return h;
+       
 }      
 
+                                           
+