omailcmd (trunk only)
The revised newmail() wouldn't compile (Strncpy doesn't exist, `buf' was an array of pointers rather than of char). Simplify it substantially, and adjust the one caller (vms) that relied on the old convoluted bit.
This commit is contained in:
@@ -1112,7 +1112,7 @@ E void FDECL(newomid, (struct obj *));
|
||||
E void FDECL(free_omid, (struct obj *));
|
||||
E void FDECL(newolong, (struct obj *));
|
||||
E void FDECL(free_olong, (struct obj *));
|
||||
E void FDECL(new_omailcmd, (struct obj *,char *));
|
||||
E void FDECL(new_omailcmd, (struct obj *,const char *));
|
||||
E void FDECL(free_omailcmd, (struct obj *));
|
||||
E struct obj *FDECL(mkobj_at, (CHAR_P,int,int,BOOLEAN_P));
|
||||
E struct obj *FDECL(mksobj_at, (int,int,int,BOOLEAN_P,BOOLEAN_P));
|
||||
|
||||
22
src/mail.c
22
src/mail.c
@@ -379,25 +379,15 @@ struct mail_info *info;
|
||||
|
||||
if (info->message_typ) {
|
||||
struct obj *obj = mksobj(SCR_MAIL, FALSE, FALSE);
|
||||
|
||||
if (info->object_nam)
|
||||
obj = oname(obj, info->object_nam);
|
||||
if (info->response_cmd)
|
||||
new_omailcmd(obj, info->response_cmd);
|
||||
|
||||
if (distu(md->mx,md->my) > 2)
|
||||
verbalize("Catch!");
|
||||
display_nhwindow(WIN_MESSAGE, FALSE);
|
||||
if (info->object_nam) {
|
||||
char *buf[BUFSZ];
|
||||
Strncpy(buf, info->object_nam, BUFSZ - 1);
|
||||
buf[BUFSZ - 1] = '\0';
|
||||
if (info->response_cmd) { /*(hide extension of the obj name)*/
|
||||
int namelth = info->response_cmd - info->object_nam - 1;
|
||||
if ( namelth <= 0 )
|
||||
impossible("mail delivery screwed up");
|
||||
else {
|
||||
*(buf + namelth) = '\0';
|
||||
obj = oname(obj, buf);
|
||||
new_omailcmd(obj, info->response_cmd);
|
||||
}
|
||||
/* Note: renaming object won't discard the hidden cmd anymore. */
|
||||
}
|
||||
}
|
||||
obj = hold_another_object(obj, "Oops!",
|
||||
(const char *)0, (const char *)0);
|
||||
}
|
||||
|
||||
20
src/mkobj.c
20
src/mkobj.c
@@ -161,19 +161,16 @@ struct obj *otmp;
|
||||
}
|
||||
|
||||
void
|
||||
new_omailcmd(otmp,response_cmd)
|
||||
new_omailcmd(otmp, response_cmd)
|
||||
struct obj *otmp;
|
||||
char *response_cmd;
|
||||
const char *response_cmd;
|
||||
{
|
||||
unsigned lth = strlen(response_cmd) + 1;
|
||||
|
||||
if (!otmp->oextra) otmp->oextra = newoextra();
|
||||
if (!OMAILCMD(otmp)) {
|
||||
unsigned lth = strlen(response_cmd) + 1;
|
||||
OMAILCMD(otmp) = (char *)alloc(lth);
|
||||
if (OMAILCMD(otmp)) {
|
||||
(void) memset((genericptr_t)OMAILCMD(otmp), 0, lth);
|
||||
Strcpy(OMAILCMD(otmp), response_cmd);
|
||||
}
|
||||
}
|
||||
if (OMAILCMD(otmp)) free_omailcmd(otmp);
|
||||
OMAILCMD(otmp) = (char *)alloc(lth);
|
||||
Strcpy(OMAILCMD(otmp), response_cmd);
|
||||
}
|
||||
|
||||
void
|
||||
@@ -360,9 +357,8 @@ struct obj *obj2, *obj1;
|
||||
(genericptr_t)OLONG(obj1),
|
||||
sizeof(long));
|
||||
}
|
||||
|
||||
if (has_omailcmd(obj1)) {
|
||||
if (!OMAILCMD(obj2)) new_omailcmd(obj2, OMAILCMD(obj1));
|
||||
new_omailcmd(obj2, OMAILCMD(obj1));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* SCCS Id: @(#)vmsmail.c 3.5 1995/06/01 */
|
||||
/* SCCS Id: @(#)vmsmail.c 3.5 2006/04/14 */
|
||||
/* Copyright (c) Robert Patrick Rankin, 1991. */
|
||||
/* NetHack may be freely redistributed. See license for details. */
|
||||
|
||||
@@ -59,16 +59,14 @@ static long pasteboard_id = 0; /* SMG's magic cookie */
|
||||
* passed to newmail(). Routine newmail() generates a mail-daemon monster
|
||||
* who approaches the character, "speaks" the display text, and delivers
|
||||
* a scroll of mail pre-named to the object name; the response command is
|
||||
* initially appended to the name, so that the object is tagged with both
|
||||
* of them; a NUL is inserted to terminate the ordinary name and hide the
|
||||
* command. (If the player renames such a scroll, the hidden command will
|
||||
* be lost; who cares?) Unrecognized broadcasts result in the mail-daemon
|
||||
* also attached to the scroll's oextra->omailcmd field.
|
||||
* Unrecognized broadcasts result in the mail-daemon
|
||||
* arriving and announcing the display text, but no scroll being created.
|
||||
* If SHELL is undefined, then all broadcasts are treated as 'other'; since
|
||||
* no subproceses are allowed, there'd be no way to respond to the scroll.
|
||||
*
|
||||
* When a scroll of mail is read by the character, readmail() extracts
|
||||
* the hidden command string and uses it for the default when prompting the
|
||||
* the command string and uses it for the default when prompting the
|
||||
* player for a system command to spawn. The player may enter any command
|
||||
* he or she chooses, or just <return> to accept the default or <escape> to
|
||||
* avoid executing any command. If the command is "SPAWN", a regular shell
|
||||
@@ -105,7 +103,8 @@ static long pasteboard_id = 0; /* SMG's magic cookie */
|
||||
*/
|
||||
|
||||
static struct mail_info msg; /* parse_*()'s return buffer */
|
||||
static char nam_cmd_buf[63], /* maximum onamelth, size of ONAME(object) */
|
||||
static char nam_buf[63], /* maximum onamelth, size of ONAME(object) */
|
||||
cmd_buf[99], /* arbitrary */
|
||||
txt_buf[255+1]; /* same size as used for message buf[] */
|
||||
|
||||
/* try to decipher and categorize broadcast message text
|
||||
@@ -120,7 +119,7 @@ char *buf; /* input: filtered broadcast text */
|
||||
# ifdef SHELL /* only parse if spawned commands are enabled */
|
||||
register char *p, *q;
|
||||
boolean is_jnet_send;
|
||||
char cmd_buf[127+1], user[127+1], node[127+1], sentinel;
|
||||
char user[127+1], node[127+1], sentinel;
|
||||
|
||||
/* Check these first; otherwise, their arbitrary text would enable
|
||||
easy spoofing of some other message patterns. Unfortunately,
|
||||
@@ -253,16 +252,15 @@ other:
|
||||
/* Daemon in newmail() will append period when the text is displayed */
|
||||
if ((p = eos(txt)) > txt && *--p == '.') *p = '\0';
|
||||
|
||||
/* newmail() and readmail() assume that nam and cmd are concatenated */
|
||||
if (nam) { /* object name to attach to scroll of mail */
|
||||
char *join = strcpy(nam_cmd_buf, nam);
|
||||
if (cmd) { /* append command to name; readmail() requires it */
|
||||
int len = sizeof nam_cmd_buf - sizeof "" - (strlen(join) + 1);
|
||||
cmd_buf[len] = '\0'; /* possibly truncate */
|
||||
(void) strcat(join, " ");
|
||||
cmd = strcpy(eos(join), cmd);
|
||||
}
|
||||
nam = join;
|
||||
/* newmail() and readmail() used to assume that nam and cmd are
|
||||
concatenated but that is no longer the case */
|
||||
if (nam && nam != nam_buf) {
|
||||
(void) strncpy(nam_buf, nam, sizeof nam_buf - 1);
|
||||
nam_buf[sizeof nam_buf - 1] = '\0';
|
||||
}
|
||||
if (cmd && cmd != cmd_buf) {
|
||||
(void) strncpy(cmd_buf, cmd, sizeof cmd_buf - 1);
|
||||
cmd_buf[sizeof cmd_buf - 1] = '\0';
|
||||
}
|
||||
# endif /* SHELL */
|
||||
/* truncate really long messages to prevent verbalize() from blowing up */
|
||||
|
||||
Reference in New Issue
Block a user