From: Mauro Carvalho Chehab Date: Tue, 24 Jan 2012 14:00:00 +0000 (-0200) Subject: dvb-file: improve parser description structures X-Git-Tag: v4l-utils-0.9.0-test1~15 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=f113667499c8d21a4bfb82bcd502a04d4cf12927;p=platform%2Fupstream%2Fv4l-utils.git 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 --- 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)