Exemplo n.º 1
0
int mailbill()
{
    int i;
    char buf[128];
    
    wait(0);
    pid = getpid();

    if(fork() == 0) {
	resetscroll();

	for(i = 0; i < (sizeof(pfn) / sizeof(int(*)())); ++i) {
	    if((*pfn[i])()) {
		sleep(20);
		sprintf(buf, "mail %s < %s", loginname, mail600);
		
		if(system(buf) == -1) {
		    exit(1);
		}
		
		unlink(mail600);
	    }
	}
	
	exit(0);
    }

    return 0;
}
Exemplo n.º 2
0
/*
 *	subroutine to clear screen depending on # lines to display
 */
static void
t_setup(int count)
{
	if (count < 20) {	/* how do we clear the screen? */
		cl_up(79, count);
		cursor(1, 1);
	} else {
		resetscroll();
		clear();
	}
}
Exemplo n.º 3
0
/*
 *	routine to open the help file and return the first character - '0'
 */
static int
openhelp(void)
{
	if (lopen(helpfile) < 0) {
		lprintf("Can't open help file \"%s\" ", helpfile);
		lflush();
		sleep(4);
		drawscreen();
		setscroll();
		return (-1);
	}
	resetscroll();
	return (lgetc() - '0');
}
Exemplo n.º 4
0
Arquivo: bill.c Projeto: HunterZ/larn
/* 
 * Page the mail to the terminal    - dgk
 */
void readmail(long gold)
{
	int i;

	for (i = 0; i < (sizeof pfn) / (sizeof pfn[0]); i++) {
		
		resetscroll();
		clear();
		
		/* a bit dirty 'cause of args */
		(*pfn[i])(gold);

		retcont();
	}
}
Exemplo n.º 5
0
mailbill()
	{
	register int i;
	char buf[128];
	wait(0);  pid=getpid();
	if (fork() == 0)
		{
		resetscroll();
		for (i=0; i<sizeof(pfn)/sizeof(int (*)()); i++)
			if ((*pfn[i])())
				{
				sleep(20);  sprintf(buf,"mail %s < %s",loginname,mail600);
				system(buf);  unlink(mail600);
				}
		exit();
		}
	}
Exemplo n.º 6
0
mailbill ()
{
	int i, system_rtn;
	char buf[128];

	wait((int *)0);
	pid=getpid();
	if (fork() == 0) {
		resetscroll();
		for (i=0; i<sizeof(pfn)/sizeof(int (*)()); i++)
			if (pfn[i]()) {
				sleep(20);  
				sprintf(buf,"/bin/mail %s < %s",
					loginname,mail600);
				system_rtn = system(buf);  
				unlink(mail600);
			}
		exit(0);
	}
}
Exemplo n.º 7
0
void
mailbill()
{
	register int i;
	char fname[32];
	char buf[128];
	char **cp;
	int fd;

	wait(0);
	if (fork() == 0) {
		resetscroll();
		cp = mail;
		sprintf(fname, "/tmp/#%dlarnmail", getpid());
		for (i = 0; i < 6; i++) {
			if ((fd = open(fname, O_WRONLY | O_TRUNC | O_CREAT),
			    0666) == -1)
				exit(0);
			while (*cp != NULL) {
				if (*cp[0] == '1') {
					sprintf(buf, "\n%d gold pieces back with you from your journey.  As the",
					    (long)c[GOLD]);
					write(fd, buf, strlen(buf));
				} else if (*cp[0] == '2') {
					sprintf(buf, "\nin preparing your tax bill.  You owe %d gold pieces as", (long)c[GOLD]*TAXRATE);
					write(fd, buf, strlen(buf));
				} else
					write(fd, *cp, strlen(*cp));
				cp++;
			}
			cp++;

			close(fd);
			sprintf(buf, "mail -I %s < %s > /dev/null",
			    loginname, fname);
			system(buf);
			unlink(fname);
		}
	}
	exit(0);
}
Exemplo n.º 8
0
void
died(int x)
{
	int    f, win;
	char            ch;
	const char     *mod;
	time_t          zzz;
	if (c[LIFEPROT] > 0) {	/* if life protection */
		switch ((x > 0) ? x : -x) {
		case 256:
		case 257:
		case 262:
		case 263:
		case 265:
		case 266:
		case 267:
		case 268:
		case 269:
		case 271:
		case 282:
		case 284:
		case 285:
		case 300:
			goto invalid;	/* can't be saved */
		};
		--c[LIFEPROT];
		c[HP] = 1;
		--c[CONSTITUTION];
		cursors();
		lprcat("\nYou feel wiiieeeeerrrrrd all over! ");
		emit_beep();
		lflush();
		sleep(4);
		return;		/* only case where died() returns */
	}
invalid:
	clearvt100();
	lflush();
	f = 0;
	if (ckpflag)
		unlink(ckpfile);/* remove checkpoint file if used */
	if (x < 0) {
		f++;
		x = -x;
	}			/* if we are not to display the scores */
	if ((x == 300) || (x == 257))
		exit(0);		/* for quick exit or saved game */
	if (x == 263)
		win = 1;
	else
		win = 0;
	c[GOLD] += c[BANKACCOUNT];
	c[BANKACCOUNT] = 0;
	/* now enter the player at the end of the scoreboard */
	newscore(c[GOLD], logname, x, win);
	diedsub(x);		/* print out the score line */
	lflush();

	set_score_output();
	if ((wizard == 0) && (c[GOLD] > 0)) {	/* wizards can't score		 */
#ifndef NOLOG
		if (gid != egid)
			setegid(egid);
		if (lappend(logfile) < 0) {	/* append to file */
			if (lcreat(logfile) < 0) {	/* and can't create new
							 * log file */
				lcreat((char *) 0);
				lprcat("\nCan't open record file:  I can't post your score.\n");
				sncbr();
				resetscroll();
				lflush();
				exit(0);
			}
			if (gid != egid)
				setegid(egid);
			chmod(logfile, 0660);
			if (gid != egid)
				setegid(gid);
		}
		if (gid != egid)
			setegid(gid);
		strcpy(logg.who, loginname);
		logg.score = c[GOLD];
		logg.diff = c[HARDGAME];
		if (x < 256) {
			ch = *monster[x].name;
			if (ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u')
				mod = "an";
			else
				mod = "a";
			snprintf(logg.what, sizeof(logg.what),
			    "killed by %s %s", mod, monster[x].name);
		} else
			snprintf(logg.what, sizeof(logg.what),
			    "%s", whydead[x - 256]);
		logg.cavelev = level;
		time(&zzz);	/* get CPU time -- write out score info */
		logg.diedtime = zzz;
#ifdef EXTRA
		times(&cputime);/* get CPU time -- write out score info */
		logg.cputime = i = (cputime.tms_utime + cputime.tms_stime) / 60 + c[CPUTIME];
		logg.lev = c[LEVEL];
		logg.ac = c[AC];
		logg.hpmax = c[HPMAX];
		logg.hp = c[HP];
		logg.elapsedtime = (zzz - initialtime + 59) / 60;
		logg.usage = (10000 * i) / (zzz - initialtime);
		logg.bytin = c[BYTESIN];
		logg.bytout = c[BYTESOUT];
		logg.moves = c[MOVESMADE];
		logg.spused = c[SPELLSCAST];
		logg.killed = c[MONSTKILLED];
#endif
		lwrite((char *) &logg, sizeof(struct log_fmt));
		lwclose();
#endif	/* NOLOG */

		/*
		 * now for the scoreboard maintenance -- not for a suspended
		 * game
		 */
		if (x != 257) {
			if (sortboard()) {
				set_score_output();
				scorerror = writeboard();
			}
		}
	}
	if ((x == 256) || (x == 257) || (f != 0))
		exit(0);
	if (scorerror == 0)
		showscores();	/* if we updated the scoreboard */
	if (x == 263)
		mailbill();
	exit(0);
}
Exemplo n.º 9
0
/*
	lexical analyzer for larn
 */
int
yylex(void)
{
	char cc;
	int ic;
	if (hit2flag) {
		hit2flag = 0;
		yrepcount = 0;
		return (' ');
	}
	if (yrepcount > 0) {
		--yrepcount;
		return (lastok);
	} else
		yrepcount = 0;
	if (yrepcount == 0) {
		bottomdo();
		showplayer();
	}			/* show where the player is */
	lflush();
	while (1) {
		c[BYTESIN]++;
		/* check for periodic checkpointing */
		if (ckpflag)
			if ((c[BYTESIN] % CHECKPOINT_INTERVAL) == 0) {
#ifndef DOCHECKPOINTS
				savegame(ckpfile);
#else
				wait(0);	/* wait for other forks to finish */
				if (fork() == 0) {
					savegame(ckpfile);
					exit(0);
				}
#endif
#ifdef TIMECHECK
				if (dayplay == 0)
					if (playable()) {
						cursor(1, 19);
						lprcat("\nSorry, but it is now time for work.  Your game has been saved.\n");
						beep();
						lflush();
						savegame(savefilename);
						wizard = nomove = 1;
						sleep(4);
						died(-257);
					}
#endif /* TIMECHECK */
			}

		do {		/* if keyboard input buffer is too big, flush some of it */
			ioctl(0, FIONREAD, &ic);
			if (ic > flushno)
				read(0, &cc, 1);
		} while (ic > flushno);

		if (read(0, &cc, 1) != 1)
			return (lastok = -1);

		if (cc == 'Y' - 64) {	/* control Y -- shell escape */
			resetscroll();
			clear();	/* scrolling region, home, clear, no attributes */
			if ((ic = fork()) == 0) {	/* child */
				/* revoke */
				setgid(getgid());
				execl("/bin/csh", "csh", NULL);
				exit(1);
			}
			wait(0);
			if (ic < 0) {	/* error */
				write(2, "Can't fork off a shell!\n", 25);
				sleep(2);
			}

			setscroll();
			return (lastok = 'L' - 64);	/* redisplay screen */
		}

		if ((cc <= '9') && (cc >= '0')) {
			yrepcount = yrepcount * 10 + cc - '0';
		} else {
			if (yrepcount > 0)
				--yrepcount;
			return (lastok = cc);
		}
	}
}
Exemplo n.º 10
0
void
died (int x)
{
  int f, win;
  /*char ch, *mod;
     time_t zzz; */

  if (cdesc[LIFEPROT] > 0)	/* if life protection */
    {
      switch ((x > 0) ? x : -x)
	{
	case 256:
	case 257:
	case 262:
	case 263:
	case 265:
	case 266:
	case 267:
	case 268:
	case 269:
	case 271:
	case 282:
	case 284:
	case 285:
	case 300:
	  goto invalid;		/* can't be saved */
	};
      --cdesc[LIFEPROT];
      cdesc[HP] = 1;
      --cdesc[CONSTITUTION];
      cursors ();
      lprcat ("\nYou feel wiiieeeeerrrrrd all over! ");
      lflush ();
      nap (NAPTIME);
      return;			/* only case where died() returns */
    }

  cursors ();
  lprcat ("\nPress any key to continue. ");
  ttgetch ();

invalid:
  /*clearvt100(); */
  lflush ();
  f = 0;

  /* if we are not to display the scores */
  if (x < 0)
    {
      f++;
      x = -x;
    }

  /* for quick exit or saved game */
  if ((x == 300) || (x == 257))
    {
      clearvt100 ();
      exit (EXIT_SUCCESS);
    }

  if (x == 263)
    win = 1;
  else
    win = 0;

  cdesc[GOLD] += cdesc[BANKACCOUNT];
  cdesc[BANKACCOUNT] = 0;

  /*  now enter the player at the end of the scoreboard */
  newscore (cdesc[GOLD], logname, x, win);
  diedsub (x);			/* print out the score line */
  lflush ();

  set_score_output ();
  if ((wizard == 0) && (cdesc[GOLD] > 0))	/*  wizards can't score     */
    {
      /*if (lappend(logfile)<0)
         {
         if (lcreat(logfile)<0) {
         lcreat((char*)0);
         lprcat("\nCan't open record file:  I can't post your score.\n");
         sncbr();
         resetscroll();
         lflush();
         clearvt100();
         exit(EXIT_SUCCESS);
         }
         _chmod(logfile,0666);
         }
         strcpy(logg.who,logname);
         logg.score = cdesc[GOLD];  
         logg.diff = cdesc[HARDGAME];
         if (x < 256) {
         ch = *monster[x].name;
         if (ch=='a' || ch=='e' || ch=='i' || ch=='o' || ch=='u')
         mod="an";
         else
         mod="a";
         sprintf(logg.what,"killed by %s %s",mod,monster[x].name);
         }
         else sprintf(logg.what,"%s",whydead[x - 256]);
         logg.cavelev=level;
         time(&zzz);
         logg.diedtime=zzz;
         #ifdef EXTRA
         logg.lev=cdesc[LEVEL];          logg.ac=cdesc[AC];
         logg.hpmax=cdesc[HPMAX];        logg.hp=cdesc[HP];
         logg.elapsedtime=(zzz-initialtime+59)/60;
         logg.usage=(10000*i)/(zzz-initialtime);
         logg.bytin=cdesc[BYTESIN];      logg.bytout=cdesc[BYTESOUT];
         logg.moves=cdesc[MOVESMADE];    logg.spused=cdesc[SPELLSCAST];
         logg.killed=cdesc[MONSTKILLED];
         #endif
         lwrite((char*)&logg,sizeof(struct log_fmt));
         lwclose(); */

      /*  now for the scoreboard maintenance -- not for a suspended game  */
      if (x != 257)
	{
	  if (sortboard ())
	    scorerror = writeboard ();
	}
    }
  if ((x == 256) || (x == 257) || (f != 0))
    {
      clearvt100 ();
      exit (EXIT_SUCCESS);
    }
  if (scorerror == 0)
    {
      lflush ();
      clear ();
      resetscroll ();
      showscores ();		/* if we updated the scoreboard */
      cursors ();
      lprcat ("\nPress any key to exit. ");
      scbr ();
      ttgetch ();
    }
  clearvt100 ();
  exit (EXIT_SUCCESS);
}
Exemplo n.º 11
0
/*
 *	clearvt100() 	 	
 *		Subroutine to clean up terminal when the game is over
 *	Attributes off, clear screen, unset scrolling region, restore tty mode 
 */
clearvt100 ()
{
	resetscroll();  
	settty();
}