2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2007, Dave Pare, Jeff Bailey, Thomas Ruschak,
4 * Ken Stevens, Steve McClure
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 * See files README, COPYING and CREDITS in the root of the source
23 * tree for related information and legal notices. It is expected
24 * that future projects/authors will amend these files as needed.
28 * getele.c: Read a telegram from a file or stdin and send it to a country
30 * Known contributors to this file:
37 #include "prototypes.h"
40 static int tilde_escape(char *s);
43 * Read a telegram for RECIPIENT into BUF, in UTF-8.
44 * BUF must have space for MAXTELSIZE+1 characters.
45 * Return telegram length, or -1 on error.
48 getele(char *recipient, char *buf)
52 char buffer[MAXTELSIZE + 2]; /* UTF-8 */
55 pr("Enter telegram for %s\n", recipient);
56 pr("undo last line with ~u, print with ~p, abort with ~q, end with ^D or .\n");
59 while (!player->aborted) {
60 sprintf(left, "%4d left: ", (int)(buf + MAXTELSIZE - bp));
61 if (uprmptrd(left, buffer, sizeof(buffer) - 2) <= 0)
63 switch (tilde_escape(buffer)) {
68 pr("No more lines to undo\n");
71 for (bp -= 2; bp >= buf && *bp != '\n'; --bp) ;
73 pr("Last line deleted.\n");
76 pr("This is what you have written so far:\n");
80 if (buffer[0] == '.' && buffer[1] == 0)
82 if (buffer[0] == '>') /* forgery attempt? */
83 buffer[0] = '?'; /* foil it */
85 if (CANT_HAPPEN(len > sizeof(buffer) - 2))
86 len = sizeof(buffer) - 2;
89 if (bp + len > buf + MAXTELSIZE)
90 pr("Too long. Try that last line again...\n");
92 memcpy(bp, buffer, len + 1);
102 * If S is a `tilde escape', return its code, else 0.
103 * A tilde escape is '~' followed by the code character.
106 tilde_escape(char *s)
108 return s[0] == '~' && s[2] == 0 ? s[1] : 0;