Exemple #1
0
/*
	*******
	OSCROLL
	*******

	function to process a magic scroll
 */
void oscroll(int typ)
{
	lprcat("\nDo you ");
	if (c[BLINDCOUNT]==0) 
		lprcat("(r) read it, "); 
	lprcat("(t) take it"); 
	iopts();
	while (1) switch(getcharacter()) {
	case ESC:
	case 'i':	
		ignore();  
		return;

	case 'r':	
		if (c[BLINDCOUNT]) break;
		lprcat("read.");
		forget();
		if (typ==2 || typ==15)  { 
			show1cell(playerx,playery); 
			cursors(); 
		}
		/*	destroy it	*/	
		read_scroll(typ);  
		return;

	case 't':	
		lprcat("take.");
		if (take(OSCROLL,typ)==0)
			forget();	/*	destroy it	*/
		return;
	};
}
Exemple #2
0
/*
 * get a line
 *   buf: receive buffer
 *   len: buffer length
 *   return: line length on success; 0 on failed
 */
int getline(char *buf, int len)
{
	int n = 0, term = 0;
	char c;

//	while(c=getchar(), c!=0 && c!='\n' && n<len)
	do{
		c=getcharacter();
		//kprintf("rx char: %c (%d)\n", c, c);
		if(c == '\b')	//backspace
		{
			if(n>0)
			{
				serial_putc('\b');
				serial_putc(' ');
				serial_putc('\b');
				n--;
			}
		}
		else if(c == '\n' || c == '\r')
		{
			serial_putc('\n');
			term = 1;
		}
		else{
			buf[n++] = c;
			serial_putc(c);
		}
	}
	while(term==0 && n<len);
	
	buf[n] = '\0';

	return n;
}
Exemple #3
0
/* function to keep the screen open if not launched from bash */
void _NonAppStop( void )
{
  if (getenv("_IN_NETWARE_BASH_") == NULL) {
    printf("\r\n<Press any key to close screen> ");
    getcharacter();
  }
}
Exemple #4
0
void do_create(void)
{
	int t, a;

gett:
	cursors();
	lprintf("\nType of item (Scroll/Potion/Monster/Other) : ");
	do {
		t=getcharacter();
	} while (isspace(t));
	switch(t) {
	case ESC:	return;
	case 's':
	case 'S':
		cursors();
		cl_dn(1, 23);
		lprcat("Scroll Arg: ");
		a=readnum((long)MAXSCROLL);
		lprintf("createitem(OSCROLL, %d)", a);
		createitem(playerx,playery,OSCROLL, a);
		dropflag=1;
		return;
	case 'p':
	case 'P':
		cursors();
		cl_dn(1, 23);
		lprcat("Potion Arg: ");
		a=readnum((long)MAXPOTION);
		lprintf("createitem(OPOTION, %d)", a);
		createitem(playerx,playery,OPOTION, a);
		dropflag=1;
		return;
	case 'o':
	case 'O':
		cursors();
		lprcat("\n\n");
		cl_dn(1, 23);
		lprcat("Item : ");
		t=readnum(0);
		lprcat("Arg : ");
		a=readnum(0);
		lprintf("\ncreateitem(%d, %d)", t, a);
		createitem(playerx,playery,t, a);
		dropflag=1;
		return;
	case 'm':
	case 'M':
		cursors();
		lprcat("\n\n");
		cl_dn(1, 23);
		lprcat("Monst : ");
		t=readnum(0);
		lprintf("\ncreatemonster(%d)", t);
		createmonster(t);
		dropflag=1;
		return;
	default:
		goto gett;
	}
}
Exemple #5
0
void odeadthrone()
{
	int k;

	lprcat("\nDo you (s) sit down"); 
	iopts();
	while (1) {
		while (1) switch(getcharacter()) {
		case 's': 	
			lprcat(" sit down");  
			k=rnd(101);
			if (k<5) raiselevel();
			else if (k<25) {
			      lprcat("\nZaaaappp!  You've been teleported!\n"); 
				beep(); 
				oteleport(0); 
			}
			else lprcat("\nNothing happens.");
			return;

		case 'i':
		case ESC: 
			ignore(); 
			return;
		};
	} /* NOTREACHED */
}
Exemple #6
0
void ocookie()
{
	char *fortune(), *p;

	lprcat("\nDo you (e) eat it, (t) take it"); 
	iopts();
	while (1) 
		switch(getcharacter()) {
		case ESC:
		case 'i':	
			ignore();	
			return;

		case 'e':	
			lprcat("eat.\nThe cookie tasted good.");
			forget(); /* no more cookie	*/
			if (c[BLINDCOUNT]) return;
			if ((p=fortune(fortfile))==(char *)NULL) return;
			lprcat("  A message inside the cookie reads:\n"); 
			lprcat(p);
			return;

		case 't':	
			lprcat("take.");  
			if (take(OCOOKIE,0)==0) forget();
			return;
		};
}
Exemple #7
0
void obook()
{
	lprcat("\nDo you ");
	if (c[BLINDCOUNT]==0) lprcat("(r) read it, "); 
	lprcat("(t) take it"); 
	iopts();
	while (1) 
		switch(getcharacter()) {
		case ESC:
		case 'i':	
			ignore();	
			return;

		case 'r':	
			if (c[BLINDCOUNT]) break;
			lprcat("read.");
			readbook(iarg[playerx][playery]);   
			/* no more book	*/
			forget();
			return;

		case 't':	
			lprcat("take.");
			if (take(OBOOK,iarg[playerx][playery])==0)  
				forget();	/* no more book	*/
			return;
		};
}
Exemple #8
0
maze::maze() {
    // open the file
    mazefile = fopen("Maze.txt", "r");

    // get the dimensions of the maze
    ydim = getdimension();
    xdim = getdimension();

    // allocate memory for the maze array
    mazearray = new char*[xdim];
    for (int x = 0; x < xdim; x++) {
        mazearray[x] = new char[ydim];
    }

    // start constructing the maze
    for (int y = 0; y < ydim; y++) {
        for (int x = 0; x < xdim; x++) {
            char c = getcharacter();
            mazearray[x][y] = c;
            // if we found the start point, record it
            if (c == '*') {
                start[0] = x;
                start[1] = y;
                // std::cout << "found the start at location: " << start[0] << ", " << start[1] << std::endl;
            }
        }
    }

    // close the file
    fclose(mazefile);
}
Exemple #9
0
char * _csv_get_line(FILE * fp, int * length_p, int encoding)
{
  /*
  this function returns a single plain text line.
  it does no parsing and might not be a complete csv line due to embedded carriage returns and line feeds.
  csv_get_line() calls this function until a complete row is achieved
  */
  
  char * line = NULL;
  int alloc_size = 0;
  int length = 0;
  int c;
  while (!feof(fp))
  {
    c = getcharacter(fp, encoding);
    
    if (c == 0x0D)
    {
      fpos_t pos;
      fgetpos(fp, &pos);
      
      int c2 = getcharacter(fp, encoding);
      
      if (c2 != 0x0A) fsetpos(fp, &pos); // get the next char - if it's 0x0A skip it, otherwise rewind once
      break;
    }
    else if (c == 0x0A) break;    // end of the line
    else if (c == 0x00) continue; // ignore null characters, some files prepend lots of them for fun
    else if (c != EOF)
    {
      length++;
      if (length >= alloc_size)
      {
        alloc_size += 1000;
        line = realloc(line, (sizeof(char) * alloc_size) + 1);
      }
      line[length-1] = c;
    }
  }
  if (line != NULL)
    line[length] = 0;
  
  *length_p = length;
  return line;
}
Exemple #10
0
void _NonAppStop()
{
    uint16_t row, col;

    GetScreenSize(&row, &col);
    gotorowcol(row-1, 0);
    /* pressanykey(); */
    printf("<Press any key to close screen> ");
    getcharacter();
}
Exemple #11
0
void term(){
	if(look == '*'){
		match("*");
		term();
		emitln("xor ebx, ebx");
		settype(reduceptr(current_type));
		STRSWITCH(current_type)
			STRCASE("short")
				emitln("mov bx, word [eax]");
			STRCASE("char")
				emitln("mov bl, byte [eax]");
			STRDEFAULT
				emitln("mov ebx, dword [eax]");
		STRSWITCHEND
		emitln("xchg eax, ebx");
	} else if(look == '('){
		match("(");
		emitln("push eax");
		expression();
		match(")");
	}

	else if(look == '"'){
		emitln("mov eax, %s", add_string(getstring('"')));
		current_type = "char*";
	}
	
	else if(look == '\''){
		match("'");
		emitln("mov eax, %d", look);
		getcharacter();
		match("'");
		current_type = "char";
	}

	else if(is_in(dynstring("%c", look), "+", "-", NULL)){
		emitln("push dword 0");
		operator();
	}

	else if(isalpha(look)){
		identifier();
	}

	else if(isdigit(look)){
		emitln("mov eax, %s", getnumber());
	}

	else
		expected("Number or variable");
}
Exemple #12
0
/*
 *	subroutine to get a number from the player
 *	and allow * to mean return amt, else return the number entered
 */
