From a6a057aabb423d77fe9736daf7a9a7905119768c Mon Sep 17 00:00:00 2001 From: jmallett Date: Tue, 4 Jun 2002 06:14:11 +0000 Subject: Add support for non-numeric key lookup via the 'cmds' file, by using the key base as the key number. --- usr.bin/help/help.c | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) (limited to 'usr.bin') 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; } -- cgit v1.1