DataMuseum.dk

Presents historical artifacts from the history of:

DKUUG/EUUG Conference tapes

This is an automatic "excavation" of a thematic subset of
artifacts from Datamuseum.dk's BitArchive.

See our Wiki for more about DKUUG/EUUG Conference tapes

Excavated with: AutoArchaeologist - Free & Open Source Software.


top - metrics - download
Index: T t

⟦b94a30520⟧ TextFile

    Length: 5535 (0x159f)
    Types: TextFile
    Names: »tok.c«

Derivation

└─⟦b20c6495f⟧ Bits:30007238 EUUGD18: Wien-båndet, efterår 1987
    └─⟦this⟧ »EUUGD18/General/Ularn/tok.c« 

TextFile

/* tok.c */
#include "header.h"

#define FLUSHNO 5
#define MAXUM 52	/* maximum number of user re-named monsters */
#define MAXMNAME 40	/* max length of a monster re-name */

static char lastok=0;
int yrepcount=0,dayplay=0;
#ifdef BSD
static int flushno=FLUSHNO;	/* input queue flushing threshold */
#endif /* BSD */
static char usermonster[MAXUM][MAXMNAME]; 
static char usermpoint=0;			/* the user monster pointer */

/*
	lexical analyzer for larn
 */
yylex()
{
	char cc;
	int i, ic;

	if (hit2flag) { 
		hit2flag=0;  
		yrepcount=0;  
		return(' '); 
	}
	if (yrepcount>0)	{ 
		--yrepcount;  
		return(lastok);	
	} 
	else yrepcount=0;

	/*show where the player is*/
	if (yrepcount==0) { 
		bottomdo(); 
		showplayer(); 
	}	
	lflush();  
	while (1) {
		c[BYTESIN]++;
		if (ckpflag)
			/* check for periodic checkpointing */
			if ( c[BYTESIN] == 1 || (c[BYTESIN] % 400) == 0) {
			    wait((int *)0);/* wait for other forks to finish */
				if (fork() == 0) { 
					savegame(ckpfile); 
					exit(0); 
				}
			}
		flushall();
		if (read(0,&cc,1) != 1) 
			return(lastok = -1);

		if (cc == '!')	/* shell escape */
		{ 	
			resetscroll();  
			clear();
			sncbr();
			cl_dn(0,0);
			lflush();
			if ((ic=fork())==0) {
				execl("/bin/csh", "/bin/csh", (char *)0);	
				exit(1);
			}
			do { 
				i = wait(0);
			} while (i != ic && i != -1);

			if (ic<0) { 	
				fprintf(stderr,"Can't fork /bin/csh!\n"); 
				fflush(stderr);
				sleep(2);
			}
			setscroll();
			scbr();
			return(lastok = 'L'-64);	/* redisplay screen */
		}
		if ((cc <= '9') && (cc >= '0')) 
			yrepcount = yrepcount*10 + cc - '0'; 
		else {	
			if (yrepcount>0) --yrepcount;  
			return(lastok = cc); 
		}
	}
}

/*
 *	flushall()	Function to flush all type-ahead in the input buffer
 */
flushall()
{
#ifdef BSD
	char cc;
	int ic;

	for (;;)/* if keyboard input buffer is too big, flush some of it */
	{
		ioctl(0,FIONREAD,&ic);
		if (ic<=0) return;
		while (ic>0)   { 
			read(0,&cc,1); 
			--ic; 
		} /* gobble up the byte */
	}
#else /* SYSV */
#  ifdef TCIFLUSH
	tcflush(0, TCIFLUSH);		/* SYSV w/POSIX 1003 tcflush() */
#  else
        ioctl(0, TCFLSH);		/* standard ioctl */
#  endif /* TCIFLUSH */
#endif /* BSD */
}

/*
	function to set the desired hardness 
	enter with hard= -1 for default hardness, else any desired hardness
 */
sethard(hard)
int hard;
{
	register int j,k,i;

	if (restorflag==0)  {      /* don't set c[HARDGAME] if restoring game */
		if (hashewon() == 0) {
			if (hard >= 0) 
				c[HARDGAME] = hard;
		}
		else  if (hard > c[HARDGAME]) c[HARDGAME] = hard;
	}

	if (k=c[HARDGAME])
		for (j=0; j<=MAXMONST+8; j++) {
			i = ((6+k)*monster[j].hitpoints+1)/6;
			monster[j].hitpoints = (i<0) ? 32767 : i;
			i = ((6+k)*monster[j].damage+1)/5;
			monster[j].damage = (i>127) ? 127 : i;
			i = (10*monster[j].gold)/(10+k);
			monster[j].gold = (i>32767) ? 32767 : i;
			i = monster[j].armorclass - k;
			monster[j].armorclass = (i< -127) ? -127 : i;
			i = (7*monster[j].experience)/(7+k) + 1;
			monster[j].experience = (i<=0) ? 1 : i;
		}				
}

/*
	function to read and process the larn options file
 */
readopts()
{
	register char *i;
	register int j,k;
	extern int char_picked;
	int flag=1;

	if (lopen(optsfile) < 0) {
		strcpy(logname,loginname); 
		return; /* user name if no character name */
	}
	i = " ";
	while (*i) {
		if ((i=(char *)lgetw()) == 0) break; /* check for EOF */
		while ((*i==' ') || (*i=='\t')) i++; /* eat leading whitespace*/
		switch(*i) {
		case 'b':	
			if (strcmp(i,"bold-off") == 0)  
				boldon=0;
			break;

		case 'e':	
			if (strcmp(i,"enable-checkpointing") == 0) 
				ckpflag=1;
			break;

		case 'f':	
			if (strcmp(i,"female") == 0)	
				sex=0; /* male or female */
			break;

			/* name favorite monster */
		case 'm':	
			if (strcmp(i,"monster:")== 0)   {
				if ((i=lgetw())==0) break;
				if (strlen(i)>=MAXMNAME) i[MAXMNAME-1]=0;
				strcpy(usermonster[usermpoint],i);
				/* defined all of em */
				if (usermpoint >= MAXUM) break; 
				if (isalpha(j=usermonster[usermpoint][0])) {
					for (k=1; k<MAXMONST+8; k++)
						if (monstnamelist[k] == j) {
				monster[k].name = &usermonster[usermpoint++][0];
							break;
						}
				}
			}
			else if (strcmp(i,"male") == 0)	sex=1;
			break;

		case 'n':	
			if (strcmp(i,"name:") == 0) {
				if ((i=lgetw())==0) break;
				if (strlen(i)>=LOGNAMESIZE) 
					i[LOGNAMESIZE-1]=0;
				strcpy(logname,i); 
				flag=0;
			}
			else if (strcmp(i,"no-introduction") == 0) 
				nowelcome=1;
			else if (strcmp(i,"no-beep") == 0) 
				nobeep=1;
			break;

		case 'c':
			if (strncmp(i,"character:",strlen("character:")) == 0) {
				int k=0, j=0;
				j = strlen("character:");
				do { 
					char_class[k++] = i[j]; 
				} while (i[j++] != '\0');
				flag = 0;
				if (!strcmp(char_class, "ogre"))
					char_picked = 'a';
				else if (!strcmp(char_class, "wizard"))
					char_picked = 'b';
				else if (!strcmp(char_class, "klingon"))
					char_picked = 'c';
				else if (!strcmp(char_class, "elf"))
					char_picked = 'd';
				else if (!strcmp(char_class, "rogue"))
					char_picked = 'e';
				else if (!strcmp(char_class, "geek"))
					char_picked = 'f';
				else if (!strcmp(char_class, "dwarf"))
					char_picked = 'g';
				else if (!strcmp(char_class, "rambo"))
					char_picked = 'h';
			}
			break;
		case 's':	
			if (strcmp(i,"savefile:") == 0) {
				if ((i=lgetw())==0) break;
				if (strlen(i)>=SAVEFILENAMESIZE)
					i[SAVEFILENAMESIZE-1]=0;
				strcpy(savefilename,i); 
				flag=0;
			}
			break;
		};
	}
	if (flag)  strcpy(logname,loginname);
}