Esempio n. 1
0
ATTR_HOT inline void netlist_core_terminal_t::update_dev(const UINT32 mask)
{
	inc_stat(netdev().stat_call_count);
	if ((state() & mask) != 0)
	{
		netdev().update_dev();
	}
}
Esempio n. 2
0
ATTR_HOT /* inline */ void core_terminal_t::update_dev(const UINT32 mask)
{
	inc_stat(netdev().stat_call_count);
	if ((state() & mask) != 0)
	{
		device().update_dev();
	}
}
Esempio n. 3
0
/* ------------------------------------------------------------------
 * Opens and iterates through a given directory, operating on allowed
 * files found within it.  . and .. are skipped, as are files beginning
 * with . unless it's been enabled in the flags.  All other entries,
 * both files and directories, are thrown to process_entry to determine
 * whether they're a file/directory/link, and to read/explore them if
 * appropriate.  If threads are being used, they wait for their children
 * threads to terminate after they themselves are done with their work.
 *
 * flags:	The usual I/O option flags.
 * list_head:	A list of already visited directories.  Always will have
 *		the working directory low was called from as the tail,
 *		and will always have the current directory being explored
 *		as the head (so the src = list_head->next->path assignment
 *		is always safe).
 * fullpath:	The realpath of the current directory being explored.
 * dir_depth:	Passed to process_entry.
 * ------------------------------------------------------------------
 */
int explore_dir(params *P, visited_dir *list_head, char *nextpath, 
		int dir_depth)
{
	DIR *d;
	struct dirent *entry;
	struct dirent **done;
	int len;
	
	if ( (d = opendir(nextpath)) == 0)
	{
		return print_file_error(P, errno, nextpath);
	}
	
	if (((P->max_dir_depth) - dir_depth) > read_stat(P, t_ddepth))
		update_stat(P, t_ddepth, ((P->max_dir_depth) - dir_depth));
	
	len = offsetof(struct dirent, d_name) + 
		pathconf(nextpath, _PC_NAME_MAX) + 1;
	if ((entry = malloc(len)) == NULL || 
			(done = malloc(sizeof(struct dirent*))) == NULL)
	{
		fprintf(stderr, "Malloc failed in explore_dir.\n");
		return -1;
	}
	done = &entry;

	while ( (readdir_r(d, entry, done)) == 0 && (*done != NULL))
	{
		/* don't process '.' or '..' in a directory! */
		if ( (strcmp(entry->d_name, THIS_DIR) == 0) 
			|| (strcmp(entry->d_name, PARENT_DIR) == 0))
			continue;

		/* do all files but ones beginning with a dot,
		 * unless we've enabled it! */
		if (entry->d_name[0] == '.')
		{
			if (enabled(P, READ_DOT_FILES))
			{
				process_entry(P, list_head, entry->d_name,
					nextpath, dir_depth, 0);
			}
			else
				inc_stat(P, t_dotfiles, 1);
		}
		else
			process_entry(P, list_head, entry->d_name, nextpath,
				dir_depth, 0);
	}
	closedir(d);
	wait_for_children(list_head);
	free(nextpath);
	return 0;	
}
Esempio n. 4
0
ATTR_HOT inline void netlist_net_t::update_dev(const netlist_core_terminal_t *inp, const UINT32 mask) const
{
	if ((inp->state() & mask) != 0)
	{
		netlist_core_device_t &netdev = inp->netdev();
		begin_timing(netdev.total_time);
		inc_stat(netdev.stat_count);
		netdev.update_dev();
		end_timing(netdev().total_time);
	}
}
Esempio n. 5
0
/* ------------------------------------------------------------------
 * Interface for threads to call explore_dir from, pretty much.
 * ------------------------------------------------------------------
 */
void* thread_dir_setup(void *info)
{
	dir_info *d = (dir_info*) info;
	params *P = d->parameters;
	inc_stat(P, t_threadsmade, 1);
	
	pthread_mutex_lock(&stats_mutex);
	(P->threads_left) -= 1;
	pthread_mutex_unlock(&stats_mutex);

	inc_stat(P, current_tcount,1);
	if (read_stat(P, current_tcount) > read_stat(P, t_threadssim))
		update_stat(P, t_threadssim, read_stat(P, current_tcount));
	explore_dir(P, d->list, d->path, d->dir_d);

	pthread_mutex_lock(&stats_mutex);
	(P->threads_left) += 1;
	pthread_mutex_unlock(&stats_mutex);
	inc_stat(P, current_tcount, -1);
	free_dir_info(info);
	return 0;
}	
Esempio n. 6
0
/* ------------------------------------------------------------------
 * Special method for a directory to clean up after itself if it has
 * spawned any threads.
 * ------------------------------------------------------------------
 */
