diff --git a/src/stubser/cfile.c b/src/stubser/cfile.c index e58dfab..bde9088 100644 --- a/src/stubser/cfile.c +++ b/src/stubser/cfile.c @@ -59,7 +59,7 @@ int8_t cfile_freeVariables(cfile_variableList_t *aVariable) while (work) { next = work->next; - free(work->type); + free(work->dataType); free(work->name); free(work); work = next; @@ -77,3 +77,23 @@ void cfile_free(cfile_t *aCfile) cfile_freeVariables(&aCfile->variables); cfunction_freeList(&aCfile->functions); } + +void cfile_print(cfile_t *aCfile) +{ + cfile_variable_t *work = NULL; + + if (NULL == aCfile) + { + return; + } + + work = aCfile->variables.head; + + while (work) + { + printf("[ cva]%d:<%s> (%s) %s\n", work->type, work->prefix, work->dataType, work->name); + work = work->next; + } + + cfunction_printList(&aCfile->functions); +} diff --git a/src/stubser/cfile_if.h b/src/stubser/cfile_if.h index fff067d..a53525f 100644 --- a/src/stubser/cfile_if.h +++ b/src/stubser/cfile_if.h @@ -16,11 +16,22 @@ #include "cfunction_if.h" +/*! @brief Type of function definition */ +typedef enum _CFILE_VARIABLE_TYPE_T +{ + CVARIABLE_TYPE_UNDEF = 0, /*!< @brief undefined */ + CVARIABLE_TYPE_REGULAR = 1, /*!< @brief Regular C function definition */ + CVARIABLE_TYPE_STATIC = 2, /*!< @brief Static C function definition */ + CVARIABLE_TYPE_EXTERN = 4, /*!< @brief External C function definition */ + CVARIABLE_TYPE_LAST_ENUM +} cfile_variable_type_t; + /*! @brief Parameter list node */ typedef struct _CFILE_VARIABLE_T { + cfile_variable_type_t type; char* prefix; /*!< @brief variable prefix (e.g. static) */ - char* type; /*!< @brief data type */ + char* dataType; /*!< @brief data type */ char* name; /*!< @brief name */ struct _CFILE_VARIABLE_T *next; } cfile_variable_t; @@ -49,5 +60,6 @@ typedef struct _CFILE_T cfile_variable_t* cfile_newVariable(cfile_variableList_t *aList); int8_t cfile_freeVariables(cfile_variableList_t *aVariable); void cfile_free(cfile_t *aCfile); +void cfile_print(cfile_t *aCfile); #endif /* STUBSER_CFILE_IF_H_ */ diff --git a/src/stubser/cfile_parser.c b/src/stubser/cfile_parser.c index 826c501..89f870f 100644 --- a/src/stubser/cfile_parser.c +++ b/src/stubser/cfile_parser.c @@ -32,15 +32,7 @@ typedef enum _CFILE_BLOCK_RETURN_T } cfile_block_return_t; STATIC bool cfile_parser_initialized = false; -STATIC uint8_t cfile_parser_functionLine = 0; -STATIC cfunction_t *cfile_parser_function = NULL; -STATIC regex_t regX; -STATIC regex_t regXsl; -STATIC regex_t regXmlStart; -STATIC regex_t regXmlPar; -STATIC regex_t regXmlEnd; -STATIC regex_t regXmlProto; -STATIC regex_t regXproto; +STATIC regex_t regXfunction; STATIC regex_t regXprefix; STATIC regex_t regXparameter; STATIC regex_t regXvariable; @@ -65,37 +57,7 @@ int8_t cfile_parser_init() perror("Error regex\n"); return -1; } - if (0 > regcomp(®X, FUNCTION_BASE, (REG_EXTENDED | REG_NEWLINE))) - { - perror("Error regex\n"); - return -1; - } - if (0 > regcomp(®Xsl, FUNCTION_SL, (REG_EXTENDED | REG_NEWLINE))) - { - perror("Error regex\n"); - return -1; - } - if (0 > regcomp(®XmlStart, FUNCTION_ML_SOF, (REG_EXTENDED | REG_NEWLINE))) - { - perror("Error regex\n"); - return -1; - } - if (0 > regcomp(®XmlPar, FUNCTION_ML_PAR, (REG_EXTENDED | REG_NEWLINE))) - { - perror("Error regex\n"); - return -1; - } - if (0 > regcomp(®XmlEnd, FUNCTION_ML_END, (REG_EXTENDED | REG_NEWLINE))) - { - perror("Error regex\n"); - return -1; - } - if (0 > regcomp(®XmlProto, FUNCTION_ML_PROTO, (REG_EXTENDED | REG_NEWLINE))) - { - perror("Error regex\n"); - return -1; - } - if (0 > regcomp(®Xproto, FUNCTION_PROTO, (REG_EXTENDED | REG_NEWLINE))) + if (0 > regcomp(®Xfunction, CPARS_REGEX_FUNCTION, (REG_EXTENDED | REG_NEWLINE))) { perror("Error regex\n"); return -1; @@ -120,7 +82,7 @@ int8_t cfile_parser_init() return 0; } -#if(0) +#if isDebugLevel(1) STATIC void printMatchGroup(char *aString, regmatch_t *aMatchGroup) { char match[1024] = @@ -131,47 +93,91 @@ STATIC void printMatchGroup(char *aString, regmatch_t *aMatchGroup) { if (aMatchGroup[i].rm_so < aMatchGroup[i].rm_eo) { - DEBUG_LOG_APPEND(1, "[%02d](%.3ld - %.3ld)[%03d]:", i, aMatchGroup[i].rm_so, aMatchGroup[i].rm_eo, (int) (aMatchGroup[i].rm_eo - aMatchGroup[i].rm_so)); + DEBUG_LOG_APPEND(1, "[%02d](%.3ld - %.3ld)[%03d]:", i, aMatchGroup[i].rm_so, aMatchGroup[i].rm_eo, + (int ) (aMatchGroup[i].rm_eo - aMatchGroup[i].rm_so)); strlcpy(match, &aString[aMatchGroup[i].rm_so], (size_t) (aMatchGroup[i].rm_eo - aMatchGroup[i].rm_so + 1)); DEBUG_LOG_APPEND(1, "%s", match); DEBUG_LOG_APPEND(1, "\n"); } } } +#else +#define printMatchGroup(aString, aMatchgroup) do { /*nothing*/ } while(0) #endif -STATIC void checkFunctionType(cfunction_t *aFunction) +STATIC void checkFunctionType(cfunction_t *aFunction, char *aExpression) { + char *tempChar = NULL; + + if (NULL == aFunction || NULL == aExpression) + { + return; + } + + aFunction->type = CFUNCTION_TYPE_REGULAR; + + tempChar = strrchr(aExpression, CPARS_PROTOTYPE_END_C); + if (tempChar) + { + aFunction->type = CFUNCTION_TYPE_PROTO; + } + if (NULL == aFunction->prefix) { return; } - if ((NULL != strstr(aFunction->prefix, "static") || NULL != strstr(aFunction->prefix, "STATIC")) // - && CFUNCTION_TYPE_PROTO != aFunction->type) + if (NULL != strstr(aFunction->prefix, CPARS_PREFIX_EXTERN_S)) + { + aFunction->type = CFUNCTION_TYPE_EXTERN; + } + else if (NULL != strstr(aFunction->prefix, CPARS_PREFIX_STATIC_S) && CFUNCTION_TYPE_PROTO != aFunction->type) { aFunction->type = CFUNCTION_TYPE_STATIC; } } /*! - * @brief Extract function prefix and data type and removing trailing blanks - * @param [out] *aFunction Pointer to function structure + * @brief Extract C expression prefix and data type and removing trailing blanks + * @param [out] *aElement Pointer to C element structure + * @param [in] aElementType C element type (CELEMENT_TYPE_VARIABLE, CELEMENT_TYPE_FUNCTION supported) * @param [in] *aString Pointer to a substring containing data type and/or prefix * @param [in] aSize Length of string * @retval 0 processing successful * @retval -1 processing failed */ -STATIC int8_t matchFunctionStart(cfunction_t *aFunction, char *aString, size_t aSize) +STATIC int8_t matchPrefix(void *aElement, celement_type_t aElementType, char *aString, size_t aSize) { regmatch_t matchGroup[CFILE_PARSER_MAX_REGEX_MATCHING_GROUPS]; char *temp = NULL; char *end = NULL; + char **prefix = NULL; + char **type = NULL; - if (NULL == aFunction || NULL == aString || 0 == aSize) + if (NULL == aElement || NULL == aString || 0 == aSize) { return -1; } + switch (aElementType) + { + case CELEMENT_TYPE_VARIABLE: + { + prefix = &((cfile_variable_t*) aElement)->prefix; + type = &((cfile_variable_t*) aElement)->dataType; + break; + } + case CELEMENT_TYPE_FUNCTION: + { + prefix = &((cfunction_t*) aElement)->prefix; + type = &((cfunction_t*) aElement)->dataType; + break; + } + default: + { + return -1; + } + } + temp = (char*) xmalloc(aSize + 1); if (NULL == temp) { @@ -187,21 +193,36 @@ STATIC int8_t matchFunctionStart(cfunction_t *aFunction, char *aString, size_t a } *(end + 1) = '\0'; + if (CELEMENT_TYPE_VARIABLE == aElementType) + { + ((cfunction_t*) aElement)->type = CFUNCTION_TYPE_REGULAR; + } + if (0 == regexec(®Xprefix, temp, CFILE_PARSER_MAX_REGEX_MATCHING_GROUPS, matchGroup, 0)) { if (XREGEX_IS_MATCHGROUP(matchGroup, 1)) { - xmallocStrlcpy(&aFunction->prefix, &temp[matchGroup[1].rm_so], XREGEX_SIZEOF_MATCHGROUP(matchGroup, 1)); - checkFunctionType(aFunction); + xmallocStrlcpy(prefix, &temp[matchGroup[1].rm_so], XREGEX_SIZEOF_MATCHGROUP(matchGroup, 1)); + if (CELEMENT_TYPE_VARIABLE == aElementType) + { + if (*prefix && NULL != strstr(*prefix, CPARS_PREFIX_EXTERN_S)) + { + ((cfunction_t*) aElement)->type = CFUNCTION_TYPE_EXTERN; + } + else if (*prefix && NULL != strstr(*prefix, CPARS_PREFIX_STATIC_S)) + { + ((cfunction_t*) aElement)->type = CFUNCTION_TYPE_STATIC; + } + } } if (XREGEX_IS_MATCHGROUP(matchGroup, 2)) { - xmallocStrlcpy(&aFunction->dataType, &temp[matchGroup[2].rm_so], XREGEX_SIZEOF_MATCHGROUP(matchGroup, 2)); + xmallocStrlcpy(type, &temp[matchGroup[2].rm_so], XREGEX_SIZEOF_MATCHGROUP(matchGroup, 2)); } } else { - xmallocStrlcpy(&aFunction->dataType, temp, strlen(temp)); + xmallocStrlcpy(type, temp, strlen(temp)); } free(temp); @@ -489,160 +510,50 @@ STATIC int8_t evaluateParameter(char *aParameter, cfunction_t *aFunction) return 0; } -#if(0) -/*! - * @brief Process a string (e.g. from getline()) if it is a single or multiple line function definition - * @todo closing parenthesis within parameter list will break the detection - * @retval -1 Invalid regular expressions - * @retval -2 Given String not a function - * @retval 0 function evaluated - */ -STATIC cfunction_t* cfile_parser_evaluateLine1(char *aLine) +STATIC int8_t cfile_parser_evaluateExpression(char *aExpression, cfile_t *aCfile) { - const size_t maxGroup = CFILE_PARSER_MAX_REGEX_MATCHING_GROUPS; - regmatch_t matchGroup[maxGroup]; - bool functionEnd = false; - cfunction_type_t tempFunctionType = CFUNCTION_TYPE_UNDEF; + char *tempChar = NULL; + cfile_variable_t *variable = NULL; + cfunction_t *function = NULL; + regmatch_t matchGroup[CFILE_PARSER_MAX_REGEX_MATCHING_GROUPS]; - if (0 != removeCcomments(aLine)) + if (NULL == aExpression || NULL == aCfile) { - return NULL; - } - if (0 != cBlockRemoval(aLine, "{", "}", &cfile_parser_removeBraceHelper, false, false)) - { - return NULL; + return -1; } - if (cfile_parser_functionLine) + if (0 == regexec(®Xfunction, aExpression, CFILE_PARSER_MAX_REGEX_MATCHING_GROUPS, matchGroup, + REG_NOTEOL) && CFILE_PARSER_IS_MATCHGROUP_FUNCTION(matchGroup)) { - if (0 == regexec(®XmlEnd, aLine, maxGroup, matchGroup, REG_NOTEOL)) + printMatchGroup(aExpression, matchGroup); + function = cfunction_addNewFunction(&aCfile->functions); + (void) matchPrefix(function, CELEMENT_TYPE_FUNCTION, &aExpression[matchGroup[1].rm_so], XREGEX_SIZEOF_MATCHGROUP(matchGroup, 1)); + checkFunctionType(function, aExpression); + xmallocStrlcpy(&function->name, &aExpression[matchGroup[2].rm_so], XREGEX_SIZEOF_MATCHGROUP(matchGroup, 2)); + if (XREGEX_IS_MATCHGROUP(matchGroup, 3)) { - tempFunctionType = CFUNCTION_TYPE_REGULAR; - DEBUG_LOG_APPEND(1, "[ mle]"); - functionEnd = true; - } - else if (0 == regexec(®XmlProto, aLine, maxGroup, matchGroup, REG_NOTEOL)) - { - tempFunctionType = CFUNCTION_TYPE_PROTO; - DEBUG_LOG_APPEND(1, "[ mlp]"); - functionEnd = true; - } - else if (0 == regexec(®XmlPar, aLine, maxGroup, matchGroup, REG_NOTEOL)) - { - DEBUG_LOG_APPEND(1, "[ ml+]"); - } - else - { - DEBUG_LOG_APPEND(1, "[ na ]"); - tempFunctionType = CFUNCTION_TYPE_UNDEF; - functionEnd = true; - } - - ++cfile_parser_functionLine; - } - else if (0 == regexec(®Xsl, aLine, maxGroup, matchGroup, REG_NOTEOL) && CFILE_PARSER_IS_MATCHGROUP_FUNCTION(matchGroup)) - { - tempFunctionType = CFUNCTION_TYPE_REGULAR; - DEBUG_LOG_APPEND(1, "[ sl ]"); - } - else if (0 == regexec(®XmlStart, aLine, maxGroup, matchGroup, REG_NOTEOL) && CFILE_PARSER_IS_MATCHGROUP_FUNCTION(matchGroup)) - { - tempFunctionType = CFUNCTION_TYPE_REGULAR; - DEBUG_LOG_APPEND(1, "[ mls]"); - ++cfile_parser_functionLine; - } - else if (0 == regexec(®Xproto, aLine, maxGroup, matchGroup, REG_NOTEOL) && CFILE_PARSER_IS_MATCHGROUP_FUNCTION(matchGroup)) - { - tempFunctionType = CFUNCTION_TYPE_PROTO; - DEBUG_LOG_APPEND(1, "[prot]"); - } - else if (0 == regexec(®X, aLine, maxGroup, matchGroup, REG_NOTEOL) && CFILE_PARSER_IS_MATCHGROUP_FUNCTION(matchGroup)) - { - tempFunctionType = CFUNCTION_TYPE_UNDEF; - DEBUG_LOG_APPEND(1, "[ fuX]"); - } - else - { - return NULL; - } -#if (0) - { - uint8_t i = 0; - char match[1024] = - { 0}; - - for (i = 0; i < maxGroup && 0 <= matchGroup[i].rm_so; ++i) - { - if (matchGroup[i].rm_so < matchGroup[i].rm_eo) + xmallocStrlcat(&tempChar, &aExpression[matchGroup[3].rm_so], XREGEX_SIZEOF_MATCHGROUP(matchGroup, 3)); + if (NULL != tempChar) { - if (0 < i) - DEBUG_LOG_APPEND(1, " "); - DEBUG_LOG_APPEND(1, "[%02d](%.3ld - %.3ld)[%03d]: ", i, matchGroup[i].rm_so, matchGroup[i].rm_eo, (int) (matchGroup[i].rm_eo - matchGroup[i].rm_so)); - strlcpy(match, &aLine[matchGroup[i].rm_so], (size_t) (matchGroup[i].rm_eo - matchGroup[i].rm_so + 1)); - DEBUG_LOG_APPEND(1, "%s", match); - DEBUG_LOG_APPEND(1, "\n"); + evaluateParameter(tempChar, function); } - } - if (functionEnd) - { - cfile_parser_functionLine = 0; + xfree((void**) &tempChar); } } -#else - switch (cfile_parser_functionLine) + else if (0 == regexec(®Xvariable, aExpression, CFILE_PARSER_MAX_REGEX_MATCHING_GROUPS, matchGroup, + REG_NOTEOL) && XREGEX_IS_MATCHGROUP(matchGroup, 1)) { - case 0: // single line function definition - case 1:// first line of multi line function definition + printMatchGroup(aExpression, matchGroup); + variable = cfile_newVariable(&aCfile->variables); + if (variable) { - // TODO multiple functions in one line - cfile_parser_function = cfunction_newFunction(); - cfile_parser_function->type = tempFunctionType; - matchFunctionStart(cfile_parser_function, &aLine[matchGroup[1].rm_so], XREGEX_SIZEOF_MATCHGROUP(matchGroup, 1)); - xmallocStrlcpy(&cfile_parser_function->name, &aLine[matchGroup[2].rm_so], XREGEX_SIZEOF_MATCHGROUP(matchGroup, 2)); - if (XREGEX_IS_MATCHGROUP(matchGroup, 3)) - { - xmallocStrlcat(&cfile_parser_parameterStorage, &aLine[matchGroup[3].rm_so], XREGEX_SIZEOF_MATCHGROUP(matchGroup, 3)); - } - break; - } - default: // further lines - { - if (XREGEX_IS_MATCHGROUP(matchGroup, 1)) - { - xmallocStrlcat(&cfile_parser_parameterStorage, &aLine[matchGroup[1].rm_so], XREGEX_SIZEOF_MATCHGROUP(matchGroup, 1)); - } - if (functionEnd) - { - if (CFUNCTION_TYPE_UNDEF == tempFunctionType) - { - cfunction_freeFunction(&cfile_parser_function); - } - else - { - cfile_parser_function->type = tempFunctionType; - checkFunctionType(cfile_parser_function); - } - cfile_parser_functionLine = 0; - } - break; + (void) matchPrefix(variable, CELEMENT_TYPE_VARIABLE, &aExpression[matchGroup[1].rm_so], XREGEX_SIZEOF_MATCHGROUP(matchGroup, 1)); + xmallocStrlcpy(&variable->name, &aExpression[matchGroup[2].rm_so], XREGEX_SIZEOF_MATCHGROUP(matchGroup, 2)); } } - // return evaluated function - if (0 == cfile_parser_functionLine) - { - evaluateParameter(cfile_parser_parameterStorage, cfile_parser_function); - free(cfile_parser_parameterStorage); - cfile_parser_parameterStorage = NULL; - cfunction_t *funTemp = cfile_parser_function; - cfile_parser_function = NULL; - return funTemp; - } -#endif - - return NULL; + return 0; } -#endif STATIC int8_t cfile_parser_evaluateLine(uint32_t aNumber, char *aLine, cfile_t *aCfile) { @@ -650,16 +561,26 @@ STATIC int8_t cfile_parser_evaluateLine(uint32_t aNumber, char *aLine, cfile_t * int8_t result = 0; static char *match = NULL; static uint8_t depth = 0; + char *tempMatch = NULL; regex_t *matchStart = ®XExpressionStart; regex_t *matchEnd = ®XExpressionEnd; while (position) { + if (NULL != (tempMatch = strstr(position, "#include"))) + { + // TODO save include information + DEBUG_LOG_APPEND(1, "[ Re %04u] Works %zu %s\n", aNumber, strlen(tempMatch), tempMatch); + position = NULL; + continue; + } result = regExWorker(&match, &position, matchStart, matchEnd, &depth, false); if (match && 0 == result && 0 == depth) { DEBUG_LOG_APPEND(1, "[ Re %04u] Works %zu %s\n", aNumber, strlen(match), match); + // Evaluate C expression + (void) cfile_parser_evaluateExpression(match, aCfile); xfree((void**) &match); } if (0 > result) diff --git a/src/stubser/cfile_parser_loc.h b/src/stubser/cfile_parser_loc.h index c18226b..26ca9c7 100644 --- a/src/stubser/cfile_parser_loc.h +++ b/src/stubser/cfile_parser_loc.h @@ -21,20 +21,20 @@ #define CPARS_COMMENT_BLOCK_START "/*" #define CPARS_COMMENT_BLOCK_END "*/" -#define FUNCTION_BASE "^[[:blank:]]*([ _\\*[:alnum:]]* +\\**)([_\\*[:alnum:]]*)[[:blank:]]*\\([[:blank:]]*([^\r\\)]*)" -#define FUNCTION_SL FUNCTION_BASE "\\)[^;]*$" -#define FUNCTION_ML_SOF FUNCTION_BASE "[\r]*$" -#define FUNCTION_ML_PAR "^[[:blank:]]*([^\r]*)" -#define FUNCTION_ML_END FUNCTION_ML_PAR "\\)[^;]*$" -#define FUNCTION_ML_PROTO FUNCTION_ML_PAR "\\).*[[:blank:]]*;" -#define FUNCTION_PROTO FUNCTION_BASE "\\).*[[:blank:]]*;" +#define CPARS_PROTOTYPE_END_C ';' +#define CPARS_PREFIX_STATIC_S "static" +#define CPARS_PREFIX_EXTERN_S "extern" -#define CPARS_REGEX_VARIABLE "^[[:blank:]]*([ _\\*[:alnum:]]*)[[:blank:]]*[;=]" +#define CPARS_EXPRESSION_BASE "^[[:blank:]]*([ _\\*[:alnum:]]* +\\**)([_\\*[:alnum:]]+)" + +#define FUNCTION_BASE CPARS_EXPRESSION_BASE "[[:blank:]]*\\([[:blank:]]*" +#define CPARS_REGEX_FUNCTION FUNCTION_BASE "(.*)\\)[[:blank:]\\{\\};]+[[:blank:]]*" +#define CPARS_REGEX_VARIABLE CPARS_EXPRESSION_BASE "[[:blank:]]*[;=]" #define CPARS_REGEX_PARAMETER "[[:blank:]]*([ _\\*[:alnum:]]* +\\**)([_\\*[:alnum:]]*)[[:blank:]]*" -#define CPARS_REGEX_PREFIX "(extern|EXTERN|static|STATIC|volatile|near|far)[[:blank:]]+([^\\*]*\\**)" +#define CPARS_REGEX_PREFIX "("CPARS_PREFIX_EXTERN_S"|EXTERN|"CPARS_PREFIX_STATIC_S"|STATIC|volatile|near|far)[[:blank:]]*(.*)" #define CPARS_EXPRESSION_START "^[[:blank:]]*([A-Za-z\\_][\\_\\*[:alnum:]]*)" -#define CPARS_EXPRESSION_END "[[:blank:]]*([\\};]+)" +#define CPARS_EXPRESSION_END "[[:blank:]]*([\\};]+)" #define CFILE_PARSER_IS_MATCHGROUP_FUNCTION(matchGroup) (XREGEX_IS_MATCHGROUP(matchGroup, 1) && XREGEX_IS_MATCHGROUP(matchGroup, 2)) diff --git a/src/stubser/cfunction.c b/src/stubser/cfunction.c index 2f21d22..f1a2d5d 100644 --- a/src/stubser/cfunction.c +++ b/src/stubser/cfunction.c @@ -16,39 +16,35 @@ #include "xmalloc.h" #include "cfunction_if.h" -cfunction_t* cfunction_newFunction() +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)); - return new; -} - -int8_t cfunction_addFunction(cfunction_list_t *aList, cfunction_t *aNew) -{ - if (NULL == aList || NULL == aNew) - { - perror("Null pointer"); - return -1; - } - if (NULL == aList->head) { - aList->head = aNew; - aList->current = aNew; + aList->amount = 0; + aList->head = new; + aList->current = new; } else { - aList->current->next = aNew; - aList->current = aNew; + aList->current->next = new; + aList->current = new; } - - return 0; + ++aList->amount; + return new; } -cfunction_parameter_t* cfunction_newParameter(struct _CFUNCTION_PARAMETER_LIST_T *aList) +cfunction_parameter_t* cfunction_newParameter(cfunction_parameterList_t *aList) { cfunction_parameter_t *new = NULL; @@ -63,6 +59,7 @@ cfunction_parameter_t* cfunction_newParameter(struct _CFUNCTION_PARAMETER_LIST_T if (NULL == aList->head) { + aList->amount = 0; aList->head = new; aList->current = new; } @@ -162,7 +159,7 @@ void cfunction_printList(cfunction_list_t *aList) while (work) { param = work->parameter.head; - printf("[ cfu]%d:%s %s %s [%d] ", work->type, work->prefix, work->dataType, work->name, work->parameter.amount); + printf("[ cfu]%d:<%s> (%s) %s [%d] ", work->type, work->prefix, work->dataType, work->name, work->parameter.amount); while (param) { printf("%s|%s,", param->type, param->name); @@ -170,6 +167,6 @@ void cfunction_printList(cfunction_list_t *aList) } printf("\n"); work = work->next; - } + printf(" %d Functions\n", aList->amount); } diff --git a/src/stubser/cfunction_if.h b/src/stubser/cfunction_if.h index 0981656..ec18ef6 100644 --- a/src/stubser/cfunction_if.h +++ b/src/stubser/cfunction_if.h @@ -18,9 +18,10 @@ typedef enum _CFUNCTION_TYPE_T { CFUNCTION_TYPE_UNDEF = 0, /*!< @brief undefined */ - CFUNCTION_TYPE_REGULAR = 1, /*!< @brief Regular c function definition */ - CFUNCTION_TYPE_STATIC = 2, /*!< @brief Static c function definition */ - CFUNCTION_TYPE_PROTO = 3, /*!< @brief Prototype c function definition */ + CFUNCTION_TYPE_REGULAR = 1, /*!< @brief Regular C function definition */ + CFUNCTION_TYPE_STATIC = 2, /*!< @brief Static C function definition */ + CFUNCTION_TYPE_PROTO = 3, /*!< @brief Prototype C function definition */ + CFUNCTION_TYPE_EXTERN = 4, /*!< @brief External C function definition */ CFUNCTION_TYPE_LAST_ENUM } cfunction_type_t; @@ -54,17 +55,18 @@ typedef struct _CFUNCTION_T /*! @brief Dynamic function list */ typedef struct _CFUNCTION_LIST_T { + uint16_t amount; cfunction_t *head; cfunction_t *current; } cfunction_list_t; #define CFUNCTION_LIST_DEFAULT {\ + .amount = 0, \ .head = NULL, \ .current = NULL } -cfunction_t* cfunction_newFunction(); -int8_t cfunction_addFunction(cfunction_list_t *aList, cfunction_t *aNew); -cfunction_parameter_t* cfunction_newParameter(struct _CFUNCTION_PARAMETER_LIST_T *aList); +cfunction_t* cfunction_addNewFunction(cfunction_list_t *aList); +cfunction_parameter_t* cfunction_newParameter(cfunction_parameterList_t *aList); int8_t cfunction_freeFunction(cfunction_t **aFunction); int8_t cfunction_freeList(cfunction_list_t *aList); void cfunction_printList(cfunction_list_t *aList); diff --git a/src/stubser/stubser.c b/src/stubser/stubser.c index 887bd4c..33fef9e 100644 --- a/src/stubser/stubser.c +++ b/src/stubser/stubser.c @@ -311,6 +311,10 @@ int stubser_createStub(char *path, char* aNoSuffix, char *aOutput) } printf(STUB_CONSOLE_CREATE_OK_S1, fileName); +#if isDebugLevel(1) + cfile_print(&cFile); +#endif + end_stubser_createStub: // function end target cfile_free(&cFile);