diff --git a/src/stubser/cfile_parser.c b/src/stubser/cfile_parser.c index 1f87026..2a3dbf0 100644 --- a/src/stubser/cfile_parser.c +++ b/src/stubser/cfile_parser.c @@ -286,7 +286,7 @@ STATIC cfile_block_return_t cBlockDetection(const char *aBlockStart, const char * @retval -1 Invalid block ending ("end" without corresponding "start") * @retval -2 Null pointer detected */ -STATIC int8_t cBlockRemoval(char *aLine, const char *aBlockStart, const char *aBlockEnd, uint32_t *aHelper, bool aRemove) +STATIC int8_t cBlockRemoval(char *aLine, const char *aBlockStart, const char *aBlockEnd, uint32_t *aHelper, bool aRemove, bool aIgnore) { const uint8_t depth = 1; // preparation to support which depth should be removed for nested block bool blockLine = false; @@ -316,10 +316,19 @@ STATIC int8_t cBlockRemoval(char *aLine, const char *aBlockStart, const char *aB { case CFILE_BLOCK_DETECT_START: { - ++*aHelper; - if (NULL == blockStart && depth <= *aHelper) + // additional starts within depth are ignored if aIgnore is true + // e.g. C comments are not allowed to be nested + if (!(aIgnore && depth <= *aHelper)) { - blockStart = blockMatch; + ++*aHelper; + if (NULL == blockStart && depth <= *aHelper) + { + blockStart = blockMatch; + } + } + else + { + printf("[WARN] Nested block start (see file below): %s", aLine); } blockWorker = (aRemove ? blockMatch + strlen(aBlockStart) : blockMatch); break; @@ -419,7 +428,7 @@ STATIC int8_t removeCcomments(char *aLine) comment = NULL; } - return cBlockRemoval(aLine, CPARS_COMMENT_BLOCK_START, CPARS_COMMENT_BLOCK_END, &cfile_parser_removeCommentHelper, true); + return cBlockRemoval(aLine, CPARS_COMMENT_BLOCK_START, CPARS_COMMENT_BLOCK_END, &cfile_parser_removeCommentHelper, true, true); } STATIC int8_t evaluateParameter(char *aParameter, cfunction_t *aFunction) @@ -480,7 +489,7 @@ STATIC cfunction_t* cfile_parser_evaluateLine(char *aLine) { return NULL; } - if (0 != cBlockRemoval(aLine, "{", "}", &cfile_parser_removeBraceHelper, false)) + if (0 != cBlockRemoval(aLine, "{", "}", &cfile_parser_removeBraceHelper, false, false)) { return NULL; }