void handle_directory(params *P, visited_dir *list, char *nextpath, dev_t dev,
		ino_t ino, char *prevpath, int dir_d)
{
	pthread_t new_thread;
	dir_info *new_dir_info;
	visited_dir *parent_dir;
	parent_dir = list;
	inc_stat(P, t_dirs, 1);

	pthread_mutex_lock(&stack_mutex);
	list = add_visited(list, prevpath, dev, ino);
	pthread_mutex_unlock(&stack_mutex);

	pthread_mutex_lock(&stats_mutex);
	if (!enabled(P, THREAD_LIMIT) || (P->threads_left) > 0)
	{
		pthread_mutex_unlock(&stats_mutex);
		new_dir_info = create_dir_info(P, list, nextpath, dir_d);
		if (pthread_create(&new_thread, NULL, 
			thread_dir_setup, new_dir_info) == 0)
		{
			add_child(parent_dir, new_thread);
		}
		else
		{
			inc_stat(P, t_threadfails, 1);
			explore_dir(P, list, nextpath, dir_d);
			free_dir_info(new_dir_info);
		}
	}
	else
	{
		pthread_mutex_unlock(&stats_mutex);
		inc_stat(P, t_threadskips, 1);
		explore_dir(P, list, nextpath, dir_d);
	}
}
Esempio n. 7
0
ATTR_HOT /* inline */ void net_t::update_devs()
{
	//assert(m_num_cons != 0);
	nl_assert(this->isRailNet());

	const int masks[4] = { 1, 5, 3, 1 };
	const int mask = masks[ (m_cur_Q  << 1) | m_new_Q ];

	m_in_queue = 2; /* mark as taken ... */
	m_cur_Q = m_new_Q;

	for (core_terminal_t *p = m_list_active.first(); p != nullptr; p = p->next())
	{
		inc_stat(p->netdev().stat_call_count);
		if ((p->state() & mask) != 0)
			p->device().update_dev();
	}
}
Esempio n. 8
0
/* ------------------------------------------------------------------
 * Given a string to a file or path, first determines the full 'real' path.
 *
 * If the filename is a symlink, we resolve the link and call this function
 * again, with the from_link flag set.  This is used in deciding which
 * parameter (filename or fullpath) to use when calling lstat, and in
 * determining whether it is necessary to check for loops in the directory
 * hierarchy.
 *
 * If the filename is actually a directory, (and is not already open),
 * explore_dir is called to take care of its entries.  If the directory is
 * found within the visited_dir list, then we have found a loop, and the
 * directory is not explored.
 *
 * Otherwise, it's a regular ol' file and we just call read_file on it.
 *
 * list:	Linked list of visited directories.  Loops are detected
 *		by comparing absolute pathnames.
 * filename:	Name of entity being examined (directory or file).
 * fullpath:	Buffer to hold the full pathname of a file.
 * dir_d:	Maxmimum allowed depth of directory recursion to perform.
 * from_link:	Flag denoting whether this function has been called from
 *		a symbolic link or not.
 * ------------------------------------------------------------------
 */
