Example #1
0
xml_element *Floor::xml(xml_document *document) { // new on 011102
   xml_element *floor_element = create_xml_element(xml_tag(),document);
	if (previous_mouse != NULL && tt_dumping_background != NULL) { // new on 131202
		previous_mouse->add_xml(floor_element,L"PreviousMouse",document);
	};
	// folllowing new on 070103 - checked through all state variables
	if (body_cubby != NULL) {
		body_cubby->add_xml(floor_element,L"MainBox",document);
		if (room != NULL) { // only needed if in thought bubble
			xml_append_child(room->xml_path(document),floor_element);
		};
	};
	if (alternative_body_cubbies != NULL) { // new on 151204
		xml_element *alternative_body_cubbies_element = create_xml_element(L"AlternativesForMyBox",document);	
		alternative_body_cubbies->add_xml(alternative_body_cubbies_element,document);
		xml_append_child(alternative_body_cubbies_element,floor_element); // new on 161204
	};		
	if (initial_robot != NULL) {
		initial_robot->add_xml(floor_element,L"InitialRobot",document);
	};
	if (toolbox_status != TOOLBOX_CACHE_STATUS_UNINITIALIZED) {
		xml_set_attribute(floor_element,L"ToolBoxStatusCode",(int) toolbox_status);
	};
	if (items != NULL) { // moved here so these don't generate include files if the above refers to them (or their parts)
      xml_element *on_floor_element = create_xml_element(L"OnFloor",document);
      xml_set_attribute(on_floor_element,L"Z",current_priority); // only need this if there are some items on the floor
#if TT_DEBUG_ON
		if (tt_debug_mode == 160703) {
			tt_error_file() << "About to dump floor items." << endl;
		};
#endif
		items->add_xml(on_floor_element,document,NULL,TRUE);
		xml_append_child(on_floor_element,floor_element); // moved here on 190804
#if TT_DEBUG_ON
		if (tt_debug_mode == 160703) {
			tt_error_file() << "Done dumping floor items." << endl;
		};
#endif
		// following not needed as of 160703 so restored above
		// new on 120703 so that mice who might cause others to not dump as an include file are processed first
		// what about running robots?? -- ok since tt_running_robots is processed first - right?
  //    items->add_xml(on_floor_element,document,NULL,TRUE,FALSE,first_to_be_dumped); 
		//items->add_xml(on_floor_element,document,NULL,TRUE,FALSE,not_first_to_be_dumped);
   };
	xml_set_attribute(floor_element,L"FloorID",floor_id);
	if (at_left_wall) {
		xml_set_attribute(floor_element,L"AtLeftWall",1);
	};
	if (at_right_wall) {
		xml_set_attribute(floor_element,L"AtRightWall",1);
	};
	if (at_front_wall) {
		xml_set_attribute(floor_element,L"AtFrontWall",1);
	};
//	add_xml(floor_element,document); // new on 090404 -- this wasn't needed since all this containment stuff is now computed from sit_llx etc on load
   return(floor_element);
};
Example #2
0
/** Handle start tag */
static
void handle_starttag(
   PPOS*                 ppos
   )
{
   XML_NODE* node;
   char* name;

   assert(ppos != NULL);

   if ((name = get_name(ppos)) == NULL)
   {
      xml_error(ppos, "Missing name in tagstart");
      ppos->state = STATE_ERROR;
   }
   else
   {
      if (NULL == (node = xml_new_node(name, ppos->lineno)))
      {
         xml_error(ppos, "Can't create new node");
         ppos->state = STATE_ERROR;
      }
      else
      {
         xml_append_child(top_pstack(ppos), node);

         if ( push_pstack(ppos, node) )
            ppos->state = STATE_IN_TAG;
         else
            ppos->state = STATE_ERROR;
      }
      BMSfreeMemoryArray(&name);
   }
}
Example #3
0
xml_element *Room::xml(xml_document *document) { // new on 011102
   xml_element *room_element = create_xml_element(L"Room",document);
   if (wall_decoration != NULL) {
      xml_element *decoration_element = create_xml_element(L"OnWall",document);
      wall_decoration->xml_create_and_append_element(decoration_element,document)->Release();
		xml_append_child(decoration_element,room_element); // moved here on 190804
      // don't need to restore this since it'll be dumped here but not as an item below
		wall_decoration->set_ok_to_dump(FALSE); // so not dumped as an item as well
      // i.e. not when items are dumped below - note this really means don't dump if part of a list - will still be dumped as decoration from here
	};
   if (items != NULL && !(items->rest() == NULL && !items->first()->ok_to_dump())) {
      xml_element *inside_element = create_xml_element(L"Inside",document);    
      items->add_xml(inside_element,document,NULL,TRUE);
		xml_append_child(inside_element,room_element); // moved here on 190804
   };
	if (explosion_time != 0) { // new on 030204
		xml_set_attribute(room_element,L"ExplosionTime",explosion_time);
	};
   return(room_element);
};
Example #4
0
/* Handles PCDATA */
static
void proc_pcdata(
   PPOS*                 ppos                /**< input stream position */
   )
{
   XML_NODE* node;
   char*   data   = NULL;
   size_t  size   = 0;
   size_t  len    = 0;
   int     c;

   assert(ppos        != NULL);
   assert(ppos->state == STATE_PCDATA);

#ifndef SPEC_LIKE_SPACE_HANDLING
   if ((c = skip_space(ppos)) != EOF)
      ungetsymbol(ppos, c);
#endif
   c = getsymbol(ppos);

   while ((c != EOF) && (c != '<'))
   {
      if (len >= size - 1) /* leave space for terminating '\0' */
      {
         size += DATA_EXT_SIZE;

         if ( data == NULL )
         {
            ALLOC_ABORT( BMSallocMemoryArray(&data, size) );
         }
         else
         {
            ALLOC_ABORT( BMSreallocMemoryArray(&data, size) );
         }
      }
      assert(data != NULL);
      assert(size > len + 1);

      data[len++] = (char)c;

      c = getsymbol(ppos);
   }
   if (data == NULL)
   {
      if (c == EOF)
         ppos->state = STATE_EOF;
      else if (c == '<')
      {
         ppos->state = STATE_BEFORE;
         ungetsymbol(ppos, c);
      }
      else
      {
         ppos->state = STATE_ERROR;
      }
   }
   else
   {
      assert(len < size);
      data[len] = '\0';

      if (c == EOF)
         ppos->state = STATE_ERROR;
      else
      {
         ungetsymbol(ppos, c);

         if (NULL == (node = xml_new_node("#PCDATA", ppos->lineno)))
         {
            xml_error(ppos, "Can't create new node");
            ppos->state = STATE_ERROR;
         }
         else
         {
            BMSduplicateMemoryArray(&node->data, data, strlen(data)+1);
            xml_append_child(top_pstack(ppos), node);
            ppos->state = STATE_BEFORE;
         }
         BMSfreeMemoryArray(&data);
      }
   }
}
Example #5
0
/** Handles declarations that start with a <!.
 *
 *  This includes comments. Does currenlty not work very well, because of DTDs.
 */