long readnum (long mx)
{
	int i;
	long amt=0;

		/* allow him to say * for all gold */
	if ((i=getcharacter()) == '*')   {
		lprcat("*\n");
		return (mx);
	} else 
	while (i != '\n') {
		lprc(i);
		if (i==ESC || isspace(i)) { 
			lprcat(" aborted.");
			return(-1L); /* Return -1 to indicate abort. */
		}
		if ((i <= '9') && (i >= '0') && (amt<999999999L))
			amt = (long) (amt * 10L + i - '0');
		i = getcharacter();
	}
	lprc(i);
	return (amt);
}
Exemple #13
0
/*
 *	*******
 *	OTHRONE
 *	*******
 *
 */
void othrone(int arg)
{
	int i,k;

	lprcat("\nDo you (p) pry off jewels, (s) sit down"); 
	iopts();
	while (1) {
		while (1) switch(getcharacter()) {
		case 'p':	
			lprcat(" pry off");  
			k=rnd(101);
			if (k<25) {
				for (i=0; i<rnd(4); i++) 
					creategem(); /*gems pop off the throne*/
				item[playerx][playery]=ODEADTHRONE;
				know[playerx][playery]=0;
			}
			else if (k<40 && arg==0) {
				createmonster(GNOMEKING);
				item[playerx][playery]=OTHRONE2;
				know[playerx][playery]=0;
			}
			else lprcat("\nNothing happens.");
			return;

		case 's': 	
			lprcat(" sit down");  
			k=rnd(101);
			if (k<30 && arg==0) {
				createmonster(GNOMEKING);
				item[playerx][playery]=OTHRONE2;
				know[playerx][playery]=0;
			}
			else if (k<35) {
			    lprcat("\nZaaaappp!  You've been teleported!\n"); 
				beep();
				oteleport(0); 
			}
			else lprcat("\nNothing happens.");
			return;

		case 'i':
		case ESC: 
			ignore(); 
			return;
		};
	} /* NOTREACHED */
}
Exemple #14
0
/*
	function to say what object we found and ask if player wants to take it
 */
void finditem(int itm)
{
	int tmp,i;
	lprintf("\n\nYou find %s",objectname[itm]);
	tmp=iarg[playerx][playery];
	switch(itm)
	{
	case ODIAMOND:		
	case ORUBY:			
	case OEMERALD:
	case OSAPPHIRE:		
	case OSPIRITSCARAB:	
	case OORBOFDRAGON:
	case OORB:
	case OHANDofFEAR:
	case OWWAND:
	case OCUBEofUNDEAD:	
	case ONOTHEFT:
		lprcat(".");
		break;

	default:
		if (tmp>0) 
			lprintf(" + %d",(long)tmp); 
		else if (tmp<0) lprintf(" %d",(long)tmp);
	}
	lprcat("\nDo you want to (t) take it"); 
	iopts();
	i=0; 
	while (i!='t' && i!='i' && i!=ESC) i=getcharacter();
	if (i == 't') {	
		lprcat("take.");
		if (take(itm,tmp)==0)  
			forget();	
		return;	
	}
	ignore();
}
Exemple #15
0
/*
	*******
	OPOTION
	*******

	function to process a potion
 */
void opotion(int pot)
{
	lprcat("\nDo you (d) drink it, (t) take it"); 
	iopts();
	while (1) switch(getcharacter())
	{
	case ESC:
	case 'i':	
		ignore();  
		return;

	case 'd':	
		lprcat("drink.\n");
		forget();	/*	destroy potion	*/
		quaffpotion(pot);		
		return;

	case 't':	
		lprcat("take.\n");
		if (take(OPOTION,pot)==0)  forget();
		return;
	};
}
Exemple #16
0
char maze::getcharacter() {
    // reads the next character of the maze into a variable
    // skips over whitespace and newlines
    // complains if one of the characters is not *, -, $, or x
    char c;
    c = fgetc(mazefile);
    switch (c) {
        case 'x' :
        case '-' :
        case '*' :
        case '$' :
            return c;
            break;
        case '\n' :
        case ' ' :
            return getcharacter();
            break;
        default:
            std::cout << "an error occured with character: " << c << std::endl;
            exit(1);
            break;
    }
}
Exemple #17
0
int qwhatitem (void)
{
	int j, i=0;
	char tmp[IVENSIZE];

	cursors();
	for (j=0; j<IVENSIZE; j++)
		switch(iven[j]) {
			case OPOTION:	tmp[i++] = j;
		};
	lprintf("\nWhat do you want to quaff [");
	if (i)
		for (j=0;j<i;j++) 
			lprintf("%c",tmp[j] + 'a');
	lprintf(" * for all] ?");
	i=0; 
	while (i>'z' || (i<'a' && i!='*' && !isspace(i) && i!=ESC )) 
		i=getcharacter();
	if (i==ESC || isspace(i))  
		lprcat(" aborted.");
	if (isspace(i)) i= ESC;

	return(i);
}
Exemple #18
0
/*
 *	******
 *	OCHEST
 *	******
 *
 */
void ochest()
{
	int i,k;

	lprcat("\nDo you (t) take it, (o) try to open it"); 
	iopts();
	while (1) {
		while (1) switch(getcharacter()) {
		case 'o':	
			lprcat(" open it.");  
			k=rnd(101);
			if (k<40) {
				lprcat("\nThe chest explodes as you open it."); 
				beep();
				i = rnd(10);
				if (i > c[HP]) i = c[HP];
				lastnum=281;  /* in case he dies */
				lprintf("\nYou suffer %d hit point%s damage!", (long)i,
						i==1?"":"s");
				checkloss(i);
				switch(rnd(10))	{
				case 1:	
					c[ITCHING]+= rnd(1000)+100;
					lprcat("\nYou feel an irritation spread over your skin!");
					beep();
					break;

				case 2:	
					c[CLUMSINESS]+= rnd(1600)+200;
					lprcat("\nYou begin to lose hand-eye co-ordination!");
					beep();
					break;

				case 3:	
					c[HALFDAM]+= rnd(1600)+200;
					lprcat("\nYou suddenly feel sick and BARF all over your "
						   "shoes!");
					beep();
					break;
				};
				item[playerx][playery]=know[playerx][playery]=0;
				if (rnd(100)<69) 
					creategem(); /* gems from the chest */
				dropgold(rnd(110*iarg[playerx][playery]+200));
				for (i=0; i<rnd(4); i++) 
					something(playerx, playery, iarg[playerx][playery]+2);
			}
			else lprcat("\nNothing happens.");
			return;

		case 't':	
			lprcat(" take");
			if (take(OCHEST,iarg[playerx][playery])==0)
				item[playerx][playery]=know[playerx][playery]=0;
			return;

		case 'i':
		case ESC: 
			ignore(); 
			return;
		};
	} /* NOTREACHED */
}
Exemple #19
0
/*
 *	******
 *	OALTAR
 *	******
 *
 */
