示例#1
0
void 
read_channel_data (void)
{
  FILE *fp;
  CHANNEL *c;
  CHANNEL *c_next;
  char buf[500];

  for (c = chan_first; c != NULL; c = c_next)
    {
      c_next = c->next;
      free_m (c);
    }
  chan_first = NULL;

  if ((fp = fopen ("channel.dat", "r")) == NULL)
    {
      fprintf (stderr, "Could not read channel.dat!\n");
      return;
    }

  c = NULL;
  for (;;)
    {
      strcpy (buf, fread_word (fp));
      if (!str_cmp ("END", buf))
	{
	  break;
	}
      if (!str_cmp ("#", buf))
	{
	  fread_to_eol (fp);
	  continue;
	}
      if (!str_cmp ("NEW_CHANNEL", buf))
	{
	  c = mem_alloc (sizeof (*c));
	  c->clan = FALSE;
	  c->clan2 = FALSE;
	  c->channel_name = &str_empty[0];
	  c->moves = 0;
	  c->commands[0] = NULL;
	  c->commands[1] = NULL;
	  c->commands[2] = NULL;
	  c->level = 0;
	  c->to_level = 0;
	  c->color = &str_empty[0];
	  c->to_align = TO_SAME;
	  c->next = chan_first;
	  chan_first = c;
	  continue;
	}
      if (!str_cmp ("NAME", buf))
	{
	  c->channel_name = str_dup (fread_word (fp));
	  continue;
	}
      if (!str_cmp ("LEVEL", buf))
	{
	  c->level = fread_number (fp);
	  continue;
	}
      if (!str_cmp ("MOVES", buf))
	{
	  c->moves = fread_number (fp);
	  continue;
	}
      if (!str_cmp ("CLAN", buf))
	{
	  char t[20];
	  strcpy (t, fread_word (fp));
	  if (!str_cmp (t, "yes"))
	    c->clan = TRUE;
	  continue;
	}
      if (!str_cmp ("CLAN2", buf))
	{
	  char t[20];
	  strcpy (t, fread_word (fp));
	  if (!str_cmp (t, "yes"))
	    c->clan2 = TRUE;
	  continue;
	}
      if (!str_cmp ("COMMAND", buf))
	{
	  char cmd[40];
	  int i = 0;
	  strcpy (cmd, fread_word (fp));
	  while (c->commands[i])
	    i++;
	  c->commands[i] = str_dup (cmd);
	  continue;
	}
      if (!str_cmp ("COLOR", buf))
	{
	  c->color = str_dup (fread_word (fp));
	  continue;
	}
      if (!str_cmp ("ALIGNMENT", buf))
	{
	  char t[20];
	  strcpy (t, fread_word (fp));
	  
	  if (!str_cmp ("both", t))
	    c->to_align = TO_ALL;
	  else if (!str_cmp ("same", t))
	    c->to_align = TO_SAME;
	  else c->to_align = TO_SAME;
	  continue;
	}
      if (!str_cmp ("TO_LEVEL", buf))
	{
	  c->to_level = fread_number (fp);
	  continue;
	}
      fprintf (stderr, "Unknown read in channel.dat: %s\n", buf);
      fread_to_eol (fp);
    }

  fclose (fp);
  return;
}
示例#2
0
文件: MWXml.cpp 项目: ak4hige/myway3d
	void XmlHelper::XmlFree(char * data)
	{
		d_assert (data);

		free_m(data);
	}