int process_entry(params *P, visited_dir *list, char *filename,
		  char *path, int dir_d, int from_link)
{
	struct stat statbuf;
	dev_t dev;
	ino_t ino;
	char *absolute_filename;
	int myerrno;
	if ((absolute_filename = malloc(path_size)) == NULL)
	{
		fprintf(stderr, "Malloc failed in process_entry.\n");
		return -1;
	}
	pthread_mutex_lock(&chdir_mutex);
	chdir(path);
	if (lstat(filename, &statbuf) < 0)
	{
		myerrno = errno;
		pthread_mutex_unlock(&chdir_mutex);
		if (filename[0] == '/')
		{
			snprintf(absolute_filename,path_size, "%s", filename);
		}
		else
		{
			snprintf(absolute_filename,path_size, "%s/%s", 
				path, filename);
		}
		if (!enabled(P, NO_SYMLINKS) || (myerrno != ELOOP))
			print_file_error(P, myerrno, absolute_filename);
		free(absolute_filename);
		return 0;
	}

	if (realpath(filename, absolute_filename) == 0)
	{
		myerrno = errno;
		pthread_mutex_unlock(&chdir_mutex);
		if (filename[0] == '/')
		{
			snprintf(absolute_filename,path_size, "%s", filename);
		}
		else
		{
			snprintf(absolute_filename,path_size, "%s/%s", 
				path, filename);
		}

		if (!enabled(P, NO_SYMLINKS) || (myerrno != ELOOP))
			print_file_error(P, myerrno, absolute_filename);
		free(absolute_filename);
		return 0;
	}
	if ( S_ISLNK(statbuf.st_mode))
	{ /* symbolic link: could be either file or dir, so resolve & process */
		if (!enabled(P, NO_SYMLINKS))
		{
			if (lstat(absolute_filename, &statbuf) < 0)
			{
				myerrno = errno;
				pthread_mutex_unlock(&chdir_mutex);
				/*snprintf(absolute_filename,path_size, "%s/%s", 
						path, filename);*/
				print_file_error(P, myerrno, absolute_filename);

				free(absolute_filename);
				return 0;
			}
		}
		else
		{
			free(absolute_filename);
			return 0;
		}
	}
	pthread_mutex_unlock(&chdir_mutex);
	dev = statbuf.st_dev;
	ino = statbuf.st_ino;
	myerrno = 0;
	if (S_ISREG(statbuf.st_mode) || S_ISCHR(statbuf.st_mode))
	{ /* regular, readable file */
		read_file(P, absolute_filename);
		inc_stat(P, t_infiles, 1);
		free(absolute_filename);
	}
	else if (!S_ISDIR(statbuf.st_mode))
	{ /* if not link, file, or dir, error (if appropriate) */
		print_file_error(P, 0, absolute_filename);
		free(absolute_filename);
		return 0;
	}
		
	else if (S_ISDIR(statbuf.st_mode) && dir_d != 0)
	{ /* directory, and dir_depth allows us to explore it */
		if(have_visited(list, dev, ino))
		{ /* if loop found, print it, but don't explore */
			inc_stat(P, t_dloops, 1);
			if (!enabled(P, QUIET_FILENAME))
			{
				print_loop(P, filename, path, 
					absolute_filename, list, dev, ino);
			}
			free(absolute_filename);
		}
		else
		{ /* add a list node, explore the dir, then free the node */
			handle_directory(P, list, absolute_filename, 
				dev, ino, path, (dir_d - 1));
		}
	}
	else if (S_ISDIR(statbuf.st_mode) && dir_d == 0)
	{
		inc_stat(P, t_dskips, 1);
		free(absolute_filename);
	}
	return 0;
}
Esempio n. 9
0
/* Potions for the quaffing				-RAK-	*/
void quaff()
{
  int32u i, l;
  int j, k, item_val;
  int ident;
  register inven_type *i_ptr;
  register struct misc *m_ptr;
  register struct flags *f_ptr;
#if 0
  /* used by ifdefed out learn_spell potion */
  register class_type *c_ptr;
#endif

  free_turn_flag = TRUE;
  if (inven_ctr == 0)
    msg_print("But you are not carrying anything.");
  else if (!find_range(TV_POTION1, TV_POTION2, &j, &k))
    msg_print("You are not carrying any potions.");
  else if (get_item(&item_val, "Quaff which potion?", j, k, CNIL, CNIL))
    {
      i_ptr = &inventory[item_val];
      i = i_ptr->flags;
      free_turn_flag = FALSE;
      ident = FALSE;
      if (i == 0)
	{
	  msg_print ("You feel less thirsty.");
	  ident = TRUE;
	}
      else while (i != 0)
	{
	  j = bit_pos(&i) + 1;
	  if (i_ptr->tval == TV_POTION2)
	    j += 32;
	  /* Potions						*/
	  switch(j)
	    {
	    case 1:
	      if (inc_stat (A_STR))
		{
		  msg_print("Wow!  What bulging muscles!");
		  ident = TRUE;
		}
	      break;
	    case 2:
	      ident = TRUE;
	      lose_str();
	      break;
	    case 3:
	      if (res_stat (A_STR))
		{
		  msg_print("You feel warm all over.");
		  ident = TRUE;
		}
	      break;
	    case 4:
	      if (inc_stat (A_INT))
		{
		  msg_print("Aren't you brilliant!");
		  ident = TRUE;
		}
	      break;
	    case 5:
	      ident = TRUE;
	      lose_int();
	      break;
	    case 6:
	      if (res_stat (A_INT))
		{
		  msg_print("You have have a warm feeling.");
		  ident = TRUE;
		}
	      break;
	    case 7:
	      if (inc_stat (A_WIS))
		{
		  msg_print("You suddenly have a profound thought!");
		  ident = TRUE;
		}
	      break;
	    case 8:
	      ident = TRUE;
	      lose_wis();
	      break;
	    case 9:
	      if (res_stat (A_WIS))
		{
		  msg_print("You feel your wisdom returning.");
		  ident = TRUE;
		}
	      break;
	    case 10:
	      if (inc_stat (A_CHR))
		{
		  msg_print("Gee, ain't you cute!");
		  ident = TRUE;
		}
	      break;
	    case 11:
	      ident = TRUE;
	      lose_chr();
	      break;
	    case 12:
	      if (res_stat (A_CHR))
		{
		  msg_print("You feel your looks returning.");
		  ident = TRUE;
		}
	      break;
	    case 13:
	      ident = hp_player(damroll(2, 7));
	      break;
	    case 14:
	      ident = hp_player(damroll(4, 7));
	      break;
	    case 15:
	      ident = hp_player(damroll(6, 7));
	      break;
	    case 16:
	      ident = hp_player(1000);
	      break;
	    case 17:
	      if (inc_stat (A_CON))
		{
		  msg_print("You feel tingly for a moment.");
		  ident = TRUE;
		}
	      break;
	    case 18:
	      m_ptr = &py.misc;
	      if (m_ptr->exp < MAX_EXP)
		{
		  l = (m_ptr->exp / 2) + 10;
		  if (l > 100000L)  l = 100000L;
		  m_ptr->exp += l;
		  msg_print("You feel more experienced.");
		  prt_experience();
		  ident = TRUE;
		}
	      break;
	    case 19:
	      f_ptr = &py.flags;
	      if (!f_ptr->free_act)
		{
		  /* paralysis must == 0, otherwise could not drink potion */
		  msg_print("You fall asleep.");
		  f_ptr->paralysis += randint(4) + 4;
		  ident = TRUE;
		}
	      break;
	    case 20:
	      f_ptr = &py.flags;
	      if (f_ptr->blind == 0)
		{
		  msg_print("You are covered by a veil of darkness.");
		  ident = TRUE;
		}
	      f_ptr->blind += randint(100) + 100;
	      break;
	    case 21:
	      f_ptr = &py.flags;
	      if (f_ptr->confused == 0)
		{
		  msg_print("Hey!  This is good stuff!  * Hick! *");
		  ident = TRUE;
		}
	      f_ptr->confused += randint(20) + 12;
	      break;
	    case 22:
	      f_ptr = &py.flags;
	      if (f_ptr->poisoned == 0)
		{
		  msg_print("You feel very sick.");
		  ident = TRUE;
		}
	      f_ptr->poisoned += randint(15) + 10;
	      break;
	    case 23:
	      if (py.flags.fast == 0)
		ident = TRUE;
	      py.flags.fast += randint(25) + 15;
	      break;
	    case 24:
	      if (py.flags.slow == 0)
		ident = TRUE;
	      py.flags.slow += randint(25) + 15;
	      break;
	    case 26:
	      if (inc_stat (A_DEX))
		{
		  msg_print("You feel more limber!");
		  ident = TRUE;
		}
	      break;
	    case 27:
	      if (res_stat (A_DEX))
		{
		  msg_print("You feel less clumsy.");
		  ident = TRUE;
		}
	      break;
	    case 28:
	      if (res_stat (A_CON))
		{
		  msg_print("You feel your health returning!");
		  ident = TRUE;
		}
	      break;
	    case 29:
	      ident = cure_blindness();
	      break;
	    case 30:
	      ident = cure_confusion();
	      break;
	    case 31:
	      ident = cure_poison();
	      break;
#if 0
	    case 33:
	      /* this is no longer useful, now that there is a 'G'ain magic
		 spells command */
	      m_ptr = &py.misc;
	      c_ptr = &class[m_ptr->pclass];
	      if (c_ptr->spell == MAGE)
		{
		  calc_spells(A_INT);
		  calc_mana(A_INT);
		}
	      else if (c_ptr->spell == PRIEST)
		{
		  calc_spells(A_WIS);
		  calc_mana(A_WIS);
		}
	      else
		{
		  /* A warrior learns something about his equipment. -CJS- */
		  inven_type *w_ptr;
		  vtype tmp_str;
		  extern char *describe_use ();

		  for (k = 22; k < INVEN_ARRAY_SIZE; k++)
		    {
		      w_ptr = &inventory[k];
		      if (w_ptr->tval != TV_NOTHING && enchanted (w_ptr))
			{
			  (void) sprintf (tmp_str,
				  "There's something about what you are %s...",
					  describe_use(k));
			  msg_print (tmp_str);
			  add_inscribe(w_ptr, ID_MAGIK);
			  ident = TRUE;
			}
		    }
		}
	      break;
#endif
	    case 34:
	      if (py.misc.exp > 0)
		{
		  int32 m, scale;
		  msg_print("You feel your memories fade.");
		  /* Lose between 1/5 and 2/5 of your experience */
		  m = py.misc.exp / 5;
		  if (py.misc.exp > MAX_SHORT)
		    {
		      scale = MAX_LONG / py.misc.exp;
		      m += (randint((int)scale) * py.misc.exp) / (scale * 5);
		    }
		  else
		    m += randint((int)py.misc.exp) / 5;
		  lose_exp(m);
		  ident = TRUE;
		}
	      break;
	    case 35:
	      f_ptr = &py.flags;
	      (void) cure_poison();
	      if (f_ptr->food > 150)  f_ptr->food = 150;
	      f_ptr->paralysis = 4;
	      msg_print("The potion makes you vomit!");
	      ident = TRUE;
	      break;
	    case 36:
	      if (py.flags.invuln == 0)
		ident = TRUE;
	      py.flags.invuln += randint(10) + 10;
	      break;
	    case 37:
	      if (py.flags.hero == 0)
		ident = TRUE;
	      py.flags.hero += randint(25) + 25;
	      break;
	    case 38:
	      if (py.flags.shero == 0)
		ident = TRUE;
	      py.flags.shero += randint(25) + 25;
	      break;
	    case 39:
	      ident = remove_fear();
	      break;
	    case 40:
	      ident = restore_level();
	      break;
	    case 41:
	      f_ptr = &py.flags;
	      if (f_ptr->resist_heat == 0)
		ident = TRUE;
	      f_ptr->resist_heat += randint(10) + 10;
	      break;
	    case 42:
	      f_ptr = &py.flags;
	      if (f_ptr->resist_cold == 0)
		ident = TRUE;
	      f_ptr->resist_cold += randint(10) + 10;
	      break;
	    case 43:
	      if (py.flags.detect_inv == 0)
		ident = TRUE;
	      detect_inv2(randint(12)+12);
	      break;
	    case 44:
	      ident = slow_poison();
	      break;
	    case 45:
	      ident = cure_poison();
	      break;
	    case 46:
	      m_ptr = &py.misc;
	      if (m_ptr->cmana < m_ptr->mana)
		{
		  m_ptr->cmana = m_ptr->mana;
		  ident = TRUE;
		  msg_print("Your feel your head clear.");
		  prt_cmana();
		}
	      break;
	    case 47:
	      f_ptr = &py.flags;
	      if (f_ptr->tim_infra == 0)
		{
		  msg_print("Your eyes begin to tingle.");
		  ident = TRUE;
		}
	      f_ptr->tim_infra += 100 + randint(100);
	      break;
	    default:
	      msg_print ("Internal error in potion()");
	      break;
	    }
	  /* End of Potions.					*/
	}
      if (ident)
	{
	  if (!known1_p(i_ptr))
	    {
	      m_ptr = &py.misc;
	      /* round half-way case up */
	      m_ptr->exp += (i_ptr->level + (m_ptr->lev >> 1)) / m_ptr->lev;
	      prt_experience();

	      identify(&item_val);
	      i_ptr = &inventory[item_val];
	    }
	}
Esempio n. 10
0
/* Potions for the quaffing				-RAK-	*/
void quaff()
{
  int32u i, l;
  int j, k, item_val;
  int ident;
  register inven_type *i_ptr;
  register struct misc *m_ptr;
  register struct flags *f_ptr;

  free_turn_flag = TRUE;
  if (inven_ctr == 0)
    msg_print("But you are not carrying anything.");
  else if (!find_range(TV_POTION1, TV_POTION2, &j, &k))
    msg_print("You are not carrying any potions.");
  else if (get_item(&item_val, "Quaff which potion?", j, k, 0))
    {
      i_ptr = &inventory[item_val];
      i = i_ptr->flags;
      free_turn_flag = FALSE;
      ident = FALSE;
      if (i == 0)
	{
	  msg_print ("You feel less thirsty.");
	  ident = TRUE;
	}
      else while (i != 0)
	{
	  j = bit_pos(&i) + 1;
	  if (i_ptr->tval == TV_POTION2)
	    j += 32;
	  /* Potions						*/
	  switch(j)
	    {
	    case 1:
	      if (inc_stat (A_STR))
		{
		  msg_print("Wow!  What bulging muscles!");
		  ident = TRUE;
		}
	      break;
	    case 2:
	      ident = TRUE;
	      lose_str();
	      break;
	    case 3:
	      if (res_stat (A_STR))
		{
		  msg_print("You feel warm all over.");
		  ident = TRUE;
		}
	      break;
	    case 4:
	      if (inc_stat (A_INT))
		{
		  msg_print("Aren't you brilliant!");
		  ident = TRUE;
		}
	      break;
	    case 5:
	      ident = TRUE;
	      lose_int();
	      break;
	    case 6:
	      if (res_stat (A_INT))
		{
		  msg_print("You have a warm feeling.");
		  ident = TRUE;
		}
	      break;
	    case 7:
	      if (inc_stat (A_WIS))
		{
		  msg_print("You suddenly have a profound thought!");
		  ident = TRUE;
		}
	      break;
	    case 8:
	      ident = TRUE;
	      lose_wis();
	      break;
	    case 9:
	      if (res_stat (A_WIS))
		{
		  msg_print("You feel your wisdom returning.");
		  ident = TRUE;
		}
	      break;
	    case 10:
	      if (inc_stat (A_CHR))
		{
		  msg_print("Gee, ain't you cute!");
		  ident = TRUE;
		}
	      break;
	    case 11:
	      ident = TRUE;
	      lose_chr();
	      break;
	    case 12:
	      if (res_stat (A_CHR))
		{
		  msg_print("You feel your looks returning.");
		  ident = TRUE;
		}
	      break;
	    case 13:
	      ident = hp_player(damroll(2, 7));
	      if (py.flags.cut>0) {
		py.flags.cut-=10;
		if (py.flags.cut<0) py.flags.cut=0;
		ident = TRUE;
		msg_print("Your wounds heal.");
	      }
	      break;
	    case 14:
	      ident = hp_player(damroll(4, 7));
	      if (py.flags.cut>0) {
		py.flags.cut=(py.flags.cut/2)-50;
		if (py.flags.cut<0) py.flags.cut=0;
		ident = TRUE;
		msg_print("Your wounds heal.");
	      }
	      break;
	    case 15:
	      ident = hp_player(damroll(6, 7));
	      if (py.flags.cut>0) {
		py.flags.cut=0;
		ident = TRUE;
		msg_print("Your wounds heal.");
	      }
 	      if (py.flags.stun>0) {
		if (py.flags.stun>50) {
		  py.misc.ptohit+=20;
		  py.misc.ptodam+=20;
		} else {
		  py.misc.ptohit+=5;
		  py.misc.ptodam+=5;
		}
		py.flags.stun=0;
		ident = TRUE;
		msg_print("Your head stops stinging.");
	      }
	      break;
	    case 16:
	      ident = hp_player(400);
	      if (py.flags.stun>0) {
		if (py.flags.stun>50) {
		  py.misc.ptohit+=20;
		  py.misc.ptodam+=20;
		} else {
		  py.misc.ptohit+=5;
		  py.misc.ptodam+=5;
		}
		py.flags.stun=0;
		ident = TRUE;
		msg_print("Your head stops stinging.");
	      }
	      if (py.flags.cut>0) {
		py.flags.cut=0;
		ident = TRUE;
		msg_print("Your wounds heal.");
	      }
	      break;
	    case 17:
	      if (inc_stat (A_CON))
		{
		  msg_print("You feel tingly for a moment.");
		  ident = TRUE;
		}
	      break;
	    case 18:
	      m_ptr = &py.misc;
	      if (m_ptr->exp < MAX_EXP)
		{
		  l = (m_ptr->exp / 2) + 10;
		  if (l > 100000L)  l = 100000L;
		  m_ptr->exp += l;
		  msg_print("You feel more experienced.");
		  prt_experience();
		  ident = TRUE;
		}
	      break;
	    case 19:
	      f_ptr = &py.flags;
	      if (!f_ptr->free_act)
		{
		  /* paralysis must == 0, otherwise could not drink potion */
		  msg_print("You fall asleep.");
		  f_ptr->paralysis += randint(4) + 4;
		  ident = TRUE;
		}
	      break;
	    case 20:
	      f_ptr = &py.flags;
	      if (!py.flags.blindness_resist) {
	        if (f_ptr->blind == 0)
		  {
		    msg_print("You are covered by a veil of darkness.");
		    ident = TRUE;
		  }
	        f_ptr->blind += randint(100) + 100;
	      }
	      break;
	    case 21:
	      f_ptr = &py.flags;
	      if (!f_ptr->confusion_resist)
		{
	          if (f_ptr->confused == 0)
		    {
		      msg_print("Hey!  This is good stuff!  * Hick! *");
		      ident = TRUE;
		    }
	          f_ptr->confused += randint(20) + 12;
                }
              break;
	    case 22:
	      f_ptr = &py.flags;
	      if (f_ptr->poisoned == 0)
		{
		  msg_print("You feel very sick.");
		  ident = TRUE;
		}
	      if (!f_ptr->poison_resist)
		f_ptr->poisoned += randint(15) + 10;
	      break;
	    case 23:
	      if (py.flags.fast == 0)
		ident = TRUE;
	      if (py.flags.fast <= 0)
		  {
		    py.flags.fast += randint(25) + 15;
		  }
	      else
		py.flags.fast += randint(5);
	      break;
	    case 24:
	      if (py.flags.slow == 0)
		ident = TRUE;
	      py.flags.slow += randint(25) + 15;
	      break;
	    case 26:
	      if (inc_stat (A_DEX))
		{
		  msg_print("You feel more limber!");
		  ident = TRUE;
		}
	      break;
	    case 27:
	      if (res_stat (A_DEX))
		{
		  msg_print("You feel less clumsy.");
		  ident = TRUE;
		}
	      break;
	    case 28:
	      if (res_stat (A_CON))
		{
		  msg_print("You feel your health returning!");
		  ident = TRUE;
		}
	      break;
	    case 29:
	      ident = cure_blindness();
	      break;
	    case 30:
	      ident = cure_confusion();
	      break;
	    case 31:
	      ident = cure_poison();
	      break;
	    case 34:
	      if (!py.flags.hold_life && py.misc.exp>0) {
		  int32 m, scale;
		  msg_print("You feel your memories fade.");
		  m = py.misc.exp / 5;
		  if (py.misc.exp > MAX_SHORT) {
		    scale = MAX_LONG / py.misc.exp;
		    m+=(randint((int)scale)*py.misc.exp)/(scale*5);
		  }
		  else m+=randint((int)py.misc.exp)/5;
		  lose_exp(m);
		  ident=TRUE;
	      }
	      else msg_print
	     ("You feel you memories fade for a moment, but quickly return.");
	      break;
	    case 35:
	      f_ptr = &py.flags;
	      (void) cure_poison();
	      if (f_ptr->food > 150)  f_ptr->food = 150;
	      f_ptr->paralysis = 4;
	      msg_print("The potion makes you vomit!");
	      ident = TRUE;
	      break;
	    case 37:
	      if (py.flags.hero == 0)
		ident = TRUE;
	      py.flags.hero += randint(25) + 25;
	      break;
	    case 38:
	      if (py.flags.shero == 0)
		ident = TRUE;
	      py.flags.shero += randint(25) + 25;
	      break;
	    case 39:
	      ident = remove_fear();
	      break;
	    case 40:
	      ident = restore_level();
	      break;
	    case 41:
	      f_ptr = &py.flags;
	      if (f_ptr->resist_heat == 0)
		ident = TRUE;
	      f_ptr->resist_heat += randint(10) + 10;
	      break;
	    case 42:
	      f_ptr = &py.flags;
	      if (f_ptr->resist_cold == 0)
		ident = TRUE;
	      f_ptr->resist_cold += randint(10) + 10;
	      break;
	    case 43:
	      if (py.flags.detect_inv == 0)
		ident = TRUE;
	      detect_inv2(randint(12)+12);
	      break;
	    case 44:
	      ident = slow_poison();
	      break;
	    case 45:
	      ident = cure_poison();
	      break;
	    case 46:
	      m_ptr = &py.misc;
	      if (m_ptr->cmana < m_ptr->mana)
		{
		  m_ptr->cmana = m_ptr->mana;
		  ident = TRUE;
		  msg_print("Your feel your head clear.");
		  prt_cmana();
		}
	      break;
	    case 47:
	      f_ptr = &py.flags;
	      if (f_ptr->tim_infra == 0)
		{
		  msg_print("Your eyes begin to tingle.");
		  ident = TRUE;
		}
	      f_ptr->tim_infra += 100 + randint(100);
	      break;
	    case 48:
	      wizard_light(TRUE);
	      if (!res_stat(A_WIS)) inc_stat(A_WIS);
	      if (!res_stat(A_INT)) inc_stat(A_INT);
	      msg_print("You feel more enlightened!");
	      identify_pack();
	      ident=TRUE;
	      break;
	    case 49:
	      msg_print("Massive explosions rupture your body!");
	      take_hit(damroll(50,20),"a potion of Detonation");
	      cut_player(5000);
	      stun_player(75);
	      ident=TRUE;
	      break;
	    case 50:
	      msg_print("A feeling of Death flows through your body.");
	      take_hit(5000,"a potion of Death");
	      ident=TRUE;
	      break;
	    case 51:
	      if (restore_level() | res_stat(A_STR) | res_stat(A_CON) |
		  res_stat(A_DEX) | res_stat(A_WIS) | res_stat(A_INT) |
		  res_stat(A_CHR) | hp_player(5000) | cure_poison() |
		  cure_blindness() | cure_confusion() | (py.flags.stun>0) |
		  (py.flags.cut>0) | (py.flags.image>0) | remove_fear()) {
	       ident=TRUE;
	       py.flags.cut=0;
	       py.flags.image=0;
	       if (py.flags.stun>0) {
	         if (py.flags.stun>50) {
		   py.misc.ptohit+=20;
		   py.misc.ptodam+=20;
		 } else {
		   py.misc.ptohit+=5;
		   py.misc.ptodam+=5;
	         }
		 py.flags.stun=0;
               }
  	      }
	      break;
            case 52:
	      if (inc_stat(A_DEX) | inc_stat(A_WIS) | inc_stat(A_INT) |
		  inc_stat(A_STR) | inc_stat(A_CHR) | inc_stat(A_CON)) {
		ident=TRUE;
		msg_print("You feel power flow through your body!");
	      }
	      break;
	    case 53:
	      take_hit(damroll(10,10),"a potion of Ruination");
	      ruin_stat(A_DEX);
	      ruin_stat(A_WIS);
	      ruin_stat(A_CON);
	      ruin_stat(A_STR);
	      ruin_stat(A_CHR);
	      ruin_stat(A_INT);
	      ident=TRUE;
	      msg_print("Your nerves and muscles feel weak and lifeless");
	      break;
	    case 54:
	      wizard_light(TRUE);
	      msg_print("An image of your surroundings forms in your mind");
	      ident = TRUE;
	      break;
	    case 55:
	      msg_print("You feel you know yourself a little better...");
	      self_knowledge();
	      ident = TRUE;
	      break; 
	    case 56: /*  *Healing*  */
              ident = hp_player(1200);
              if (py.flags.stun>0) {
                if (py.flags.stun>50) {
                  py.misc.ptohit+=20;
                  py.misc.ptodam+=20;
	        } else {
                  py.misc.ptohit+=5;
                  py.misc.ptodam+=5;
	        }
                py.flags.stun=0;
                ident = TRUE;
                msg_print("Your head stops stinging.");
	      }
              if (py.flags.cut>0) {
                py.flags.cut=0;
                ident = TRUE;
                msg_print("Your wounds heal.");
	      }
              if (cure_blindness()) ident = TRUE;
              if (cure_confusion()) ident = TRUE;
              if (cure_poison()) ident = TRUE;
              break;
	    default:
	      if (1) {
		char tmp_str[100];
		msg_print ("Internal error in potion()");
		sprintf(tmp_str, "Number %d...", j);
		msg_print (tmp_str);
	      }
	      break;
	    }
	  /* End of Potions.					*/
	}
      if (ident)
	{
	  if (!known1_p(i_ptr))
	    {
	      m_ptr = &py.misc;
	      /* round half-way case up */
	      m_ptr->exp += (i_ptr->level + (m_ptr->lev >> 1)) / m_ptr->lev;
	      prt_experience();

	      identify(&item_val);
	      i_ptr = &inventory[item_val];
	    }
	}