tech-userlevel archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: proplib and the jet age



On Sun, Jan 06, 2013 at 04:07:51AM +0000, David Holland wrote:
> Developers need to learn parsing tools anyway, but that's not much of
> an argument since the only parsing tools you need for handling simple
> config files are fgets(3), strchr(3), and strtok_r(3).

and strtoul() ...

It is worth applying a little structure, but key=value pairs where the
values are either numeric, selector strings (like an enum), string names
or filenames (pesky embedded spaces) is unually enough.

I wrote some code (for dayjob) that parses such config sequences by
processing a table that contains (name, offsetof(field), decode_function)
triples (+flags and  bounds/default for numerics).
(With some #defines to help initialise things correctly.)
This actually made adding new parameters too easy!

It also made it fairly simple to process the same data to dump out
the structure values.

        David

-- 
David Laight: david%l8s.co.uk@localhost


Home | Main Index | Thread Index | Old Index