refactoring xml structure parsing

This commit is contained in:
Adrien Bourmault 2021-08-31 01:03:02 +02:00
parent 2bae3c1f3a
commit eb3f2c29cf
No known key found for this signature in database
GPG Key ID: 6EB408FE0ACEC664
1 changed files with 48 additions and 36 deletions

View File

@ -323,50 +323,62 @@ void ModelSystemDestroy(void)
/* -------------------------------------------------------------------------- */
static inline void CreateField(ModelField_t *modelField,
const char *tag,
const bool mandatory,
const char *value,
const size_t valueSize,
const ModelField_t *son,
const ModelField_t *next)
{
strncpy(modelField->tag, tag, 25);
modelField->mandatory = mandatory;
modelField->value = value;
modelField->valueSize = valueSize;
modelField->son = son;
modelField->next = next;
}
static inline int ModelParseFile(Model_t *model)
{
ModelField_t identityField;
ModelField_t authorField;
ModelField_t nameField;
ModelField_t dateField;
ModelField_t versionField;
char date[25];
strcpy(identityField.tag, "identity");
identityField.mandatory = false;
identityField.value = NULL;
identityField.valueSize = 0;
identityField.son = &nameField;
identityField.next = NULL;
ModelField_t identityField;
ModelField_t identityNameField;
ModelField_t identityAuthorField;
ModelField_t identityDateField;
ModelField_t identityVersionField;
ModelField_t parametersField;
ModelField_t parametersModelizationField;
ModelField_t parametersSpaceField;
strcpy(nameField.tag, "name");
nameField.mandatory = true;
nameField.value = model->name;
nameField.valueSize = MAX_MODEL_NAME_SIZE;
nameField.son = NULL;
nameField.next = &authorField;
CreateField(&identityField,
"identity", false, NULL, 0, &identityNameField, NULL);
strcpy(authorField.tag, "author");
authorField.mandatory = true;
authorField.value = model->author;
authorField.valueSize = MAX_AUTHOR_NAME_SIZE;
authorField.son = NULL;
authorField.next = &dateField;
CreateField(&identityNameField,
"name", true, model->name, MAX_MODEL_NAME_SIZE,
NULL, &identityAuthorField);
strcpy(dateField.tag, "date");
dateField.mandatory = true;
dateField.value = date;
dateField.valueSize = 25;
dateField.son = NULL;
dateField.next = &versionField;
CreateField(&identityAuthorField,
"author", true, model->author, MAX_AUTHOR_NAME_SIZE,
NULL, &identityDateField);
CreateField(&identityDateField,
"date", true, date, 25,
NULL, &identityVersionField);
CreateField(&identityVersionField,
"version", true, model->version, MAX_VERSION_SIZE, NULL, NULL);
CreateField(&parametersField,
"parameters", false, NULL, NULL, NULL, NULL);
CreateField(&parametersModelizationField,
"modelization", false, NULL, NULL, NULL, NULL);
CreateField(&parametersSpaceField,
"space", false, NULL, NULL, NULL, NULL);
strcpy(versionField.tag, "version");
versionField.mandatory = true;
versionField.value = model->version;
versionField.valueSize = MAX_VERSION_SIZE;
versionField.son = NULL;
versionField.next = NULL;
// TODO modify model according to things in file