mirror of
https://github.com/lcn2/calc.git
synced 2025-08-16 01:03:29 +03:00
Improved help error messages
The help and man commands now issue an error message when the help file cannot be opened: say because there is a help command typo and there is no such help file.
This commit is contained in:
5
CHANGES
5
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.
|
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:
|
The following are the changes from calc version 2.13.0.0 to 2.13.0.0:
|
||||||
|
|
||||||
|
16
help.c
16
help.c
@@ -29,6 +29,7 @@
|
|||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
|
#include <sys/errno.h>
|
||||||
|
|
||||||
#include "calc.h"
|
#include "calc.h"
|
||||||
#include "conf.h"
|
#include "conf.h"
|
||||||
@@ -262,6 +263,7 @@ givehelp(char *type)
|
|||||||
}
|
}
|
||||||
snprintf(helppath, snprintf_len, "%s/%s", calc_helpdir, type);
|
snprintf(helppath, snprintf_len, "%s/%s", calc_helpdir, type);
|
||||||
helppath[snprintf_len] = '\0'; /* paranoia */
|
helppath[snprintf_len] = '\0'; /* paranoia */
|
||||||
|
errno = 0;
|
||||||
stream = fopen(helppath, "r");
|
stream = fopen(helppath, "r");
|
||||||
if (stream != NULL) {
|
if (stream != NULL) {
|
||||||
|
|
||||||
@@ -279,7 +281,8 @@ givehelp(char *type)
|
|||||||
char *cust_helppath; /* path to the custom help file */
|
char *cust_helppath; /* path to the custom help file */
|
||||||
size_t cust_snprintf_len; /* malloced custom snprintf buf len */
|
size_t cust_snprintf_len; /* malloced custom snprintf buf len */
|
||||||
|
|
||||||
cust_snprintf_len = strlen(calc_customhelpdir)+1+strlen(type) + 1;
|
cust_snprintf_len =
|
||||||
|
strlen(calc_customhelpdir)+1+strlen(type) + 1;
|
||||||
cust_helppath = (char *)malloc(cust_snprintf_len+1);
|
cust_helppath = (char *)malloc(cust_snprintf_len+1);
|
||||||
if (cust_helppath == NULL) {
|
if (cust_helppath == NULL) {
|
||||||
fprintf(stderr, "malloc failure for givehelp #1\n");
|
fprintf(stderr, "malloc failure for givehelp #1\n");
|
||||||
@@ -288,6 +291,7 @@ givehelp(char *type)
|
|||||||
snprintf(cust_helppath, cust_snprintf_len,
|
snprintf(cust_helppath, cust_snprintf_len,
|
||||||
"%s/%s", calc_customhelpdir, type);
|
"%s/%s", calc_customhelpdir, type);
|
||||||
cust_helppath[cust_snprintf_len] = '\0'; /* paranoia */
|
cust_helppath[cust_snprintf_len] = '\0'; /* paranoia */
|
||||||
|
errno = 0;
|
||||||
stream = fopen(cust_helppath, "r");
|
stream = fopen(cust_helppath, "r");
|
||||||
if (stream != NULL) {
|
if (stream != NULL) {
|
||||||
|
|
||||||
@@ -296,10 +300,20 @@ givehelp(char *type)
|
|||||||
*/
|
*/
|
||||||
page_file(stream);
|
page_file(stream);
|
||||||
(void) fclose(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);
|
free(cust_helppath);
|
||||||
cust_helppath = NULL;
|
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 */
|
#endif /* CUSTOM */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user