From: Thibaut VARÈNE Date: 2021年8月25日 21:08:21 +0000 (+0200) Subject: ticv02.l: separate etiquettes from data processing X-Git-Tag: v2.0~1 X-Git-Url: http://vcs.slashdirt.org/git/?a=commitdiff_plain;h=3862c996d25146c26e4cd8e33dd9b93cae133f59;p=sw%2Ftic2json.git ticv02.l: separate etiquettes from data processing 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 05293c7..a81f6ca 100644 --- 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 [ \t\n]+ /* ignore whitespace */ /* balises */ -\x02 { return TOK_STX; } -\x03 { return TOK_ETX; } -\x0a { checksum=0; return FIELD_START; } -{SEP} { checksum += (uint8_t)*yytext; return TOK_SEP; } -{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; } -{HORODATE} { crc_calc(); ticv02yylval.text = strdup(yytext); return TOK_HDATE; } -{DATAC}+ { crc_calc(); ticv02yylval.text = strdup(yytext); return TOK_DATA; } +{HORODATE} { crc_calc(); ticv02yylval.text = strdup(yytext); return TOK_HDATE; } +{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; } <> { yyterminate(); } %%

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