tom@uw-warp.UUCP (F. Thomas May) (01/11/88)
Forget about any other implementation of savemonchn()/restmonchn(). The
following implementation is much more maintainable than the
distributed/patched version and eliminates most of the differences between the
Unix code and the MSDOS code.
First, delete all remnants of the MSDOS savemonchn() and restmonchn()
routines. Then replace the Unix restmonchn() with this (note that only two
#indefs needed to be added to the Unix code to make it MSDOS compatible):
struct monst *
restmonchn(fd)
register fd;
{
register struct monst *mtmp, *mtmp2;
register struct monst *first = 0;
int xl;
struct permonst *monbegin;
long differ;
mread(fd, (char *)&monbegin, sizeof(monbegin));
#ifndef MSDOS
differ = (char *)(&mons[0]) - (char *)(monbegin);
#else
differ = (long)(&mons[0]) - (long)(monbegin);
#endif
#ifdef LINT
/* suppress "used before set" warning from lint */
mtmp2 = 0;
#endif
while(1) {
mread(fd, (char *) &xl, sizeof(xl));
if(xl == -1) break;
mtmp = newmonst(xl);
if(!first) first = mtmp;
else mtmp2->nmon = mtmp;
mread(fd, (char *) mtmp, (unsigned) xl + sizeof(struct monst));
if(!mtmp->m_id)
mtmp->m_id = flags.ident++;
#ifndef MSDOS
mtmp->data = (struct permonst *)
((char *) mtmp->data + differ);
#else
mtmp->data = (struct permonst *)
((long) mtmp->data + differ);
#endif
if(mtmp->minvent)
mtmp->minvent = restobjchn(fd);
mtmp2 = mtmp;
}
if(first && mtmp2->nmon){
impossible("Restmonchn: error reading monchn.");
mtmp2->nmon = 0;
}
return(first);
}
The result will work under both Unix and MSDOS. The existing Unix
savemonchn() code will now work with either operating system.
--
Tom May
uw-nsr!uw-warp!tom@beaver.cs.washington.edu
uw-beaver!uw-nsr!uw-warp!tom