Example #1
0
void CFormDfn::CEntry::setDfn (CFormLoader &loader, const char *filename)
{
	TypeElement = EntryDfn;
	Filename = filename;
	Type = NULL;
	Dfn = loader.loadFormDfn (filename, false);
}
Example #2
0
void CFormDfn::CEntry::setType (CFormLoader &loader, const char *filename)
{
	TypeElement = EntryType;
	Dfn = NULL;
	Filename = filename;
	Type = loader.loadType (filename);
}
Example #3
0
void CFormDfn::setParent (uint parent, CFormLoader &loader, const char *filename)
{
	if (strcmp (filename, "")==0)
		Parents[parent].Parent = NULL;
	else
		Parents[parent].Parent = loader.loadFormDfn (filename, false);
	Parents[parent].ParentFilename = filename;
}
// ---------------------------------------------------------------------------
void CGeorgesImpl::createInstanceFile (const std::string &_sxFullnameWithoutExt, const std::string &_dfnname)
{
	AFX_MANAGE_STATE(AfxGetStaticModuleState());

	CFormLoader formLoader;
	CFormDfn *dfn = formLoader.loadFormDfn (_dfnname.c_str(), false);
	if (!dfn)
	{
		char msg[512];
		smprintf (msg, 512, "Can't load DFN '%s'", _dfnname);
		theApp.outputError (msg);
		return;
	}

	NLMISC::CSmartPtr<NLGEORGES::UForm> Form = new CForm;

	std::string fullName;
	fullName = _sxFullnameWithoutExt + ".";

	int i = 0;
	if (_dfnname[i] == '.') ++i;
	for (; i < (int)_dfnname.size(); ++i)
	{
		if (_dfnname[i] == '.') break;
		fullName += _dfnname[i];
	}

	((CFormElmStruct*)&Form->getRootNode ())->build (dfn);
	COFile f;
	COXml ox;
	if (f.open (fullName))
	{
		ox.init(&f);
		((NLGEORGES::CForm*)((UForm*)Form))->write (ox.getDocument(), _sxFullnameWithoutExt.c_str ());
		ox.flush();
		f.close();
	}
	else
	{
		char msg[512];
		smprintf (msg, 512, "Can't write '%s'", fullName);
		theApp.outputError (msg);
		return;
	}
}
Example #5
0
void CFormDfn::read (xmlNodePtr root, CFormLoader &loader, bool forceLoad, const char *filename)
{
	// Save filename
	_Filename = CFile::getFilename (filename);

	// Check node name
	if ( ((const char*)root->name == NULL) || (strcmp ((const char*)root->name, "DFN") != 0) )
	{
		// Throw exception
		warning (true, "read", "XML Syntax error in block line %d, node (%s) should be DFN.", (ptrdiff_t)root->content, root->name);
	}

	// Count the parent
	uint parentCount = CIXml::countChildren (root, "PARENT");
	Parents.resize (parentCount);

	// For each element entry
	uint parentNumber = 0;
	xmlNodePtr parent = CIXml::getFirstChildNode (root, "PARENT");
	while (parentNumber<parentCount)
	{
		// Get the Parent
		const char *parentFilename = (const char*)xmlGetProp (parent, (xmlChar*)"Name");
		if (parentFilename)
		{
			Parents[parentNumber].ParentFilename = parentFilename;

			// Delete the value
			xmlFree ((void*)parentFilename);

			// Load the parent
			Parents[parentNumber].Parent = loader.loadFormDfn (Parents[parentNumber].ParentFilename.c_str (), forceLoad);
			if ((Parents[parentNumber].Parent == NULL) && !forceLoad)
			{
				// Throw exception
				warning (true, "read", "Can't load parent DFN file (%s).", Parents[parentNumber].ParentFilename.c_str ());
			}
		}
		else
		{
			// Throw exception
			warning (true, "read", "XML Syntax error in block (%s) line %d, aguments Name not found.",
				parent->name, (ptrdiff_t)parent->content);
		}

		// Next parent
		parent = CIXml::getNextChildNode (parent, "PARENT");
		parentNumber++;
	}

	// Count the element children
	uint childCount = CIXml::countChildren (root, "ELEMENT");

	// Resize the element table
	Entries.resize (childCount);

	// For each element entry
	uint childNumber = 0;
	xmlNodePtr child = CIXml::getFirstChildNode (root, "ELEMENT");
	while (childNumber<childCount)
	{
		// Checks
		nlassert (child);

		// Get the name
		const char *value = (const char*)xmlGetProp (child, (xmlChar*)"Name");
		if (value)
		{
			// Store the value
			Entries[childNumber].Name = value;

			// Delete the value
			xmlFree ((void*)value);

			// Reset
			Entries[childNumber].Dfn = NULL;
			Entries[childNumber].Type = NULL;
			Entries[childNumber].Default.clear ();

			const char *filename = (const char*)xmlGetProp (child, (xmlChar*)"Filename");

			if ( filename )
			{
				Entries[childNumber].Filename = filename;

				// Delete the value
				xmlFree ((void*)filename);
			}
			else
			{
				Entries[childNumber].Filename.clear ();
			}

			const char *filenameExt = (const char*)xmlGetProp (child, (xmlChar*)"FilenameExt");
			if ( filenameExt )
			{
				Entries[childNumber].FilenameExt = filenameExt;

				// Delete the value
				xmlFree ((void*)filenameExt);
			}
			else
			{
				Entries[childNumber].FilenameExt = "*.*";
			}

			// Read the type
			const char *typeName = (const char*)xmlGetProp (child, (xmlChar*)"Type");
			if (typeName)
			{
				bool type = false;
				bool dfn = false;
				if (stricmp (typeName, "Type") == 0)
				{
					Entries[childNumber].TypeElement = UFormDfn::EntryType;
					type = true;

					// Load the filename
					if (!Entries[childNumber].Filename.empty ())
					{
						Entries[childNumber].Type = loader.loadType (Entries[childNumber].Filename.c_str ());
						if ((Entries[childNumber].Type == NULL) && !forceLoad)
						{
							// Throw exception
							warning (true, "read", "In XML block (%s) line %d, file not found %s.",
								child->name, (ptrdiff_t)child->content, Entries[childNumber].Filename.c_str ());
						}

						// Read the default value
						const char *defaultName = (const char*)xmlGetProp (child, (xmlChar*)"Default");
						if (defaultName)
						{
							Entries[childNumber].Default = defaultName;

							// Delete the value
							xmlFree ((void*)defaultName);
						}
					}
					else
					{
						// Throw exception
						warning (true, "read", "XML In block (%s) line %d, no filename found for the .typ file.",
							child->name, (ptrdiff_t)child->content, Entries[childNumber].Filename.c_str ());
					}
				}
				else if (stricmp (typeName, "Dfn") == 0)
				{
					Entries[childNumber].TypeElement = UFormDfn::EntryDfn;
					dfn = true;

					// Load the filename
					if (!Entries[childNumber].Filename.empty ())
					{
						// Load the filename
						Entries[childNumber].Dfn = loader.loadFormDfn (Entries[childNumber].Filename.c_str (), forceLoad);
						if ((Entries[childNumber].Dfn == NULL) && !forceLoad)
						{
							// Throw exception
							warning (true, "read", "XML In block (%s) line %d, file not found %s.",
								child->name, (ptrdiff_t)child->content, Entries[childNumber].Filename.c_str ());
						}
					}
					else
					{
						// Throw exception
						warning (true, "read", "XML In block (%s) line %d, no filename found for the .typ file.",
							child->name, (ptrdiff_t)child->content, Entries[childNumber].Filename.c_str ());
					}
				}
				else if (stricmp (typeName, "DfnPointer") == 0)
				{
					Entries[childNumber].TypeElement = UFormDfn::EntryVirtualDfn;
				}
				else
				{
					// Throw exception
					warning (true, "read", "XML Syntax error in block (%s) line %d, element has not a valid type name attribut \"Type = %s\".",
						child->name, (ptrdiff_t)child->content, typeName);
				}

				// Delete the value
				xmlFree ((void*)typeName);
			}
			else
			{
				// Throw exception
				warning (true, "read", "XML Syntax error in block (%s) line %d, element has no type name attribut \"Type = [Type][Dfn][DfnPointer]\".",
					child->name, (ptrdiff_t)child->content);
			}

			// Get the array attrib
			Entries[childNumber].Array = false;
			const char* arrayFlag = (const char*)xmlGetProp (child, (xmlChar*)"Array");
			if (arrayFlag)
			{
				Entries[childNumber].Array =  (stricmp (arrayFlag, "true") == 0);

				// Delete the value
				xmlFree ((void*)arrayFlag);
			}
		}
		else
		{
			// Throw exception
			warning (true, "read", "XML Syntax error in block (%s) line %d, aguments Name not found.",
				root->name, (ptrdiff_t)root->content);
		}

		// Next child
		child = CIXml::getNextChildNode (child, "ELEMENT");
		childNumber++;
	}

	// Read the header
	Header.read (root);
}