]> git.pond.sub.org Git - empserver/blobdiff - src/lib/subs/pr.c
Update copyright notice
[empserver] / src / lib / subs / pr.c
index 5cf6833d7e11d76b54b74f5dc2ff5af9a09c9f02..db8943acc438562462378ac771676a1157ca1d3f 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *  Empire - A multi-player, client/server Internet based war game.
- *  Copyright (C) 1986-2011, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ *  Copyright (C) 1986-2016, Dave Pare, Jeff Bailey, Thomas Ruschak,
  *                Ken Stevens, Steve McClure, Markus Armbruster
  *
  *  Empire is free software: you can redistribute it and/or modify
@@ -30,7 +30,7 @@
  *     Dave Pare, 1986, 1989
  *     Steve McClure, 1998-2000
  *     Ron Koenderink, 2005
- *     Markus Armbruster, 2005-2011
+ *     Markus Armbruster, 2005-2012
  */
 
 /*
@@ -52,7 +52,6 @@
 
 #include <stdarg.h>
 #include <stdlib.h>
-#include "com.h"
 #include "empio.h"
 #include "file.h"
 #include "journal.h"
 #include "proto.h"
 #include "prototypes.h"
 #include "server.h"
-#include "tel.h"
 #include "xy.h"
 
 static void pr_player(struct player *pl, int id, char *buf);
 static void upr_player(struct player *pl, int id, char *buf);
 static void outid(struct player *pl, int n);
+static void player_output_some(void);
 
 /*
  * Print to current player similar to printf().
- * Use printf-style FORMAT with the optional arguments.
+ * Use printf-style @format with the optional arguments.
  * Note: `to print' without further qualifications means sending
  * C_DATA text.
  */
@@ -93,7 +92,7 @@ pr(char *format, ...)
 }
 
 /*
- * Print UTF-8 text BUF to current player.
+ * Print UTF-8 text @buf to current player.
  */
 void
 uprnf(char *buf)
@@ -110,8 +109,8 @@ uprnf(char *buf)
 }
 
 /*
- * Send some text to P with id ID, line-buffered.
- * Format text to send using printf-style FORMAT and optional
+ * Send some text to @p with id @id, line-buffered.
+ * Format text to send using printf-style @format and optional
  * arguments.  It is assumed to be already user text.  Plain ASCII and
  * text received from the same player are fine, for anything else the
  * caller has to deal with output filtering.
@@ -135,8 +134,8 @@ pr_id(struct player *p, int id, char *format, ...)
 }
 
 /*
- * Send C_FLASH text to PL.
- * Format text to send using printf-style FORMAT and optional
+ * Send C_FLASH text to @pl.
+ * Format text to send using printf-style @format and optional
  * arguments.  It is assumed to be UTF-8.
  * Initiate an output queue flush, but do not wait for it to complete.
  */
@@ -158,8 +157,8 @@ pr_flash(struct player *pl, char *format, ...)
 }
 
 /*
- * Send C_INFORM text to PL.
- * Format text to send using printf-style FORMAT and optional
+ * Send C_INFORM text to @pl.
+ * Format text to send using printf-style @format and optional
  * arguments.  It is assumed to be plain ASCII.
  * Initiate an output queue flush, but do not wait for it to complete.
  */
@@ -180,7 +179,7 @@ pr_inform(struct player *pl, char *format, ...)
 
 /*
  * Send C_FLASH text to everyone.
- * Format text to send using printf-style FORMAT and optional
+ * Format text to send using printf-style @format and optional
  * arguments.  It is assumed to be plain ASCII.
  * Prefix text it with a header suitable for broadcast from deity.
  * Initiate an output queue flush, but do not wait for it to complete.
@@ -212,8 +211,8 @@ pr_wall(char *format, ...)
 }
 
 /*
- * Send ID text BUF to PL, line-buffered.
- * BUF is user text.
+ * Send @id text @buf to @pl, line-buffered.
+ * @buf is user text.
  * If a partial line with different id is buffered, terminate it with
  * a newline first.
  */
@@ -246,15 +245,12 @@ pr_player(struct player *pl, int id, char *buf)
        }
     }
 
-    if (player == pl) {
-       while (io_output_if_queue_long(pl->iop,
-                       pl->may_sleep == PLAYER_SLEEP_FREELY) > 0)
-           ;
-    }
+    if (player == pl)
+       player_output_some();
 }
 
 /*
- * Send ID text BUF to PL, line-buffered.
+ * Send @id text @buf to @pl, line-buffered.
  * This function translates from normal text to user text.
  * If a partial line with different id is buffered, terminate it with
  * a newline first.
@@ -304,15 +300,12 @@ upr_player(struct player *pl, int id, char *buf)
        }
     }
 
-    if (player == pl) {
-       while (io_output_if_queue_long(pl->iop,
-                       pl->may_sleep == PLAYER_SLEEP_FREELY) > 0)
-           ;
-    }
+    if (player == pl)
+       player_output_some();
 }
 
 /*
- * Send id N to PL.
+ * Send id @n to @pl.
  * This runs always at the beginning of a line.
  */
 static void
@@ -333,9 +326,18 @@ outid(struct player *pl, int n)
     pl->curid = n;
 }
 
+static void
+player_output_some(void)
+{
+    time_t deadline = player_io_deadline(player, 1);
+
+    while (io_output_if_queue_long(player->iop, deadline) > 0)
+       ;
+}
+
 /*
- * Send redirection request REDIR to the current player.
- * REDIR is UTF-8, but non-ASCII characters can occur only if the
+ * Send redirection request @redir to the current player.
+ * @redir is UTF-8, but non-ASCII characters can occur only if the
  * player sent them.  Therefore, it is also user text.
  */
 void
