- WIP (dynamic function structure implementation started; only function type at the moment; running)

This commit is contained in:
2017-03-01 08:02:44 +00:00
parent 53f530fb6f
commit da56a3b6cf
7 changed files with 208 additions and 56 deletions

View File

@@ -12,13 +12,17 @@
*/
#include <stdio.h>
#include <stdlib.h>
#include <regex.h>
#include "xregex.h"
#include "xtypes.h"
#include "xstring.h"
#include "cfile_parser_loc.h"
#include "cfunction_if.h"
#include "cfile_parser_loc.h"
#define CFILE_PARSTER_MAX_REGEX_MATCHING_GROUPS 10
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;
@@ -221,74 +225,135 @@ int8_t cfile_parser_init()
//
// return 0;
//}
STATIC void cfile_parser_evaluateLine(char *aLine)
STATIC cfunction_t* cfile_parser_evaluateLine(char *aLine)
{
uint8_t i;
const size_t maxGroup = 10;
const size_t maxGroup = CFILE_PARSTER_MAX_REGEX_MATCHING_GROUPS;
regmatch_t matchGroup[maxGroup];
bool functionEnd = false;
cfunction_type_t tempFunctionType = CFUNCTION_TYPE_UNDEF;
char match[1024] =
{ 0 };
static uint8_t mlFlag = 0;
if (mlFlag)
if (cfile_parser_functionLine)
{
if (0 == regexec(&regXmlEnd, aLine, maxGroup, matchGroup, REG_NOTEOL))
{
tempFunctionType = CFUNCTION_TYPE_REGULAR;
printf("[ mle]");
mlFlag = 0;
++cfile_parser_functionLine;
functionEnd = true;
}
else if (0 == regexec(&regXmlProto, aLine, maxGroup, matchGroup, REG_NOTEOL))
{
tempFunctionType = CFUNCTION_TYPE_PROTO;
printf("[ mlp]");
mlFlag = 0;
++cfile_parser_functionLine;
functionEnd = true;
}
else if (0 == regexec(&regXmlPar, aLine, maxGroup, matchGroup, REG_NOTEOL))
{
printf("[ ml+]");
++mlFlag;
++cfile_parser_functionLine;
}
else
{
// fallback
mlFlag = 0;
return;
tempFunctionType = CFUNCTION_TYPE_UNDEF;
++cfile_parser_functionLine;
functionEnd = true;
// TODO fallback (free currently used memory)
return NULL;
}
}
else if (0 == regexec(&regXsl, aLine, maxGroup, matchGroup, REG_NOTEOL) && matchGroup[2].rm_so < matchGroup[2].rm_eo)
else if (0 == regexec(&regXsl, aLine, maxGroup, matchGroup, REG_NOTEOL) && CFILE_PARSER_IS_MATCHGROUP_FUNCTION(matchGroup))
{
tempFunctionType = CFUNCTION_TYPE_REGULAR;
printf("[ sl ]");
}
else if (0 == regexec(&regXmlStart, aLine, maxGroup, matchGroup, REG_NOTEOL) && matchGroup[2].rm_so < matchGroup[2].rm_eo)
else if (0 == regexec(&regXmlStart, aLine, maxGroup, matchGroup, REG_NOTEOL) && CFILE_PARSER_IS_MATCHGROUP_FUNCTION(matchGroup))
{
tempFunctionType = CFUNCTION_TYPE_REGULAR;
printf("[ mls]");
++mlFlag;
++cfile_parser_functionLine;
}
else if (0 == regexec(&regXproto, aLine, maxGroup, matchGroup, REG_NOTEOL) && matchGroup[2].rm_so < matchGroup[2].rm_eo)
else if (0 == regexec(&regXproto, aLine, maxGroup, matchGroup, REG_NOTEOL) && CFILE_PARSER_IS_MATCHGROUP_FUNCTION(matchGroup))
{
tempFunctionType = CFUNCTION_TYPE_PROTO;
printf("[prot]");
}
else if (0 == regexec(&regX, aLine, maxGroup, matchGroup, REG_NOTEOL) && matchGroup[2].rm_so < matchGroup[2].rm_eo)
else if (0 == regexec(&regX, aLine, maxGroup, matchGroup, REG_NOTEOL) && CFILE_PARSER_IS_MATCHGROUP_FUNCTION(matchGroup))
{
tempFunctionType = CFUNCTION_TYPE_UNDEF;
printf("[ fuX]");
}
else
{
return;
return NULL;
}
for (i = 0; i < maxGroup && 0 <= matchGroup[i].rm_so; ++i)
#if (0)
{
if (matchGroup[i].rm_so < matchGroup[i].rm_eo)
uint8_t i = 0;
char *tempChar = NULL;
char match[1024] =
{ 0};
for (i = 0; i < maxGroup && 0 <= matchGroup[i].rm_so; ++i)
{
if (0 < i)
if (matchGroup[i].rm_so < matchGroup[i].rm_eo)
{
if (0 < i)
printf(" ");
printf("[%02d](%.3ld - %.3ld)[%03d]: ", i, matchGroup[i].rm_so, matchGroup[i].rm_eo, (int) (matchGroup[i].rm_eo - matchGroup[i].rm_so));
printf("%.*s", (int) (matchGroup[i].rm_eo - matchGroup[i].rm_so), &aLine[matchGroup[i].rm_so]);
strlcpy(match, &aLine[matchGroup[i].rm_so], (size_t) (matchGroup[i].rm_eo - matchGroup[i].rm_so + 1));
printf("\n");
printf("[%02d](%.3ld - %.3ld)[%03d]: ", i, matchGroup[i].rm_so, matchGroup[i].rm_eo, (int) (matchGroup[i].rm_eo - matchGroup[i].rm_so));
//printf("%.*s", (int) (matchGroup[i].rm_eo - matchGroup[i].rm_so), &aLine[matchGroup[i].rm_so]);
strlcpy(match, &aLine[matchGroup[i].rm_so], (size_t) (matchGroup[i].rm_eo - matchGroup[i].rm_so + 1));
tempChar = strstr(match, "//");
if (NULL != tempChar)
{
*tempChar = '\0';
}
printf("%s", match);
printf("\n");
}
}
}
#endif
switch (cfile_parser_functionLine)
{
case 0: // single line function definition
case 1: // first line of multi line function definition
{
cfile_parser_function = cfunction_newFunction();
cfile_parser_function->type = tempFunctionType;
break;
}
default: // further lines
{
// TODO process parameter
if (functionEnd)
{
// TODO clean function
if (CFUNCTION_TYPE_UNDEF == tempFunctionType)
{
cfunction_freeFunction(&cfile_parser_function);
}
else
{
cfile_parser_function->type = tempFunctionType;
}
cfile_parser_functionLine = 0;
}
break;
}
}
// return evaluated function
if (0 == cfile_parser_functionLine)
{
cfunction_t *funTemp = cfile_parser_function;
cfile_parser_function = NULL;
return funTemp;
}
return NULL;
}
int8_t cfile_parser(char *aPath, cfunction_list_t *aList)
@@ -315,7 +380,12 @@ int8_t cfile_parser(char *aPath, cfunction_list_t *aList)
charRead = getline(&fileLine, &lineSize, fdesc);
if (0 <= charRead)
{
(void) cfile_parser_evaluateLine(fileLine);
cfunction_t *function = NULL;
function = cfile_parser_evaluateLine(fileLine);
if (NULL != function)
{
(void) cfunction_addFunction(aList, function);
}
}
} while (0 <= charRead);