Global parsing sucessfull; lack of arrows now
This commit is contained in:
parent
048857a9af
commit
fc10d5de14
|
@ -1,80 +0,0 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
|
|
||||||
<!-- TODO DTD -->
|
|
||||||
|
|
||||||
<gem-graph-model version="0.1">
|
|
||||||
|
|
||||||
<!-- Model identity informations -->
|
|
||||||
<identity>
|
|
||||||
<name>Modèle de test</name>
|
|
||||||
<author>Adrien Bourmault</author>
|
|
||||||
<author_id>1</author_id>
|
|
||||||
<date>1629822515</date>
|
|
||||||
<version>1.0</version>
|
|
||||||
|
|
||||||
</identity>
|
|
||||||
|
|
||||||
<!-- Model parameters -->
|
|
||||||
<parameters id="" date="" author="">
|
|
||||||
<modelization>
|
|
||||||
<max_thread value="0"/>
|
|
||||||
<max_cycle value="13"/>
|
|
||||||
|
|
||||||
</modelization>
|
|
||||||
|
|
||||||
<space>
|
|
||||||
<dimension value="2"/>
|
|
||||||
<size x="" y="" z=""/>
|
|
||||||
<site_multiplicity value="2"/>
|
|
||||||
<!-- <boundaries/>, TODO -->
|
|
||||||
|
|
||||||
</space>
|
|
||||||
|
|
||||||
</parameters>
|
|
||||||
|
|
||||||
<!-- Model objects definition -->
|
|
||||||
<objects>
|
|
||||||
<object id="0" date="" author="">
|
|
||||||
<arrow id="0" x="0" y="0" z="0" site="0" weight="1"/>
|
|
||||||
|
|
||||||
</object>
|
|
||||||
|
|
||||||
</objects>
|
|
||||||
|
|
||||||
<!-- Space description (initial state) -->
|
|
||||||
<space id="" date="" author="">
|
|
||||||
<arrow id="0" x="0" y="0" z="0" site="0" weight="1"/>
|
|
||||||
|
|
||||||
</space>
|
|
||||||
|
|
||||||
<!-- Saved space description (saved states) -->
|
|
||||||
<savestates id="" date="" author="">
|
|
||||||
<space id="" date="">
|
|
||||||
<arrow id="0" x="0" y="0" z="0" site="0" weight="1"/>
|
|
||||||
|
|
||||||
</space>
|
|
||||||
|
|
||||||
</savestates>
|
|
||||||
|
|
||||||
<!-- Model transitions definition (rules) -->
|
|
||||||
<transitions id="" date="" author="">
|
|
||||||
<transition id="" date="" author="" probability="">
|
|
||||||
<if>
|
|
||||||
<arrow id="0" x="0" y="0" z="0" site="0" weight="1"/>
|
|
||||||
|
|
||||||
</if>
|
|
||||||
|
|
||||||
<then>
|
|
||||||
<arrow id="0" x="0" y="0" z="0" site="0" weight="1"/>
|
|
||||||
|
|
||||||
</then>
|
|
||||||
|
|
||||||
</transition>
|
|
||||||
|
|
||||||
</transitions>
|
|
||||||
|
|
||||||
<!-- Non context-specific tags -->
|
|
||||||
<ref id="" date="">https://www.a-lec.org</ref>
|
|
||||||
<quote id="" date="" author="" lang="">Quote</quote>
|
|
||||||
|
|
||||||
</gem-graph-model>
|
|
|
@ -7,7 +7,7 @@
|
||||||
<!-- Model identity informations -->
|
<!-- Model identity informations -->
|
||||||
<identity>
|
<identity>
|
||||||
<name>Modèle de test</name>
|
<name>Modèle de test</name>
|
||||||
<owner>Jean Sirmai</owner>
|
<name value="(Trois dimères)"/>
|
||||||
<owner_id>2</owner_id>
|
<owner_id>2</owner_id>
|
||||||
<date>1629830000</date> <!--Warning: it's an arbitrary unchecked date...-->
|
<date>1629830000</date> <!--Warning: it's an arbitrary unchecked date...-->
|
||||||
<version>1.0</version>
|
<version>1.0</version>
|
||||||
|
@ -64,7 +64,7 @@
|
||||||
|
|
||||||
<!-- Saved space description (saved states) -->
|
<!-- Saved space description (saved states) -->
|
||||||
<savestates id="" date="" author=""> <!-- TODO or NOT TODO (not today...)-->
|
<savestates id="" date="" author=""> <!-- TODO or NOT TODO (not today...)-->
|
||||||
<space id="" date="">
|
<space id="" date="" author="">
|
||||||
</space>
|
</space>
|
||||||
|
|
||||||
</savestates>
|
</savestates>
|
||||||
|
|
|
@ -28,10 +28,6 @@
|
||||||
|
|
||||||
#define MODEL_STRING_SIZE 48
|
#define MODEL_STRING_SIZE 48
|
||||||
#define MAX_MODEL_NUMBER 1
|
#define MAX_MODEL_NUMBER 1
|
||||||
#define MAX_MODEL_NAME_SIZE MODEL_STRING_SIZE
|
|
||||||
#define MAX_MODEL_FILENAME_SIZE MODEL_STRING_SIZE
|
|
||||||
#define MAX_OWNER_NAME_SIZE MODEL_STRING_SIZE
|
|
||||||
#define MAX_VERSION_SIZE MODEL_STRING_SIZE
|
|
||||||
|
|
||||||
#define ARROW_NUMBER 6
|
#define ARROW_NUMBER 6
|
||||||
#define SITE_NUMBER 2
|
#define SITE_NUMBER 2
|
||||||
|
|
26
src/model.c
26
src/model.c
|
@ -178,16 +178,16 @@ void ModelAddToKnown(Model_t **newModel) // TODO manage deletion and empty slots
|
||||||
|
|
||||||
// continue. model population
|
// continue. model population
|
||||||
knownModel[knownModelSize-1]->name =
|
knownModel[knownModelSize-1]->name =
|
||||||
(char *) calloc(1, sizeof(char) * MAX_MODEL_NAME_SIZE);
|
(char *) calloc(1, sizeof(char) * MODEL_STRING_SIZE);
|
||||||
|
|
||||||
knownModel[knownModelSize-1]->filename =
|
knownModel[knownModelSize-1]->filename =
|
||||||
(char *) calloc(1, sizeof(char) * MAX_MODEL_NAME_SIZE);
|
(char *) calloc(1, sizeof(char) * MODEL_STRING_SIZE);
|
||||||
|
|
||||||
knownModel[knownModelSize-1]->owner =
|
knownModel[knownModelSize-1]->owner =
|
||||||
(char *) calloc(1, sizeof(char) * MAX_OWNER_NAME_SIZE);
|
(char *) calloc(1, sizeof(char) * MODEL_STRING_SIZE);
|
||||||
|
|
||||||
knownModel[knownModelSize-1]->version =
|
knownModel[knownModelSize-1]->version =
|
||||||
(char *) calloc(1, sizeof(char) * MAX_VERSION_SIZE);
|
(char *) calloc(1, sizeof(char) * MODEL_STRING_SIZE);
|
||||||
|
|
||||||
knownModel[knownModelSize-1]->space_xMax = XMAX;
|
knownModel[knownModelSize-1]->space_xMax = XMAX;
|
||||||
knownModel[knownModelSize-1]->space_yMax = YMAX;
|
knownModel[knownModelSize-1]->space_yMax = YMAX;
|
||||||
|
@ -305,21 +305,3 @@ void ModelSystemDestroy(void)
|
||||||
free(knownModel);
|
free(knownModel);
|
||||||
knownModel = NULL;
|
knownModel = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -------------------------------------------------------------------------- */
|
|
||||||
|
|
||||||
static inline void CreateField(ModelField_t *modelField,
|
|
||||||
const char *tag,
|
|
||||||
const bool mandatory,
|
|
||||||
char *value,
|
|
||||||
size_t valueSize,
|
|
||||||
ModelField_t *son,
|
|
||||||
ModelField_t *next)
|
|
||||||
{
|
|
||||||
strncpy(modelField->tag, tag, 25);
|
|
||||||
modelField->mandatory = mandatory;
|
|
||||||
modelField->destination = value;
|
|
||||||
modelField->size = valueSize;
|
|
||||||
modelField->son = son;
|
|
||||||
modelField->next = next;
|
|
||||||
}
|
|
||||||
|
|
176
src/parsing.c
176
src/parsing.c
|
@ -65,21 +65,42 @@ int parseTextField(xmlDocPtr,
|
||||||
/* -------------------------------------------------------------------------- */
|
/* -------------------------------------------------------------------------- */
|
||||||
|
|
||||||
// -------------------------------------------------------------------------- //
|
// -------------------------------------------------------------------------- //
|
||||||
// Parsing NOTHING //
|
// Parsing NOTHING (but yeah that prints) //
|
||||||
// -------------------------------------------------------------------------- //
|
// -------------------------------------------------------------------------- //
|
||||||
int parseStubFieldXML (xmlDocPtr doc,
|
int parseStubFieldXML (xmlDocPtr doc,
|
||||||
ModelParserTableXML_t *ModelTable,
|
ModelParserTableXML_t *ModelTable,
|
||||||
int currentParser,
|
int currentParser,
|
||||||
xmlNodePtr currentNode)
|
xmlNodePtr currentNode)
|
||||||
{
|
{
|
||||||
xmlChar *content;
|
xmlChar *content, *contentText, *contentValueAttribute;
|
||||||
content = xmlNodeListGetString(doc, currentNode->xmlChildrenNode, 1);
|
|
||||||
|
|
||||||
printLog("%s (stub): %s\n",
|
contentText = xmlNodeListGetString(doc, currentNode->xmlChildrenNode, 1);
|
||||||
ModelTable->table[currentParser].tag,
|
contentValueAttribute = xmlGetProp(currentNode,
|
||||||
content);
|
(xmlChar*)"value");
|
||||||
|
|
||||||
|
if (contentText) {
|
||||||
|
content = contentText;
|
||||||
|
} else if (contentValueAttribute) {
|
||||||
|
content = contentValueAttribute;
|
||||||
|
|
||||||
|
// Detect children
|
||||||
|
if (currentNode->xmlChildrenNode) {
|
||||||
|
printLog("%s has children\n", ModelTable->table[currentParser].tag);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
printLog("%s: %s\n", ModelTable->table[currentParser].tag,
|
||||||
|
content);
|
||||||
|
|
||||||
|
if (!content) {
|
||||||
|
xmlFree(contentText);
|
||||||
|
xmlFree(contentValueAttribute);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
xmlFree(contentText);
|
||||||
|
xmlFree(contentValueAttribute);
|
||||||
|
|
||||||
xmlFree(content);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -91,14 +112,80 @@ int parseTextFieldXML (xmlDocPtr doc,
|
||||||
int currentParser,
|
int currentParser,
|
||||||
xmlNodePtr currentNode)
|
xmlNodePtr currentNode)
|
||||||
{
|
{
|
||||||
xmlChar *content;
|
xmlChar *content, *contentText, *contentValueAttribute;
|
||||||
content = xmlNodeListGetString(doc, currentNode->xmlChildrenNode, 1);
|
char *destination = (char*)ModelTable->table[currentParser].destination;
|
||||||
|
|
||||||
|
contentText = xmlNodeListGetString(doc, currentNode->xmlChildrenNode, 1);
|
||||||
|
contentValueAttribute = xmlGetProp(currentNode,
|
||||||
|
(xmlChar*)"value");
|
||||||
|
|
||||||
|
if (contentText) {
|
||||||
|
content = contentText;
|
||||||
|
} else if (contentValueAttribute) {
|
||||||
|
content = contentValueAttribute;
|
||||||
|
|
||||||
|
// Detect children
|
||||||
|
if (currentNode->xmlChildrenNode) {
|
||||||
|
printLog("%s has children\n", ModelTable->table[currentParser].tag);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
printLog("%s: %s\n", ModelTable->table[currentParser].tag,
|
printLog("%s: %s\n", ModelTable->table[currentParser].tag,
|
||||||
content);
|
content);
|
||||||
|
|
||||||
strncpy((char *)ModelTable->table[currentParser].destination,
|
if (!content) {
|
||||||
(char *)content, MODEL_STRING_SIZE);
|
xmlFree(contentText);
|
||||||
|
xmlFree(contentValueAttribute);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
strcat(destination, " ");
|
||||||
|
strncpy(destination + strlen(destination),
|
||||||
|
(char *)content, MODEL_STRING_SIZE - strlen(destination));
|
||||||
|
|
||||||
|
xmlFree(contentText);
|
||||||
|
xmlFree(contentValueAttribute);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// -------------------------------------------------------------------------- //
|
||||||
|
// Parsing an integer field //
|
||||||
|
// -------------------------------------------------------------------------- //
|
||||||
|
int parseIntFieldXML (xmlDocPtr doc,
|
||||||
|
ModelParserTableXML_t *ModelTable,
|
||||||
|
int currentParser,
|
||||||
|
xmlNodePtr currentNode)
|
||||||
|
{
|
||||||
|
xmlChar *content, *contentText, *contentValueAttribute;
|
||||||
|
int *destination = (int*)ModelTable->table[currentParser].destination;
|
||||||
|
|
||||||
|
contentText = xmlNodeListGetString(doc, currentNode->xmlChildrenNode, 1);
|
||||||
|
contentValueAttribute = xmlGetProp(currentNode,
|
||||||
|
(xmlChar*)"value");
|
||||||
|
|
||||||
|
if (contentText) {
|
||||||
|
content = contentText;
|
||||||
|
} else if (contentValueAttribute) {
|
||||||
|
content = contentValueAttribute;
|
||||||
|
|
||||||
|
// Detect children
|
||||||
|
if (currentNode->xmlChildrenNode) {
|
||||||
|
printLog("%s has children\n", ModelTable->table[currentParser].tag);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
printLog("%s: %s\n", ModelTable->table[currentParser].tag,
|
||||||
|
content);
|
||||||
|
|
||||||
|
if (!content) {
|
||||||
|
xmlFree(contentText);
|
||||||
|
xmlFree(contentValueAttribute);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
*destination = (int)atoi((char*)content);
|
||||||
|
|
||||||
xmlFree(content);
|
xmlFree(content);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -112,6 +199,9 @@ int parseParentFieldXML (xmlDocPtr doc,
|
||||||
xmlNodePtr currentNode)
|
xmlNodePtr currentNode)
|
||||||
{
|
{
|
||||||
currentNode = currentNode->xmlChildrenNode;
|
currentNode = currentNode->xmlChildrenNode;
|
||||||
|
|
||||||
|
printLog("%s parsed\n", ModelTable->table[currentParser].tag);
|
||||||
|
|
||||||
while (currentNode != NULL) {
|
while (currentNode != NULL) {
|
||||||
for (int i = 0; i < ModelTable->len; i++) {
|
for (int i = 0; i < ModelTable->len; i++) {
|
||||||
if ((!xmlStrcmp(currentNode->name,
|
if ((!xmlStrcmp(currentNode->name,
|
||||||
|
@ -120,6 +210,7 @@ int parseParentFieldXML (xmlDocPtr doc,
|
||||||
ModelTable,
|
ModelTable,
|
||||||
i,
|
i,
|
||||||
currentNode);
|
currentNode);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
currentNode = currentNode->next;
|
currentNode = currentNode->next;
|
||||||
|
@ -134,12 +225,58 @@ int ParseModelXML(Model_t *model)
|
||||||
{
|
{
|
||||||
ParserTableXML_t table[] =
|
ParserTableXML_t table[] =
|
||||||
{
|
{
|
||||||
{(const xmlChar *)"identity", parseParentFieldXML, model},
|
// IDENTITY
|
||||||
{(const xmlChar *)"name", parseTextFieldXML, model->name},
|
{(const xmlChar *)"identity", parseParentFieldXML,model},
|
||||||
{(const xmlChar *)"owner", parseTextFieldXML, model->owner},
|
{(const xmlChar *)"name", parseTextFieldXML, model->name},
|
||||||
{(const xmlChar *)"owner_id", parseStubFieldXML, model->owner_id},
|
{(const xmlChar *)"owner", parseTextFieldXML, model->owner},
|
||||||
{(const xmlChar *)"date", parseStubFieldXML, &model->date},
|
|
||||||
{(const xmlChar *)"version", parseTextFieldXML, model->version},
|
// TODO lacking implementation (model side)
|
||||||
|
{(const xmlChar *)"owner_id", parseStubFieldXML, model->owner_id},
|
||||||
|
|
||||||
|
{(const xmlChar *)"date", parseIntFieldXML, &model->date},
|
||||||
|
{(const xmlChar *)"version", parseTextFieldXML, model->version},
|
||||||
|
|
||||||
|
// PARAMETERS
|
||||||
|
{(const xmlChar *)"parameters", parseParentFieldXML, model},
|
||||||
|
// MODELIZATION
|
||||||
|
{(const xmlChar *)"modelization", parseParentFieldXML, model},
|
||||||
|
{(const xmlChar *)"max_thread", parseStubFieldXML, model},
|
||||||
|
{(const xmlChar *)"max_cycles", parseStubFieldXML, model},
|
||||||
|
// SPACE
|
||||||
|
{(const xmlChar *)"space", parseParentFieldXML, model},
|
||||||
|
{(const xmlChar *)"dimension", parseStubFieldXML, model},
|
||||||
|
{(const xmlChar *)"size", parseStubFieldXML, model},
|
||||||
|
{(const xmlChar *)"site_multiplicity", parseStubFieldXML, model},
|
||||||
|
|
||||||
|
// TODO lacking implementation (model side)
|
||||||
|
{(const xmlChar *)"boundaries", parseStubFieldXML, model},
|
||||||
|
|
||||||
|
// OBJECTS
|
||||||
|
{(const xmlChar *)"objects", parseParentFieldXML, model},
|
||||||
|
{(const xmlChar *)"object", parseParentFieldXML, model},
|
||||||
|
|
||||||
|
// SPACE
|
||||||
|
{(const xmlChar *)"space", parseParentFieldXML, model},
|
||||||
|
|
||||||
|
// SAVESTATES
|
||||||
|
{(const xmlChar *)"savestates", parseParentFieldXML, model},
|
||||||
|
|
||||||
|
// TRANSITIONS
|
||||||
|
{(const xmlChar *)"transitions", parseParentFieldXML, model},
|
||||||
|
// TRANSITION
|
||||||
|
// TODO probability
|
||||||
|
{(const xmlChar *)"transition", parseParentFieldXML, model},
|
||||||
|
{(const xmlChar *)"if", parseParentFieldXML, model},
|
||||||
|
{(const xmlChar *)"then", parseParentFieldXML, model},
|
||||||
|
|
||||||
|
// ARROW
|
||||||
|
{(const xmlChar *)"arrow", parseStubFieldXML, model},
|
||||||
|
|
||||||
|
// REF
|
||||||
|
{(const xmlChar *)"ref", parseStubFieldXML, model},
|
||||||
|
|
||||||
|
// QUOTE
|
||||||
|
{(const xmlChar *)"quote", parseStubFieldXML, model},
|
||||||
};
|
};
|
||||||
|
|
||||||
ModelParserTableXML_t modelParserTable =
|
ModelParserTableXML_t modelParserTable =
|
||||||
|
@ -193,10 +330,7 @@ int ParseModelXML(Model_t *model)
|
||||||
|
|
||||||
xmlFreeDoc(xmlDocument);
|
xmlFreeDoc(xmlDocument);
|
||||||
|
|
||||||
// Interpret what needs to be
|
|
||||||
//model->date = strtol(date, NULL, 0);
|
|
||||||
|
|
||||||
// validate when we're finished
|
// validate when we're finished
|
||||||
// model->validated = true;
|
model->validated = true;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue