linux - Is there any configure file read/write C code generator? -
i know how generate c scanner code flex or bison, unluckily, need c code read && -write- configure file, can not generate such code flex or bison, may can use configure file read/write library, think it's not flexible when want custom format of configure file, tips?
i know of no such dedicated tool that, because it's not hard job.
the reason have lexical , semantic analysis on input because have turn complex (free form text possibility of errors) simple (in-memory representation no errors).
going other way simpler because can step through in-memory structures , output string representations. simplified example, let's config file has line:
define xyzzy integer size 5 1 3 5 7 9 ;
to create array called xyzzy
5 elements.
on input, have tokenise (lexical analysis) character stream like:
keyword:define name:xyzzy keyword:integer keyword:size constant:5 keyword:is constant:1 constant:3 constant:5 constant:7 constant:9 keyword:semicolon
and use semantic analysis form can use within program, such structure:
type = array name = xyzzy underlyingtype = integer size = 5 element[1..5] = {1,3,5,7,9}
now, out configuration file relatively easy. walk through in-memory structure, such with:
for each in-memory-thing imt: if imt.type array: output "define ", imt.name, " ", imt.underlyingtype output " size ", imt.size, " " = 1 imt.size inclusive: output imt.element[i], " " output " ;" newline fi // handle other types of imt here rof
so can see act of writing configuration file lot easier reding it.
Comments
Post a Comment