refactoring xml structure parsing
This commit is contained in:
parent
2bae3c1f3a
commit
eb3f2c29cf
84
src/model.c
84
src/model.c
|
@ -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)
|
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];
|
char date[25];
|
||||||
|
|
||||||
strcpy(identityField.tag, "identity");
|
ModelField_t identityField;
|
||||||
identityField.mandatory = false;
|
ModelField_t identityNameField;
|
||||||
identityField.value = NULL;
|
ModelField_t identityAuthorField;
|
||||||
identityField.valueSize = 0;
|
ModelField_t identityDateField;
|
||||||
identityField.son = &nameField;
|
ModelField_t identityVersionField;
|
||||||
identityField.next = NULL;
|
ModelField_t parametersField;
|
||||||
|
ModelField_t parametersModelizationField;
|
||||||
|
ModelField_t parametersSpaceField;
|
||||||
|
|
||||||
strcpy(nameField.tag, "name");
|
CreateField(&identityField,
|
||||||
nameField.mandatory = true;
|
"identity", false, NULL, 0, &identityNameField, NULL);
|
||||||
nameField.value = model->name;
|
|
||||||
nameField.valueSize = MAX_MODEL_NAME_SIZE;
|
|
||||||
nameField.son = NULL;
|
|
||||||
nameField.next = &authorField;
|
|
||||||
|
|
||||||
strcpy(authorField.tag, "author");
|
CreateField(&identityNameField,
|
||||||
authorField.mandatory = true;
|
"name", true, model->name, MAX_MODEL_NAME_SIZE,
|
||||||
authorField.value = model->author;
|
NULL, &identityAuthorField);
|
||||||
authorField.valueSize = MAX_AUTHOR_NAME_SIZE;
|
|
||||||
authorField.son = NULL;
|
|
||||||
authorField.next = &dateField;
|
|
||||||
|
|
||||||
strcpy(dateField.tag, "date");
|
CreateField(&identityAuthorField,
|
||||||
dateField.mandatory = true;
|
"author", true, model->author, MAX_AUTHOR_NAME_SIZE,
|
||||||
dateField.value = date;
|
NULL, &identityDateField);
|
||||||
dateField.valueSize = 25;
|
|
||||||
dateField.son = NULL;
|
CreateField(&identityDateField,
|
||||||
dateField.next = &versionField;
|
"date", true, date, 25,
|
||||||
|
NULL, &identityVersionField);
|
||||||
|
|
||||||
|
CreateField(&identityVersionField,
|
||||||
|
"version", true, model->version, MAX_VERSION_SIZE, NULL, NULL);
|
||||||
|
|
||||||
|
CreateField(¶metersField,
|
||||||
|
"parameters", false, NULL, NULL, NULL, NULL);
|
||||||
|
|
||||||
|
CreateField(¶metersModelizationField,
|
||||||
|
"modelization", false, NULL, NULL, NULL, NULL);
|
||||||
|
|
||||||
|
CreateField(¶metersSpaceField,
|
||||||
|
"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
|
// TODO modify model according to things in file
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue