Your question is a little vague, however it sounds like you need to develop some kind of parser to read in the cfg files and translate it into some form of intermediate language or object graph, optimize it, and then output it to c++. Sounds to me like a job for a home-grown compiler.
If you aren't familar with the different phases of a compiler I would highly recommend you check out the infamous dragon book
http://www.amazon.com/Compilers-Principles-Techniques-Tools-2nd/dp/0321486811/ref=sr_1_2?ie=UTF8&s=books&qid=1244657404&sr=8-2
Then again, if this is for an important project with a deadline you probably don't have a lot of time to spend in the world of compiler theory. Instead you might want to check out antlr. It is really useful for creating a lexar and parser for you based on grammar rules that you define from the syntax of the cfg files. You can use the antlr parser to translate the cfg files into an AST or some other form of object graph. At that point you are going to be responsible for manipulating, optimizing and outputting the c++ syntax to a new file.
I haven't read it yet but this is supposed to be an excellent book for novice and experienced antlr users
http://www.pragprog.com/titles/tpantlr/the-definitive-antlr-reference
plus there a plenty of antlr tutorials and examples online that I've used to help learn it. Hope that helps put you in the right direction.