Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit26945d4

Browse files
committed
Enhanced flexibility in generating output
All files have initial information comment block
1 parentc07962e commit26945d4

24 files changed

+143
-98
lines changed

‎docs/RELEASES.md‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
1212
- Minor type cast improvements in the sign extension function (\_\_ext_sig\_\_)
1313
- (INFR) Test generation script takes one argument: release/debug to specify particular binary call
1414
- istream handling improved in dbcscanner
15-
- The head information with: coderdbc version, dbc file name, generation date added ([issue#28](https://github.com/astand/c-coderdbc/issues/28))
15+
- The head information with: coderdbc version, dbc file name ([issue#28](https://github.com/astand/c-coderdbc/issues/28))
16+
- General source file (not driver related) have only coderdbc version and date if enabled (see next chages)
17+
- The generation date can be added to head information with '-gendate' argument
18+
- The final output directory path is extended by the driver name when '-driverdir' argument is passed
1619

1720
###Fixed
1821
- Head part info conversion to source code comments in mon-generator module

‎src/app.cpp‎

Lines changed: 60 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,36 @@ std::string ExtractFileName(const std::string& fullfilepath)
2828
return filename;
2929
}
3030

31+
/// @brief Combines a directory path and a folder name while handling directory separators
32+
/// @param path The initial directory path
33+
/// @param folderName The folder name to append
34+
/// @return The combined path as a string
35+
std::stringCombinePath(const std::string& path,const std::string& folderName)
36+
{
37+
// check if path ends with '/' or '\\'
38+
bool pathEndsWithSeparator = !path.empty() && (path.back() =='/' || path.back() =='\\');
39+
40+
// check if folderName starts with '/' or '\\'
41+
bool folderStartsWithSeparator = !folderName.empty() && (folderName.front() =='/' || folderName.front() =='\\');
42+
43+
// combine path and folderName based on separators
44+
if (pathEndsWithSeparator && folderStartsWithSeparator)
45+
{
46+
// both have separators, remove one from folderName
47+
return path + folderName.substr(1);
48+
}
49+
elseif (!pathEndsWithSeparator && !folderStartsWithSeparator)
50+
{
51+
// neither has a separator, add one
52+
return path +'/' + folderName;
53+
}
54+
else
55+
{
56+
// exactly one has a separator, just concatenate
57+
return path + folderName;
58+
}
59+
}
60+
3161
voidCoderApp::Run()
3262
{
3363
std::cout <<"coderdbc v" << CODEGEN_LIB_VERSION_MAJ <<"." << CODEGEN_LIB_VERSION_MIN << std::endl << std::endl;
@@ -79,20 +109,31 @@ void CoderApp::GenerateCode()
79109
std::time_t now =std::time(nullptr);
80110
// convert to local time
81111
std::tm* loctime =std::localtime(&now);
82-
// prepare string for source files head part
83-
std::stringstream srcinfo;
84-
srcinfo <<"DBC filename :" << filename <<"\n";
85-
srcinfo <<"Generator version: v" << CODEGEN_LIB_VERSION_MAJ <<"." << CODEGEN_LIB_VERSION_MIN;
112+
// create driver related comment block
113+
std::stringstream driversrcinfo;
114+
driversrcinfo <<"// DBC filename :" << filename <<"\n";
115+
// create common comment block
116+
std::stringstream commonsrcinfo;
117+
commonsrcinfo <<"// Generator version : v" << CODEGEN_LIB_VERSION_MAJ <<"." << CODEGEN_LIB_VERSION_MIN <<"\n";
118+
119+
if (loctime && Params.add_gen_date)
120+
{
121+
// put the date and time inside common comment block
122+
commonsrcinfo <<"// Generation time :" <<std::put_time(loctime,"%Y.%m.%d %H:%M:%S") <<"\n";
123+
}
86124

87-
if (loctime)
125+
std::string finalpath = Params.outdir.first;
126+
127+
if (Params.is_driver_dir)
88128
{
89-
//put thedate and time into source file header
90-
srcinfo << std::endl <<"Generation time :" <<std::put_time(loctime,"%Y.%m.%d %H:%M:%S");
129+
//append thefolder name to the path
130+
finalpath =CombinePath(Params.outdir.first, Params.drvname.first);
91131
}
92132

93133
// create main destination directory
94-
fscreator.Configure(Params.drvname.first, Params.outdir.first,
95-
srcinfo.str(),
134+
fscreator.Configure(Params.drvname.first, finalpath,
135+
commonsrcinfo.str(),
136+
driversrcinfo.str(),
96137
scanner.dblist.ver.hi,
97138
scanner.dblist.ver.low);
98139

@@ -231,20 +272,29 @@ void CoderApp::PrintHelp()
231272
std::cout << std::endl;
232273
std::cout <<"optional parameters:" << std::endl;
233274
std::cout <<" -nodeutils\t will generate specific pairs of binutils drivers for each node" << std::endl;
275+
std::cout << std::endl;
234276
std::cout <<" -rw\t\t by default each new generation with previously used params" << std::endl;
235277
std::cout <<"\t\t will create new sud-directory with source files (000, 001, ... etc)" << std::endl;
236278
std::cout <<"\t\t '-rw' option enables rewriting: all source files previously generated" << std::endl;
237279
std::cout <<"\t\t will be replaced by new ones" << std::endl;
280+
std::cout << std::endl;
238281
std::cout <<" -noconfig:\t no {drivername}-config and dbccodeconfig generation" << std::endl;
239282
std::cout <<" -noinc:\t no canmonitorutil.h generation" << std::endl;
240283
std::cout <<" -nofmon:\t no ***-fmon.c generation" << std::endl;
241284
std::cout << std::endl;
285+
std::cout <<" -driverdir\t the output path (-out) will be appended by driver name" << std::endl;
286+
std::cout <<" -gendate\t the generation date will be included in the header comment section of the source file." <<
287+
std::endl;
288+
std::cout << std::endl;
242289

243290
std::cout <<"examples:" << std::endl;
244291
std::cout << std::endl;
245292

246293
std::cout <<
247-
"./dbccoder -dbc /home/user/docs/driveshaft.dbc -out /home/user/docs/gen/ -drvname drivedb -nodeutils -rw" << std::endl;
294+
"./dbccoder -dbc /home/user/docs/driveshaft.dbc -out /home/user/docs/gen/ -drvname drivedb -nodeutils -rw -driverdir -gendate"
295+
<< std::endl;
296+
std::cout <<"./dbccoder -dbc /home/user/docs/driveshaft.dbc -out /home/user/docs/gen/ -drvname drivedb -nodeutils -rw"
297+
<< std::endl;
248298

249299
std::cout <<
250300
"./dbccoder -dbc /home/user/docs/driveshaft.dbc -out /home/user/docs/gen/ -drvname drivedb -nodeutils" << std::endl;

‎src/codegen/c-main-generator.cpp‎

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -83,14 +83,8 @@ void CiMainGenerator::Generate(DbcMessageList_t& dlist, const AppSettings_t& fsd
8383
voidCiMainGenerator::Gen_MainHeader()
8484
{
8585
std::set<std::string> passed_sigs;
86-
87-
// write comment start text
88-
if (fdesc->gen.start_info.size() >0)
89-
{
90-
// replace all '\n' on "\n //" for c code comment text
91-
fwriter.Append("//" +std::regex_replace(fdesc->gen.start_info,std::regex("\n"),"\n//"));
92-
}
93-
86+
fwriter.AppendText(fdesc->gen.start_common_info);
87+
fwriter.AppendText(fdesc->gen.start_driver_info);
9488
fwriter.Append("#pragma once");
9589
fwriter.Append();
9690
fwriter.Append("#ifdef __cplusplus\nextern\"C\" {\n#endif");
@@ -336,12 +330,9 @@ void CiMainGenerator::Gen_MainHeader()
336330

337331
voidCiMainGenerator::Gen_MainSource()
338332
{
339-
if (fdesc->gen.start_info.size() >0)
340-
{
341-
// replace all '\n' on "\n //" for c code comment text
342-
fwriter.Append("//" +std::regex_replace(fdesc->gen.start_info,std::regex("\n"),"\n//"));
343-
}
344333

334+
fwriter.AppendText(fdesc->gen.start_common_info);
335+
fwriter.AppendText(fdesc->gen.start_driver_info);
345336
// include main header file
346337
fwriter.Append("#include\"%s\"", fdesc->file.core_h.fname.c_str());
347338
fwriter.Append(2);
@@ -443,11 +434,8 @@ void CiMainGenerator::Gen_MainSource()
443434

444435
voidCiMainGenerator::Gen_ConfigHeader()
445436
{
446-
if (fdesc->gen.start_info.size() >0)
447-
{
448-
// replace all '\n' on "\n //" for c code comment text
449-
fwriter.Append("//" +std::regex_replace(fdesc->gen.start_info,std::regex("\n"),"\n//"));
450-
}
437+
fwriter.AppendText(fdesc->gen.start_common_info);
438+
fwriter.AppendText(fdesc->gen.start_driver_info);
451439

452440
ConfigGenerator confgen;
453441
confgen.FillHeader(fwriter, fdesc->gen);
@@ -471,6 +459,7 @@ void CiMainGenerator::Gen_FMonSource()
471459

472460
voidCiMainGenerator::Gen_CanMonUtil()
473461
{
462+
fwriter.AppendText(fdesc->gen.start_common_info);
474463
fwriter.Append("#pragma once");
475464
fwriter.Append("");
476465
fwriter.Append("#include <stdint.h>");
@@ -530,6 +519,7 @@ void CiMainGenerator::Gen_CanMonUtil()
530519

531520
voidCiMainGenerator::Gen_DbcCodeConf()
532521
{
522+
fwriter.AppendText(fdesc->gen.start_common_info);
533523
fwriter.Append("#pragma once");
534524
fwriter.Append("");
535525
fwriter.Append("#include <stdint.h>");

‎src/codegen/c-util-generator.cpp‎

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -101,12 +101,8 @@ void CiUtilGenerator::Generate(DbcMessageList_t& dlist, const AppSettings_t& fsd
101101
voidCiUtilGenerator::PrintHeader()
102102
{
103103
tof.Flush();
104-
105-
if (gdesc->start_info.size() >0)
106-
{
107-
tof.Append("//" +std::regex_replace(gdesc->start_info,std::regex("\n"),"\n//"));
108-
}
109-
104+
tof.AppendText(gdesc->start_common_info);
105+
tof.AppendText(gdesc->start_driver_info);
110106
tof.Append("#pragma once");
111107
tof.Append();
112108

@@ -197,10 +193,8 @@ void CiUtilGenerator::PrintHeader()
197193

198194
voidCiUtilGenerator::PrintSource()
199195
{
200-
if (gdesc->start_info.size() >0)
201-
{
202-
tof.Append("//" +std::regex_replace(gdesc->start_info,std::regex("\n"),"\n//"));
203-
}
196+
tof.AppendText(gdesc->start_common_info);
197+
tof.AppendText(gdesc->start_driver_info);
204198

205199
tof.Append("#include\"%s\"", fdesc->util_h.fname.c_str());
206200
tof.Append();

‎src/codegen/fs-creator.cpp‎

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,19 @@ FsCreator::FsCreator()
1818
}
1919

2020

21-
voidFsCreator::Configure(const std::string& drvname,const std::string& outpath,
22-
const std::string& info,uint32_t h,uint32_t l)
21+
voidFsCreator::Configure(const std::string& drvname,
22+
const std::string& outpath,
23+
const std::string& commoninfo,
24+
const std::string& driverinfo,
25+
uint32_t highVer,
26+
uint32_t lowVer)
2327
{
2428
FS.file.libdir = outpath +kLibDir;
2529
FS.file.usrdir = outpath +kUsrDir;
2630
FS.file.incdir = outpath +kIncDir;
2731
FS.file.confdir = outpath +kConfDir;
2832
FS.file.utildir = outpath +kUtilDir;
29-
// directory valid and exists, set all the values
33+
// directory valid and exists, set all the values
3034
FS.gen.DrvName_orig = drvname;
3135
FS.gen.DRVNAME =str_toupper(drvname);
3236
FS.gen.drvname =str_tolower(drvname);
@@ -83,9 +87,10 @@ void FsCreator::Configure(const std::string& drvname, const std::string& outpath
8387
FS.gen.verlow_def = _tmpb;
8488

8589
// load start info to fdescriptor
86-
FS.gen.start_info = info;
87-
FS.gen.hiver = h;
88-
FS.gen.lowver = l;
90+
FS.gen.start_driver_info = driverinfo;
91+
FS.gen.start_common_info = commoninfo;
92+
FS.gen.hiver = highVer;
93+
FS.gen.lowver = lowVer;
8994
}
9095

9196
boolFsCreator::PrepareDirectory(bool rw)

‎src/codegen/fs-creator.h‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,10 @@ typedef struct
4343
std::string verhigh_def;
4444
std::string verlow_def;
4545

46-
// inforamtion to be placed at the start of each source file
47-
std::string start_info;
46+
// text comment to be placed at the beggining of the driver's related source files
47+
std::string start_driver_info;
48+
// text comment to be placed at the beggining of each source files
49+
std::string start_common_info;
4850

4951
uint32_t hiver{0};
5052
uint32_t lowver{0};
@@ -69,7 +71,12 @@ class FsCreator {
6971
public:
7072
FsCreator();
7173

72-
voidConfigure(const std::string& drvname,const std::string& outpath,const std::string& info,uint32_t h,uint32_t l);
74+
voidConfigure(const std::string& drvname,
75+
const std::string& outpath,
76+
const std::string& commoninfo,
77+
const std::string& driverinfo,
78+
uint32_t highVer,
79+
uint32_t lowVer);
7380
boolPrepareDirectory(bool rw);
7481

7582
std::stringCreateSubDir(std::string basepath, std::string subdir,bool rm =true);

‎src/codegen/mon-generator.cpp‎

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,8 @@
66
uint32_tMonGenerator::FillHeader(FileWriter& wr, std::vector<CiExpr_t*>& sigs,
77
const AppSettings_t& aset)
88
{
9-
if (aset.gen.start_info.size() >0)
10-
{
11-
// replace all '\n' on "\n //" for c code comment text
12-
wr.Append("//" +std::regex_replace(aset.gen.start_info,std::regex("\n"),"\n//"));
13-
}
14-
9+
wr.AppendText(aset.gen.start_common_info);
10+
wr.AppendText(aset.gen.start_driver_info);
1511
wr.Append("#pragma once");
1612
wr.Append();
1713

@@ -89,11 +85,8 @@ separated .c file. If it won't be done the linkage error will happen\n*/");
8985
uint32_tMonGenerator::FillSource(FileWriter& wr, std::vector<CiExpr_t*>& sigs,
9086
const AppSettings_t& aset)
9187
{
92-
if (aset.gen.start_info.size() >0)
93-
{
94-
wr.Append("//" +std::regex_replace(aset.gen.start_info,std::regex("\n"),"\n//"));
95-
}
96-
88+
wr.AppendText(aset.gen.start_common_info);
89+
wr.AppendText(aset.gen.start_driver_info);
9790
wr.Append("#include\"%s\"", aset.file.fmon_h.fname.c_str());
9891
wr.Append();
9992
// put diagmonitor ifdef selection for including @drv-fmon header

‎src/options-parser.cpp‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,14 @@ OptionsParser::GenOptions OptionsParser::GetOptions(int argc, char** argv)
7878
{
7979
retpairs.is_nofmon =true;
8080
}
81+
elseif (temppairs[i].first.compare("-driverdir") ==0)
82+
{
83+
retpairs.is_driver_dir =true;
84+
}
85+
elseif (temppairs[i].first.compare("-gendate") ==0)
86+
{
87+
retpairs.add_gen_date =true;
88+
}
8189
}
8290

8391
return retpairs;

‎src/options-parser.h‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ class OptionsParser {
2828
/// @brief rewrite previously generated files or generate to next subdirectory
2929
bool is_rewrite{false};
3030

31+
/// @brief add additional directory named as dbc driver inside generation output directory
32+
bool is_driver_dir{false};
33+
34+
/// @brief add generation date at the beggining of the source file
35+
bool add_gen_date{false};
36+
3137
/// @brief generate specific utility drivers for each ECU defined in the matrix
3238
bool is_nodeutils{false};
3339

‎test/gencode/butl/bcm_testdb-binutil.c‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
// DBC filename : testdb.dbc
2-
// Generator version: v3.1
3-
// Generation time : 2024.06.30 12:22:02
1+
// Generator version : v3.1
2+
// DBC filename : testdb.dbc
43
#include"bcm_testdb-binutil.h"
54

65
// DBC file version

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp