Skip to content

Commit 92b7887

Browse files
committed
Bug in the mnemo file parsing
In case of an error on a line, the data of the line, previously parsed, wasn't cleaned up. That made the next line incorrect and/or rejected.
1 parent 8ffb9ba commit 92b7887

1 file changed

Lines changed: 30 additions & 7 deletions

File tree

cpp_version/params_input_mnemos.cpp

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ bool mnemos_bytes_stream::get_event(istream&i_stm)
4343
// until the eof "is fixed"
4444
unsigned char val_read;
4545

46-
bool shoottheline;
46+
enum { shoot_line, clear_line, idle_line } action_line;
4747

4848
if( state == state_end )
4949
{
@@ -58,7 +58,7 @@ bool mnemos_bytes_stream::get_event(istream&i_stm)
5858

5959
while( (i_stm.eof() == false) && (status != end_track) && (state != state_end) )
6060
{
61-
shoottheline = false;
61+
action_line = idle_line;
6262
i_stm.read( (char*)(&val_read) , 1 );
6363
if ( ( val_read >= 'a' && val_read <= 'z' ) || ( val_read >= 'A' && val_read <= 'Z' ) || val_read == '/' )
6464
{
@@ -84,6 +84,7 @@ bool mnemos_bytes_stream::get_event(istream&i_stm)
8484
break;
8585
case ls_spctab_mnemo:
8686
info_out_str << "Line " << track_line << ": numerical digits are expected for the value" << endl;
87+
action_line = clear_line;
8788
line_state = ls_wait_eol_comment;
8889
break;
8990
case ls_in_val_left:
@@ -99,6 +100,8 @@ bool mnemos_bytes_stream::get_event(istream&i_stm)
99100
case ls_in_crlf:
100101
case ls_start:
101102
info_out_str << "Line " << track_line << ": numerical digits are expected for the time-stamp" << endl;
103+
// may be irrelevant is ls_start state
104+
action_line = clear_line;
102105
line_state = ls_wait_eol_comment;
103106
break;
104107
case ls_wait_eol_comment:
@@ -121,6 +124,7 @@ bool mnemos_bytes_stream::get_event(istream&i_stm)
121124
break;
122125
case ls_in_ts_unit:
123126
info_out_str << "Line " << track_line << ": no numerical digit is allowed in the TS unit" << endl;
127+
action_line = clear_line;
124128
line_state = ls_wait_eol_comment;
125129
break;
126130
case ls_spctab_ts:
@@ -143,6 +147,7 @@ bool mnemos_bytes_stream::get_event(istream&i_stm)
143147
break;
144148
case ls_in_val_unit:
145149
info_out_str << "Line " << track_line << ": no numerical digit is allowed in the value unit" << endl;
150+
action_line = clear_line;
146151
line_state = ls_wait_eol_comment;
147152
break;
148153
case ls_spctab_val:
@@ -163,20 +168,24 @@ bool mnemos_bytes_stream::get_event(istream&i_stm)
163168
break;
164169
case ls_in_ts_right:
165170
info_out_str << "Line " << track_line << ": no second decimal separator is allowed in the TS" << endl;
171+
action_line = clear_line;
166172
line_state = ls_wait_eol_comment;
167173
break;
168174
case ls_in_ts_unit:
169175
info_out_str << "Line " << track_line << ": no decimal separator is allowed in the TS unit" << endl;
176+
action_line = clear_line;
170177
line_state = ls_wait_eol_comment;
171178
break;
172179
case ls_spctab_ts:
173180
case ls_in_channel:
174181
info_out_str << "Line " << track_line << ": no decimal separator is allowed in the channel" << endl;
182+
action_line = clear_line;
175183
line_state = ls_wait_eol_comment;
176184
break;
177185
case ls_spctab_channel:
178186
case ls_in_mnemo:
179187
info_out_str << "Line " << track_line << ": no decimal separator is allowed in the mnemonic" << endl;
188+
action_line = clear_line;
180189
line_state = ls_wait_eol_comment;
181190
break;
182191
case ls_spctab_mnemo:
@@ -185,16 +194,17 @@ bool mnemos_bytes_stream::get_event(istream&i_stm)
185194
break;
186195
case ls_in_val_right:
187196
info_out_str << "Line " << track_line << ": no second decimal separator is allowed in the value" << endl;
197+
action_line = clear_line;
188198
line_state = ls_wait_eol_comment;
189199
break;
190200
case ls_in_val_unit:
191201
info_out_str << "Line " << track_line << ": no second decimal separator is allowed in the value unit" << endl;
202+
action_line = clear_line;
192203
line_state = ls_wait_eol_comment;
193204
break;
194205
case ls_spctab_val:
195206
info_out_str << "Line " << track_line << ": warning, please start comments with a comment character" << endl;
196207
line_state = ls_wait_eol_comment;
197-
shoottheline = true;
198208
break;
199209
case ls_wait_eol_comment:
200210
break;
@@ -234,10 +244,10 @@ bool mnemos_bytes_stream::get_event(istream&i_stm)
234244
case ls_in_val_left:
235245
case ls_in_val_right:
236246
case ls_in_val_unit:
247+
action_line = shoot_line;
237248
case ls_spctab_val:
238249
crlf_first_used = val_read;
239250
track_line += 1;
240-
shoottheline = true;
241251
break;
242252
case ls_wait_eol_comment:
243253
crlf_first_used = val_read;
@@ -275,12 +285,12 @@ bool mnemos_bytes_stream::get_event(istream&i_stm)
275285
break;
276286
case ls_in_val_left:
277287
line_state = ls_spctab_val;
278-
shoottheline = true;
288+
action_line = shoot_line;
279289
break;
280290
case ls_in_val_right:
281291
case ls_in_val_unit:
282292
line_state = ls_spctab_val;
283-
shoottheline = true;
293+
action_line = shoot_line;
284294
break;
285295
case ls_spctab_val:
286296
break;
@@ -316,9 +326,22 @@ bool mnemos_bytes_stream::get_event(istream&i_stm)
316326
if ( line_state != ls_wait_eol_comment )
317327
info_out_str << "Line " << track_line << ": exotic characters ( " << val_read << " ) allowed only in comments" << endl;
318328
}
319-
if ( shoottheline == true )
329+
switch ( action_line )
320330
{
331+
case shoot_line:
321332
state = state_end;
333+
break;
334+
case clear_line:
335+
// The structure should change. For now initialize one by one
336+
TS_left.clear();
337+
TS_right.clear();
338+
TS_unit.clear();
339+
channel.clear();
340+
mnemo.clear();
341+
value_left.clear();
342+
value_right.clear();
343+
value_unit.clear();
344+
break;
322345
}
323346
}
324347
if ((state == state_end) && (status != end_track))

0 commit comments

Comments
 (0)