static
void handle_decl(
   PPOS*                 ppos
   )
{
   enum XmlSection {
      IS_COMMENT,
      IS_ATTLIST,
      IS_DOCTYPE,
      IS_ELEMENT,
      IS_ENTITY,
      IS_NOTATION,
      IS_CDATA
   };
   typedef enum XmlSection XMLSECTION;
   
   static struct
   {
      const char* name;
      XMLSECTION  what;
   } key[] =
   {
      { "--",       IS_COMMENT  },
      { "ATTLIST",  IS_ATTLIST  },
      { "DOCTYPE",  IS_DOCTYPE  },
      { "ELEMENT",  IS_ELEMENT  },
      { "ENTITY",   IS_ENTITY   },
      { "NOTATION", IS_NOTATION },
      { "[CDATA[",  IS_CDATA    }
   };
   XML_NODE* node;
   char*   data;
   int     c;
   int     k      = 0;
   int     beg    = 0;
   int     end    = (sizeof(key) / sizeof(key[0])) - 1;

   assert(ppos        != NULL);
   assert(ppos->state == STATE_BEFORE);

   do
   {
      c = getsymbol(ppos);

      for(; (beg <= end) && (c != key[beg].name[k]); beg++)
         ;
      for(; (end >= beg) && (c != key[end].name[k]); end--)
         ;
      k++;
   } while(beg < end);

   if (beg != end)
   {
      xml_error(ppos, "Unknown declaration");

      while((c != EOF) && (c != '>'))
         c = getsymbol(ppos);
   }
   else
   {
      assert(beg == end);
      assert(beg <  (int)(sizeof(key) / sizeof(*key)));

      switch(key[beg].what)
      {
      case IS_COMMENT :
         if (do_comment(ppos))
            ppos->state = STATE_ERROR;
         break;
      case IS_CDATA :
         if ((data = do_cdata(ppos)) == NULL)
            ppos->state = STATE_ERROR;
         else
         {
            if (NULL == (node = xml_new_node("#CDATA", ppos->lineno)))
            {
               xml_error(ppos, "Can't create new node");
               ppos->state = STATE_ERROR;
            }
            else
            {
               BMSduplicateMemoryArray(&node->data, data, strlen(data)+1);
               BMSfreeMemoryArray(&data);
               xml_append_child(top_pstack(ppos), node);
            }
         }
         break;
      case IS_ATTLIST :
      case IS_ELEMENT :
      case IS_NOTATION :
      case IS_ENTITY :
      case IS_DOCTYPE :
         break;
      default :
         abort();
      }
   }
}