X-Git-Url: https://pd.if.org/git/?p=pd_readline;a=blobdiff_plain;f=history.c;h=498cbe8e86af1a9267a7b4c9b89374fe1fa4df50;hp=f8a0d256d81c6b29b3a0ac7d4eb99c7508734088;hb=d56fdb0ce92c92e27ef45a8315ff26c272a1f23d;hpb=36403b46c9eec27a672b0cfbfad9a79c7d153dca diff --git a/history.c b/history.c index f8a0d25..498cbe8 100644 --- a/history.c +++ b/history.c @@ -6,6 +6,11 @@ /* "Share and enjoy...." ;) */ /* See the UNLICENSE file for details. */ +#include +#include +#include +#include +#include "pd_readline.h" /* Helper function, to let us see if a file */ @@ -30,15 +35,14 @@ char *chop(char *s) } -/* An array to store the command-history file in. */ -/* Only 20 lines are read. */ -char hist[20][80]; - - -/* Read the file into the array of strings. */ -void readhistory(char *fname) +/* Read the file into the array of strings. */ +hist readhistory(char *fname) { + + /* Create a history buffer. */ + hist h; + int retval = fexists(fname); int i; @@ -48,18 +52,33 @@ 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) ; + + /* TO DO: fix the "too few arguments" bug here.... */ + memcpy(&h.array[i], line, 80) ; + puts(h.array[i]); } } /* retval == 0 */ else puts("Error! File does not exist. \n"); + + /* Set the curindex to 19. */ + h.curindex = 19; + + return h; } + + +