From 010f1438edde37cc8feaaddc98f39dbfaf07551d Mon Sep 17 00:00:00 2001 From: =?utf8?q?Thibaut=20VAR=C3=88NE?= Date: 2021年8月15日 23:58:10 +0200 Subject: [PATCH] minor reformat --- tic2json.l | 5 +++++ tic2json.y | 34 ++++++++++++++++++---------------- 2 files changed, 23 insertions(+), 16 deletions(-) diff --git a/tic2json.l b/tic2json.l index 1a27512..21714ad 100644 --- a/tic2json.l +++ b/tic2json.l @@ -6,6 +6,11 @@ // License: GPLv2 - http://www.gnu.org/licenses/gpl-2.0.html */ +/* + * Complete lexer for ENEDIS' TIC protocol. + * Currently only supports version 02, a.k.a "standard" as found on ENEDIS' LINKY smart meter. + */ + /* noyywrap disables automatic rewinding for the next file to parse. Since we always parse only a single string, there's no need to do any wraps. And using yywrap requires linking with -lfl, which provides the default yywrap diff --git a/tic2json.y b/tic2json.y index c812b62..4f29ea5 100644 --- a/tic2json.y +++ b/tic2json.y @@ -14,21 +14,25 @@ * * Data errors can result in some/all fields being omitted in the output frame: the JSON root object is empty but still emitted. * Output JSON is guaranteed to always be valid for each frame. By default only frames are separated with newlines. - * This parser complies with Enedis-NOI-CPT_54E.pdf version 3. + * This parser implements a complete grammar that supports TIC version 02 as specified in Enedis-NOI-CPT_54E.pdf version 3. + * + * This parser does not allocate memory, except if a filter configuration is used in which case the etiq_en array will + * be allocated (it's a few hundred bytes). */ %{ - #include - #include - #include - #include - #include "tic2json.h" - - int yylex(); - int yylex_destroy(); - extern FILE *yyin; - void yyerror(const char *); - int filter_mode; +#include +#include +#include +#include +#include "tic2json.h" + +int yylex(); +int yylex_destroy(); +extern FILE *yyin; +void yyerror(const char *); + +int filter_mode; static char framedelims[2]; static char fdelim; @@ -57,11 +61,9 @@ static const char * tic_units[] = { void make_field(struct tic_field *field, const struct tic_etiquette *etiq, char *horodate, char *data) { + // args come from the bison stack int base; - if (!field) - return; - field->horodate = horodate; memcpy(&field->etiq, etiq, sizeof(field->etiq)); @@ -179,7 +181,7 @@ void free_field(struct tic_field *field) %token