- WIP also creating stub header (include guards missing)
This commit is contained in:
@@ -17,6 +17,7 @@
|
|||||||
#include <regex.h>
|
#include <regex.h>
|
||||||
#include "xtypes.h"
|
#include "xtypes.h"
|
||||||
#include "xstring.h"
|
#include "xstring.h"
|
||||||
|
#include "xmalloc.h"
|
||||||
#include "cfunction_if.h"
|
#include "cfunction_if.h"
|
||||||
#include "cfile_parser_if.h"
|
#include "cfile_parser_if.h"
|
||||||
#include "stubser_if.h"
|
#include "stubser_if.h"
|
||||||
@@ -34,12 +35,12 @@ STATIC bool isDatatypeVoid(char *aType)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
STATIC int8_t createStubFunctionBlock(FILE *aFile, cfunction_t *aFunction)
|
STATIC int8_t createStubFunctionBlock(FILE *aFile, FILE *aHeader, cfunction_t *aFunction)
|
||||||
{
|
{
|
||||||
cfunction_parameter_t *parameter = NULL;
|
cfunction_parameter_t *parameter = NULL;
|
||||||
char parameterIndex = 'a';
|
char parameterIndex = 'a';
|
||||||
|
|
||||||
if (NULL == aFile || NULL == aFunction)
|
if (NULL == aFile || NULL == aHeader || NULL == aFunction)
|
||||||
{
|
{
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@@ -86,6 +87,21 @@ STATIC int8_t createStubFunctionBlock(FILE *aFile, cfunction_t *aFunction)
|
|||||||
aFunction->name);
|
aFunction->name);
|
||||||
NEWLINE(aFile);
|
NEWLINE(aFile);
|
||||||
|
|
||||||
|
// stub function init header
|
||||||
|
fprintf(aHeader, "void init_%s(uint8_t "STUBINIT_PARAM_INSTANCE_S", uint8_t "STUBINIT_PARAM_CALLTEST_S, aFunction->name);
|
||||||
|
if (!isDatatypeVoid(aFunction->dataType))
|
||||||
|
{
|
||||||
|
fprintf(aHeader, ", %s "STUBINIT_PARAM_RETURN_S, aFunction->dataType);
|
||||||
|
}
|
||||||
|
parameter = aFunction->parameter.head;
|
||||||
|
parameterIndex = 'a';
|
||||||
|
while (parameter)
|
||||||
|
{
|
||||||
|
fprintf(aHeader, ", %s "STUBINIT_PARAM_PARAMETER_S1, NCHECK(parameter->type), parameterIndex++);
|
||||||
|
parameter = parameter->next;
|
||||||
|
}
|
||||||
|
fprintf(aHeader, ");" NEWLINES);
|
||||||
|
|
||||||
// stub function init
|
// stub function init
|
||||||
fprintf(aFile, "void init_%s(uint8_t "STUBINIT_PARAM_INSTANCE_S", uint8_t "STUBINIT_PARAM_CALLTEST_S, aFunction->name);
|
fprintf(aFile, "void init_%s(uint8_t "STUBINIT_PARAM_INSTANCE_S", uint8_t "STUBINIT_PARAM_CALLTEST_S, aFunction->name);
|
||||||
if (!isDatatypeVoid(aFunction->dataType))
|
if (!isDatatypeVoid(aFunction->dataType))
|
||||||
@@ -108,7 +124,8 @@ STATIC int8_t createStubFunctionBlock(FILE *aFile, cfunction_t *aFunction)
|
|||||||
fprintf(aFile, "\t"STUBINSTANCE_S1" = 0;" NEWLINES, aFunction->name);
|
fprintf(aFile, "\t"STUBINSTANCE_S1" = 0;" NEWLINES, aFunction->name);
|
||||||
if (!isDatatypeVoid(aFunction->dataType))
|
if (!isDatatypeVoid(aFunction->dataType))
|
||||||
{
|
{
|
||||||
fprintf(aFile, "\t"STUBPARAMETER_STRUCT_S1"["STUBINIT_PARAM_INSTANCE_S"]."STUBPARAMETER_RETURN_S" = "STUBINIT_PARAM_RETURN_S";" NEWLINES, aFunction->name);
|
fprintf(aFile, "\t"STUBPARAMETER_STRUCT_S1"["STUBINIT_PARAM_INSTANCE_S"]."STUBPARAMETER_RETURN_S" = "STUBINIT_PARAM_RETURN_S";" NEWLINES,
|
||||||
|
aFunction->name);
|
||||||
}
|
}
|
||||||
parameter = aFunction->parameter.head;
|
parameter = aFunction->parameter.head;
|
||||||
parameterIndex = 'a';
|
parameterIndex = 'a';
|
||||||
@@ -177,7 +194,10 @@ STATIC int8_t createStubFunctionBlock(FILE *aFile, cfunction_t *aFunction)
|
|||||||
|
|
||||||
STATIC int8_t createStub(char *aOutput, cfunction_list_t *aFunctionList)
|
STATIC int8_t createStub(char *aOutput, cfunction_list_t *aFunctionList)
|
||||||
{
|
{
|
||||||
FILE *fdesc;
|
FILE *cfile;
|
||||||
|
FILE *cheader;
|
||||||
|
char *cFileName = NULL;
|
||||||
|
char *cHeaderName = NULL;
|
||||||
cfunction_t *function = NULL;
|
cfunction_t *function = NULL;
|
||||||
|
|
||||||
if (NULL == aOutput || NULL == aFunctionList)
|
if (NULL == aOutput || NULL == aFunctionList)
|
||||||
@@ -185,25 +205,48 @@ STATIC int8_t createStub(char *aOutput, cfunction_list_t *aFunctionList)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
fdesc = fopen(aOutput, "w");
|
xmallocStrlcpy(&cFileName, aOutput, strlen(aOutput));
|
||||||
if (NULL == fdesc)
|
xmallocStrlcat(&cFileName, ".c", 2);
|
||||||
|
xmallocStrlcpy(&cHeaderName, aOutput, strlen(aOutput));
|
||||||
|
xmallocStrlcat(&cHeaderName, ".h", 2);
|
||||||
|
|
||||||
|
cfile = fopen(cFileName, "w");
|
||||||
|
if (NULL == cfile)
|
||||||
{
|
{
|
||||||
|
free(cFileName);
|
||||||
perror("Error open file");
|
perror("Error open file");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
fprintf(fdesc, "/* @file %s"NEWLINES, gnu_basename(aOutput));
|
cheader = fopen(cHeaderName, "w");
|
||||||
fprintf(fdesc, " * @details"NEWLINES" * This is a stub for CUnit.\\n"NEWLINES);
|
if (NULL == cfile)
|
||||||
fprintf(fdesc, " * - generated by stubser -"NEWLINES" */" NEWLINES NEWLINES);
|
{
|
||||||
|
free(cFileName);
|
||||||
|
free(cHeaderName);
|
||||||
|
fclose(cfile);
|
||||||
|
perror("Error open file");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
fprintf(cfile, "/* @file %s"NEWLINES, gnu_basename(cFileName));
|
||||||
|
fprintf(cfile, " * @details"NEWLINES" * This is a stub for CUnit.\\n"NEWLINES);
|
||||||
|
fprintf(cfile, " * - generated by stubser -"NEWLINES" */" NEWLINES NEWLINES);
|
||||||
|
|
||||||
|
fprintf(cheader, "/* @file %s"NEWLINES, gnu_basename(cHeaderName));
|
||||||
|
fprintf(cheader, " * @details"NEWLINES" * This is a stub header for CUnit.\\n"NEWLINES);
|
||||||
|
fprintf(cheader, " * - generated by stubser -"NEWLINES" */" NEWLINES NEWLINES);
|
||||||
|
|
||||||
function = aFunctionList->head;
|
function = aFunctionList->head;
|
||||||
while (function)
|
while (function)
|
||||||
{
|
{
|
||||||
(void) createStubFunctionBlock(fdesc, function);
|
(void) createStubFunctionBlock(cfile, cheader, function);
|
||||||
function = function->next;
|
function = function->next;
|
||||||
}
|
}
|
||||||
|
|
||||||
fclose(fdesc);
|
free(cFileName);
|
||||||
|
free(cHeaderName);
|
||||||
|
fclose(cfile);
|
||||||
|
fclose(cheader);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -231,7 +274,7 @@ int stubser_createStub(char *path, char *aOutput)
|
|||||||
}
|
}
|
||||||
printf(STUB_CONSOLE_PARSE_OK_S1, gnu_basename(path));
|
printf(STUB_CONSOLE_PARSE_OK_S1, gnu_basename(path));
|
||||||
|
|
||||||
sprintf(fileName, "%s/%s_stub.c", aOutput, strtok(gnu_basename(path), ".")); // todo only cut suffix (last ".")
|
sprintf(fileName, "%s/stub_%s", aOutput, strtok(gnu_basename(path), ".")); // todo only cut suffix (last ".")
|
||||||
ret = createStub(fileName, &functionList);
|
ret = createStub(fileName, &functionList);
|
||||||
if (0 != ret)
|
if (0 != ret)
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user