- new directory traversal method

- using debug output from debug.h
This commit is contained in:
2017-03-06 12:43:23 +00:00
parent 07aef603ff
commit 28fb99e4b6
7 changed files with 335 additions and 87 deletions

View File

@@ -33,6 +33,9 @@
<option id="gnu.c.compiler.option.include.paths.1914441723" name="Include paths (-I)" superClass="gnu.c.compiler.option.include.paths" useByScannerDiscovery="false" valueType="includePath"> <option id="gnu.c.compiler.option.include.paths.1914441723" name="Include paths (-I)" superClass="gnu.c.compiler.option.include.paths" useByScannerDiscovery="false" valueType="includePath">
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/src/ext}&quot;"/> <listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/src/ext}&quot;"/>
</option> </option>
<option id="gnu.c.compiler.option.preprocessor.def.symbols.2046516674" name="Defined symbols (-D)" superClass="gnu.c.compiler.option.preprocessor.def.symbols" useByScannerDiscovery="false" valueType="definedSymbols">
<listOptionValue builtIn="false" value="_DEBUG_OUTPUT=1"/>
</option>
<inputType id="cdt.managedbuild.tool.gnu.c.compiler.input.cygwin.1850965" superClass="cdt.managedbuild.tool.gnu.c.compiler.input.cygwin"/> <inputType id="cdt.managedbuild.tool.gnu.c.compiler.input.cygwin.1850965" superClass="cdt.managedbuild.tool.gnu.c.compiler.input.cygwin"/>
</tool> </tool>
<tool id="cdt.managedbuild.tool.gnu.c.linker.cygwin.exe.debug.1913673353" name="Cygwin C Linker" superClass="cdt.managedbuild.tool.gnu.c.linker.cygwin.exe.debug"> <tool id="cdt.managedbuild.tool.gnu.c.linker.cygwin.exe.debug.1913673353" name="Cygwin C Linker" superClass="cdt.managedbuild.tool.gnu.c.linker.cygwin.exe.debug">
@@ -80,6 +83,9 @@
<tool id="cdt.managedbuild.tool.gnu.c.compiler.cygwin.exe.release.1463094971" name="Cygwin C Compiler" superClass="cdt.managedbuild.tool.gnu.c.compiler.cygwin.exe.release"> <tool id="cdt.managedbuild.tool.gnu.c.compiler.cygwin.exe.release.1463094971" name="Cygwin C Compiler" superClass="cdt.managedbuild.tool.gnu.c.compiler.cygwin.exe.release">
<option defaultValue="gnu.c.optimization.level.most" id="gnu.c.compiler.cygwin.exe.release.option.optimization.level.1258615624" name="Optimization Level" superClass="gnu.c.compiler.cygwin.exe.release.option.optimization.level" useByScannerDiscovery="false" valueType="enumerated"/> <option defaultValue="gnu.c.optimization.level.most" id="gnu.c.compiler.cygwin.exe.release.option.optimization.level.1258615624" name="Optimization Level" superClass="gnu.c.compiler.cygwin.exe.release.option.optimization.level" useByScannerDiscovery="false" valueType="enumerated"/>
<option id="gnu.c.compiler.cygwin.exe.release.option.debugging.level.929161689" name="Debug Level" superClass="gnu.c.compiler.cygwin.exe.release.option.debugging.level" useByScannerDiscovery="false" value="gnu.c.debugging.level.none" valueType="enumerated"/> <option id="gnu.c.compiler.cygwin.exe.release.option.debugging.level.929161689" name="Debug Level" superClass="gnu.c.compiler.cygwin.exe.release.option.debugging.level" useByScannerDiscovery="false" value="gnu.c.debugging.level.none" valueType="enumerated"/>
<option id="gnu.c.compiler.option.include.paths.816204774" superClass="gnu.c.compiler.option.include.paths" valueType="includePath">
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/src/ext}&quot;"/>
</option>
<inputType id="cdt.managedbuild.tool.gnu.c.compiler.input.cygwin.257656751" superClass="cdt.managedbuild.tool.gnu.c.compiler.input.cygwin"/> <inputType id="cdt.managedbuild.tool.gnu.c.compiler.input.cygwin.257656751" superClass="cdt.managedbuild.tool.gnu.c.compiler.input.cygwin"/>
</tool> </tool>
<tool id="cdt.managedbuild.tool.gnu.c.linker.cygwin.exe.release.1085070010" name="Cygwin C Linker" superClass="cdt.managedbuild.tool.gnu.c.linker.cygwin.exe.release"> <tool id="cdt.managedbuild.tool.gnu.c.linker.cygwin.exe.release.1085070010" name="Cygwin C Linker" superClass="cdt.managedbuild.tool.gnu.c.linker.cygwin.exe.release">

