index 4b21b71290cf83bf7b1be0e56341103cfc1db657..a11de61e1051055ce1288af9e3c56af841bb5f05 100644 (file)
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
new file mode 100644
(file)
index 0000000..
db7a295
--- /dev/null
+//
+// 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;
+ }
+}
index 6889196c9009adf0da868c6335cf0b32fd4c5a59..11ca15a8b13607fb49a2562d193648e8cea6df80 100644 (file)
//
// tic.h
-//
+// Interface for TIC parsers
//
// (C) 2021 Thibaut VARENE
// License: GPLv2 - http://www.gnu.org/licenses/gpl-2.0.html
#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,
};
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);
index 896ded48dae48b9dc20d10157325da18def14f83..4322af0f6e0b345579ac6ae999f77adfc63b573b 100644 (file)
#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;
[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)
{
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--) {