5 /* This code is released to the public domain. */
6 /* "Share and enjoy...." ;) */
7 /* See the UNLICENSE file for details. */
13 #include "pd_readline.h"
16 /* Helper function, to let us see if a file */
17 /* exists in the current directory. */
18 int fexists(char *fname)
21 fptr = fopen(fname, "r") ;
22 if ( !fptr ) return -1 ; /* File does not exist in dir. */
24 return 0; /* File DOES exist in dir. */
28 /* Helper function to chop newlines off the lines read in. */
29 /* Without this being done, an extra newline is inserted */
30 /* (which is usually not what is wanted). */
33 s[strcspn(s,"\n")] = '\0';
39 /* Read the file into the array of strings. */
40 hist readhistory(char *fname)
43 /* Create a history buffer. */
46 int retval = fexists(fname);
50 /* File exists, so open it. */
51 /* We open it in read-write mode so we can */
52 /* append new commands to it. */
54 fptr = fopen(fname, "rw");
60 fgets(line, 80, fptr);
63 /* TO DO: fix the "too few arguments" bug here.... */
64 memcpy(&h.array[i], line, 80) ;
70 else puts("Error! File does not exist. \n");
72 /* Set the curindex to 19. */