]> 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: 0634c0b)
Further split out parser from output producer
2021年8月21日 13:53:05 +0000 (15:53 +0200)
2021年8月21日 14:31:06 +0000 (16:31 +0200)
tic.c [new file with mode: 0644] patch | blob

diff --git a/Makefile b/Makefile
index 4b21b71290cf83bf7b1be0e56341103cfc1db657..a11de61e1051055ce1288af9e3c56af841bb5f05 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -20,7 +20,7 @@ all: $(MAIN)
tic2json.o: $(addsuffix .tab.h,$(TICS))
-$(MAIN): $(addsuffix .tab.o,$(TICS)) $(addsuffix .lex.o,$(TICS)) tic2json.o
+$(MAIN): $(addsuffix .tab.o,$(TICS)) $(addsuffix .lex.o,$(TICS)) tic.o tic2json.o
clean:
$(RM) $(MAIN) *.output *.tab.h *.tab.c *.lex.c *.o
diff --git a/tic.c b/tic.c
new file mode 100644 (file)
index 0000000..db7a295
--- /dev/null
+++ b/tic.c
@@ -0,0 +1,50 @@
+//
+// tic.c
+// Common routines for TIC parsers
+//
+// (C) 2021 Thibaut VARENE
+// License: GPLv2 - http://www.gnu.org/licenses/gpl-2.0.html
+//
+
+#include <stdlib.h>
+#include <string.h>
+
+#include "tic.h"
+
+bool filter_mode;
+uint8_t *etiq_en; // type: < 255 tokens. This could be made a bit field if memory is a concern
+
+void make_field(struct tic_field *field, const struct tic_etiquette *etiq, char *horodate, char *data)
+{
+ // args come from the bison stack
+ int base;
+
+ field->horodate = horodate;
+ memcpy(&field->etiq, etiq, sizeof(field->etiq));
+
+ switch ((etiq->unittype & 0xF0)) {
+ case T_STRING:
+ field->data.s = data;
+ return;
+ case T_HEX:
+ base = 16;
+ break;
+ default:
+ base = 10;
+ break;
+ }
+ field->data.i = (int)strtol(data, NULL, base);
+ free(data);
+}
+
+void free_field(struct tic_field *field)
+{
+ free(field->horodate);
+ switch ((field->etiq.unittype & 0xF0)) {
+ case T_STRING:
+ free(field->data.s);
+ break;
+ default:
+ break;
+ }
+}
diff --git a/tic.h b/tic.h
index 6889196c9009adf0da868c6335cf0b32fd4c5a59..11ca15a8b13607fb49a2562d193648e8cea6df80 100644 (file)
--- a/tic.h
+++ b/tic.h
@@ -1,6 +1,6 @@
//
// tic.h
-//
+// Interface for TIC parsers
//
// (C) 2021 Thibaut VARENE
// License: GPLv2 - http://www.gnu.org/licenses/gpl-2.0.html
@@ -19,8 +19,6 @@
#define pr_err(format, ...) fprintf(stderr, "ERREUR: " format, ## __VA_ARGS__)
#endif
-#define TIC2JSON_VER "1.1"
-
// The code assumes this fits on 4 bits
enum tic_unit {
U_SANS = 0x00,
@@ -58,8 +56,10 @@ struct tic_field {
};
void make_field(struct tic_field *field, const struct tic_etiquette *etiq, char *horodate, char *data);
-void print_field(struct tic_field *field);
void free_field(struct tic_field *field);
+
+void print_field(struct tic_field *field);
+// The following functions must be provided by the output interface
void frame_sep(void);
void frame_err(void);
diff --git a/tic2json.c b/tic2json.c
index 896ded48dae48b9dc20d10157325da18def14f83..4322af0f6e0b345579ac6ae999f77adfc63b573b 100644 (file)
--- a/tic2json.c
+++ b/tic2json.c
@@ -43,8 +43,10 @@
#warning BAREBUILD currently requires editing the code by hand
#endif
-bool filter_mode;
-uint8_t *etiq_en; // type: < 255 tokens. This could be made a bit field if memory is a concern
+#define TIC2JSON_VER "1.1"
+
+extern bool filter_mode;
+extern uint8_t *etiq_en;
static struct {
const char *idtag;
@@ -76,29 +78,6 @@ static const char * tic_units[] = {
[U_MIN] = "mn",
};
-void make_field(struct tic_field *field, const struct tic_etiquette *etiq, char *horodate, char *data)
-{
- // args come from the bison stack
- int base;
-
- field->horodate = horodate;
- memcpy(&field->etiq, etiq, sizeof(field->etiq));
-
- switch ((etiq->unittype & 0xF0)) {
- case T_STRING:
- field->data.s = data;
- return;
- case T_HEX:
- base = 16;
- break;
- default:
- base = 10;
- break;
- }
- field->data.i = (int)strtol(data, NULL, base);
- free(data);
-}
-
#ifdef TICV02
static void print_stge_data(int data)
{
@@ -266,18 +245,6 @@ void print_field(struct tic_field *field)
tp.fdelim = ',';
}
-void free_field(struct tic_field *field)
-{
- free(field->horodate);
- switch ((field->etiq.unittype & 0xF0)) {
- case T_STRING:
- free(field->data.s);
- break;
- default:
- break;
- }
-}
-
void frame_sep(void)
{
if (!tp.framecount--) {
tic2json TIC parser/converter
RSS Atom

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