diff --git a/src/model.c b/src/model.c index 21551d4..2049b76 100644 --- a/src/model.c +++ b/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) { - 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(¶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