- code format update

pull/535/head
Michael Zillgith 11 months ago
parent b86806ef13
commit 4ab7bf556b

@ -35,16 +35,19 @@ MmsVariableSpecification_destroy(MmsVariableSpecification* typeSpec)
if (typeSpec->name != NULL) if (typeSpec->name != NULL)
GLOBAL_FREEMEM(typeSpec->name); GLOBAL_FREEMEM(typeSpec->name);
if (typeSpec->type == MMS_STRUCTURE) { if (typeSpec->type == MMS_STRUCTURE)
{
int elementCount = typeSpec->typeSpec.structure.elementCount; int elementCount = typeSpec->typeSpec.structure.elementCount;
int i; int i;
for (i = 0; i < elementCount; i++) { for (i = 0; i < elementCount; i++)
{
MmsVariableSpecification_destroy(typeSpec->typeSpec.structure.elements[i]); MmsVariableSpecification_destroy(typeSpec->typeSpec.structure.elements[i]);
} }
GLOBAL_FREEMEM(typeSpec->typeSpec.structure.elements); GLOBAL_FREEMEM(typeSpec->typeSpec.structure.elements);
} }
else if (typeSpec->type == MMS_ARRAY) { else if (typeSpec->type == MMS_ARRAY)
{
MmsVariableSpecification_destroy(typeSpec->typeSpec.array.elementTypeSpec); MmsVariableSpecification_destroy(typeSpec->typeSpec.array.elementTypeSpec);
} }
@ -56,7 +59,9 @@ directChildStrLen(const char* childId)
{ {
size_t i = 0; size_t i = 0;
size_t childIdLen = strlen(childId); size_t childIdLen = strlen(childId);
while (i < childIdLen) {
while (i < childIdLen)
{
if (*(childId + i) == '$') if (*(childId + i) == '$')
break; break;
if (*(childId + i) == '.') if (*(childId + i) == '.')
@ -71,22 +76,26 @@ directChildStrLen(const char* childId)
MmsValue* MmsValue*
MmsVariableSpecification_getChildValue(MmsVariableSpecification* typeSpec, MmsValue* value, const char* childId) MmsVariableSpecification_getChildValue(MmsVariableSpecification* typeSpec, MmsValue* value, const char* childId)
{ {
if ((typeSpec->type == MMS_STRUCTURE) && (value->type == MMS_STRUCTURE)) { if ((typeSpec->type == MMS_STRUCTURE) && (value->type == MMS_STRUCTURE))
{
size_t childLen = directChildStrLen(childId); size_t childLen = directChildStrLen(childId);
int i; int i;
if (typeSpec->typeSpec.structure.elementCount != value->value.structure.size) if (typeSpec->typeSpec.structure.elementCount != value->value.structure.size)
return NULL; return NULL;
for (i = 0; i < typeSpec->typeSpec.structure.elementCount; i++) { for (i = 0; i < typeSpec->typeSpec.structure.elementCount; i++)
{
if (strlen(typeSpec->typeSpec.structure.elements[i]->name) == childLen) { if (strlen(typeSpec->typeSpec.structure.elements[i]->name) == childLen)
{
if (strncmp(typeSpec->typeSpec.structure.elements[i]->name, childId, childLen) == 0) { if (strncmp(typeSpec->typeSpec.structure.elements[i]->name, childId, childLen) == 0)
if (childLen == strlen(childId)) { {
if (childLen == strlen(childId))
{
return value->value.structure.components[i]; return value->value.structure.components[i];
} }
else { else
{
return MmsVariableSpecification_getChildValue(typeSpec->typeSpec.structure.elements[i], return MmsVariableSpecification_getChildValue(typeSpec->typeSpec.structure.elements[i],
value->value.structure.components[i], childId + childLen + 1); value->value.structure.components[i], childId + childLen + 1);
} }
@ -148,18 +157,19 @@ MmsVariableSpecification_isValueOfType(MmsVariableSpecification* self, const Mms
if (self->typeSpec.bitString < 0) if (self->typeSpec.bitString < 0)
return true; return true;
} }
else if (self->type == MMS_FLOAT) { else if (self->type == MMS_FLOAT)
{
if ((self->typeSpec.floatingpoint.exponentWidth == value->value.floatingPoint.exponentWidth) && if ((self->typeSpec.floatingpoint.exponentWidth == value->value.floatingPoint.exponentWidth) &&
(self->typeSpec.floatingpoint.formatWidth == value->value.floatingPoint.formatWidth)) (self->typeSpec.floatingpoint.formatWidth == value->value.floatingPoint.formatWidth))
return true; return true;
} }
else if (self->type == MMS_BINARY_TIME) { else if (self->type == MMS_BINARY_TIME)
{
if (self->typeSpec.binaryTime == value->value.binaryTime.size) if (self->typeSpec.binaryTime == value->value.binaryTime.size)
return true; return true;
} }
else else
return true; return true;
} }
return false; return false;
@ -180,7 +190,8 @@ MmsVariableSpecification_getStructureElements(MmsVariableSpecification* self)
LinkedList elementNames = LinkedList_create(); LinkedList elementNames = LinkedList_create();
int i; int i;
for (i = 0; i < self->typeSpec.structure.elementCount; i++) { for (i = 0; i < self->typeSpec.structure.elementCount; i++)
{
MmsVariableSpecification* typeSpec = self->typeSpec.structure.elements[i]; MmsVariableSpecification* typeSpec = self->typeSpec.structure.elements[i];
LinkedList_add(elementNames, StringUtils_copyString(typeSpec->name)); LinkedList_add(elementNames, StringUtils_copyString(typeSpec->name));
@ -197,15 +208,16 @@ MmsVariableSpecification_getNamedVariableRecursive(MmsVariableSpecification* var
} }
const char* separator = strchr(nameId, '$'); const char* separator = strchr(nameId, '$');
int i; int i;
if (separator == NULL) { if (separator == NULL)
{
i = 0; i = 0;
if (variable->type == MMS_STRUCTURE) { if (variable->type == MMS_STRUCTURE)
for (i = 0; i < variable->typeSpec.structure.elementCount; i++) { {
for (i = 0; i < variable->typeSpec.structure.elementCount; i++)
{
if (strcmp(variable->typeSpec.structure.elements[i]->name, nameId) == 0) { if (strcmp(variable->typeSpec.structure.elements[i]->name, nameId) == 0) {
return variable->typeSpec.structure.elements[i]; return variable->typeSpec.structure.elements[i];
} }
@ -214,27 +226,31 @@ MmsVariableSpecification_getNamedVariableRecursive(MmsVariableSpecification* var
return NULL; return NULL;
} }
else { else
{
MmsVariableSpecification* namedVariable = NULL; MmsVariableSpecification* namedVariable = NULL;
i = 0; i = 0;
for (i = 0; i < variable->typeSpec.structure.elementCount; i++) { for (i = 0; i < variable->typeSpec.structure.elementCount; i++)
{
if (strlen(variable->typeSpec.structure.elements[i]->name) == (unsigned) (separator - nameId)) { if (strlen(variable->typeSpec.structure.elements[i]->name) == (unsigned) (separator - nameId))
{
if (strncmp(variable->typeSpec.structure.elements[i]->name, nameId, separator - nameId) == 0) { if (strncmp(variable->typeSpec.structure.elements[i]->name, nameId, separator - nameId) == 0)
{
namedVariable = variable->typeSpec.structure.elements[i]; namedVariable = variable->typeSpec.structure.elements[i];
break; break;
} }
} }
} }
if (namedVariable != NULL) { if (namedVariable != NULL)
if (namedVariable->type == MMS_STRUCTURE) { {
if (namedVariable->type == MMS_STRUCTURE)
{
namedVariable = MmsVariableSpecification_getNamedVariableRecursive(namedVariable, separator + 1); namedVariable = MmsVariableSpecification_getNamedVariableRecursive(namedVariable, separator + 1);
} }
else if (namedVariable->type == MMS_ARRAY) { else if (namedVariable->type == MMS_ARRAY)
{
namedVariable = namedVariable->typeSpec.array.elementTypeSpec; namedVariable = namedVariable->typeSpec.array.elementTypeSpec;
namedVariable = MmsVariableSpecification_getNamedVariableRecursive(namedVariable, separator + 1); namedVariable = MmsVariableSpecification_getNamedVariableRecursive(namedVariable, separator + 1);
@ -250,7 +266,8 @@ MmsVariableSpecification_getNamedVariableRecursive(MmsVariableSpecification* var
int int
MmsVariableSpecification_getSize(MmsVariableSpecification* self) MmsVariableSpecification_getSize(MmsVariableSpecification* self)
{ {
switch (self->type) { switch (self->type)
{
case MMS_STRUCTURE: case MMS_STRUCTURE:
return self->typeSpec.structure.elementCount; return self->typeSpec.structure.elementCount;
case MMS_ARRAY: case MMS_ARRAY:
@ -274,7 +291,6 @@ MmsVariableSpecification_getSize(MmsVariableSpecification* self)
default: default:
return -1; return -1;
} }
} }
MmsVariableSpecification* MmsVariableSpecification*
@ -300,9 +316,10 @@ MmsVariableSpecification_getChildSpecificationByName(MmsVariableSpecification* s
int i; int i;
for (i = 0; i < self->typeSpec.structure.elementCount; i++) { for (i = 0; i < self->typeSpec.structure.elementCount; i++)
if (!strcmp(self->typeSpec.structure.elements[i]->name, name)) { {
if (!strcmp(self->typeSpec.structure.elements[i]->name, name))
{
if (index != NULL) if (index != NULL)
*index = i; *index = i;

Loading…
Cancel
Save