@@ -28,6 +28,36 @@ std::string ExtractFileName(const std::string& fullfilepath)
2828return 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+ else if (!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+
3161void CoderApp::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;