- possibility to ignore block starts within block (warning is issued to stdout); used for removing comments

This commit is contained in:
2017-03-06 15:39:04 +00:00
parent 39e5ad42bb
commit 16f0c0224a

View File

@@ -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 -1 Invalid block ending ("end" without corresponding "start")
* @retval -2 Null pointer detected * @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 const uint8_t depth = 1; // preparation to support which depth should be removed for nested block
bool blockLine = false; bool blockLine = false;
@@ -316,10 +316,19 @@ STATIC int8_t cBlockRemoval(char *aLine, const char *aBlockStart, const char *aB
{ {
case CFILE_BLOCK_DETECT_START: case CFILE_BLOCK_DETECT_START:
{ {
++*aHelper; // additional starts within depth are ignored if aIgnore is true
if (NULL == blockStart && depth <= *aHelper) // 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); blockWorker = (aRemove ? blockMatch + strlen(aBlockStart) : blockMatch);
break; break;
@@ -419,7 +428,7 @@ STATIC int8_t removeCcomments(char *aLine)
comment = NULL; 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) STATIC int8_t evaluateParameter(char *aParameter, cfunction_t *aFunction)
@@ -480,7 +489,7 @@ STATIC cfunction_t* cfile_parser_evaluateLine(char *aLine)
{ {
return NULL; return NULL;
} }
if (0 != cBlockRemoval(aLine, "{", "}", &cfile_parser_removeBraceHelper, false)) if (0 != cBlockRemoval(aLine, "{", "}", &cfile_parser_removeBraceHelper, false, false))
{ {
return NULL; return NULL;
} }