diff --git a/CHANGES b/CHANGES index 324665d..1f6667f 100644 --- a/CHANGES +++ b/CHANGES @@ -243,6 +243,11 @@ The following are the changes from calc version 2.13.0.1 to 2.13.0.1: Updated HOWTO.INSTALL to mention Makefile.local. + Fizzbin is better. :-) + + The help and man builtin commands now return an error when a + help file cannot be opened, such as when there is no help file. + The following are the changes from calc version 2.13.0.0 to 2.13.0.0: diff --git a/help.c b/help.c index c236e9d..3f8145f 100644 --- a/help.c +++ b/help.c @@ -29,6 +29,7 @@ #include #include #include +#include #include "calc.h" #include "conf.h" @@ -262,6 +263,7 @@ givehelp(char *type) } snprintf(helppath, snprintf_len, "%s/%s", calc_helpdir, type); helppath[snprintf_len] = '\0'; /* paranoia */ + errno = 0; stream = fopen(helppath, "r"); if (stream != NULL) { @@ -276,30 +278,42 @@ givehelp(char *type) * open the helpfile (looking in CUSTOMHELPDIR last) */ } else { - char *cust_helppath; /* path to the custom help file */ - size_t cust_snprintf_len; /* malloced custom snprintf buf len */ + char *cust_helppath; /* path to the custom help file */ + size_t cust_snprintf_len; /* malloced custom snprintf buf len */ - cust_snprintf_len = strlen(calc_customhelpdir)+1+strlen(type) + 1; - cust_helppath = (char *)malloc(cust_snprintf_len+1); - if (cust_helppath == NULL) { - fprintf(stderr, "malloc failure for givehelp #1\n"); - return; - } - snprintf(cust_helppath, cust_snprintf_len, - "%s/%s", calc_customhelpdir, type); - cust_helppath[cust_snprintf_len] = '\0'; /* paranoia */ - stream = fopen(cust_helppath, "r"); - if (stream != NULL) { + cust_snprintf_len = + strlen(calc_customhelpdir)+1+strlen(type) + 1; + cust_helppath = (char *)malloc(cust_snprintf_len+1); + if (cust_helppath == NULL) { + fprintf(stderr, "malloc failure for givehelp #1\n"); + return; + } + snprintf(cust_helppath, cust_snprintf_len, + "%s/%s", calc_customhelpdir, type); + cust_helppath[cust_snprintf_len] = '\0'; /* paranoia */ + errno = 0; + stream = fopen(cust_helppath, "r"); + if (stream != NULL) { - /* - * we have the help file open, now display it - */ - page_file(stream); - (void) fclose(stream); - } - free(cust_helppath); - cust_helppath = NULL; + /* + * we have the help file open, now display it + */ + page_file(stream); + (void) fclose(stream); + /* unable to open help file */ + } else { + fprintf(stderr, "unable to open help file: %s - %s\n", + type, strerror(errno)); + } + free(cust_helppath); + cust_helppath = NULL; + +#else /* CUSTOM */ + /* unable to open help file */ + } else { + fprintf(stderr, "unable to open help file: %s - %s\n", + type, strerror(errno)); #endif /* CUSTOM */ }