void oaltar()
{
	long k;
	int  p;

start:
	lprcat("\nDo you (p) pray  (d) desecrate"); 
	iopts();
	while (1) {
		while (1) switch(getcharacter()) {
		case 'p':	
		    lprcat(" pray.\nDo you (m) give money or (j) just pray? ");
			while (1) switch(getcharacter()) {
			case 'j':
				p = rund(100);
				if      (p < 12) createmonster(makemonst(level+2));
				else if (p < 17) enchweapon(ENCH_ALTAR);
				else if (p < 22) enchantarmor(ENCH_ALTAR);
				else if (p < 27) ohear();
				else             lprcat("\nNothing happens.");

				return;

			case 'm':
				cursor(1,24);
				cltoeoln();
				cursor(1,23);
				cltoeoln();
				lprcat("how much do you donate? ");
				if ((k = readnum(c[GOLD])) < 0)
					goto start;
				if (c[GOLD] < k) {
					lprcat("You don't have that much!");
					nap(1001);
					goto start;
				}
				if (k < (c[GOLD]/10) && rnd(60)<30 && !wizard) {
					lprcat("Cheapskate! The Gods are insulted by such a "
						   "tiny offering!");
					forget();
					createmonster(DEMONPRINCE);
					c[AGGRAVATE] += 1500;
					return;
				}

				c[GOLD] -= k;
				if (k < (c[GOLD]+k)/10 || k < rnd(50) && !wizard) {
					createmonster(makemonst(level+2));
					c[AGGRAVATE] += 500;
					bottomline();
					return;
				}

				p = rund(16);
				if (p <  4) 
					lprcat("Thank you.");
				else if (p <  6) { 
					enchantarmor(ENCH_ALTAR);
					enchantarmor(ENCH_ALTAR);
				}
				else if (p < 8) {
					enchweapon(ENCH_ALTAR);
					enchweapon(ENCH_ALTAR);
				}
				else
					ohear();

				bottomline();
				return;
			} /* end while switch : case j or m */

		case 'd': 
			lprcat(" desecrate");
			if (rnd(100)<60) { 
				createmonster(makemonst(level+3)+8); 
				c[AGGRAVATE] += 2500; 
			}
			else if(rnd(100)<5) raiselevel();
			else if (rnd(101)<30) {
	lprcat("\nThe altar crumbles into a pile of dust before your eyes.");
				forget();    /*remember to destroy the altar*/
			}
			else lprcat("\nNothing happens.");
			return;

		case 'i':
		case ESC: 
			ignore();
			if (rnd(100)<30) { 
				createmonster(makemonst(level+2)); 
				c[AGGRAVATE] += rnd(450); 
			}
			else	
				lprcat("\nNothing happens.");
			return;
		} /* end while switch: pray, des, ignore */
	} /* NOTREACHED */
} /* end oaltar */
Exemple #20
0
void ohome()
{
	int i;

	nosignal = 1;	/* disable signals */
	for (i=0; i<IVENSIZE; i++) 
		/* remove the potion of cure dianthroritis from inventory */
		if (iven[i]==OPOTION) 
			if (ivenarg[i]==21) {   
				iven[i]=0;	
				clear(); 
				lprcat("Congratulations.  You found the potion of cure "
					   "dianthroritis!\n");
				lprcat("\nFrankly, No one thought you could do it.");
				lprcat("  Boy!  Did you surprise them!\n");
				nap(1000);
				if (gtime>TIMELIMIT) {
					lprcat("\nHowever... the doctor has the sad duty to "
						   "inform you that your daughter has\n");
					lprcat("died! You didn't make it in time.  In your agony, "
						   "you kill the doctor,\nyour ");
					if (sex == 1)
						lprcat("wife");
					else
						lprcat("husband");
					lprcat(" and yourself!  Too bad...\n");
					nap(5000); 
					died(269);
				}
				else {
					lprcat("\nThe doctor is now administering the potion and, "
						   "in a few moments,\n");
					lprcat("your daughter should be well on her way to "
						   "recovery.\n");
					nap(6000);
					lprcat("\nThe potion is."); 
					nap(1000); 
					lprcat(".");
					nap(1000); 
					lprcat(".");
					nap(1000); 
					lprcat(" working!  The doctor thinks that\n");
					lprcat("your daughter will recover in a few days.  "
						   "Congratulations!");
					beep(); 
					nap(5000); 
					died(263);
				}
			}

	while (1) {
		clear();
		lprintf("Welcome home %s.",logname);
		lprcat("  Latest word from the doctor is not good.\n");

		if (gtime>TIMELIMIT) {
			lprcat("\nThe doctor has the sad duty to inform you that your "
				   "daughter has died!\n");
			lprcat("You didn't make it in time.");
			lprcat("In your agony, you kill the doctor,\nyour ");
			if (sex == 1)
				lprcat("wife");
			else
				lprcat("husband");
			lprcat(" and yourself!  Too bad...");
			nap(5000); 
			died(269);
		}

		lprcat("\nThe diagnosis is confirmed as dianthroritis.  "
			   "He guesses that\n");
		lprintf("your daughter has only %d mobuls left in this world.  "
				"It's up to you,\n",(long)((TIMELIMIT-gtime+99)/100));
		lprintf("%s, to find the only hope for your daughter, the very rare\n",
				logname);
		lprcat("potion of cure dianthroritis.  It is rumored that only deep "
			   "in the\n");
		lprcat("depths of the caves can this potion be found.\n\n\n");
		lprcat("\n     ----- press "); 
		ularn_standout("return");
		lprcat(" to continue, "); 
		ularn_standout("escape");
		lprcat(" to leave ----- ");
		i=getcharacter();  
		while (i!=ESC && i!='\n') 
			i=getcharacter();
		if (i==ESC) { 
			drawscreen(); 
			nosignal = 0; /* enable signals */

			return; 
		}
	}
}
Exemple #21
0
/*
	***************
	LOOK_FOR_OBJECT
	***************

	subroutine to look for an object and give the player his options
	if an object was found.
 */
