12 Nov 2002 ModernRonin   » (Observer)

So my friend asked me an interesting question today, and I found that I didn't have a good answer for him.

He wanted a little program to generate a .h file based on the contents of a .c file. As anyone who's programmed professionally for very long will tell you, writing and maintaining header files is tedious and error-prone - exactly the kind of thing that should be automated.

Auto-generating headers is easy to do poorly, but harder than one might first think to do well in all cases. Basically, to do it right I think you need to have a full C language parser. There are several reasons that a regexp won't always work the way you want it to, but the most obvious example is that if you just naively tell it '[a-z][a-z0-9_]*(.*)', you're going to find a lot of declarations for functions named "void while()" and "void if()" in your auto-generated header file...

I've found several programs to generate .h files based on special comments in .c files. That's no good, he wants something that he doesn't have to use special comments for. I've also found tons of .c -> .html documentation scripts, but it doesn't seem obvious to me how to adapt these to generate .h files.

Does anyone know of a program to do this? Or is anyone interested in hacking on such a project with me? This strikes me as an interesting test of my lex and yacc skills...

Latest blog entries     Older blog entries

New Advogato Features

New HTML Parser: The long-awaited libxml2 based HTML parser code is live. It needs further work but already handles most markup better than the original parser.

Keep up with the latest Advogato features by reading the Advogato status blog.

If you're a C programmer with some spare time, take a look at the mod_virgule project page and help us with one of the tasks on the ToDo list!