github pull request - fake mail

Fixes #216

A github pull request changed one of the fake mail messages so that
our web site's URL is added at compile time instead of being hard-
coded.  However, it wouldn't compile with a pre-ANSI compiler since
it relied on concatenating adjacent string literals.  This is more
complex but achieves the same result, and also makes the existing
run-time subsitution be a bit clearer.

Testing was a hassle but eventually successful.
This commit is contained in:
PatR
2019-09-14 17:52:02 -07:00
parent 2a66ce54ad
commit 7c2b7d4417

View File

@@ -1,4 +1,4 @@
/* NetHack 3.6 mail.c $NHDT-Date: 1545597424 2018/12/23 20:37:04 $ $NHDT-Branch: NetHack-3.6.2-beta01 $:$NHDT-Revision: 1.39 $ */
/* NetHack 3.6 mail.c $NHDT-Date: 1568508711 2019/09/15 00:51:51 $ $NHDT-Branch: NetHack-3.6 $:$NHDT-Revision: 1.40 $ */
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
/*-Copyright (c) Pasi Kallinen, 2018. */
/* NetHack may be freely redistributed. See license for details. */
@@ -460,28 +460,65 @@ void
readmail(otmp)
struct obj *otmp UNUSED;
{
static char *junk[] = {
NULL, /* placeholder for "Report bugs to <devteam@nethack.org>.", */
"Please disregard previous letter.", "Welcome to NetHack.",
static const char *junk[] = {
"Report bugs to <%s>.", /*** must be first entry ***/
"Please disregard previous letter.",
"Welcome to NetHack.",
#ifdef AMIGA
"Only Amiga makes it possible.", "CATS have all the answers.",
"Only Amiga makes it possible.",
"CATS have all the answers.",
#endif
"This mail complies with the Yendorian Anti-Spam Act (YASA)",
"Please find enclosed a small token to represent your Owlbear",
"**FR33 P0T10N 0F FULL H34L1NG**",
"Please return to sender (Asmodeus)",
/* when enclosed by "It reads: \"...\"", this is too long
for an ordinary 80-column display so wraps to a second line
(suboptimal but works correctly);
dollar sign and fractional zorkmids are inappropriate within
nethack but are suitable for typical dysfunctional spam mail */
"Buy a potion of gain level for only $19.99! Guaranteed to be blessed!",
"Invitation: Visit the NetHack web site at http://www.nethack.org!"
/* DEVTEAM_URL will be substituted for "%s"; terminating punctuation
(formerly "!") has deliberately been omitted so that it can't be
mistaken for part of the URL (unfortunately that is still followed
by a closing quote--in the pline below, not the data here) */
"Invitation: Visit the NetHack web site at %s"
};
/* XXX replace with more general substitution code and add local
* contact message. Also use DEVTEAM_URL */
if (junk[0] == NULL) {
#define BUGS_FORMAT "Report bugs to <%s>."
/* +2 from '%s' suffices as substitute for usual +1 for terminator */
junk[0] = (char *) alloc(strlen(BUGS_FORMAT) + strlen(DEVTEAM_EMAIL));
Sprintf(junk[0], BUGS_FORMAT, DEVTEAM_EMAIL);
#undef BUGS_FORMAT
* contact message.
*
* FIXME: this allocated memory is never freed. However, if the
* game is restarted, the junk[] update will be a no-op for second
* and subsequent runs and this updated text will still be appropriate.
*/
if (index(junk[0], '%')) {
char *tmp;
int i;
for (i = 0; i < SIZE(junk); ++i) {
if (index(junk[i], '%')) {
if (i == 0) {
/* +2 from '%s' in junk[0] suffices as substitute
for usual +1 for terminator */
tmp = (char *) alloc(strlen(junk[0])
+ strlen(DEVTEAM_EMAIL));
Sprintf(tmp, junk[0], DEVTEAM_EMAIL);
junk[0] = tmp;
} else if (strstri(junk[i], "web site")) {
/* as with junk[0], room for terminator is present */
tmp = (char *) alloc(strlen(junk[i])
+ strlen(DEVTEAM_URL));
Sprintf(tmp, junk[i], DEVTEAM_URL);
junk[i] = tmp;
} else {
/* could check for "%%" but unless that becomes needed,
handling it is more complicated than necessary */
impossible("fake mail #%d has undefined substitution", i);
junk[i] = "Bad fake mail...";
}
}
}
}
if (Blind) {
pline("Unfortunately you cannot see what it says.");