summaryrefslogtreecommitdiffstats
path: root/usr.bin
diff options
context:
space:
mode:
authorjmallett <jmallett@FreeBSD.org>2002-06-04 06:14:11 +0000
committerjmallett <jmallett@FreeBSD.org>2002-06-04 06:14:11 +0000
commita6a057aabb423d77fe9736daf7a9a7905119768c (patch)
tree6c804bf0a9c4762a26231961f0b6ed492a6708b8 /usr.bin
parentd943c30f90b901f9ad306fdb1cf1ab98c9097827 (diff)
downloadFreeBSD-src-a6a057aabb423d77fe9736daf7a9a7905119768c.zip
FreeBSD-src-a6a057aabb423d77fe9736daf7a9a7905119768c.tar.gz
Add support for non-numeric key lookup via the 'cmds' file, by using the key
base as the key number.
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/help/help.c24
1 files changed, 18 insertions, 6 deletions
diff --git a/usr.bin/help/help.c b/usr.bin/help/help.c
index 91e7f89..05667ce 100644
--- a/usr.bin/help/help.c
+++ b/usr.bin/help/help.c
@@ -33,6 +33,11 @@ __FBSDID("$FreeBSD$");
*/
#define _PATH_DEFAULT _PATH_LIBHELP "/default"
+/*
+ * The file we check for command help.
+ */
+#define _PATH_COMMANDS _PATH_LIBHELP "/cmds"
+
int help(const char *);
int
@@ -103,20 +108,21 @@ help(const char *key)
keynumber = key;
key = keyname;
*p = '\0';
+ numlen = strlen(keynumber);
/*
* Try the default help file if we have a numeric key.
+ * If we have no numeric part of the key, use the command help.
* Or else, use the non-numeric part of the key.
*/
if (strlen(keybase) == 0) {
strlcpy(path, _PATH_DEFAULT, sizeof(path));
+ } else if (numlen == 0) {
+ keynumber = keybase;
+ numlen = strlen(keynumber);
+ strlcpy(path, _PATH_COMMANDS, sizeof(path));
} else {
snprintf(path, sizeof(path), _PATH_LIBHELP "/%s", keybase);
}
- free(keybase);
- numlen = strlen(keynumber);
- if (!numlen) {
- goto fail;
- }
helpfile = fopen(path, "r");
if (helpfile == NULL) {
@@ -127,7 +133,7 @@ help(const char *key)
case '*':
continue;
case '-':
- if (len < numlen + 1) {
+ if (len < numlen) {
continue;
}
if (strncmp(++p, keynumber, numlen) == 0) {
@@ -147,10 +153,16 @@ help(const char *key)
}
}
fclose(helpfile);
+ if (keybase != NULL) {
+ free(keybase);
+ }
if (found) {
return 0;
}
fail:
+ if (keybase != NULL) {
+ free(keybase);
+ }
printf("Key '%s' not found.\n", key);
return 1;
}
OpenPOWER on IntegriCloud