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:
nethack.rankin
2006-04-15 02:14:36 +00:00
parent b76a0fe091
commit 5501922aa8
4 changed files with 31 additions and 47 deletions

View File

@@ -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);
}

View File

@@ -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));
}
}