- possibility to ignore block starts within block (warning is issued to stdout); used for removing comments
This commit is contained in:
@@ -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;
|
||||||
@@ -315,12 +315,21 @@ STATIC int8_t cBlockRemoval(char *aLine, const char *aBlockStart, const char *aB
|
|||||||
switch (blockDetected)
|
switch (blockDetected)
|
||||||
{
|
{
|
||||||
case CFILE_BLOCK_DETECT_START:
|
case CFILE_BLOCK_DETECT_START:
|
||||||
|
{
|
||||||
|
// additional starts within depth are ignored if aIgnore is true
|
||||||
|
// e.g. C comments are not allowed to be nested
|
||||||
|
if (!(aIgnore && depth <= *aHelper))
|
||||||
{
|
{
|
||||||
++*aHelper;
|
++*aHelper;
|
||||||
if (NULL == blockStart && depth <= *aHelper)
|
if (NULL == blockStart && depth <= *aHelper)
|
||||||
{
|
{
|
||||||
blockStart = blockMatch;
|
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;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user