#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 */
}
-/* 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. */
-/* TO DO - look at reading file into a series of structs. */
-
-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;
/* 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;
}
-
-/* TO DO - a function that reads in the 2d history array, and */
-/* returns a struct with one line from the array, and the index */
-/* of the line. */
+