Пример #1
0
int
test_func16(const char *path_name, const struct stat64 *stat_pointer,
	    int ftw_integer, struct FTW *ftwp)
{
	const char *p;
	temp = stderr;

	if ((p = strstr(path_name, NFTW2)) != (char *)NULL) {
		p += strlen(NFTW2) + 1;
	} else {
		p = path_name;
	}

	if (ftwp->level != getlev(p)) {
		fprintf(temp, "ERROR: Incorrect value of level for %s\n",
			path_name);
		fprintf(temp, "       Expected %d, received %d\n",
			getlev(p), ftwp->level);
		return 999;
	}
	if (ftwp->base != getbase(path_name)) {
		fprintf(temp, "ERROR: Incorrect value of base for %s\n",
			path_name);
		fprintf(temp, "       Expected %d, received %d\n",
			getbase(path_name), ftwp->base);
		return 999;
	}
	return 0;
}
Пример #2
0
/* returns 1 if save successful */
static int
dosave0(int hu)
{
	int		fd, ofd;
	int             tmp;	/* not ! */

	(void) signal(SIGHUP, SIG_IGN);
	(void) signal(SIGINT, SIG_IGN);
	if ((fd = creat(SAVEF, FMASK)) < 0) {
		if (!hu)
			pline("Cannot open save file. (Continue or Quit)");
		(void) unlink(SAVEF);	/* ab@unido */
		return (0);
	}
	if (flags.moonphase == FULL_MOON)	/* ut-sally!fletcher */
		u.uluck--;	/* and unido!ab */
	savelev(fd, dlevel);
	saveobjchn(fd, invent);
	saveobjchn(fd, fcobj);
	savemonchn(fd, fallen_down);
	tmp = getuid();
	bwrite(fd, &tmp, sizeof tmp);
	bwrite(fd, &flags, sizeof(struct flag));
	bwrite(fd, &dlevel, sizeof dlevel);
	bwrite(fd, &maxdlevel, sizeof maxdlevel);
	bwrite(fd, &moves, sizeof moves);
	bwrite(fd, &u, sizeof(struct you));
	if (u.ustuck)
		bwrite(fd, &(u.ustuck->m_id), sizeof u.ustuck->m_id);
	bwrite(fd, pl_character, sizeof pl_character);
	bwrite(fd, genocided, sizeof genocided);
	bwrite(fd, fut_geno, sizeof fut_geno);
	savenames(fd);
	for (tmp = 1; tmp <= maxdlevel; tmp++) {

		if (tmp == dlevel || !level_exists[tmp])
			continue;
		glo(tmp);
		if ((ofd = open(lock, O_RDONLY)) < 0) {
			if (!hu)
				pline("Error while saving: cannot read %s.", lock);
			(void) close(fd);
			(void) unlink(SAVEF);
			if (!hu)
				done("tricked");
			return (0);
		}
		getlev(ofd, hackpid, tmp);
		(void) close(ofd);
		bwrite(fd, &tmp, sizeof tmp);	/* level number */
		savelev(fd, tmp);	/* actual level */
		(void) unlink(lock);
	}
	(void) close(fd);
	glo(dlevel);
	(void) unlink(lock);	/* get rid of current level --jgm */
	glo(0);
	(void) unlink(lock);
	return (1);
}
Пример #3
0
int
getbones()
{
	int fd,x,y,ok;

	if(rn2(3)) return(0);	/* only once in three times do we find bones */
	bones[6] = '0' + dlevel/10;
	bones[7] = '0' + dlevel%10;
	if((fd = open(bones, O_RDONLY)) < 0) return(0);
	if((ok = uptodate(fd)) != 0){
		getlev(fd, 0, dlevel);
		for(x = 0; x < COLNO; x++) for(y = 0; y < ROWNO; y++)
			levl[x][y].seen = levl[x][y].new = 0;
	}
Пример #4
0
void mysub (int id)
{ int iopt, idev;
  char cdev[5], *cstr;

  if (getlev () != 0) return;
  if (id != id_pbut) return;
  iopt = gwglis (id_lis1);
  idev = gwglis (id_lis2);

  cstr = itmstr (cl1, idev);
  strncpy (cdev, cstr, 4);
  cdev[4] = '\0';
  
  exa (cdev, iopt);
  return;
}
Пример #5
0
bool dorecover (void)
{
    char savefile [PATH_MAX];
    snprintf (ArrayBlock(savefile), HACK_SAVEFILE, getenv("HOME"));
    int fd = open (savefile, O_RDONLY);
    if (fd < 0)
	return false;
    mread (fd, &_u, sizeof(struct you));
    if (_u.maxdlevel < 1 || _u.maxdlevel > MAXLEVEL) {
	close (fd);
	you_dtor();
	return false;
    }
    invent = restobjchn (fd);
    for (struct obj* o = invent; o; o = o->nobj)
	if (o->owornmask)
	    setworn (o, o->owornmask);
    fcobj = restobjchn (fd);
    fallen_down = restmonchn (fd);
    mread (fd, &_wflags, sizeof(struct worldflag));
    mread (fd, pl_character, sizeof pl_character);
    restnames (fd);
    restgenocided (fd);
    for (unsigned i = 0; i < _u.maxdlevel; ++i) {
	level_dtor (&_levels[i]);
	getlev (fd, &_levels[i]);
    }
    if (_u.dlevel < 1 || _u.dlevel > _u.maxdlevel)
	_u.dlevel = _u.maxdlevel;
    _level = &_levels[_u.dlevel-1];
    setsee();	// only to recompute seelx etc. - these weren't saved
    docrt();
    close (fd);
    unlink (savefile);
    return true;
}
Пример #6
0
void
goto_level(int newlevel, boolean at_stairs)
{
	int fd;
	boolean up = (newlevel < dlevel);

	if(newlevel <= 0) done("escaped");    /* in fact < 0 is impossible */
	if(newlevel > MAXLEVEL) newlevel = MAXLEVEL;	/* strange ... */
	if(newlevel == dlevel) return;	      /* this can happen */

	glo(dlevel);
	fd = creat(lock, FMASK);
	if(fd < 0) {
		/*
		 * This is not quite impossible: e.g., we may have
		 * exceeded our quota. If that is the case then we
		 * cannot leave this level, and cannot save either.
		 * Another possibility is that the directory was not
		 * writable.
		 */
		pline("A mysterious force prevents you from going %s.",
			up ? "up" : "down");
		return;
	}

	if(Punished) unplacebc();
	u.utrap = 0;				/* needed in level_tele */
	u.ustuck = 0;				/* idem */
	keepdogs();
	seeoff(1);
	if(u.uswallow)				/* idem */
		u.uswldtim = u.uswallow = 0;
	flags.nscrinh = 1;
	u.ux = FAR;				/* hack */
	(void) inshop();			/* probably was a trapdoor */

	savelev(fd,dlevel);
	(void) close(fd);

	dlevel = newlevel;
	if(maxdlevel < dlevel)
		maxdlevel = dlevel;
	glo(dlevel);

	if(!level_exists[(int)dlevel])
		mklev();
	else {
		extern int hackpid;

		if((fd = open(lock, O_RDONLY)) < 0) {
			pline("Cannot open %s .", lock);
			pline("Probably someone removed it.");
			done("tricked");
		}
		getlev(fd, hackpid, dlevel);
		(void) close(fd);
	}

	if(at_stairs) {
	    if(up) {
		u.ux = xdnstair;
		u.uy = ydnstair;
		if(!u.ux) {		/* entering a maze from below? */
		    u.ux = xupstair;	/* this will confuse the player! */
		    u.uy = yupstair;
		}
		if(Punished && !Levitation){
			pline("With great effort you climb the stairs.");
			placebc(1);
		}
	    } else {
		u.ux = xupstair;
		u.uy = yupstair;
		if(inv_weight() + 5 > 0 || Punished){
			pline("You fall down the stairs.");	/* %% */
			losehp(rnd(3), "fall");
			if(Punished) {
			    if(uwep != uball && rn2(3)){
				pline("... and are hit by the iron ball.");
				losehp(rnd(20), "iron ball");
			    }
			    placebc(1);
			}
			selftouch("Falling, you");
		}
	    }
	    { struct monst *mtmp = m_at(u.ux, u.uy);
	      if(mtmp)
		mnexto(mtmp);
	    }
	} else {	/* trapdoor or level_tele */
	    do {
		u.ux = rnd(COLNO-1);
		u.uy = rn2(ROWNO);
	    } while(levl[(int)u.ux][(int)u.uy].typ != ROOM ||
			m_at(u.ux,u.uy));
	    if(Punished){
		if(uwep != uball && !up /* %% */ && rn2(5)){
			pline("The iron ball falls on your head.");
			losehp(rnd(25), "iron ball");
		}
		placebc(1);
	    }
	    selftouch("Falling, you");
	}
	(void) inshop();
	initrack();

	losedogs();
	{ struct monst *mtmp;
	  if ((mtmp = m_at(u.ux, u.uy)))
		  mnexto(mtmp);	/* riv05!a3 */
	}
	flags.nscrinh = 0;
	setsee();
	seeobjs();	/* make old cadavers disappear - riv05!a3 */
	docrt();
	pickup(1);
	read_engr_at(u.ux,u.uy);
}
Пример #7
0
int
dorecover(int fd)
{
	int nfd;
	int             tmp;	/* not a ! */
	unsigned        mid;	/* idem */
	struct obj     *otmp;

	restoring = TRUE;
	getlev(fd, 0, 0);
	invent = restobjchn(fd);
	for (otmp = invent; otmp; otmp = otmp->nobj)
		if (otmp->owornmask)
			setworn(otmp, otmp->owornmask);
	fcobj = restobjchn(fd);
	fallen_down = restmonchn(fd);
	mread(fd, &tmp, sizeof tmp);
	if (tmp != (int) getuid()) {	/* strange ... */
		(void) close(fd);
		(void) unlink(SAVEF);
		puts("Saved game was not yours.");
		restoring = FALSE;
		return (0);
	}
	mread(fd, &flags, sizeof(struct flag));
	mread(fd, &dlevel, sizeof dlevel);
	mread(fd, &maxdlevel, sizeof maxdlevel);
	mread(fd, &moves, sizeof moves);
	mread(fd, &u, sizeof(struct you));
	if (u.ustuck)
		mread(fd, &mid, sizeof mid);
	mread(fd, pl_character, sizeof pl_character);
	mread(fd, genocided, sizeof genocided);
	mread(fd, fut_geno, sizeof fut_geno);
	restnames(fd);
	while (1) {
		if (read(fd, &tmp, sizeof tmp) != sizeof tmp)
			break;
		getlev(fd, 0, tmp);
		glo(tmp);
		if ((nfd = creat(lock, FMASK)) < 0)
			panic("Cannot open temp file %s!\n", lock);
		savelev(nfd, tmp);
		(void) close(nfd);
	}
	(void) lseek(fd, (off_t) 0, SEEK_SET);
	getlev(fd, 0, 0);
	(void) close(fd);
	(void) unlink(SAVEF);
	if (Punished) {
		for (otmp = fobj; otmp; otmp = otmp->nobj)
			if (otmp->olet == CHAIN_SYM)
				goto chainfnd;
		panic("Cannot find the iron chain?");
chainfnd:
		uchain = otmp;
		if (!uball) {
			for (otmp = fobj; otmp; otmp = otmp->nobj)
				if (otmp->olet == BALL_SYM && otmp->spe)
					goto ballfnd;
			panic("Cannot find the iron ball?");
	ballfnd:
			uball = otmp;
		}
	}
	if (u.ustuck) {
		struct monst   *mtmp;

		for (mtmp = fmon; mtmp; mtmp = mtmp->nmon)
			if (mtmp->m_id == mid)
				goto monfnd;
		panic("Cannot find the monster ustuck.");
monfnd:
		u.ustuck = mtmp;
	}
#ifndef QUEST
	setsee();		/* only to recompute seelx etc. - these
				 * weren't saved */
#endif	/* QUEST */
	docrt();
	restoring = FALSE;
	return (1);
}