@@ -345,8 +347,8 @@ prredir(char *redir)
 }
 
 /*
- * Send script execute request FILE to the current player.
- * REDIR is UTF-8, but non-ASCII characters can occur only if the
+ * Send script execute request @file to the current player.
+ * @file is UTF-8, but non-ASCII characters can occur only if the
  * player sent them.  Therefore, it is also user text.
  */
 void
@@ -366,11 +368,11 @@ prprompt(int min, int btu)
 
 /*
  * Prompt for a line of non-command input.
- * Send C_FLUSH prompt PROMPT to the current player.
- * Read a line of input into BUF[SIZE] and convert it to ASCII.
+ * Send C_FLUSH prompt @prompt to the current player.
+ * Read a line of input into @buf[@size] and convert it to ASCII.
  * This may block for input, yielding the processor.  Flush buffered
  * output when blocking, to make sure player sees the prompt.
- * Return number of bytes in BUF[], not counting the terminating 0,
+ * Return number of bytes in @buf[], not counting the terminating 0,
  * or -1 on error.
  */
 int
@@ -394,12 +396,12 @@ prmptrd(char *prompt, char *buf, int size)
 
 /*
  * Prompt for a line of non-command, UTF-8 input.
- * Send C_FLUSH prompt PROMPT to the current player.
- * Read a line of input into BUF[SIZE], replacing funny characters by
+ * Send C_FLUSH prompt @prompt to the current player.
+ * Read a line of input into @buf[@size], replacing funny characters by
  * '?'.  The result is UTF-8.
  * This may block for input, yielding the processor.  Flush buffered
  * output when blocking, to make sure player sees the prompt.
- * Return number of bytes in BUF[], not counting the terminating 0,
+ * Return number of bytes in @buf[], not counting the terminating 0,
  * or -1 on error.
  */
 int
@@ -430,12 +432,12 @@ prdate(void)
     time_t now;
 
     (void)time(&now);
-    pr(ctime(&now));
+    pr("%s", ctime(&now));
 }
 
 /*
- * Print coordinates X, Y.
- * FORMAT must be a printf-style format string that converts exactly
+ * Print coordinates @x,@y.
+ * @format must be a printf-style format string that converts exactly
  * two int values.
  */
 void
@@ -460,11 +462,11 @@ pr_beep(void)
 }
 
 /*
- * Print complete lines to country CN similar to printf().
- * Use printf-style FORMAT with the optional arguments.  FORMAT must
+ * Print complete lines to country @cn similar to printf().
+ * Use printf-style @format with the optional arguments.  @format must
  * end with '\n'.
- * If CN is zero, don't print anything.
- * Else, if CN is the current player and we're not in the update,
+ * If @cn is zero, don't print anything.
+ * Else, if @cn is the current player and we're not in the update,
  * print just like pr().  Else print into a bulletin.
  * Because printing like pr() requires normal text, and bulletins
  * require user text, only plain ASCII is allowed.
@@ -482,17 +484,17 @@ mpr(int cn, char *format, ...)
     (void)vsprintf(buf, format, ap);
     va_end(ap);
     if (update_running || cn != player->cnum)
-       typed_wu(0, cn, buf, TEL_BULLETIN);
+       wu(0, cn, "%s", buf);
     else
        pr_player(player, C_DATA, buf);
 }
 
 /*
- * Copy SRC without funny characters to DST.
+ * Copy @src without funny characters to @dst.
  * Drop control characters, except for '\t'.
  * Replace non-ASCII characters by '?'.
- * Return length of DST.
- * DST must have space.  If it overlaps SRC, then DST <= SRC must
+ * Return length of @dst.
+ * @dst must have space.  If it overlaps @src, then @dst <= @src must
  * hold.
  */
 size_t
@@ -516,11 +518,11 @@ copy_ascii_no_funny(char *dst, char *src)
 }
 
 /*
- * Copy UTF-8 SRC without funny characters to DST.
+ * Copy UTF-8 @src without funny characters to @dst.
  * Drop control characters, except for '\t'.
  * FIXME Replace malformed UTF-8 sequences by '?'.
- * Return byte length of DST.
- * DST must have space.  If it overlaps SRC, then DST <= SRC must
+ * Return byte length of @dst.
+ * @dst must have space.  If it overlaps @src, then @dst <= @src must
  * hold.
  */
 size_t
@@ -543,11 +545,11 @@ copy_utf8_no_funny(char *dst, char *src)
 }
 
 /*
- * Copy UTF-8 SRC without funny characters to ASCII DST.
+ * Copy UTF-8 @src without funny characters to ASCII @dst.
  * Drop control characters, except for '\t'.
  * Replace non-ASCII characters by '?'.
- * Return length of DST.
- * DST must have space.  If it overlaps SRC, then DST <= SRC must
+ * Return length of @dst.
+ * @dst must have space.  If it overlaps @src, then @dst <= @src must
  * hold.
  */
 size_t
@@ -563,7 +565,8 @@ copy_utf8_to_ascii_no_funny(char *dst, char *src)
            ;                   /* ignore funny control */
        else if (ch > 0x7f) {
            *p++ = '?';         /* replace non-ASCII */
-           while ((*src++ & 0xc0) == 0x80) ;
+           while ((*src & 0xc0) == 0x80)
+               src++;
        } else
            *p++ = ch;
     }
@@ -573,8 +576,8 @@ copy_utf8_to_ascii_no_funny(char *dst, char *src)
 }
 
 /*
- * Return byte-index of the N-th UTF-8 character in UTF-8 string S.
- * If S doesn't have that many characters, return its length instead.
+ * Return byte-index of the @n-th UTF-8 character in UTF-8 string @s.
+ * If @s doesn't have that many characters, return its length instead.
  */
 int
 ufindpfx(char *s, int n)