/*
* Empire - A multi-player, client/server Internet based war game.
- * Copyright (C) 1986-2007, Dave Pare, Jeff Bailey, Thomas Ruschak,
- * Ken Stevens, Steve McClure
+ * Copyright (C) 1986-2020, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ * Ken Stevens, Steve McClure, Markus Armbruster
*
- * This program is free software; you can redistribute it and/or modify
+ * Empire is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
+ * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* ---
*
* ---
*
* info.c: display an info page
- *
+ *
* Known contributors to this file:
* Dave Pare, 1986
* Mike Wise, 1997 - added apropos and case insensitivity
#include <ctype.h>
#include <errno.h>
#include <sys/stat.h>
+#include <stdio.h>
#if !defined(_WIN32)
+#include <strings.h>
#include <dirent.h>
-#else
-#include <windows.h>
#endif
#include "commands.h"
#include "optlist.h"
int nmatch = 0;
int width = 0;
char sep;
-
+
name = player->argp[1];
if (name) {
/*
}
if (!name || !*name)
name = "TOP";
-
+
snprintf(filename, sizeof(filename), "%s/%s", infodir, name);
fp = fopen(filename, "r");
if (fp == NULL) {
- /* may be a "partial" request. */
+ /* may be a "partial" request. */
info_dp = opendir(infodir);
- if (info_dp == 0) {
+ if (!info_dp) {
pr("Can't open info dir\n");
logerror("Can't open info dir \"%s\"\n", infodir);
- return RET_SYS;
+ return RET_FAIL;
}
- while ((dp = readdir(info_dp)) != 0) {
+ while ((dp = readdir(info_dp))) {
if (strncasecmp(name, dp->d_name, strlen(name)) != 0)
continue;
nmatch++;
pr(".\n");
return RET_FAIL;
}
- snprintf(filename, sizeof(filename), "%s/%s", infodir,
- last);
+ 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 fstat for \"%s\" info file (%s)",
filename, strerror(errno));
fclose(fp);
- return RET_SYS;
+ return RET_FAIL;
}
- if ((statb.st_mode & S_IFREG) == 0) {
+ if (!S_ISREG(statb.st_mode)) {
pr("Error reading info file for %s\n", name);
logerror("The info file \"%s\" is not regular file\n", filename);
fclose(fp);
- return RET_SYS;
+ return RET_FAIL;
}
- pr("Information on: %s Last modification date: %s",
- name, ctime(&statb.st_mtime));
- while (fgets(buf, sizeof(buf), fp) != 0)
+
+ while (fgets(buf, sizeof(buf), fp))
pr("%s", buf);
(void)fclose(fp);
return RET_OK;
int lhitlim;
struct stat statb;
- if (player->argp[1] == 0 || !*player->argp[1]) {
+ if (!player->argp[1] || !*player->argp[1]) {
pr("Apropos what?\n");
return RET_FAIL;
}
info_dp = opendir(infodir);
if (info_dp == NULL) {
- pr("Can't open info dir \n");
+ pr("Can't open info dir\n");
logerror("Can't open info dir \"%s\"", infodir);
- return RET_SYS;
+ return RET_FAIL;
}
fbuf = malloc(256);
* search
*/
nf = nhf = nl = nhl = 0;
- while ((dp = readdir(info_dp)) != 0) {
+ while ((dp = readdir(info_dp))) {
if (dp->d_name[0] == '.')
continue;
- snprintf(filename, sizeof(filename), "%s/%s", infodir,
- dp->d_name);
+ snprintf(filename, sizeof(filename), "%s/%s", infodir, dp->d_name);
fp = fopen(filename, "r");
alreadyhit = 0;
nll = nlhl = 0;
fclose(fp);
continue;
}
- if ((statb.st_mode & S_IFREG) == 0) {
+ if (!S_ISREG(statb.st_mode)) {
logerror("The info file \"%s\" is not regular file\n",
filename);
fclose(fp);
snprintf(filename, sizeof(filename) - 1, "%s\\%s", infodir, name);
fp = fopen(filename, "rb");
if (fp == NULL) {
- /* may be a "partial" request. */
+ /* may be a "partial" request. */
HANDLE hDir;
WIN32_FIND_DATA fData;
strcat(filename, "*");
switch (GetLastError()) {
case ERROR_FILE_NOT_FOUND:
pr("Sorry, there is no info on %s\n", name);
- return RET_FAIL;
break;
case ERROR_PATH_NOT_FOUND:
pr("Can't open info dir\n");
default:
pr("Error reading info dir\n");
logerror("Error (%lu) reading info dir(%s)\\file(%s)",
- GetLastError(), infodir, filename);
+ GetLastError(), infodir, filename);
}
- return RET_SYS;
+ return RET_FAIL;
}
do {
if ((fData.dwFileAttributes != (DWORD)-1) &&
pr(".\n");
return RET_FAIL;
}
- snprintf(filename, sizeof(filename), "%s/%s",
- infodir, last);
+ snprintf(filename, sizeof(filename), "%s/%s", infodir, last);
fp = fopen(filename, "rb");
if (fp == NULL) {
pr("Error reading info file for %s\n", name);
filename, strerror(errno));
return RET_FAIL;
}
- }
- else {
+ } else {
DWORD fAttrib = GetFileAttributes(filename);
if ((fAttrib == (DWORD)-1) || /* INVALID_FILE_ATTRIBUTES */
((fAttrib != FILE_ATTRIBUTE_NORMAL) &&
logerror("The info file \"%s\" is not regular file\n",
filename);
fclose(fp);
- return RET_SYS;
+ return RET_FAIL;
}
}
- pr("Information on: %s", name);
while (fgets(buf, sizeof(buf), fp) != 0)
pr("%s", buf);
(void)fclose(fp);
lhitlim = 100;
}
- snprintf(filename, sizeof(filename), "%s\\*",infodir);
+ snprintf(filename, sizeof(filename), "%s\\*", infodir);
hDir = FindFirstFile(filename, &fData);
if (hDir == INVALID_HANDLE_VALUE) {
if (GetLastError() == ERROR_PATH_NOT_FOUND) {
} else {
pr("Error reading info dir\n");
logerror("Error (%lu) reading info dir(%s)\\file(%s)",
- GetLastError(), infodir, filename);
+ GetLastError(), infodir, filename);
}
- return RET_SYS;
+ return RET_FAIL;
}
fbuf = malloc(256);
(fData.dwFileAttributes == FILE_ATTRIBUTE_ARCHIVE) ||
(fData.dwFileAttributes == FILE_ATTRIBUTE_READONLY))) {
snprintf(filename, sizeof(filename), "%s\\%s", infodir,
- fData.cFileName);
+ fData.cFileName);
fp = fopen(filename, "rb");
alreadyhit = 0;
nll = nlhl = 0;