From f113667499c8d21a4bfb82bcd502a04d4cf12927 Mon Sep 17 00:00:00 2001 From: Mauro Carvalho Chehab Date: Tue, 24 Jan 2012 12:00:00 -0200 Subject: [PATCH] dvb-file: improve parser description structures Move delimiter to a parser structure. This will allow adding a generic routine to create one-line formats. Signed-off-by: Mauro Carvalho Chehab --- utils/dvb/dvb-file.c | 10 +++++---- utils/dvb/dvb-file.h | 14 ++++++++---- utils/dvb/dvb-format-convert.c | 7 +++--- utils/dvb/dvb-legacy-channel-format.c | 42 +++++++++++++++++++---------------- utils/dvb/dvb-zap-format.c | 38 +++++++++++++++---------------- utils/dvb/dvbv5-scan.c | 8 +++---- utils/dvb/dvbv5-zap.c | 4 ++-- 7 files changed, 68 insertions(+), 55 deletions(-) diff --git a/utils/dvb/dvb-file.c b/utils/dvb/dvb-file.c index 0b3cdf7..1274122 100644 --- a/utils/dvb/dvb-file.c +++ b/utils/dvb/dvb-file.c @@ -49,10 +49,12 @@ static const char *parm_name(const struct parse_table *table) * Generic parse function for all formats each channel is contained into * just one line. */ -struct dvb_file *parse_format_oneline(const char *fname, const char *delimiter, +struct dvb_file *parse_format_oneline(const char *fname, uint32_t delsys, - const struct parse_struct *formats) + const struct parse_file *parse_file) { + const char *delimiter = parse_file->delimiter; + const struct parse_struct *formats = parse_file->formats; char *buf = NULL, *p; size_t size = 0; int len = 0; @@ -89,7 +91,7 @@ struct dvb_file *parse_format_oneline(const char *fname, const char *delimiter, if (*p == '\n' || *p == '#' || *p == '\a' || *p == '\0') continue; - if (!delsys) { + if (!parse_file->has_delsys_id) { p = strtok(p, delimiter); if (!p) { sprintf(err_msg, "unknown delivery system type for %s", @@ -104,7 +106,7 @@ struct dvb_file *parse_format_oneline(const char *fname, const char *delimiter, } } else { /* Seek for the delivery system */ - for (i = 0; formats[i].id != NULL; i++) { + for (i = 0; formats[i].delsys != 0; i++) { if (formats[i].delsys == delsys) break; } diff --git a/utils/dvb/dvb-file.h b/utils/dvb/dvb-file.h index 30c3628..de3dc7e 100644 --- a/utils/dvb/dvb-file.h +++ b/utils/dvb/dvb-file.h @@ -59,6 +59,12 @@ struct parse_struct { unsigned int size; }; +struct parse_file { + int has_delsys_id; + char *delimiter; + struct parse_struct formats[]; +}; + #define PTABLE(a) .table = a, .size=ARRAY_SIZE(a) /* FAKE DTV codes, for internal usage */ @@ -100,15 +106,15 @@ static inline void dvb_file_free(struct dvb_file *dvb_file) } /* From dvb-legacy-channel-format.c */ -extern const const struct parse_struct channel_formats[]; +extern const struct parse_file channel_file_format; /* From dvb-zap-format.c */ -extern const const struct parse_struct zap_formats[]; +extern const struct parse_file channel_file_zap_format; /* From dvb-file.c */ -struct dvb_file *parse_format_oneline(const char *fname, const char *delimiter, +struct dvb_file *parse_format_oneline(const char *fname, uint32_t delsys, - const struct parse_struct *formats); + const struct parse_file *parse_file); struct dvb_file *read_dvb_file(const char *fname); diff --git a/utils/dvb/dvb-format-convert.c b/utils/dvb/dvb-format-convert.c index b151e4e..b0cec3c 100644 --- a/utils/dvb/dvb-format-convert.c +++ b/utils/dvb/dvb-format-convert.c @@ -41,8 +41,8 @@ static int convert_file(const char *fname, const char *delsys, printf("Reading file %s\n", fname); switch (format) { case 1: /* DVB channel/transponder old format */ - dvb_file = parse_format_oneline(fname, " \n", SYS_UNDEFINED, - channel_formats); + dvb_file = parse_format_oneline(fname, SYS_UNDEFINED, + &channel_file_format); break; case 2: /* DVB old zap format */ if (!delsys) { @@ -61,7 +61,8 @@ static int convert_file(const char *fname, const char *delsys, fprintf(stderr, "Delivery system unknown\n"); return -1; } - dvb_file = parse_format_oneline(fname, ":", sys, zap_formats); + dvb_file = parse_format_oneline(fname, sys, + &channel_file_zap_format); break; } if (!dvb_file) diff --git a/utils/dvb/dvb-legacy-channel-format.c b/utils/dvb/dvb-legacy-channel-format.c index 5edc4a9..61ba495 100644 --- a/utils/dvb/dvb-legacy-channel-format.c +++ b/utils/dvb/dvb-legacy-channel-format.c @@ -134,24 +134,28 @@ static const struct parse_table sys_dvbt_table[] = { { DTV_HIERARCHY, PTABLE(channel_parse_hierarchy) }, }; -const struct parse_struct channel_formats[] = { - { - .id = "A", - .delsys = SYS_ATSC, - PTABLE(sys_atsc_table), - }, { - .id = "C", - .delsys = SYS_DVBC_ANNEX_A, - PTABLE(sys_dvbc_table), - }, { - .id = "S", - .delsys = SYS_DVBS, - PTABLE(sys_dvbs_table), - }, { - .id = "T", - .delsys = SYS_DVBT, - PTABLE(sys_dvbt_table), - }, { - NULL, 0, NULL, 0, +const struct parse_file channel_file_format = { + .has_delsys_id = 1, + .delimiter = " \n", + .formats = { + { + .id = "A", + .delsys = SYS_ATSC, + PTABLE(sys_atsc_table), + }, { + .id = "C", + .delsys = SYS_DVBC_ANNEX_A, + PTABLE(sys_dvbc_table), + }, { + .id = "S", + .delsys = SYS_DVBS, + PTABLE(sys_dvbs_table), + }, { + .id = "T", + .delsys = SYS_DVBT, + PTABLE(sys_dvbt_table), + }, { + NULL, 0, NULL, 0, + } } }; diff --git a/utils/dvb/dvb-zap-format.c b/utils/dvb/dvb-zap-format.c index 9033f31..53a2eb3 100644 --- a/utils/dvb/dvb-zap-format.c +++ b/utils/dvb/dvb-zap-format.c @@ -169,24 +169,24 @@ static const struct parse_table sys_dvbt_table[] = { { DTV_SERVICE_ID, NULL, 0 }, }; -const struct parse_struct zap_formats[] = { - { - .id = "A", - .delsys = SYS_ATSC, - PTABLE(sys_atsc_table), - }, { - .id = "C", - .delsys = SYS_DVBC_ANNEX_A, - PTABLE(sys_dvbc_table), - }, { - .id = "S", - .delsys = SYS_DVBS, - PTABLE(sys_dvbs_table), - }, { - .id = "T", - .delsys = SYS_DVBT, - PTABLE(sys_dvbt_table), - }, { - NULL, 0, NULL, 0, +const struct parse_file channel_file_zap_format = { + .has_delsys_id = 0, + .delimiter = ":\n", + .formats = { + { + .delsys = SYS_ATSC, + PTABLE(sys_atsc_table), + }, { + .delsys = SYS_DVBC_ANNEX_A, + PTABLE(sys_dvbc_table), + }, { + .delsys = SYS_DVBS, + PTABLE(sys_dvbs_table), + }, { + .delsys = SYS_DVBT, + PTABLE(sys_dvbt_table), + }, { + NULL, 0, NULL, 0, + } } }; diff --git a/utils/dvb/dvbv5-scan.c b/utils/dvb/dvbv5-scan.c index 8050667..ba164cc 100644 --- a/utils/dvb/dvbv5-scan.c +++ b/utils/dvb/dvbv5-scan.c @@ -279,9 +279,9 @@ static int run_scan(struct arguments *args, dvb_file = read_dvb_file(args->confname); break; case 1: /* DVB channel/transponder old format */ - dvb_file = parse_format_oneline(args->confname, " \n", + dvb_file = parse_format_oneline(args->confname, SYS_UNDEFINED, - channel_formats); + &channel_file_format); break; case 2: /* DVB old zap format */ switch (parms->current_sys) { @@ -304,8 +304,8 @@ static int run_scan(struct arguments *args, ERROR("Doesn't know how to emulate the delivery system"); return -1; } - dvb_file = parse_format_oneline(args->confname, ":", sys, - zap_formats); + dvb_file = parse_format_oneline(args->confname, sys, + &channel_file_zap_format); break; } if (!dvb_file) diff --git a/utils/dvb/dvbv5-zap.c b/utils/dvb/dvbv5-zap.c index d5071a9..39c2d12 100644 --- a/utils/dvb/dvbv5-zap.c +++ b/utils/dvb/dvbv5-zap.c @@ -132,8 +132,8 @@ static int parse(struct arguments *args, } if (args->old_format) - dvb_file = parse_format_oneline(args->confname, ":", - sys, zap_formats); + dvb_file = parse_format_oneline(args->confname, sys, + &channel_file_zap_format); else dvb_file = read_dvb_file(args->confname); if (!dvb_file) -- 2.7.4