5 /* This code is released to the public domain. */
6 /* "Share and enjoy...." ;) */
7 /* See the UNLICENSE file for details. */
11 /* Helper function, to let us see if a file */
12 /* exists in the current directory. */
13 int fexists(char *fname)
16 fptr = fopen(fname, "r") ;
17 if ( !fptr ) return -1 ; /* File does not exist in dir. */
19 return 0; /* File DOES exist in dir. */
23 /* Helper function to chop newlines off the lines read in. */
24 /* Without this being done, an extra newline is inserted */
25 /* (which is usually not what is wanted). */
28 s[strcspn(s,"\n")] = '\0';
33 /* An array to store the command-history file in. */
34 /* Only 20 lines are read. */
39 /* Read the file into the array of strings. */
40 void readhistory(char *fname)
42 int retval = fexists(fname);
46 /* File exists, so open it. */
47 /* We open it in read-write mode so we can */
48 /* append new commands to it. */
50 fptr = fopen(fname, "rw");
54 chop(fgets(hist[i], 80, fptr) );
59 else puts("Error! File does not exist. \n");