Files
stubser/src/stubser/cfunction.c
2019-04-04 15:45:29 +02:00

173 lines
3.3 KiB
C

/*!
* @file cfunction.c
* @brief
* @details
* Project: \n
* Subsystem: \n
* Module: \n
* Code: GNU-C\n
*
* @date 28.02.2017
* @author Martin Winkler
*/
#include <stdio.h>
#include <string.h>
#include "xtypes.h"
#include "xmalloc.h"
#include "cfunction_if.h"
cfunction_t* cfunction_addNewFunction(cfunction_list_t *aList)
{
cfunction_t *new = NULL;
if (NULL == aList)
{
perror("Null pointer");
return NULL;
}
new = (cfunction_t*) xmalloc(sizeof(cfunction_t));
memset(new, 0, sizeof(cfunction_t));
if (NULL == aList->head)
{
aList->amount = 0;
aList->head = new;
aList->current = new;
}
else
{
aList->current->next = new;
aList->current = new;
}
++aList->amount;
return new;
}
cfunction_parameter_t* cfunction_newParameter(cfunction_parameterList_t *aList)
{
cfunction_parameter_t *new = NULL;
if (NULL == aList)
{
perror("Null pointer");
return NULL;
}
new = (cfunction_parameter_t*) xmalloc(sizeof(cfunction_parameter_t));
memset(new, 0, sizeof(cfunction_parameter_t));
if (NULL == aList->head)
{
aList->amount = 0;
aList->head = new;
aList->current = new;
}
else
{
aList->current->next = new;
aList->current = new;
}
++aList->amount;
return new;
}
STATIC int8_t cfunction_freeParameter(struct _CFUNCTION_PARAMETER_LIST_T *aParameter)
{
cfunction_parameter_t *work = NULL;
cfunction_parameter_t *next = NULL;
if (NULL == aParameter)
{
perror("Null pointer");
return -1;
}
work = aParameter->head;
while (work)
{
next = work->next;
free(work->dataType);
free(work->name);
free(work);
work = next;
}
aParameter->head = NULL;
aParameter->current = NULL;
return 0;
}
int8_t cfunction_freeFunction(cfunction_t **aFunction)
{
cfunction_t *work = *aFunction;
if (NULL == aFunction || NULL == *aFunction)
{
return -1;
}
free(work->prefix);
free(work->dataType);
free(work->name);
cfunction_freeParameter(&work->parameter);
free(work);
*aFunction = NULL;
return 0;
}
int8_t cfunction_freeList(cfunction_list_t *aList)
{
cfunction_t *work = NULL;
cfunction_t *next = NULL;
if (NULL == aList)
{
perror("Null pointer");
return -1;
}
work = aList->head;
while (work)
{
next = work->next;
cfunction_freeFunction(&work);
work = next;
}
aList->head = NULL;
aList->current = NULL;
return 0;
}
void cfunction_printList(cfunction_list_t *aList)
{
cfunction_t *work = aList->head;
cfunction_parameter_t *param = NULL;
if (NULL == aList)
{
return;
}
while (work)
{
param = work->parameter.head;
printf("[ cfu]%d:<%s> (%s) %s [%d] ", work->type, work->prefix, work->dataType, work->name, work->parameter.amount);
while (param)
{
printf("%d(%s)%s%s%s", param->type, param->dataType, param->name, (param->array ? param->array : ""), (param->next ? "," : ""));
param = param->next;
}
printf("\n");
work = work->next;
}
printf(" %d Functions\n", aList->amount);
}