(info): Print the info topics found when the abbreviation is not unique. Closes #1018302.
This commit is contained in:
parent
8fdd0259f2
commit
d40ea86b61
1 changed files with 48 additions and 8 deletions
|
@ -76,7 +76,9 @@ info(void)
|
||||||
struct stat statb;
|
struct stat statb;
|
||||||
struct dirent *dp;
|
struct dirent *dp;
|
||||||
s_char filename[1024];
|
s_char filename[1024];
|
||||||
|
s_char last[256];
|
||||||
DIR *info_dp;
|
DIR *info_dp;
|
||||||
|
int nmatch = 0;
|
||||||
|
|
||||||
name = player->argp[1];
|
name = player->argp[1];
|
||||||
if (name) {
|
if (name) {
|
||||||
|
@ -101,16 +103,34 @@ info(void)
|
||||||
return RET_SYS;
|
return RET_SYS;
|
||||||
}
|
}
|
||||||
|
|
||||||
while ((dp = readdir(info_dp)) != 0 && fp == 0) {
|
while ((dp = readdir(info_dp)) != 0) {
|
||||||
if (strncasecmp(name, dp->d_name, strlen(name)) != 0)
|
if (strncasecmp(name, dp->d_name, strlen(name)) != 0)
|
||||||
continue;
|
continue;
|
||||||
sprintf(filename, "%s/%s", infodir, dp->d_name);
|
nmatch++;
|
||||||
fp = fopen(filename, "r");
|
if (nmatch == 1) {
|
||||||
|
snprintf(last, sizeof(last), "%s", dp->d_name);
|
||||||
|
} else {
|
||||||
|
if (nmatch == 2)
|
||||||
|
pr("The following info topics were found %s", last);
|
||||||
|
pr(", %s", dp->d_name);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
closedir(info_dp);
|
closedir(info_dp);
|
||||||
if (fp == NULL) {
|
if (nmatch == 0) {
|
||||||
pr("Sorry, there is no info on %s\n", name);
|
pr("Sorry, there is no info on %s\n", name);
|
||||||
return RET_FAIL;
|
return RET_FAIL;
|
||||||
|
} else if (nmatch > 1) {
|
||||||
|
pr("\n");
|
||||||
|
return RET_FAIL;
|
||||||
|
}
|
||||||
|
snprintf(filename, sizeof(filename), "%s/%s", infodir,
|
||||||
|
last);
|
||||||
|
fp = fopen(filename, "r");
|
||||||
|
if (fp == NULL) {
|
||||||
|
pr("Error reading info file for %s\n", name);
|
||||||
|
logerror("Cannot open for \"%s\" info file (%s)",
|
||||||
|
filename, strerror(errno));
|
||||||
|
return RET_FAIL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (fstat(fileno(fp), &statb) < 0) {
|
if (fstat(fileno(fp), &statb) < 0) {
|
||||||
|
@ -253,6 +273,7 @@ info(void)
|
||||||
s_char *name;
|
s_char *name;
|
||||||
s_char *tmp_name;
|
s_char *tmp_name;
|
||||||
s_char filename[1024];
|
s_char filename[1024];
|
||||||
|
s_char last[256];
|
||||||
int nmatch = 0;
|
int nmatch = 0;
|
||||||
|
|
||||||
name = player->argp[1];
|
name = player->argp[1];
|
||||||
|
@ -302,14 +323,33 @@ info(void)
|
||||||
(fData.dwFileAttributes == FILE_ATTRIBUTE_ARCHIVE) ||
|
(fData.dwFileAttributes == FILE_ATTRIBUTE_ARCHIVE) ||
|
||||||
(fData.dwFileAttributes == FILE_ATTRIBUTE_READONLY)) &&
|
(fData.dwFileAttributes == FILE_ATTRIBUTE_READONLY)) &&
|
||||||
(strncasecmp(name, fData.cFileName, strlen(name)) == 0)) {
|
(strncasecmp(name, fData.cFileName, strlen(name)) == 0)) {
|
||||||
_snprintf(filename, sizeof(filename), "%s\\%s", infodir, fData.cFileName);
|
nmatch++;
|
||||||
fp = fopen(filename, "r");
|
if (nmatch == 1) {
|
||||||
|
_snprintf(last, sizeof(last), "%s", fData.cFileName);
|
||||||
|
} else {
|
||||||
|
if (nmatch == 2)
|
||||||
|
pr("The following info topics were found %s",
|
||||||
|
last);
|
||||||
|
pr(", %s", fData.cFileName);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} while (!fp && FindNextFile(hDir, &fData));
|
} while (FindNextFile(hDir, &fData));
|
||||||
FindClose(hDir);
|
FindClose(hDir);
|
||||||
if (fp == NULL) {
|
if (nmatch == 0) {
|
||||||
pr("Sorry, there is no info on %s\n", name);
|
pr("Sorry, there is no info on %s\n", name);
|
||||||
return RET_FAIL;
|
return RET_FAIL;
|
||||||
|
} else if (nmatch > 1) {
|
||||||
|
pr("\n");
|
||||||
|
return RET_FAIL;
|
||||||
|
}
|
||||||
|
_snprintf(filename, sizeof(filename), "%s/%s",
|
||||||
|
infodir, last);
|
||||||
|
fp = fopen(filename, "r");
|
||||||
|
if (fp == NULL) {
|
||||||
|
pr("Error reading info file for %s\n", name);
|
||||||
|
logerror("Cannot open for \"%s\" info file (%s)",
|
||||||
|
filename, strerror(errno));
|
||||||
|
return RET_FAIL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue