]> 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: 6fe5042)
fix error handling/recovery
2021年8月13日 14:21:09 +0000 (16:21 +0200)
2021年8月15日 11:21:02 +0000 (13:21 +0200)
Improve error reporting too.

Error messages are sent to stderr, so stdout still carries a valid JSON
stream.


diff --git a/tic.l b/tic.l
index 971e61c0d2afc093642bc359685a0ff9157bb868..c2eeafce9427b9ba3255b6ced9f3dfecbf994cfd 100644 (file)
--- a/tic.l
+++ b/tic.l
@@ -158,7 +158,7 @@ PPOINTE { crc_calc(); yylval.text = strdup(yytext); return ET_PPOINTE; }
{HORODATE} { crc_calc(); yylval.text = strdup(yytext); return TOK_HDATE; }
{DATAC}+ { crc_calc(); yylval.text = strdup(yytext); return TOK_DATA; }
-. { printf("spurious character %c\n", *yytext); return 0; }
+. { fprintf(stderr, "spurious character 0x%02hhx\n", *yytext); /* ignore */ }
<<EOF>> { yyterminate(); }
%%
diff --git a/tic.y b/tic.y
index 3654f78337e0bb0919ab101ca2982b0cb7ce88ec..fa2fc06c54612716f738a4fbd01d52a9ac931195 100644 (file)
--- a/tic.y
+++ b/tic.y
@@ -6,6 +6,14 @@
// License: GPLv2 - http://www.gnu.org/licenses/gpl-2.0.html
//
+/*
+ * Outputs as JSON a list of frames which contains a list of fields.
+ * Fields are { "label": "xxx", "data": "xxx", horodate: "xxx" } with horodate optional and data possibly empty.
+ * Data errors can result in some/all fields being omitted in the output frame.
+ * Output JSON is guaranteed to always be valid.
+ * This parser complies with Enedis-NOI-CPT_54E.pdf version 3.
+ */
+
%{
#include <stdio.h>
#include <stdlib.h>
@@ -90,7 +98,11 @@ frame:
if (!hooked) { hooked=1; printf("[\n["); }
else { fdelim=' '; printf ("],\n["); }
}
- | error TOK_ETX { hooked=0; }
+ | error TOK_ETX
+ {
+ if (hooked) { fdelim=' '; printf ("],\n["); }
+ fprintf(stderr, "frame error\n");
+ }
;
datasets:
@@ -111,9 +123,9 @@ dataset:
}
free_field(2ドル);
}
- | FIELD_START field FIELD_KO { if (!2ドル) YYABORT; printf("invalid checksum\n"); free_field(2ドル); }
- | FIELD_START error FIELD_OK
- | FIELD_START error FIELD_KO
+ | FIELD_START field FIELD_KO { if (!2ドル) YYABORT; fprintf(stderr, "dataset invalid checksum\n"); free_field(2ドル); }
+ | error FIELD_OK { fprintf(stderr, "dataset error with valid checksum\n"); }
+ | error FIELD_KO { fprintf(stderr, "dataset error with invalid checksum\n"); }
;
field: field_horodate
tic2json TIC parser/converter
RSS Atom

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