1
0
mirror of https://git.FreeBSD.org/src.git synced 2024-12-11 09:50:12 +00:00

Add support for non-numeric key lookup via the 'cmds' file, by using the key

base as the key number.
This commit is contained in:
Juli Mallett 2002-06-04 06:14:11 +00:00
parent 22ed0c9ade
commit 6aab7a863f
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=97796

View File

@ -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;
}