X-Git-Url: https://pd.if.org/git/?p=pd_readline;a=blobdiff_plain;f=history.c;fp=history.c;h=0000000000000000000000000000000000000000;hp=498cbe8e86af1a9267a7b4c9b89374fe1fa4df50;hb=050f646dd55e7fef8b2d0dcf5d1740ea8484f9c1;hpb=d56fdb0ce92c92e27ef45a8315ff26c272a1f23d diff --git a/history.c b/history.c deleted file mode 100644 index 498cbe8..0000000 --- a/history.c +++ /dev/null @@ -1,84 +0,0 @@ - - -/* history.c */ -/* Command history. */ -/* This code is released to the public domain. */ -/* "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 */ -/* exists in the current directory. */ -int fexists(char *fname) -{ - FILE *fptr; - fptr = fopen(fname, "r") ; - if ( !fptr ) return -1 ; /* File does not exist in dir. */ - fclose(fptr); - return 0; /* File DOES exist in dir. */ -} - - -/* Helper function to chop newlines off the lines read in. */ -/* Without this being done, an extra newline is inserted */ -/* (which is usually not what is wanted). */ -char *chop(char *s) -{ - s[strcspn(s,"\n")] = '\0'; - return s; -} - - - -/* Read the file into the array of strings. */ -hist readhistory(char *fname) -{ - - /* Create a history buffer. */ - hist h; - - int retval = fexists(fname); - - int i; - if (retval == 0) { - /* File exists, so open it. */ - /* We open it in read-write mode so we can */ - /* append new commands to it. */ - FILE *fptr; - fptr = fopen(fname, "rw"); - - char line[80] ; - - for(i=0; i<20; i++) - { - 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; - -} - - - - - - -