lookforobject()
{
	int i,j;

	/* can't find objects is time is stopped*/
	if (c[TIMESTOP])  return;	

	i=item[playerx][playery];	
	if (i==0) return;

	showcell(playerx,playery);  
	cursors();  
	yrepcount=0;

	switch(i) {
	case OGOLDPILE:	
	case OMAXGOLD:
	case OKGOLD:	
	case ODGOLD:	
		ogold(i);	
		break;

	case OPOTION:	
		lprcat("\n\nYou find a magic potion");
		i = iarg[playerx][playery];
		if (potionknown[i]) lprintf(" of %s",&potionname[i][1]);
		lprcat(".");
		opotion(i);  
		break;

	case OSCROLL:	
		lprcat("\n\nYou find a magic scroll");
		i = iarg[playerx][playery];
		if (scrollknown[i]) lprintf(" of %s",&scrollname[i][1]);
		lprcat(".");
		oscroll(i);  
		break;

	case OALTAR:	
		if (nearbymonst()) return;
		lprcat("\n\nThere is a holy altar here.");
		oaltar(); 
		break;

	case OBOOK:	
		lprcat("\n\nYou find a book.");
		obook(); 
		break;

	case OCOOKIE:	
		lprcat("\n\nYou find a fortune cookie.");
		ocookie(); 
		break;

	case OTHRONE:	
		if (nearbymonst()) return;
		lprintf("\n\nThere is %s here.",objectname[i]);
		othrone(0); 
		break;

	case OTHRONE2:	
		if (nearbymonst()) return;
		lprintf("\n\nThere is %s here.",objectname[i]);
		othrone(1); 
		break;

	case ODEADTHRONE: 
		lprintf("\n\nThere is %s here.",objectname[i]);
		odeadthrone(); 
		break;

	case OORB:	
		if (nearbymonst()) return;
		finditem(i);
		break;

	case OBRASSLAMP: 
		lprcat("\nYou find a brass lamp.");
	lprcat("\nDo you want to (r) rub it, (t) take it, or (i) ignore it? ");
		i=0;
		while ((i!='r') && (i!='i') && (i!='t') && (i!=ESC)) 
			i=getcharacter();
		if (i=='r') {
			i=rnd(100);
			if (i>90) {
		lprcat("\nThe magic genie was very upset at being disturbed!");
				lastnum = 286;
				losehp((int)c[HP]/2+1);
				beep();
			}
			/* higher level, better chance of spell */
			else if ( (rnd(100)+c[LEVEL]/2) > 80) {
				int a,b,d;
				lprcat("\nA magic genie appears!");
				cursors();
				lprcat("\n  What spell would you like? : ");
				while ((a=getcharacter())=='D') { 	
					seemagic(99);
					cursors();  
					lprcat("\n  What spell would you like? : ");
				}
				/* to escape casting a spell	*/
				if (a==ESC) goto over; 	
				if ((b=getcharacter())==ESC) 
					goto over;
				if ((d=getcharacter())==ESC) { 
over: 
					lprcat("aborted"); 
					return;
				}
				lprc('\n');
				for (i=0; i<SPNUM; i++)
					if ((spelcode[i][0]==a) 
					    && (spelcode[i][1]==b) 
					    && (spelcode[i][2]==d)) {
						spelknow[i]=1;
						lprintf("\nSpell \"%s\":  %s\n%s",spelcode[i],
								spelname[i],speldescript[i]); 
						lprcat("\nThe genie prefers not to be disturbed "
							   "again.");
						forget();
						bottomline();
						return;
					}
				lprcat("\nThe genie has never heard of such a spell!");
				lprcat("\nThe genie prefers not to be disturbed again.");
				forget();
				bottomline();
				return;
			}
			else lprcat("\nnothing happened.");
			if (rnd(100) < 15) {
				lprcat("\nThe genie prefers not to be disturbed again!");
				forget();
				c[LAMP]=0;  /* chance of finding lamp again */
			}
			bottomline();
		}
		else if (i=='t') {
			lprcat("take.");
			if (take(OBRASSLAMP,0)==0) 
				forget();
		}
		else lprcat("ignore.");
		return;

	case OWWAND:
		if (nearbymonst()) return;
		finditem(i);
		break;

	case OHANDofFEAR:
		if (nearbymonst()) return;
		finditem(i);
		break;

	case OPIT:	
		lprcat("\n\nYou're standing at the top of a pit."); 
		opit(); 
		break;

	case OSTAIRSUP:	
		lprcat("\n\nThere is a circular staircase here."); 
		ostairs(1);  /* up */
		break;

	case OELEVATORUP:
		lprcat("\n\nYou have found an express elevator going up.");
		oelevator(1);  /*  up  */
		break;

	case OELEVATORDOWN:	
		lprcat("\n\nYou have found an express elevator going down.");
		oelevator(-1);	/*	down	*/
		break;

	case OFOUNTAIN:	
		if (nearbymonst()) return;
		lprcat("\n\nThere is a fountain here."); 
		ofountain(); 
		break;

	case OSTATUE:	
		if (nearbymonst()) return;
		lprcat("\n\nYou stand before a statue."); 
		ostatue(); 
		break;

	case OCHEST:	
		lprcat("\n\nThere is a chest here.");  
		ochest();  
		break;

	case OIVTELETRAP:	
		if (rnd(11)<6) return;
		item[playerx][playery] = OTELEPORTER;
		know[playerx][playery] = 1;

	case OTELEPORTER:
		lprcat("\nZaaaappp!  You've been teleported!\n");
		beep(); 
		nap(3000); 
		oteleport(0);
		break; 

	case OSCHOOL:	
		if (nearbymonst()) return;
		lprcat("\n\nYou have found the College of Ularn.");
		lprcat("\nDo you (g) go inside, or (i) stay here? ");
		i=0; 
		while ((i!='g') && (i!='i') && (i!=ESC)) i=getcharacter();
		if (i == 'g') { 
			oschool();  /*	the college of larn	*/
		}
		else	lprcat(" stay here.");
		break;

	case OMIRROR:	
		if (nearbymonst()) return;
		lprcat("\n\nThere is a mirror here.");
		omirror();	
		break;

	case OBANK2:
	case OBANK:	
		if (nearbymonst()) return;
		if (i==OBANK) 
			lprcat("\n\nYou have found the bank of Ularn.");
		else 
		    lprcat("\n\nYou have found a branch office of the bank of Ularn.");
		lprcat("\nDo you (g) go inside, or (i) stay here? ");
		j=0; 
		while ((j!='g') && (j!='i') && (j!=ESC)) 
			j=getcharacter();
		if (j == 'g') {  
			if (i==OBANK) 
				obank(); 
			else 
			    obank2(); /*  the bank of larn  */

		}
		else   
			lprcat(" stay here.");
		break;

	case ODEADFOUNTAIN:	
		if (nearbymonst()) return;
		lprcat("\n\nThere is a dead fountain here.");
		break;

	case ODNDSTORE:	
		if (nearbymonst()) 
			return;
		lprcat("\n\nThere is a DND store here.");
		lprcat("\nDo you (g) go inside, or (i) stay here? ");
		i=0; 
		while ((i!='g') && (i!='i') && (i!=ESC)) i=getcharacter();
		if (i == 'g')
			dndstore();  /*  the dnd adventurers store  */
		else  
			lprcat(" stay here.");
		break;

	case OSTAIRSDOWN:
		lprcat("\n\nThere is a circular staircase here.");
		ostairs(-1); /* down */
		break;

	case OOPENDOOR:		
		lprcat("\nThere is an open door here.");
		break;


	case OCLOSEDDOOR:
		if (dropflag)
			return;
		lprintf("\n\nYou find %s",objectname[i]);
		lprcat("\nDo you (o) try to open it"); 
		iopts();
		i=0; 
		while ((i!='o') && (i!='i') && (i!=ESC)) i=getcharacter();
		if ((i==ESC) || (i=='i')) { 
			ignore();  
			playerx = lastpx;
			playery = lastpy; 
			break; 
		}
		else {
			lprcat("open.");
			if (rnd(11)<7) {
				switch(iarg[playerx][playery]) {
				case 6: 
					c[AGGRAVATE] += rnd(400);	
					break;

				case 7:	
				case 8:
					lprcat("\nYou are jolted by an electric shock!");
					lastnum=274; 
					losehp(rnd(20));  
					bottomline();  
					break;

/* Losing a level is just too harsh... */
/*				case 8:	
					loselevel();  
					break;
*/
				case 9:	
					lprcat("\nYou suddenly feel weaker!");
					if (c[STRENGTH]>3) c[STRENGTH]--;
					bottomline();  
					break;

				default:	
					break;
				}
				playerx = lastpx;  
				playery = lastpy;
			}
			else {
				forget();  
				item[playerx][playery]=OOPENDOOR;
			}
		}
		break;

	case OENTRANCE:	
		lprcat("\nYou have found ");
		lprcat(objectname[OENTRANCE]);
		lprcat("\nDo you (g) go inside"); 
		iopts();
		i=0; 
		while ((i!='g') && (i!='i') && (i!=ESC)) i=getcharacter();
		if (i == 'g')
		{
			newcavelevel(1); 
			playerx=33; 
			playery=MAXY-2;
			item[33][MAXY-1]=know[33][MAXY-1]=mitem[33][MAXY-1].mon=0;
			draws(0,MAXX,0,MAXY); 
			bot_linex(); 
			return;
		}
		else   ignore();
		break;

	case OVOLDOWN:	
		lprcat("\nYou have found "); 
		lprcat(objectname[OVOLDOWN]);
		lprcat("\nDo you (c) climb down"); 
		iopts();
		i=0; 
		while ((i!='c') && (i!='i') && (i!=ESC)) 
			i=getcharacter();
		if ((i==ESC) || (i=='i')) { 
			ignore();  
			break; 
		}
		if (level!=0) { 
			lprcat("\nThe shaft only extends 5 feet downward!"); 
			return; 
		}
		if (packweight() > 45+3*(c[STRENGTH]+c[STREXTRA])) { 
			lprcat("\nYou slip and fall down the shaft.");
			beep();
			lastnum=275;  
			losehp(30+rnd(20)); 
			bottomhp(); 
		}
		else lprcat("climb down.");
		nap(3000); 
		newcavelevel(DBOTTOM+1); /* down to V1 */
		playerx = rnd(MAXX-2);
		playery = rnd(MAXY-2);
		positionplayer(); 
		draws(0,MAXX,0,MAXY); 
		bot_linex(); 
		return;

	case OVOLUP:	
		lprcat("\nYou have found "); 
		lprcat(objectname[OVOLUP]);
		lprcat("\nDo you (c) climb up"); 
		iopts();
		i=0; 
		while ((i!='c') && (i!='i') && (i!=ESC)) i=getcharacter();
		if ((i==ESC) || (i=='i')) { 
			ignore();  
			break; 
		}
	if (packweight() > 40+5*(c[DEXTERITY]+c[STRENGTH]+c[STREXTRA])) { 
			lprcat("\nYou slip and fall down the shaft.");
			beep();
			lastnum=275; 
			losehp(15+rnd(20)); 
			bottomhp(); 
			return; 
		}
		lprcat("climb up.");
		lflush(); 
		nap(3000); 
		newcavelevel(0);
		for (i=0; i<MAXY; i++)  for (j=0; j<MAXX; j++) /* put player near volcano shaft */
			if (item[j][i]==OVOLDOWN) { 
				playerx=j; 
				playery=i; 
				j=MAXX; 
				i=MAXY; 
				positionplayer(); 
			}
		draws(0,MAXX,0,MAXY); 
		bot_linex(); 
		return;

	case OTRAPARROWIV:	
		if (rnd(17)<13) return;	/* for an arrow trap */
		item[playerx][playery] = OTRAPARROW;
		know[playerx][playery] = 0;
	case OTRAPARROW:	
		lprcat("\nYou are hit by an arrow!");
		beep();	/* for an arrow trap */
		lastnum=259;	
		losehp(rnd(10)+level);
		bottomhp();	
		return;

	case OIVDARTRAP:	
		if (rnd(17)<13) 
			return;		/* for a dart trap */
		item[playerx][playery] = ODARTRAP;
		know[playerx][playery] = 0;
	case ODARTRAP:		
		lprcat("\nYou are hit by a dart!");
		beep();	/* for a dart trap */
		lastnum=260;	
		losehp(rnd(5));
		if ((--c[STRENGTH]) < 3) c[STRENGTH] = 3;
		bottomline();	
		return;

	case OIVTRAPDOOR:	
		if (rnd(17)<13) 
			return;		/* for a trap door */
		item[playerx][playery] = OTRAPDOOR;
		know[playerx][playery] = 1;
	case OTRAPDOOR:		
		lastnum = 272; /* a trap door */
		for (i=0;i<IVENSIZE;i++)
			if (iven[i]==OWWAND) {
				lprcat("\nYou escape a trap door.");
				return;
			}
		if ((level==DBOTTOM)||(level==VBOTTOM)) { 
			lprcat("\nYou fall through a trap door leading straight to HELL!");
			beep();
			lflush();
			nap(3000);
			died(271); 
		}
		lprcat("\nYou fall through a trap door!");
		beep();	
		lflush();
		losehp(rnd(5+level));
		nap(2000);
		newcavelevel(level+1);  
		draws(0,MAXX,0,MAXY); 
		bot_linex();
		return;

	case OTRADEPOST:
		if (nearbymonst()) return;
		lprcat("\nYou have found the Ularn trading Post.");
		lprcat("\nDo you (g) go inside, or (i) stay here? ");
		i=0; 
		while ((i!='g') && (i!='i') && (i!=ESC)) i=getcharacter();
		if (i == 'g')  otradepost();  
		else  lprcat("stay here.");
		return;

	case OHOME:	
		if (nearbymonst()) return;
		lprcat("\nYou have found your way home.");
		lprcat("\nDo you (g) go inside, or (i) stay here? ");
		i=0; 
		while ((i!='g') && (i!='i') && (i!=ESC)) 
			i=getcharacter();
		if (i == 'g')  
			ohome();  
		else  lprcat("stay here.");
		return;
	case OPAD:	
		if (nearbymonst()) return;
		lprcat("\nYou have found Dealer McDope's Hideout!");
		lprcat("\nDo you (c) check it out, or (i) ignore it? ");
		i=0;
		while ((i!='c') && (i!='i') && (i!=ESC)) 
			i=getcharacter();
		if (i == 'c')  
			opad();
		else  lprcat("forget it.");
		return;

	case OSPEED:   	
		lprcat("\nYou find some speed.");
		lprcat("\nDo you (s) snort it, (t) take it, or (i) ignore it? ");
		i=0; 
		while ((i!='s') && (i!='i') && (i!='t') && (i!=ESC)) 
			i=getcharacter();
		if (i=='s') {
			lprcat("snort!");
			lprcat("\nOhwowmanlikethingstotallyseemtoslowdown!");
			c[HASTESELF] += 200 + c[LEVEL];
			c[HALFDAM] += 300 + rnd(200);
			if ((c[INTELLIGENCE]-=2) < 3)
				c[INTELLIGENCE]=3;
			if ((c[WISDOM]-=2) < 3)
				c[WISDOM]=3;
			if ((c[CONSTITUTION]-=2) <3)
				c[CONSTITUTION]=3;
			if ((c[DEXTERITY]-=2) <3)
				c[DEXTERITY]=3;
			if ((c[STRENGTH]-=2) <3)
				c[STRENGTH]=3;
			forget();
			bottomline();
		} 
		else if (i=='t') {
			lprcat("take.");
			if (take(OSPEED,0)==0) forget();
		} 
		else 
		    lprcat("ignore.");
		break;

	case OSHROOMS:	
		lprcat("\nYou find some magic mushrooms.");
		lprcat("\nDo you (e) eat them, (t) take them, or (i) ignore them? ");
		i=0; 
		while ((i!='e') && (i!='i') && (i!='t') && (i!=ESC)) 
			i=getcharacter();
		if (i=='e') {
			lprcat("eat!");
			lprcat("\nThings start to get real spacey...");
			c[HASTEMONST] += rnd(75) + 25;
			c[CONFUSE] += 30+rnd(10);
			c[WISDOM]+=2;
			c[CHARISMA]+=2;
			forget();
			bottomline();
		} 
		else if (i=='t') {
			lprcat("take.");
			if (take(OSHROOMS,0)==0) forget();
		} 
		else
			lprcat("ignore.");
		break;

	case OACID:	
		lprcat("\nYou find some LSD.");
		lprcat("\nDo you (e) eat it, (t) take it, or (i) ignore it? ");
		i=0; 
		while ((i!='e') && (i!='i') && (i!='t') && (i!=ESC)) 
			i=getcharacter();
		if (i=='e') {
			lprcat("eat!");
			lprcat("\nYou are now frying your ass off!");
			c[CONFUSE]+=30+rnd(10);
			c[WISDOM]+=2;
			c[INTELLIGENCE]+=2;
			c[AWARENESS]+=1500;
			c[AGGRAVATE]+=1500;
			{ 	
				int j,k;	/* heal monsters */
				for(j=0;j<MAXY;j++)
					for(k=0;k<MAXX;k++)
						if (mitem[k][j].mon)
							hitp[k][j]=monster[mitem[k][j].mon].hitpoints;
			}
			forget();
			bottomline();
		}
		else if (i=='t') {
			lprcat("take.");
			if (take(OACID,0)==0) forget();
		}
		else lprcat("ignore.");
		break;

	case OHASH:	
		lprcat("\nYou find some hashish.");
		lprcat("\nDo you (s) smoke it, (t) take it, or (i) ignore it? ");
		i=0; 
		while ((i!='s') && (i!='i') && (i!='t') && (i!=ESC)) 
			i=getcharacter();
		if (i=='s') {
			lprcat("smoke!");
			lprcat("\nWOW! You feel stooooooned...");
			c[HASTEMONST]+=rnd(75)+25;
			c[INTELLIGENCE]+=2;
			c[WISDOM]+=2;
			if( (c[CONSTITUTION]-=2) < 3) 
				c[CONSTITUTION]=3;
			if( (c[DEXTERITY]-=2) < 3) 
				c[DEXTERITY]=3;
			c[HALFDAM]+=300+rnd(200);
			c[CLUMSINESS]+=rnd(1800)+200;
			forget();
			bottomline();
		}
		else if (i=='t') {
			lprcat("take.");
			if (take(OHASH,0)==0) forget();
		}
		else lprcat("ignore.");
		break;

	case OCOKE:	
		lprcat("\nYou find some cocaine.");
		lprcat("\nDo you want to (s) snort it, (t) take it, or (i) ignore it? ");
		i=0; 
		while ((i!='s') && (i!='i') && (i!='t') && (i!=ESC)) 
			i=getcharacter();
		if (i=='s') {
			lprcat("snort!");
			lprcat("\nYour nose begins to bleed!");
			if ((c[DEXTERITY]-=2) <3)
				c[DEXTERITY]=3;
			if ((c[CONSTITUTION]-=2) <3)
				c[CONSTITUTION]=3;
			c[CHARISMA]+=3;
			for(i=0;i<6;i++)
				c[i]+=33;
			c[COKED]+=10;
			forget();
			bottomline();
		}
		else if (i=='t') {
			lprcat("take.");
			if (take(OCOKE,0)==0) forget();
		}
		else lprcat("ignore.");
		break;	

	case OWALL:	
		break;

	case OANNIHILATION:
		for (i=0;i<IVENSIZE;i++)
			if (iven[i]==OSPHTALISMAN) {
				lprcat("\nThe Talisman of the Sphere protects you from "
					   "annihilation!");
				return;
			}
		/* annihilated by sphere of annihilation */	
		died(283);
		return;

	case OLRS:	
		if (nearbymonst()) return;
		lprcat("\n\nThere is an LRS office here.");
		lprcat("\nDo you (g) go inside, or (i) stay here? ");
		i=0; 
		while ((i!='g') && (i!='i') && (i!=ESC)) i=getcharacter();
		if (i == 'g')
			olrs();  /*  the larn revenue service */
		else  lprcat(" stay here.");
		break;
	default:	
		finditem(i); 
		break;
	};
}
Exemple #22
0
/* rtoken - read the next CsToken */
static int rtoken(CsCompiler *c)
{
    int ch,ch2;

    /* check the next character */
    for (;;)
        switch (ch = skipspaces(c)) {
        case EOF:       return T_EOF;
        case '\"':	    
           return getstring(c);
        case '`':	    
           return getstring(c, '`');
        case '\'':      return getcharacter(c);
        case '<':       switch (ch = getch(c)) {
                        case '=':
                            return T_LE;
                        case '<':
                            if ((ch = getch(c)) == '=')
                                return T_SHLEQ;
                            else if( ch == '<' )
                            {
                              if ((ch = getch(c)) == '=')
                                return T_USHLEQ;  
                              c->savedChar = ch;
                              return T_USHL;  
                            }
                            c->savedChar = ch;
                            return T_SHL;
                        default:
                            c->savedChar = ch;
                            return '<';
                        }
        case '=':       if ((ch = getch(c)) == '=')
                        {
                            if ((ch = getch(c)) == '=')
                            {
                              return T_EQ_STRONG;
                            }
                            c->savedChar = ch;
                            return T_EQ;
                        }
                        c->savedChar = ch;
                        return '=';
        case '!':       if ((ch = getch(c)) == '=')
                        {
                            if ((ch = getch(c)) == '=')
                            {
                              return T_NE_STRONG;
                            }
                            c->savedChar = ch;
                            return T_NE;
                        }
                        c->savedChar = ch;
                        return '!';
        case '>':       switch (ch = getch(c)) {
                        case '=':
                            return T_GE;
                        case '>':
                            if ((ch = getch(c)) == '=')
                                return T_SHREQ;
                            else if( ch == '>' )
                            {
                              if ((ch = getch(c)) == '=')
                                  return T_USHREQ;
                              c->savedChar = ch;
                              return T_USHR;
                            }
                            c->savedChar = ch;
                            return T_SHR;
                        default:
                            c->savedChar = ch;
                            return '>';
                        }
        case '&':       switch (ch = getch(c)) {
                        case '&':
                            return T_AND;
                        case '=':
                            return T_ANDEQ;
                        default:
                            c->savedChar = ch;
                            return '&';
                        }
        case '%':       switch (ch = getch(c)) 
                        {
                        case '>':
                              return getoutputstring(c);
                        case '=':
                            return T_REMEQ;
                        case '~':
                           return T_RCDR;
                        default:
                            c->savedChar = ch;
                            return '%';
                        }

        case '|':       switch (ch = getch(c)) {
                        case '|':
                            return T_OR;
                        case '=':
                            return T_OREQ;
                        default:
                            c->savedChar = ch;
                            return '|';
                        }
        case '^':       if ((ch = getch(c)) == '=')
                            return T_XOREQ;
                        c->savedChar = ch;
                        return '^';
        case '+':       switch (ch = getch(c)) {
                        case '+':
                            return T_INC;
                        case '=':
                            return T_ADDEQ;
                        default:
                            c->savedChar = ch;
                            return '+';
                        }
        case '-':       switch (ch = getch(c)) {
                        case '-':
                            return T_DEC;
                        case '=':
                            return T_SUBEQ;
                        default:
                            c->savedChar = ch;
                            return '-';
                        }
        case '~':       switch (ch = getch(c)) {
                        case '/':
                            return T_CAR;
                        case '%':
                            return T_CDR;
                        default:
                            c->savedChar = ch;
                            return '~';
                        }
        case '*':       if ((ch = getch(c)) == '=')
                            return T_MULEQ;
                        c->savedChar = ch;
                        return '*';
        case '/':       switch (ch = getch(c)) {
                        case '=':
                            return T_DIVEQ;
                        case '/':
                            while ((ch = getch(c)) != EOF)
                                if (ch == '\n')
                                    break;
                            break;
                        case '*':
                            ch = ch2 = EOF;
                            for (; (ch2 = getch(c)) != EOF; ch = ch2)
                                if (ch == '*' && ch2 == '/')
                                    break;
                            break;
                        case '~':
                           return T_RCAR;
                        default:
                            c->savedChar = ch;
                            return '/';
                        }
                        break;
        case '.':       if ((ch = getch(c)) != EOF && is_digit(ch)) {
                            c->savedChar = ch;
                            return getnumber(c,'.');
                        }
                        else if (ch == '.') {
                            c->t_token[0] = '.';
                            c->t_token[1] = '.';
                            c->t_token[2] = '\0';
                            return T_DOTDOT;
                        }
                        else {
                            c->savedChar = ch;
                            c->t_token[0] = '.';
                            c->t_token[1] = '\0';
                            return '.';
                        }
                        break;
        case 1:         return T_DOTDOT;
        
        case '0':       switch (ch = getch(c)) {
                        case 'x':
                        case 'X':
                            return getradixnumber(c,16);
                        case 'b':
                        case 'B':
                            return getradixnumber(c,2);
                        default:
                            c->savedChar = ch;
                            if (ch >= '0' && ch <= '7')
                                return getradixnumber(c,8);
                            else
                                return getnumber(c,'0');
                        }
                        break;
        case '#':       return getsymbol(c);
        default:        if (is_digit(ch))
                            return getnumber(c,ch);
                        else if (isidchar(ch))
                            return getid(c,ch);
                        else {
                            c->t_token[0] = ch;
                            c->t_token[1] = '\0';
                            return ch;
                        }
        }
}
Exemple #23
0
/*
	*******
	OSTAIRS
	*******

	subroutine to process the stair cases
	if dir > 0 then up else down
 */
