[linux-dvb] Re: some libdvbcfg wishes, preset format

Kenneth Aafløy kenneth at linuxtv.org
Sat Jul 16 01:49:10 CEST 2005

lørdag 16. juli 2005, 01:14, skrev Andrew de Quincey:
> OK, I've been thinking about this. It makes it quite hard to do nicely for the 
> section oriented file formats. e.g. for multiplexes.conf:
> When you're parsing the [m], you only know it ends when you hit the [s] 
> entry... this doesn't really fit nicely if you're passing it line by line, 
> and its not really feasible to go back to a line-oriented format for these 
> more complex files. So need to keep more complex state between lines for 
> these... something like:
> struct multiplex_parser {
>  int state;
>  struct dvbcfg_multiplex* multiplex;
>  struct dvbcfg_service* service;
> };
> int dvbcfg_multiplex_parse_line(char* line, struct multiplex_parser* state);
> The return code will indicate what was just parsed. Its up to you to 
> supply/update/free suitable multiplex and source pointers - they could be 
> malloced(), they could be pointers to a local temporary variables..
> Unfortunately, parsing the entries will have to allocate temporary space - 
> e.g. for storing a list of dvbcfg_pid entries. Is this ok?
> I'll be adding a call to zap the contents of a multiplex structure so you 
> could either just let the parsing accumulate values in the multiplex 
> structure OR you could copy them out to some other place, and zap the 
> structure contents each time something is parsed.
> What do you think?

What if you don't think about the file format, but of the general structure:
Don't mind the XML, it's only used to present the format.

<multiplexes ...>
 <multiplex ...>
  <service .../>
 <multiplex .../>

You start with:

int dvbcfg_create_parser(struct dvbcfg_parser **);

Which allocates a new backend parser, then:

int dvbcfg_get_multiplexes(struct dvbcfg_parser *, struct dvb_multiplexes **);
int dvbcfg_get_next_multiplex(struct dvbcfg_parser *, struct dvb_multiplex **);
int dvbcfg_get_next_service(struct dvbcfg_parser *, struct dvb_service **);

A -EOVERFLOW or NULL value in the ptr-ptr parameter says end of list.
The backend can then choose to pre-parse the multiplexes in get_multiplexes,
and only keep track of where it is via the parser context.

The parsing in the backend itself can be helped with the string parsers
already present in dvbcfg, but it is actually free to store the data
in any format it chooses.


More information about the linux-dvb mailing list