- WIP creating user header and including it stub.c
- todo: write stubs even when there are warnings for some lines
This commit is contained in:
@@ -16,6 +16,7 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
#include <regex.h>
|
#include <regex.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
#include "xtypes.h"
|
#include "xtypes.h"
|
||||||
#include "xstring.h"
|
#include "xstring.h"
|
||||||
#include "xmalloc.h"
|
#include "xmalloc.h"
|
||||||
@@ -194,6 +195,53 @@ STATIC int8_t createStubFunctionBlock(FILE *aFile, FILE *aHeader, cfunction_t *a
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Check if file exists using stat
|
||||||
|
* @param [in] *filename Path to file
|
||||||
|
* @retval 0 file does not exist
|
||||||
|
* @retval 1 file exists
|
||||||
|
*/
|
||||||
|
int file_exist(const char *filename)
|
||||||
|
{
|
||||||
|
struct stat buffer;
|
||||||
|
return (stat(filename, &buffer) == 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
STATIC void createUserHeader(char *aOutput, char *aNoSuffix)
|
||||||
|
{
|
||||||
|
FILE *cheader;
|
||||||
|
char *cHeaderName = NULL;
|
||||||
|
xmallocStrlcpy(&cHeaderName, aOutput, strlen(aOutput));
|
||||||
|
xmallocStrlcat(&cHeaderName, "_user.h", 8);
|
||||||
|
|
||||||
|
if (file_exist(cHeaderName))
|
||||||
|
{
|
||||||
|
free(cHeaderName);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// user header doesn't exist
|
||||||
|
cheader = fopen(cHeaderName, "w");
|
||||||
|
if (NULL == cheader)
|
||||||
|
{
|
||||||
|
free(cHeaderName);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
fprintf(cheader, "/* @file %s"NEWLINES, gnu_basename(cHeaderName));
|
||||||
|
fprintf(cheader, " * @details"NEWLINES" * This is a user defined stub header.\\n"NEWLINES);
|
||||||
|
fprintf(cheader, " * Define subject header needed for compilation of stub (e.g. typedefs, structures, ...).\\n"NEWLINES);
|
||||||
|
fprintf(cheader, " * - generated by stubser -"NEWLINES" */" NEWLINES NEWLINES);
|
||||||
|
|
||||||
|
fprintf(cheader, "#ifndef _STUB_%s_USER_H"NEWLINES, aNoSuffix);
|
||||||
|
fprintf(cheader, "#define _STUB_%s_USER_H"NEWLINES NEWLINES, aNoSuffix);
|
||||||
|
|
||||||
|
fprintf(cheader, NEWLINES"#endif // _STUB_%s_USER_H"NEWLINES, aNoSuffix);
|
||||||
|
|
||||||
|
free(cHeaderName);
|
||||||
|
fclose(cheader);
|
||||||
|
}
|
||||||
|
|
||||||
STATIC int8_t createStub(char *aOutput, char *aNoSuffix, cfile_t *aCfile)
|
STATIC int8_t createStub(char *aOutput, char *aNoSuffix, cfile_t *aCfile)
|
||||||
{
|
{
|
||||||
FILE *cfile;
|
FILE *cfile;
|
||||||
@@ -231,12 +279,15 @@ STATIC int8_t createStub(char *aOutput, char *aNoSuffix, cfile_t *aCfile)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
createUserHeader(aOutput, aNoSuffix);
|
||||||
|
|
||||||
fprintf(cfile, "/* @file %s"NEWLINES, gnu_basename(cFileName));
|
fprintf(cfile, "/* @file %s"NEWLINES, gnu_basename(cFileName));
|
||||||
fprintf(cfile, " * @details"NEWLINES" * This is a stub for CUnit.\\n"NEWLINES);
|
fprintf(cfile, " * @details"NEWLINES" * This is a stub for CUnit.\\n"NEWLINES);
|
||||||
fprintf(cfile, " * - generated by stubser -"NEWLINES" */" NEWLINES NEWLINES);
|
fprintf(cfile, " * - generated by stubser -"NEWLINES" */" NEWLINES NEWLINES);
|
||||||
fprintf(cfile, "#include <CUnit/CUnit.h>"NEWLINES);
|
fprintf(cfile, "#include <CUnit/CUnit.h>"NEWLINES);
|
||||||
fprintf(cfile, "#include \"xtypes.h\""NEWLINES);
|
fprintf(cfile, "#include \"xtypes.h\""NEWLINES);
|
||||||
fprintf(cfile, "#include \"stub.h\""NEWLINES);
|
fprintf(cfile, "#include \"stub.h\""NEWLINES);
|
||||||
|
fprintf(cfile, "#include \"stub_%s_user.h\""NEWLINES, aNoSuffix);
|
||||||
fprintf(cfile, "#include \"%s\""NEWLINES NEWLINES, gnu_basename(cHeaderName));
|
fprintf(cfile, "#include \"%s\""NEWLINES NEWLINES, gnu_basename(cHeaderName));
|
||||||
|
|
||||||
fprintf(cheader, "/* @file %s"NEWLINES, gnu_basename(cHeaderName));
|
fprintf(cheader, "/* @file %s"NEWLINES, gnu_basename(cHeaderName));
|
||||||
|
Reference in New Issue
Block a user