void ostairs(int dir)
{
	int x, y;

	lprcat("\nDo you (s) stay here  or  ");
	if (dir > 0)	
		lprcat("(u) go up?  ");	
	else	
	    lprcat("(d) go down?  ");

	while (1) 
		switch(getcharacter()) {
		case ESC:
		case 's':	
		case 'i':	
			lprcat("stay here.");	
			return;

		case 'u':	
			lprcat("go up.");
			if (dir < 0)
				lprcat("\nThe stairs don't go up!");
			else
					/* not on V1 */
				if (level>=2 && level!=DBOTTOM+1) {
					newcavelevel(level-1);
					for (x=0;x<MAXX;x++)
					  for (y=0;y<MAXY;y++)
						if (item[x][y] == OSTAIRSDOWN){
							playerx=x;
							playery=y;
							x=MAXX;
							y=MAXY;
						}
					draws(0,MAXX,0,MAXY); 
					bot_linex();
				}
				else lprcat("\nThe stairs lead to a dead end!");
			return;

		case 'd':	
			lprcat("go down.");
			if (dir > 0)	
				lprcat("\nThe stairs don't go down!");
			else
				/* not on dungeon botto or V5 */
				if ((level!=0) && (level!=DBOTTOM) && 
				    (level!=VBOTTOM)) {
					newcavelevel(level+1);
					for (x=0;x<MAXX;x++)
					  for (y=0;y<MAXY;y++)
						if (item[x][y] == OSTAIRSUP){
							playerx=x;
							playery=y;
							x=MAXX;
							y=MAXY;
						}
					draws(0,MAXX,0,MAXY); 
					bot_linex();
				}
				else lprcat("\nThe stairs lead to a dead end!");
			return;
		};
}
Exemple #24
0
/*
	function to ask what player wants to do
 */
