]> vcs.slashdirt.org Git - sw/tic2json.git/commitdiff

vcs.slashdirt.org Git - sw/tic2json.git/commitdiff

git git / sw / tic2json.git / commitdiff
? search:
summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: c94a3a7)
ticv02.l: separate etiquettes from data processing
2021年8月25日 21:08:21 +0000 (23:08 +0200)
2021年8月25日 21:30:26 +0000 (23:30 +0200)
Following the previous commit and to avoid a similar issue in standard
mode, apply the same recipe:

Use an exclusive start condition to process data.
Logic: when we encounter the first SEP in INITIAL condition, everything
that comes after is DATA and not etiquette until we start a new dataset.
Only change states at delimiters and use condition catchalls for them to
ensure resync in case of data errors.
This makes initial frame sync a little more error-verbose.


diff --git a/ticv02.l b/ticv02.l
index 05293c711163a35f041a4caa0dcac32083e4d425..a81f6caec7916bda3288fe87e9d65f8ef54ca4ba 100644 (file)
--- a/ticv02.l
+++ b/ticv02.l
@@ -39,6 +39,7 @@
%option nodebug
%s FILTER
+%x DATA
HORODATE [ EeHh][0-9]{12}
DATAC [\x20-\x7e]
@@ -69,11 +70,11 @@ SEP \x09
<FILTER>[ \t\n]+ /* ignore whitespace */
/* balises */
-<INITIAL>\x02 { return TOK_STX; }
-<INITIAL>\x03 { return TOK_ETX; }
-<INITIAL>\x0a { checksum=0; return FIELD_START; }
-<INITIAL>{SEP} { checksum += (uint8_t)*yytext; return TOK_SEP; }
-<INITIAL>{CHKSUM}\x0d {
+<*>\x02 { BEGIN(INITIAL); return TOK_STX; }
+<*>\x03 { BEGIN(INITIAL); return TOK_ETX; }
+<*>\x0a { BEGIN(INITIAL); checksum=0; return FIELD_START; }
+<*>{SEP} { checksum += (uint8_t)*yytext; BEGIN(DATA); return TOK_SEP; }
+<*>{CHKSUM}\x0d {
checksum = (checksum & 0x3f) + 0x20;
if (checksum == (uint8_t)yytext[0]) return FIELD_OK;
else return FIELD_KO;
@@ -153,10 +154,10 @@ NJOURF\+1 { crc_calc(); ticv02yylval.label = "NJOURF+1"; return ET_NJOURFP1; }
PJOURF\+1 { crc_calc(); ticv02yylval.label = "PJOURF+1"; return ET_PJOURFP1; }
PPOINTE { crc_calc(); ticv02yylval.label = "PPOINTE"; return ET_PPOINTE; }
-<INITIAL>{HORODATE} { crc_calc(); ticv02yylval.text = strdup(yytext); return TOK_HDATE; }
-<INITIAL>{DATAC}+ { crc_calc(); ticv02yylval.text = strdup(yytext); return TOK_DATA; }
+<DATA>{HORODATE} { crc_calc(); ticv02yylval.text = strdup(yytext); return TOK_HDATE; }
+<DATA>{DATAC}+ { crc_calc(); ticv02yylval.text = strdup(yytext); return TOK_DATA; }
-. { pr_err("spurious character 0x%02hhx\n", *yytext); return *yytext; }
+<*>. { pr_err("spurious character 0x%02hhx\n", *yytext); return *yytext; }
<<EOF>> { yyterminate(); }
%%
tic2json TIC parser/converter
RSS Atom

AltStyle によって変換されたページ (->オリジナル) /