1
1
#include " dbcscanner.h"
2
+ #include < cstring>
2
3
#include < algorithm>
3
4
#include < math.h>
4
5
#include " ../helpers/formatter.h"
@@ -36,7 +37,8 @@ DbcScanner::~DbcScanner()
36
37
37
38
int32_t DbcScanner::TrimDbcText (istream& readstrm)
38
39
{
39
- msgs.clear ();
40
+ dblist.msgs .clear ();
41
+ dblist.ver .hi = dblist.ver .low = 0 ;
40
42
41
43
readstrm.clear ();
42
44
readstrm.seekg (0 );
@@ -70,6 +72,8 @@ void DbcScanner::ParseMessageInfo(istream& readstrm)
70
72
71
73
sline = str_trim (line);
72
74
75
+ FindVersion (sline);
76
+
73
77
// New message line has been found
74
78
if (lparser.IsMessageLine (sline))
75
79
{
@@ -127,7 +131,7 @@ void DbcScanner::ParseOtherInfo(istream& readstrm)
127
131
if (lparser.ParseCommentLine (&cmmnt, sline))
128
132
{
129
133
// update message comment field
130
- auto msg = find_message (msgs, cmmnt.MsgId );
134
+ auto msg = find_message (dblist. msgs , cmmnt.MsgId );
131
135
132
136
if (msg != nullptr )
133
137
{
@@ -194,7 +198,7 @@ void DbcScanner::ParseOtherInfo(istream& readstrm)
194
198
if (lparser.ParseValTableLine (&cmmnt, sline))
195
199
{
196
200
// update message comment field
197
- auto msg = find_message (msgs, cmmnt.MsgId );
201
+ auto msg = find_message (dblist. msgs , cmmnt.MsgId );
198
202
199
203
if (msg != nullptr )
200
204
{
@@ -220,7 +224,7 @@ void DbcScanner::ParseOtherInfo(istream& readstrm)
220
224
221
225
if (lparser.ParseAttributeLine (&attr, sline))
222
226
{
223
- auto msg = find_message (msgs, attr.MsgId );
227
+ auto msg = find_message (dblist. msgs , attr.MsgId );
224
228
225
229
if (msg != nullptr )
226
230
{
@@ -264,7 +268,7 @@ void DbcScanner::AddMessage(MessageDescriptor_t* message)
264
268
}
265
269
266
270
// save pointer on message
267
- msgs.push_back (message);
271
+ dblist. msgs .push_back (message);
268
272
}
269
273
}
270
274
@@ -287,3 +291,23 @@ void DbcScanner::SetDefualtMessage(MessageDescriptor_t* message)
287
291
message->CsmOp = 0 ;
288
292
message->CsmToByteExpr = " " ;
289
293
}
294
+
295
+
296
+ void DbcScanner::FindVersion (const std::string& instr)
297
+ {
298
+ // try to find version string which looks like: VERSION "x.x"
299
+ uint32_t h = 0 , l = 0 ;
300
+ char marker[8 ];
301
+
302
+ if (instr[0 ] != ' V' && instr[1 ] != ' E' )
303
+ return ;
304
+
305
+ int32_t ret = std::sscanf (instr.c_str (), " %8s \" %u.%u\" " , marker, &h, &l);
306
+
307
+ if ((ret == 3 ) && (std::strcmp (marker, " VERSION" ) == 0 ))
308
+ {
309
+ // versions have been found, save numeric values
310
+ dblist.ver .hi = h;
311
+ dblist.ver .low = l;
312
+ }
313
+ }
0 commit comments