5 /* This code is released to the public domain. */
6 /* "Share and enjoy...." ;) */
7 /* See the UNLICENSE file for details. */
14 /* Helper function, to let us see if a file */
15 /* exists in the current directory. */
16 int fexists(char *fname)
19 fptr = fopen(fname, "r") ;
20 if ( !fptr ) return -1 ; /* File does not exist in dir. */
22 return 0; /* File DOES exist in dir. */
26 /* Helper function to chop newlines off the lines read in. */
27 /* Without this being done, an extra newline is inserted */
28 /* (which is usually not what is wanted). */
31 s[strcspn(s,"\n")] = '\0';
36 /* An array to store the command-history file in. */
37 /* Only 20 lines are read. */
42 /* Read the file into the array of strings. */
43 void readhistory(char *fname)
45 int retval = fexists(fname);
49 /* File exists, so open it. */
50 /* We open it in read-write mode so we can */
51 /* append new commands to it. */
53 fptr = fopen(fname, "rw");
57 chop(fgets(hist[i], 80, fptr) );
62 else puts("Error! File does not exist. \n");