]> git.pond.sub.org Git - empserver/blobdiff - src/lib/commands/rea.c
Fix trailing whitespace
[empserver] / src / lib / commands / rea.c
index 047d614a7d371c4eabf24c6842f61db112ba0093..5de2bb2b9849227589d5975bcab98bd0056f7c0a 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *  Empire - A multi-player, client/server Internet based war game.
- *  Copyright (C) 1986-2005, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ *  Copyright (C) 1986-2008, Dave Pare, Jeff Bailey, Thomas Ruschak,
  *                           Ken Stevens, Steve McClure
  *
  *  This program is free software; you can redistribute it and/or modify
  *
  *  ---
  *
- *  See the "LEGAL", "LICENSE", "CREDITS" and "README" files for all the
- *  related information and legal notices. It is expected that any future
- *  projects/authors will amend these files as needed.
+ *  See files README, COPYING and CREDITS in the root of the source
+ *  tree for related information and legal notices.  It is expected
+ *  that future projects/authors will amend these files as needed.
  *
  *  ---
  *
  *  rea.c: Read telegrams
- * 
+ *
  *  Known contributors to this file:
  *     Dave Pare
  *     Doug Hay, 1998
  *     Steve McClure, 1998-2000
  */
 
-#include "misc.h"
-#include "player.h"
-#include "nat.h"
-#include "file.h"
-#include "tel.h"
-#include "commands.h"
-#include "optlist.h"
-#include "match.h"
+#include <config.h>
 
+#include <ctype.h>
 #include <stdio.h>
-#include <fcntl.h>
-#if !defined(_WIN32)
-#include <sys/file.h>
-#endif
+#include "commands.h"
+#include "match.h"
+#include "misc.h"
+#include "optlist.h"
+#include "tel.h"
 
 int
 rea(void)
 {
-    static s_char *telnames[] = {
+    static char *telnames[] = {
        /* must follow TEL_ defines in tel.h */
        "Telegram", "Announcement", "BULLETIN", "Production Report"
     };
-    register s_char *p;
-    register s_char *mbox;
-    s_char mbox_buf[256];      /* Maximum path length */
+    char *p;
+    char *mbox;
+    char mbox_buf[256];                /* Maximum path length */
     struct telstr tgm;
     FILE *telfp;
     int teles;
     int size;
-    unsigned int nbytes;
-    s_char buf[4096]; /* buf is message text */
+    unsigned nbytes;
+    char buf[1024];
+    char msgbuf[4096];         /* UTF-8 */
     int lasttype;
     int lastcnum;
     time_t lastdate;
     int header;
     int filelen;
-    s_char kind[80];
+    char *kind;
     int n;
     int num = player->cnum;
     struct natstr *np = getnatp(player->cnum);
@@ -80,11 +76,10 @@ rea(void)
     int readit;
     int may_delete = 1; /* may messages be deleted? */
 
-    memset(kind, 0, sizeof(kind));
     now = time(NULL);
 
     if (*player->argp[0] == 'w') {
-       strcpy(kind, "announcement");
+       kind = "announcement";
        if (player->argp[1] && isdigit(*player->argp[1])) {
            delta = days(atoi(player->argp[1]));
            then = now - delta;
@@ -93,11 +88,11 @@ rea(void)
            then = np->nat_annotim;
        mbox = annfil;
     } else {
-       strcpy(kind, "telegram");
+       kind = "telegram";
        if (player->god && player->argp[1] &&
            (mineq(player->argp[1], "yes") == ME_MISMATCH) &&
            (mineq(player->argp[1], "no") == ME_MISMATCH)) {
-           if ((n = natarg(player->argp[1], "")) < 0)
+           if ((n = natarg(player->argp[1], NULL)) < 0)
                return RET_SYN;
            num = n;
            may_delete = 0;
@@ -163,16 +158,15 @@ rea(void)
       skip:
        while (tgm.tel_length > 0) {
            nbytes = tgm.tel_length;
-           if (nbytes > sizeof(buf) - 1)
-               nbytes = sizeof(buf) - 1;
-           (void)fread(buf, sizeof(s_char), nbytes, telfp);
-           buf[nbytes] = 0;
+           if (nbytes > sizeof(msgbuf) - 1)
+               nbytes = sizeof(msgbuf) - 1;
+           fread(msgbuf, 1, nbytes, telfp);
+           msgbuf[nbytes] = 0;
            if (readit)
-               uprnf(buf);
+               uprnf(msgbuf);
            tgm.tel_length -= nbytes;
        }
     }
-    p = NULL;
     if (teles > 0 && player->cnum == num && may_delete) {
        pr("\n");
        if (teles == 1) {
@@ -204,7 +198,7 @@ rea(void)
                /* Here, we just re-open the file for "w" only,
                   and that will wipe the file clean automatically */
                (void)fclose(telfp);
-               telfp = fopen((char *)mbox, "wb");
+               telfp = fopen(mbox, "wb");
            }
        }
     }