diff --git a/debian/var/models/example.xml b/debian/var/models/example.xml deleted file mode 100644 index 03643ef..0000000 --- a/debian/var/models/example.xml +++ /dev/null @@ -1,80 +0,0 @@ - - - - - - - - - Modèle de test - Adrien Bourmault - 1 - 1629822515 - 1.0 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - https://www.a-lec.org - Quote - - diff --git a/debian/var/models/example_II.xml b/debian/var/models/example_II.xml index 1716654..502f83a 100644 --- a/debian/var/models/example_II.xml +++ b/debian/var/models/example_II.xml @@ -7,7 +7,7 @@ Modèle de test - Jean Sirmai + 2 1629830000 1.0 @@ -64,7 +64,7 @@ - + diff --git a/include/model.h b/include/model.h index ba55608..02b23af 100644 --- a/include/model.h +++ b/include/model.h @@ -28,10 +28,6 @@ #define MODEL_STRING_SIZE 48 #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 SITE_NUMBER 2 diff --git a/src/model.c b/src/model.c index a11b3ac..8265f16 100644 --- a/src/model.c +++ b/src/model.c @@ -178,16 +178,16 @@ void ModelAddToKnown(Model_t **newModel) // TODO manage deletion and empty slots // continue. model population 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 = - (char *) calloc(1, sizeof(char) * MAX_MODEL_NAME_SIZE); + (char *) calloc(1, sizeof(char) * MODEL_STRING_SIZE); 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 = - (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_yMax = YMAX; @@ -305,21 +305,3 @@ void ModelSystemDestroy(void) free(knownModel); 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; -} diff --git a/src/parsing.c b/src/parsing.c index dd9cd3c..105f052 100644 --- a/src/parsing.c +++ b/src/parsing.c @@ -65,21 +65,42 @@ int parseTextField(xmlDocPtr, /* -------------------------------------------------------------------------- */ // -------------------------------------------------------------------------- // -// Parsing NOTHING // +// Parsing NOTHING (but yeah that prints) // // -------------------------------------------------------------------------- // int parseStubFieldXML (xmlDocPtr doc, ModelParserTableXML_t *ModelTable, int currentParser, xmlNodePtr currentNode) { - xmlChar *content; - content = xmlNodeListGetString(doc, currentNode->xmlChildrenNode, 1); + xmlChar *content, *contentText, *contentValueAttribute; - printLog("%s (stub): %s\n", - ModelTable->table[currentParser].tag, - content); + 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; + } + + xmlFree(contentText); + xmlFree(contentValueAttribute); - xmlFree(content); return 0; } @@ -91,14 +112,80 @@ int parseTextFieldXML (xmlDocPtr doc, int currentParser, xmlNodePtr currentNode) { - xmlChar *content; - content = xmlNodeListGetString(doc, currentNode->xmlChildrenNode, 1); + xmlChar *content, *contentText, *contentValueAttribute; + 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, content); - strncpy((char *)ModelTable->table[currentParser].destination, - (char *)content, MODEL_STRING_SIZE); + if (!content) { + 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); return 0; } @@ -112,6 +199,9 @@ int parseParentFieldXML (xmlDocPtr doc, xmlNodePtr currentNode) { currentNode = currentNode->xmlChildrenNode; + + printLog("%s parsed\n", ModelTable->table[currentParser].tag); + while (currentNode != NULL) { for (int i = 0; i < ModelTable->len; i++) { if ((!xmlStrcmp(currentNode->name, @@ -120,6 +210,7 @@ int parseParentFieldXML (xmlDocPtr doc, ModelTable, i, currentNode); + break; } } currentNode = currentNode->next; @@ -134,12 +225,58 @@ int ParseModelXML(Model_t *model) { ParserTableXML_t table[] = { - {(const xmlChar *)"identity", parseParentFieldXML, model}, - {(const xmlChar *)"name", parseTextFieldXML, model->name}, - {(const xmlChar *)"owner", parseTextFieldXML, model->owner}, - {(const xmlChar *)"owner_id", parseStubFieldXML, model->owner_id}, - {(const xmlChar *)"date", parseStubFieldXML, &model->date}, - {(const xmlChar *)"version", parseTextFieldXML, model->version}, + // IDENTITY + {(const xmlChar *)"identity", parseParentFieldXML,model}, + {(const xmlChar *)"name", parseTextFieldXML, model->name}, + {(const xmlChar *)"owner", parseTextFieldXML, model->owner}, + + // 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 = @@ -193,10 +330,7 @@ int ParseModelXML(Model_t *model) xmlFreeDoc(xmlDocument); - // Interpret what needs to be - //model->date = strtol(date, NULL, 0); - // validate when we're finished - // model->validated = true; + model->validated = true; return 0; }