107
src/ext/debug.h Normal file
View File

@@ -0,0 +1,107 @@
/*
--------------------------------------------------------------------
Project : Systemsoftware MiCOM 30
Subsystem :
Modul :
--------------------------------------------------------------------
Creation date : 03.02.2012
Last change :
Version : under clearcase version control
Author : Seliger
Prog. Language : GNU-C
------------------------------------------------------------------
Description:
Some stuff to control debug messages
Definition _DEBUG_OUTPUT must be set for compilation
Activate debug messages with command line option -v
-v = DEBUG_LEVEL_INFO
-vv = DEBUG_LEVEL_WARNING
-vvv = DEBUG_LEVEL_ERROR
--------------------------------------------------------------------
*/
/*
--------------------------------------------------------------------
Change log:
Seliger First version
10.01.2012
--------------------------------------------------------------------
*/
#ifndef _DEBUG_H_INCLUDED
#define _DEBUG_H_INCLUDED
#include <stdio.h>
#include <string.h>
#define isDebugLevel(dflag) (_DEBUG_OUTPUT >= dflag)
/*!
* @brief extract only filename from __FILE__ without base path
*/
#define _DEBUG_FILENAME (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : strrchr(__FILE__, '\\') ? strrchr(__FILE__, '\\') + 1 : __FILE__)
/*!
* @brief Debug assert helper macro
* @param cond condition for output
* @param dflag eDebugLevel required to print output
* @param format format same as for printf
* @param args arguments for printf
*
* Condition as string is appended to the output.\n
* e.g. DEBUG_LOG_ASSERT(i >= 1, DEBUG_LEVEL_INFO, "Not allowed");\n
* New line must be appended manually
*/
#ifdef _DEBUG_OUTPUT
#define DEBUG_LOG_ASSERT(cond, dflag, format, args...) do { if(isDebugLevel(dflag) && (cond)) \
printf("%s:%d:%s():(" #cond "): " format, \
_DEBUG_FILENAME, __LINE__, __func__, ##args); } \
while (0)
#else
#define DEBUG_LOG_ASSERT(cond, dflag, format, args...) do{/* nothing */}while(0)
#endif
/*!
* @brief Debug output helper macro
* @param dflag eDebugLevel required to print output
* @param format format same as for printf
* @param args arguments for printf
*
* New line must be appended manually
*/
#ifdef _DEBUG_OUTPUT
#define DEBUG_LOG(dflag, format, args...) do { if(isDebugLevel(dflag)) \
printf("%s:%d:%s(): " format, \
_DEBUG_FILENAME, __LINE__, __func__, ##args); } \
while (0)
#else
#define DEBUG_LOG(dflag, format, args...) do{/* nothing */}while(0)
#endif
/*!
* @brief Debug output helper macro to append text without addition information
* @param dflag eDebugLevel required to print output
* @param format format same as for printf
* @param args arguments for printf
*
* New line must be appended manually
*/
#ifdef _DEBUG_OUTPUT
#define DEBUG_LOG_APPEND(dflag, format, args...) do { if(isDebugLevel(dflag)) \
printf(format, ##args); } \
while (0)
#else
#define DEBUG_LOG_APPEND(dflag, format, args...) do{/* nothing */}while(0)
#endif
typedef enum _EDEBUGLEVEL
{
DEBUG_LEVEL_ALWAYS = 0, /* DEBUG_LOGs are visible regardless of DEBUG_LEVEL */
DEBUG_LEVEL_INFO = 1, /* Visible when application started with -v */
DEBUG_LEVEL_WARNING = 2, /* Visible when application started with -vv */
DEBUG_LEVEL_ERROR = 3,
/* Visible when application started with -vvv */
} eDebugLevel;
#endif /* #ifndef _DEBUG_H_INCLUDED */

View File

@@ -12,67 +12,197 @@
*/ */
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <dirent.h> #include <ftw.h>
#include <regex.h> #include <errno.h>
#include "xmalloc.h"
#include "xregex.h"
#include "xtypes.h" #include "xtypes.h"
#include "xstring.h" #include "xstring.h"
#include "stubser/stubser_if.h" #include "stubser/stubser_if.h"
STATIC int one(const struct dirent *unused) /* POSIX.1 says each process has at least 20 file descriptors.
{ * Three of those belong to the standard streams.
return 1; * Here, we use a conservative estimate of 15 available;
} * assuming we use at most two for other uses in this program,
* we should never run into any problems.
/* * Most trees are shallower than that, so it is efficient.
* @brief Scan given folder for .c files * Deeper trees are traversed fine, just a bit slower.
* @param argc amount of command line arguments * (Linux allows typically hundreds to thousands of open files,
* @param **argv array of argments separated by spaces * so you'll probably never see any issues even if you used
* @retval -1 Directory not found or regex compilation error * a much higher value, say a couple of hundred, but
* @retval 0 Direcotry scanned successfully * 15 is a safe, reasonable value.)
* @details
* see printf for usage
*/ */
int main(int argc, char **argv) #ifndef USE_FDS
{ #define USE_FDS 15
struct dirent **eps; #endif
int n;
regex_t regX;
char filePath[256] =
{ 0 };
const char *pattern = "^.*\\.[cC]";
printf("%s %s\n\n", argv[1], argv[2]); #define MAIN_MAX_MATCHGROUP_FILENAME 2
#define MAIN_CFILE_PATTERN "^(.*)\\.+[cC]$"
if (3 != argc) STATIC regex_t main_regXcFile;
STATIC bool main_recurse = false;
STATIC char* main_outputDir = NULL;
/*!
* @brief Using regular expressions to scan for c files, extract filename without suffix and start stub creation
* @details
* @par Parameter
* See gnu libc documentation for details (Data Type: __nftw_func_t).
*/
int evaluateEntry(const char *filepath, const struct stat *info, const int typeflag, struct FTW *pathinfo)
{ {
printf("Usage:\n"); regmatch_t matchGroup[MAIN_MAX_MATCHGROUP_FILENAME];
printf(" %s <Source Dir> <Target Dir>\n", gnu_basename(argv[0])); char* noSuffix = NULL;
return -1; if (!main_recurse && 1 < pathinfo->level)
{
return 0;
}
if (typeflag != FTW_F)
{
return 0;
} }
if (regcomp(&regX, pattern, REG_NEWLINE)) if (0 != regexec(&main_regXcFile, gnu_basename((char*) filepath), MAIN_MAX_MATCHGROUP_FILENAME, matchGroup, 0))
{ {
fprintf(stderr, "bad pattern: '%s'\n", pattern); return 0;
return -1;
} }
n = scandir(argv[1], &eps, one, alphasort); if (XREGEX_IS_MATCHGROUP(matchGroup, 1))
if (n >= 0)
{ {
int cnt; xmallocStrlcpy(&noSuffix, &gnu_basename((char*) filepath)[matchGroup[1].rm_so], XREGEX_SIZEOF_MATCHGROUP(matchGroup, 1));
for (cnt = 0; cnt < n; ++cnt) if (NULL != noSuffix)
{ {
if (0 == regexec(&regX, eps[cnt]->d_name, 0, NULL, 0) // stubser_createStub((char*) filepath, noSuffix, main_outputDir);
&& DT_REG == eps[cnt]->d_type)
{
sprintf(filePath, "%s/%s", argv[1], eps[cnt]->d_name);
printf("%s (%d)\n", filePath, eps[cnt]->d_type);
stubser_createStub(filePath, argv[2]);
} }
free(noSuffix);
} }
}
else
perror("Couldn't open the directory");
return 0; return 0;
} }
/*!
* @brief Scan given directory recursively
*/
int evaluateDirectoryTree(const char * const dirpath)
{
int result;
/* Invalid directory path? */
if (dirpath == NULL || *dirpath == '\0')
return errno = EINVAL;
result = nftw(dirpath, evaluateEntry, USE_FDS, FTW_PHYS);
if (result >= 0)
errno = result;
return errno;
}
void printUsage(char *aAppName)
{
printf("Create stub c-files and c-header from c files for CUnit.\n\n");
printf("Usage:\n");
printf(" %s [options] [source dir] <target dir>\n", aAppName);
printf("\nOptions:\n");
printf(" -r\tSearch source Dir recursively\n");
}
/*!
* @brief Search (optionally recursive) for c file and create stubs
* @param [in] argc Amount of command line arguments
* @param [in] **argv Array of arguments
* @retval EXIT_SUCCESS stubs created successfully
* @retval EXIT_FAILURE error with arguments or input
*/
int main(int argc, char **argv)
{
int i = 0;
int ret = EXIT_FAILURE;
int outputDirIndex = 0;
uint8_t dirs = 0;
if (regcomp(&main_regXcFile, MAIN_CFILE_PATTERN, REG_EXTENDED | REG_NEWLINE))
{
fprintf(stderr, "%s.\n", strerror(errno));
ret = EXIT_FAILURE;
goto l_main_end;
}
if (argc < 2)
{
printUsage(gnu_basename(argv[0]));
ret = EXIT_FAILURE;
goto l_main_end;
}
// evaluate command line parameter
for (i = 1; i < argc && i < 4; ++i)
{
if (NULL != strstr(argv[i], "-r"))
{
main_recurse = true;
}
else
{
outputDirIndex = i;
++dirs;
}
}
if (0 == outputDirIndex)
{
// only options; no output directory provided
printUsage(gnu_basename(argv[0]));
ret = EXIT_FAILURE;
goto l_main_end;
}
if (0 > mkdir(argv[outputDirIndex], S_IRWXU))
{
// output directory not available
if (EEXIST != errno)
{
fprintf(stderr, "%s.\n", strerror(errno));
ret = EXIT_FAILURE;
goto l_main_end;
}
}
xmallocStrlcpy(&main_outputDir, argv[outputDirIndex], strlen(argv[outputDirIndex]) + 1);
if (NULL == main_outputDir)
{
fprintf(stderr, "%s.\n", strerror(errno));
ret = EXIT_FAILURE;
goto l_main_end;
}
if (1 == dirs)
{
// only output provided; input will be "."
if (evaluateDirectoryTree("."))
{
fprintf(stderr, "%s.\n", strerror(errno));
ret = EXIT_FAILURE;
goto l_main_end;
}
}
else
{
// take input directory from arguments
if (evaluateDirectoryTree(argv[outputDirIndex - 1]))
{
fprintf(stderr, "%s.\n", strerror(errno));
ret = EXIT_FAILURE;
goto l_main_end;
}
}
ret = EXIT_SUCCESS;
l_main_end: // label for ending main
free(main_outputDir);
return ret;
}

View File

@@ -19,6 +19,7 @@
#include "xmalloc.h" #include "xmalloc.h"
#include "cfunction_if.h" #include "cfunction_if.h"
#include "cfile_parser_loc.h" #include "cfile_parser_loc.h"
#include "debug.h"
#define CFILE_PARSER_MAX_REGEX_MATCHING_GROUPS 10 #define CFILE_PARSER_MAX_REGEX_MATCHING_GROUPS 10
@@ -107,10 +108,10 @@ STATIC void printMatchGroup(char *aString, regmatch_t *aMatchGroup)
{ {
if (aMatchGroup[i].rm_so < aMatchGroup[i].rm_eo) if (aMatchGroup[i].rm_so < aMatchGroup[i].rm_eo)
{ {
printf("[%02d](%.3ld - %.3ld)[%03d]:", i, aMatchGroup[i].rm_so, aMatchGroup[i].rm_eo, (int) (aMatchGroup[i].rm_eo - aMatchGroup[i].rm_so)); DEBUG_LOG_APPEND(1, "[%02d](%.3ld - %.3ld)[%03d]:", i, aMatchGroup[i].rm_so, aMatchGroup[i].rm_eo, (int) (aMatchGroup[i].rm_eo - aMatchGroup[i].rm_so));
strlcpy(match, &aString[aMatchGroup[i].rm_so], (size_t) (aMatchGroup[i].rm_eo - aMatchGroup[i].rm_so + 1)); strlcpy(match, &aString[aMatchGroup[i].rm_so], (size_t) (aMatchGroup[i].rm_eo - aMatchGroup[i].rm_so + 1));
printf("%s", match); DEBUG_LOG_APPEND(1, "%s", match);
printf("\n"); DEBUG_LOG_APPEND(1, "\n");
} }
} }
} }
@@ -417,18 +418,18 @@ STATIC int8_t removeCcomments(char *aLine)
return cBlockRemoval(aLine, CPARS_COMMENT_BLOCK_START, CPARS_COMMENT_BLOCK_END, &helper, true); return cBlockRemoval(aLine, CPARS_COMMENT_BLOCK_START, CPARS_COMMENT_BLOCK_END, &helper, true);
} }
STATIC int8_t evaluateParameter(char **aParameter, cfunction_t *aFunction) STATIC int8_t evaluateParameter(char *aParameter, cfunction_t *aFunction)
{ {
char *token = NULL; char *token = NULL;
regmatch_t matchGroup[CFILE_PARSER_MAX_REGEX_MATCHING_GROUPS]; regmatch_t matchGroup[CFILE_PARSER_MAX_REGEX_MATCHING_GROUPS];
cfunction_parameter_t *tempParameter = NULL; cfunction_parameter_t *tempParameter = NULL;
if (NULL == aParameter || NULL == *aParameter || NULL == aFunction) if (NULL == aParameter || NULL == aFunction)
{ {
return -1; return -1;
} }
token = strtok(*aParameter, ","); token = strtok(aParameter, ",");
while (token) while (token)
{ {
if (0 == regexec(&regXparameter, token, CFILE_PARSER_MAX_REGEX_MATCHING_GROUPS, matchGroup, 0)) if (0 == regexec(&regXparameter, token, CFILE_PARSER_MAX_REGEX_MATCHING_GROUPS, matchGroup, 0))
@@ -454,8 +455,6 @@ STATIC int8_t evaluateParameter(char **aParameter, cfunction_t *aFunction)
token = strtok(NULL, ","); token = strtok(NULL, ",");
} }
free(*aParameter);
*aParameter = NULL;
return 0; return 0;
} }
@@ -489,21 +488,22 @@ STATIC cfunction_t* cfile_parser_evaluateLine(char *aLine)
if (0 == regexec(&regXmlEnd, aLine, maxGroup, matchGroup, REG_NOTEOL)) if (0 == regexec(&regXmlEnd, aLine, maxGroup, matchGroup, REG_NOTEOL))
{ {
tempFunctionType = CFUNCTION_TYPE_REGULAR; tempFunctionType = CFUNCTION_TYPE_REGULAR;
printf("[ mle]"); DEBUG_LOG_APPEND(1, "[ mle]");
functionEnd = true; functionEnd = true;
} }
else if (0 == regexec(&regXmlProto, aLine, maxGroup, matchGroup, REG_NOTEOL)) else if (0 == regexec(&regXmlProto, aLine, maxGroup, matchGroup, REG_NOTEOL))
{ {
tempFunctionType = CFUNCTION_TYPE_PROTO; tempFunctionType = CFUNCTION_TYPE_PROTO;
printf("[ mlp]"); DEBUG_LOG_APPEND(1, "[ mlp]");
functionEnd = true; functionEnd = true;
} }
else if (0 == regexec(&regXmlPar, aLine, maxGroup, matchGroup, REG_NOTEOL)) else if (0 == regexec(&regXmlPar, aLine, maxGroup, matchGroup, REG_NOTEOL))
{ {
printf("[ ml+]"); DEBUG_LOG_APPEND(1, "[ ml+]");
} }
else else
{ {
DEBUG_LOG_APPEND(1, "[ na ]");
tempFunctionType = CFUNCTION_TYPE_UNDEF; tempFunctionType = CFUNCTION_TYPE_UNDEF;
functionEnd = true; functionEnd = true;
} }
@@ -513,23 +513,23 @@ STATIC cfunction_t* cfile_parser_evaluateLine(char *aLine)
else if (0 == regexec(&regXsl, aLine, maxGroup, matchGroup, REG_NOTEOL) && CFILE_PARSER_IS_MATCHGROUP_FUNCTION(matchGroup)) else if (0 == regexec(&regXsl, aLine, maxGroup, matchGroup, REG_NOTEOL) && CFILE_PARSER_IS_MATCHGROUP_FUNCTION(matchGroup))
{ {
tempFunctionType = CFUNCTION_TYPE_REGULAR; tempFunctionType = CFUNCTION_TYPE_REGULAR;
printf("[ sl ]"); DEBUG_LOG_APPEND(1, "[ sl ]");
} }
else if (0 == regexec(&regXmlStart, aLine, maxGroup, matchGroup, REG_NOTEOL) && CFILE_PARSER_IS_MATCHGROUP_FUNCTION(matchGroup)) else if (0 == regexec(&regXmlStart, aLine, maxGroup, matchGroup, REG_NOTEOL) && CFILE_PARSER_IS_MATCHGROUP_FUNCTION(matchGroup))
{ {
tempFunctionType = CFUNCTION_TYPE_REGULAR; tempFunctionType = CFUNCTION_TYPE_REGULAR;
printf("[ mls]"); DEBUG_LOG_APPEND(1, "[ mls]");
++cfile_parser_functionLine; ++cfile_parser_functionLine;
} }
else if (0 == regexec(&regXproto, aLine, maxGroup, matchGroup, REG_NOTEOL) && CFILE_PARSER_IS_MATCHGROUP_FUNCTION(matchGroup)) else if (0 == regexec(&regXproto, aLine, maxGroup, matchGroup, REG_NOTEOL) && CFILE_PARSER_IS_MATCHGROUP_FUNCTION(matchGroup))
{ {
tempFunctionType = CFUNCTION_TYPE_PROTO; tempFunctionType = CFUNCTION_TYPE_PROTO;
printf("[prot]"); DEBUG_LOG_APPEND(1, "[prot]");
} }
else if (0 == regexec(&regX, aLine, maxGroup, matchGroup, REG_NOTEOL) && CFILE_PARSER_IS_MATCHGROUP_FUNCTION(matchGroup)) else if (0 == regexec(&regX, aLine, maxGroup, matchGroup, REG_NOTEOL) && CFILE_PARSER_IS_MATCHGROUP_FUNCTION(matchGroup))
{ {
tempFunctionType = CFUNCTION_TYPE_UNDEF; tempFunctionType = CFUNCTION_TYPE_UNDEF;
printf("[ fuX]"); DEBUG_LOG_APPEND(1, "[ fuX]");
} }
else else
{ {
@@ -546,11 +546,11 @@ STATIC cfunction_t* cfile_parser_evaluateLine(char *aLine)
if (matchGroup[i].rm_so < matchGroup[i].rm_eo) if (matchGroup[i].rm_so < matchGroup[i].rm_eo)
{ {
if (0 < i) if (0 < i)
printf(" "); DEBUG_LOG_APPEND(1, " ");
printf("[%02d](%.3ld - %.3ld)[%03d]: ", i, matchGroup[i].rm_so, matchGroup[i].rm_eo, (int) (matchGroup[i].rm_eo - matchGroup[i].rm_so)); DEBUG_LOG_APPEND(1, "[%02d](%.3ld - %.3ld)[%03d]: ", i, matchGroup[i].rm_so, matchGroup[i].rm_eo, (int) (matchGroup[i].rm_eo - matchGroup[i].rm_so));
strlcpy(match, &aLine[matchGroup[i].rm_so], (size_t) (matchGroup[i].rm_eo - matchGroup[i].rm_so + 1)); strlcpy(match, &aLine[matchGroup[i].rm_so], (size_t) (matchGroup[i].rm_eo - matchGroup[i].rm_so + 1));
printf("%s", match); DEBUG_LOG_APPEND(1, "%s", match);
printf("\n"); DEBUG_LOG_APPEND(1, "\n");
} }
} }
if (functionEnd) if (functionEnd)
@@ -601,7 +601,9 @@ STATIC cfunction_t* cfile_parser_evaluateLine(char *aLine)
// return evaluated function // return evaluated function
if (0 == cfile_parser_functionLine) if (0 == cfile_parser_functionLine)
{ {
evaluateParameter(&parameterStorage, cfile_parser_function); evaluateParameter(parameterStorage, cfile_parser_function);
free(parameterStorage);
parameterStorage = NULL;
cfunction_t *funTemp = cfile_parser_function; cfunction_t *funTemp = cfile_parser_function;
cfile_parser_function = NULL; cfile_parser_function = NULL;
return funTemp; return funTemp;

View File

@@ -1,16 +1,17 @@
/*! /*!
Name : stubi.c * @file stubser.c
Author : Martin Winkler * @brief Scan a folder for .c files and generate stubs from function definitions
Version : * @attention Using regular expressions to scan c files for function definitions. No 100%
Copyright : * success rate and should be seen as helper. Result must be reviewed manually.
Description : Scan a folder for .c files and generate stubs from function definitions * @details
* Project: stubser\n
@todo complete function dissection * Subsystem: \n
@todo output stub header and function * Module: \n
@attention Using regular expressions to scan c files for function definitions. No 100% * Code: GNU-C\n
success rate and should be seen as helper. Result must be reviewed manually. *
* @date 06.03.2017
* @author SESA354004
*/ */
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <dirent.h> #include <dirent.h>
@@ -22,6 +23,7 @@
#include "cfile_parser_if.h" #include "cfile_parser_if.h"
#include "stubser_if.h" #include "stubser_if.h"
#include "stubser_loc.h" #include "stubser_loc.h"
#include "debug.h"
STATIC bool isDatatypeVoid(char *aType) STATIC bool isDatatypeVoid(char *aType)
{ {
@@ -192,7 +194,7 @@ STATIC int8_t createStubFunctionBlock(FILE *aFile, FILE *aHeader, cfunction_t *a
return 0; return 0;
} }
STATIC int8_t createStub(char *aOutput, cfunction_list_t *aFunctionList) STATIC int8_t createStub(char *aOutput, char *aNoSuffix, cfunction_list_t *aFunctionList)
{ {
FILE *cfile; FILE *cfile;
FILE *cheader; FILE *cheader;
@@ -214,6 +216,7 @@ STATIC int8_t createStub(char *aOutput, cfunction_list_t *aFunctionList)
if (NULL == cfile) if (NULL == cfile)
{ {
free(cFileName); free(cFileName);
free(cHeaderName);
perror("Error open file"); perror("Error open file");
return -1; return -1;
} }
@@ -236,8 +239,8 @@ STATIC int8_t createStub(char *aOutput, cfunction_list_t *aFunctionList)
fprintf(cheader, " * @details"NEWLINES" * This is a stub header for CUnit.\\n"NEWLINES); fprintf(cheader, " * @details"NEWLINES" * This is a stub header for CUnit.\\n"NEWLINES);
fprintf(cheader, " * - generated by stubser -"NEWLINES" */" NEWLINES NEWLINES); fprintf(cheader, " * - generated by stubser -"NEWLINES" */" NEWLINES NEWLINES);
fprintf(cheader, "#ifndef _INCLUDE_%s_H"NEWLINES, strtok(gnu_basename(cHeaderName),".")); fprintf(cheader, "#ifndef _INCLUDE_%s_H"NEWLINES, aNoSuffix);
fprintf(cheader, "#define _INCLUDE_%s_H"NEWLINES NEWLINES, strtok(gnu_basename(cHeaderName),".")); fprintf(cheader, "#define _INCLUDE_%s_H"NEWLINES NEWLINES, aNoSuffix);
function = aFunctionList->head; function = aFunctionList->head;
while (function) while (function)
@@ -246,7 +249,7 @@ STATIC int8_t createStub(char *aOutput, cfunction_list_t *aFunctionList)
function = function->next; function = function->next;
} }
fprintf(cheader, NEWLINES"#endif // _INCLUDE_%s_H"NEWLINES, strtok(gnu_basename(cHeaderName),".")); fprintf(cheader, NEWLINES"#endif // _INCLUDE_%s_H"NEWLINES, aNoSuffix);
free(cFileName); free(cFileName);
free(cHeaderName); free(cHeaderName);
@@ -261,16 +264,16 @@ STATIC int8_t createStub(char *aOutput, cfunction_list_t *aFunctionList)
* @retval 0 matching complete * @retval 0 matching complete
* @retval -1 error opening file * @retval -1 error opening file
*/ */
int stubser_createStub(char *path, char *aOutput) int stubser_createStub(char *path, char* aNoSuffix, char *aOutput)
{ {
int8_t ret = -1; int8_t ret = -1;
cfunction_list_t functionList = cfunction_list_t functionList =
CFUNCTION_LIST_DEFAULT; CFUNCTION_LIST_DEFAULT;
char fileName[512] = char fileName[PATH_MAX] =
{ '\0' }; { '\0' };
ret = cfile_parser(path, &functionList); ret = cfile_parser(path, &functionList);
printf("\n"); // todo remove when output from cfile_parser() is removed DEBUG_LOG_APPEND(1, "\n");
if (0 != ret) if (0 != ret)
{ {
printf(STUB_CONSOLE_PARSE_ERROR_S2, gnu_basename(path), ret); printf(STUB_CONSOLE_PARSE_ERROR_S2, gnu_basename(path), ret);
@@ -279,8 +282,8 @@ 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/stub_%s", aOutput, strtok(gnu_basename(path), ".")); // todo only cut suffix (last ".") sprintf(fileName, "%s/stub_%s", aOutput, aNoSuffix);
ret = createStub(fileName, &functionList); ret = createStub(fileName, aNoSuffix, &functionList);
if (0 != ret) if (0 != ret)
{ {
printf(STUB_CONSOLE_CREATE_ERROR_S2, gnu_basename(path), ret); printf(STUB_CONSOLE_CREATE_ERROR_S2, gnu_basename(path), ret);

View File

@@ -14,6 +14,6 @@
#ifndef STUBSER_STUBSER_IF_H_ #ifndef STUBSER_STUBSER_IF_H_
#define STUBSER_STUBSER_IF_H_ #define STUBSER_STUBSER_IF_H_
int stubser_createStub(char *path, char *aOutput); int stubser_createStub(char *path, char* aNoSuffix, char *aOutput);
#endif /* STUBSER_STUBSER_IF_H_ */ #endif /* STUBSER_STUBSER_IF_H_ */

View File

@@ -42,6 +42,6 @@
#define STUB_CONSOLE_FAIL "[FAIL]" #define STUB_CONSOLE_FAIL "[FAIL]"
#define STUB_CONSOLE_PARSE_ERROR_S2 STUB_CONSOLE_FAIL " %s parsing failed (%d)\n" #define STUB_CONSOLE_PARSE_ERROR_S2 STUB_CONSOLE_FAIL " %s parsing failed (%d)\n"
#define STUB_CONSOLE_PARSE_OK_S1 STUB_CONSOLE_OK " %s parsing..." #define STUB_CONSOLE_PARSE_OK_S1 STUB_CONSOLE_OK " %s parsing..."
#define STUB_CONSOLE_CREATE_ERROR_S2 STUB_CONSOLE_FAIL " %s creation failed (%d)\n" #define STUB_CONSOLE_CREATE_ERROR_S2 "fail\n"STUB_CONSOLE_FAIL " %s creation failed (%d)\n"
#define STUB_CONSOLE_CREATE_OK_S1 "ok > %s\n" #define STUB_CONSOLE_CREATE_OK_S1 "ok > %s\n"
#endif /* STUBSER_STUBSER_LOC_H_ */ #endif /* STUBSER_STUBSER_LOC_H_ */