Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit eca35e0

Browse files
committed
Project became executable (CLI).
1 parent 1d168d9 commit eca35e0

File tree

2 files changed

+101
-5
lines changed

2 files changed

+101
-5
lines changed

src/CMakeLists.txt

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
cmake_minimum_required(VERSION 3.5)
22

3-
project(dbcscanner-lib LANGUAGES CXX)
3+
project(dbccoder-cli LANGUAGES CXX)
44

55
set(CMAKE_INCLUDE_CURRENT_DIR ON)
66
set(CMAKE_AUTOUIC ON)
@@ -9,7 +9,7 @@ set(CMAKE_AUTORCC ON)
99
set(CMAKE_CXX_STANDARD 17)
1010
set(CMAKE_CXX_STANDARD_REQUIRED ON)
1111

12-
add_library(dbcscanner-lib SHARED
12+
add_executable(dbccoder
1313
${CMAKE_CURRENT_SOURCE_DIR}/codegen/c-main-generator.cpp
1414
${CMAKE_CURRENT_SOURCE_DIR}/codegen/c-util-generator.cpp
1515
${CMAKE_CURRENT_SOURCE_DIR}/codegen/conditional-tree.cpp
@@ -19,7 +19,5 @@ add_library(dbcscanner-lib SHARED
1919
${CMAKE_CURRENT_SOURCE_DIR}/helpers/formatter.cpp
2020
${CMAKE_CURRENT_SOURCE_DIR}/parser/dbclineparser.cpp
2121
${CMAKE_CURRENT_SOURCE_DIR}/parser/dbcscanner.cpp
22+
${CMAKE_CURRENT_SOURCE_DIR}/maincli.cpp
2223
)
23-
24-
25-
target_compile_definitions(dbcscanner-lib PRIVATE DBCSCANNERLIB_LIBRARY)

src/maincli.cpp

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
2+
#include <iostream>
3+
#include <fstream>
4+
#include <filesystem>
5+
#include "parser/dbcscanner.h"
6+
#include "codegen/c-main-generator.h"
7+
#include "codegen/c-util-generator.h"
8+
#include "codegen/fs-creator.h"
9+
10+
#define GEN_UTIL_CODE
11+
12+
DbcScanner* scanner;
13+
CiMainGenerator* cigen;
14+
CiUtilGenerator* ciugen;
15+
FsCreator* fscreator;
16+
17+
std::string source_files_out_path;
18+
std::string dbc_file_path;
19+
std::string dbc_driver_name;
20+
21+
int main(int argc, char* argv[])
22+
{
23+
scanner = new DbcScanner;
24+
cigen = new CiMainGenerator;
25+
ciugen = new CiUtilGenerator;
26+
fscreator = new FsCreator;
27+
28+
bool numberLines = false; // Default is no line numbers.
29+
30+
if (argc == 4)
31+
numberLines = true;
32+
33+
if (numberLines)
34+
{
35+
std::ifstream reader;
36+
// copy dbc file name to string variable
37+
dbc_file_path = argv[1];
38+
source_files_out_path = argv[2];
39+
dbc_driver_name = argv[3];
40+
41+
std::cout << "dbc file : " << argv[1] << std::endl;
42+
std::cout << "gen path : " << argv[2] << std::endl;
43+
std::cout << "drv name : " << argv[3] << std::endl;
44+
45+
if (std::filesystem::exists(dbc_file_path) == false)
46+
{
47+
std::cout << "DBC file is not exists!" << std::endl;
48+
return -1;
49+
}
50+
51+
reader.open(dbc_file_path);
52+
53+
std::istream& s = reader;
54+
55+
scanner->TrimDbcText(s);
56+
57+
std::string info("this is test");
58+
59+
auto ret = fscreator->PrepareDirectory(dbc_driver_name.c_str(), source_files_out_path.c_str(), true, info);
60+
61+
if (ret)
62+
{
63+
cigen->Generate(scanner->dblist, fscreator->FS);
64+
}
65+
else
66+
{
67+
std::cout << "One or both are invalid\n";
68+
}
69+
70+
#if defined (GEN_UTIL_CODE)
71+
72+
73+
// test utility generation
74+
75+
ret = fscreator->PrepareDirectory(dbc_driver_name.c_str() , (source_files_out_path).c_str(), true, info);
76+
77+
MsgsClassification groups;
78+
79+
for (size_t i = 0; i < scanner->dblist.msgs.size(); i++)
80+
{
81+
groups.Rx.push_back(scanner->dblist.msgs[i]->MsgID);
82+
}
83+
84+
if (ret)
85+
{
86+
ciugen->Generate(scanner->dblist, fscreator->FS, groups, dbc_driver_name);
87+
}
88+
89+
#endif
90+
91+
}
92+
else
93+
{
94+
std::cout << "Argument list is bad." << std::endl;
95+
}
96+
97+
std::cout << "Finished... Press any key." << std::endl;
98+
}

0 commit comments

Comments
 (0)