int whatitem (char *str)
{
	int j=0, flag=0, i=0;
	int wld=0, q=0, r=0, w=0, e=0, d=0;
	char tmp[IVENSIZE];

	cursors();
	if (!strcmp(str, "wield")) 
		wld = 1;
	else if (!strcmp(str, "quaff")) 
		q = 1;
 	else if (!strcmp(str, "read")) 
		r = 1;
	else if (!strcmp(str, "wear")) 
		w = 1;
	else if (!strcmp(str, "eat")) 
		e = 1;
	else if (!strcmp(str, "drop")) 
		d = 1;

	for (j=0; j<IVENSIZE; j++) {
		switch(iven[j]) {
		case OSWORDofSLASHING:
		case OHAMMER:
		case OSWORD:
		case O2SWORD:
		case OSPEAR:
		case ODAGGER:
		case OBATTLEAXE:
		case OLONGSWORD:
		case OFLAIL:
		case OSLAYER:
		case OLANCE:
		case OVORPAL:
				flag = 1; break; /* wield */
		case OPOTION:	
				flag = 2; break; /* quaff */
		case OSCROLL:
		case OBOOK:
				flag = 3; break; /* read */
		case OPLATE :
		case OCHAIN:
		case OLEATHER :
		case ORING :
		case OSTUDLEATHER :
		case OSPLINT :
		case OPLATEARMOR :
		case OSSPLATE :
		case OSHIELD :
		case OELVENCHAIN :
				flag = 4; break; /* wear */
		case OCOOKIE:
				flag = 5; break; /* eat */
		default :	flag = 0; break;
		}
		if (!d) 
			switch (flag) {
			case 1 : 	if (wld) 
						tmp[i++] = j;
					break;
			case 2 : 	if (q) 
						tmp[i++] = j;
					break;
			case 3 : 	if (r) 
						tmp[i++] = j;
					break;
			case 4 : 	if (w) 
						tmp[i++] = j;
					break;
			case 5 : 	if (e) 
						tmp[i++] = j;
			default : 	break;
			}
		else if (iven[j]) 
			tmp[i++] = j;
	}
	lprintf("\nWhat do you want to %s [", str);
	if (i) {
		for (j=0;j<i;j++) 
			lprintf("%c",tmp[j] + 'a');
		lprintf(" ");
	}
	lprintf("* for all%s] ?", (wld) ? " - for none":"");
	i=0;
	while (!((i>='a' && i<='z') || isspace(i) || i=='*' || i==ESC || i=='.'
			 || (i=='-' && wld)))
		i=getcharacter();
	if (i==ESC || isspace(i))  
		lprcat(" aborted.");
	if (isspace(i))
		 i = ESC;
	return(i);
}
Exemple #25
0
/*
 *	*********
 *	OFOUNTAIN
 *	*********
 */
void ofountain()
{
	int x;

	cursors();
	lprcat("\nDo you (d) drink, (w) wash yourself"); 
	iopts();
	while (1) switch(getcharacter()) {
	case 'd':	
		lprcat("drink");
		if (rnd(1501)<4) {
		lprcat("\nOH MY GOD!! You have caught the *dreadful sleep*!");
			beep(); 
			lflush();  
			sleep(3);  
			died(280); 
			return;
		}
		x = rnd(100);
		if (x==1) raiselevel();
		else if (x < 11) { 	
			x=rnd((level<<2)+2);
			lprintf("\nBleah! The water tasted like stale gatorade!  "
					"You lose %d hit point%s!", (long)x, x==1?"":"s");
			lastnum=273; 
			losehp(x); 
			bottomline();  
			cursors();
		}
		else if (x<14) { 	
			c[HALFDAM] += 200+rnd(200);
			lprcat("\nThe water makes you vomit.");
		}
		else if (x<17) 
			quaffpotion(17); /* giant strength */
		else if (x < 45)
			lprcat("\nNothing seems to have happened.");
		else if (rnd(3) != 2)
			fntchange(1);	/*change char levels upward*/
		else
			fntchange(-1);	/*change char levels downward*/
		if (rnd(12)<3) {      
			lprcat("\nThe fountains bubbling slowly quietens.");
			/* dead fountain */
			item[playerx][playery]=ODEADFOUNTAIN; 
			know[playerx][playery]=0;
		}
		return;

	case 'i':	
	case ESC:
		ignore();  
		return;
	case 'w':	
		lprcat("wash yourself.");
		if (rnd(100) < 11) { 	
			x=rnd((level<<2)+2);
			lprintf("\nThe water burns like acid!  You lose %d hit point%s!",
					(long)x, x==1?"":"s");
			lastnum=273; 
			losehp(x); 
			bottomline();  
			cursors();
		}
		else if (rnd(100) < 29)
			lprcat("\nYou are now clean.");
		else if (rnd(100) < 31)
		  lprcat("\nThis water needs soap -- the dirt didn't come off.");
		else if (rnd(100) < 34)
			createmonster(WATERLORD); 
		else lprcat("\nNothing seems to have happened.");
		return;
	}
}
Exemple #26
0
char * csv_get_line(FILE * fp, int * length_p, int encoding)
{
  /*
  
  This is what I would call a terrible hack at getting lines of content that span multiple lines.
  I definitely disagree that this should be allowed, but alas, csv standard it is.
  Calling get_row and get_character_distribution on every single row totally sucks.
  
  */
  
  int length = 0;
  char * line = _csv_get_line(fp, &length, encoding);
  
  char acceptable_delimiters[100] = ",|\t;";
  
  struct sCounts counts = { 0, NULL, NULL };
  get_character_distribution(&counts, line, acceptable_delimiters);
  int delimiter = get_peak_character(&counts);
  free_character_distribution(&counts);
  
  struct sRow row = { 0, NULL };
  
  int append_next_line_required = get_row(&row, line, delimiter, 0); // returns 1 if it the \n encountered wasn't properly quoted.
  free_row(&row);
  
  while (append_next_line_required)
  {
    fseek(fp, -2, SEEK_CUR);
    int c1 = getcharacter(fp, encoding);
    int c2 = getcharacter(fp, encoding);
    
    int next_length = 0;
    char * next_line = _csv_get_line(fp, &next_length, encoding);
    
    length += next_length;
    
    if (c1 == 0x0D && c2 == 0x0A) length += 2;
    else if (c2 == 0x0D || c2 == 0x0A) length += 1;
    
    line = realloc(line, length + 1);
    
    if (next_line != NULL)
      memcpy(line + (length - next_length), next_line, next_length);
    
    line[length] = 0;
    
    if (c1 == 0x0D && c2 == 0x0A) { line[length - next_length - 2] = 0x0D; line[length - next_length - 1] = 0x0A; }
    else if (c2 == 0x0D) line[length - next_length - 1] = 0x0D;
    else if (c2 == 0x0A) line[length - next_length - 1] = 0x0A;
    
    if (next_line != NULL)
    {
      append_next_line_required = get_row(&row, next_line, delimiter, 1);
      free_row(&row);
      free(next_line);
    }
    else if (feof(fp))
      append_next_line_required = 0;
  }
  
  *length_p = length;
  
  return line;
}
Exemple #27
0
/*
 * Input stream stdin is read until the end of file is reached or until
 * the section size is reached in case of ELF files. Contiguous
 * characters of >= min_size(default 4) will be displayed.
 */
int
find_strings(const char *name, off_t offset, off_t size)
{
	off_t cur_off, start_off;
	char *obuf;
	long c;
	int i;

	if ((obuf = (char*)calloc(1, min_len + 1)) == NULL) {
		(void) fprintf(stderr, "Unable to allocate memory: %s\n",
		     strerror(errno));
		return (RETURN_SOFTWARE);
	}

	(void) fseeko(stdin, offset, SEEK_SET);
	cur_off = offset;
	start_off = 0;
	while(1) {
		if ((offset + size) && (cur_off >= offset + size))
			break;
		start_off = cur_off;
		memset(obuf, 0, min_len+1);
		for(i = 0; i < min_len; i++) {
			c = getcharacter();
			if (c == EOF && feof(stdin))
				goto _exit1;
		 	if (PRINTABLE(c)) {
		 		obuf[i] = c;
		 		obuf[i+1] = 0;
		 		cur_off += encoding_size;
		 	} else {
				if (encoding == ENCODING_8BIT &&
				    (uint8_t)c > 127) {
			 		obuf[i] = c;
			 		obuf[i+1] = 0;
			 		cur_off += encoding_size;
			 		continue;
			 	}
	 			cur_off += encoding_size;
	 			break;
		 	}
		}

		if (i >= min_len && ((cur_off <= offset + size) ||
		    !(offset + size))) {
			if (show_filename)
				printf ("%s: ", name);
			if (show_loc) {
				switch(radix) {
				case RADIX_DECIMAL:
					(void) printf("%7ju ",
					    (uintmax_t)start_off);
					break;
				case RADIX_HEX:
					(void) printf("%7jx ",
					    (uintmax_t)start_off);
					break;
				case RADIX_OCTAL:
					(void) printf("%7jo ",
					    (uintmax_t)start_off);
					break;
				}
			}
			printf("%s", obuf);

			while(1) {
				if ((offset + size) &&
				    (cur_off >= offset + size))
					break;
				c = getcharacter();
				cur_off += encoding_size;
				if (encoding == ENCODING_8BIT &&
				    (uint8_t)c > 127) {
			 		putchar(c);
			 		continue;
			 	}
				if (!PRINTABLE(c) || c == EOF)
					break;
				putchar(c);
			}
			putchar('\n');
		}
	}
_exit1:
	free(obuf);
	return (RETURN_OK);
}
Exemple #28
0
int main( int argc, char *argv[] )
{
  char line[MAX_LINE] = {0}; /* buffer for input line */
  char od = '|'; /* output delimiter */
  size_t n, headlines = 0; /* header lines counters */

  char filename[PATH_MAX] = { 0 }; /* input file name */
  FILE * fp = stdin;

  int i;

  for ( i = 1; i < argc; ++i )
  {
    if ( strcmp(argv[i], "--help") == 0 || strcmp(argv[i], "-help") == 0 )
    {
      usage(argc, argv);
      return 0;
    }

    if ( strncmp(argv[i], "--stops=", 8) == 0 )
    {
      if ( parse_stops(argv[i] + 8) < 0 )
      {
        fprintf(stderr, "invalid syntax in --stops argument\n");
        return -1;
      }
    }
    else if ( strcmp(argv[i], "-d") == 0 )
    {
      if ( ++i >= argc || !( od = getcharacter(argv[i]) ) )
      {
        fprintf(stderr, "invalid value of argument '%s'\n", argv[i - 1]);
        return -1;
      }
    }
    else if ( strcmp(argv[i], "-header") == 0 )
    {
      if ( ++i >= argc || sscanf(argv[i], "%zu", &headlines) != 1 )
      {
        fprintf(stderr, "invalid value of argument '%s'\n", argv[i - 1]);
        return -1;
      }
    }
    else if ( !*filename )
    {
      strncpy(filename, argv[i], sizeof( filename ) - 1);
    }
    else
    {
      fprintf(stderr, "invalid argument '%s'\n", argv[i]);
      return -1;
    }
  }

  if ( *filename && !( fp = fopen(filename, "rb") ) )
  {
    fprintf(stderr, "can't open '%s': %s\n", filename, strerror(errno));
    return -1;
  }

  n = 0;
  while ( fgets(line, sizeof( line ) - 1, fp) )
  {
    if ( ++n < headlines || num_stops < 1 )
    {
      printf("%s", line);
    }
    else
    {
      size_t stop = 0;
      size_t pos = 0;

      size_t len = strlen(line);
      for ( pos = 0; pos < len; ++pos )
      {
        if ( pos == stops[stop] )
        {
          putc(od,stdout);
          ++stop;
        }

        putc(line[pos],stdout);
      }
    }
  }

  if ( fp != stdin )
  {
    fclose(fp);
  }

  return 0;
}