X-Git-Url: http://git.pond.sub.org/?p=empserver;a=blobdiff_plain;f=src%2Flib%2Fcommands%2Finfo.c;h=961ad606b4c93c330d5783f15bd1effd644ca36e;hp=42ba1e313be420bd3528e7435b45b49ae98d0d75;hb=7b9e579408306be4f37ac26fd6c349841dcf11dd;hpb=2a0597be8ff610ed4058d6faae2141f4616f1f3f diff --git a/src/lib/commands/info.c b/src/lib/commands/info.c index 42ba1e313..961ad606b 100644 --- a/src/lib/commands/info.c +++ b/src/lib/commands/info.c @@ -1,11 +1,11 @@ /* * 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, @@ -14,8 +14,7 @@ * 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 . * * --- * @@ -26,7 +25,7 @@ * --- * * info.c: display an info page - * + * * Known contributors to this file: * Dave Pare, 1986 * Mike Wise, 1997 - added apropos and case insensitivity @@ -42,9 +41,8 @@ #include #include #if !defined(_WIN32) +#include #include -#else -#include #endif #include "commands.h" #include "optlist.h" @@ -79,7 +77,7 @@ info(void) int nmatch = 0; int width = 0; char sep; - + name = player->argp[1]; if (name) { /* @@ -90,19 +88,19 @@ info(void) } 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++; @@ -131,8 +129,7 @@ info(void) 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); @@ -146,17 +143,16 @@ info(void) 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; @@ -177,7 +173,7 @@ apro(void) 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; } @@ -191,9 +187,9 @@ apro(void) 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); @@ -210,11 +206,10 @@ apro(void) * 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; @@ -225,7 +220,7 @@ apro(void) 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); @@ -306,7 +301,7 @@ info(void) 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, "*"); @@ -315,7 +310,6 @@ info(void) 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"); @@ -324,9 +318,9 @@ info(void) 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) && @@ -361,8 +355,7 @@ info(void) 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); @@ -370,8 +363,7 @@ info(void) filename, strerror(errno)); return RET_FAIL; } - } - else { + } else { DWORD fAttrib = GetFileAttributes(filename); if ((fAttrib == (DWORD)-1) || /* INVALID_FILE_ATTRIBUTES */ ((fAttrib != FILE_ATTRIBUTE_NORMAL) && @@ -381,11 +373,10 @@ info(void) 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); @@ -418,7 +409,7 @@ apro(void) 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) { @@ -427,9 +418,9 @@ apro(void) } 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); @@ -452,7 +443,7 @@ apro(void) (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;