From: Thibaut VARÈNE Date: 2021年8月21日 13:53:05 +0000 (+0200) Subject: Further split out parser from output producer X-Git-Tag: v2.0~13 X-Git-Url: http://vcs.slashdirt.org/git/?a=commitdiff_plain;h=2f75484d4899215b845e5fc832e3fb01689aa591;p=sw%2Ftic2json.git Further split out parser from output producer --- diff --git a/Makefile b/Makefile index 4b21b71..a11de61 100644 --- 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 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 +#include + +#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 6889196..11ca15a 100644 --- 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 896ded4..4322af0 100644 --- 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--) {

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