mario::konrad
programming / C++ / sailing / nerd stuff
C Include Parser
© 2002-02-01 / Mario Konrad

This is a parser (in fact it's just a lexer) for includes in C file, header or definition files (*.c). This parser will ignore all precompiler conditions like #ifdef etc. It will only parse all includes and lists them. You may use the output to visualize the dependencies using the GraphViz tool.

Features

Parses the specified file for all #include directives and prints them to stdout. All names become lowercase and all dots '.' become '_'.

Build

To build the program, please follow the instructions below.

First you have to use the lexer to build a C file:

$ flex -l c_includes.l

Then compile the generated file:

$ gcc -o parse lex.yy.c -lfl

Last but not least, let's make a test:

$ echo "digraph test {" > graph.dot
$ ./parse some_source_file.c >> graph.dot
$ echo "}" >> graph.dot
$ dot -Tps graph.dot -o graph.ps
$ gv graph.ps

And you may have a look at the graph and wonder what header files your program includes.

To put this a little further you may want to have a graph that shows all your source files (definition files as well as header files):

$ echo "digraph test {" > graph.dot
$ for i in *.c ;do ./parse $i >> graph.dot ;done
$ for i in *.h ;do ./parse $i >> graph.dot ;done
$ echo "}" >> graph.dot
$ dot -Tps graph.dot -o graph.ps
$ gv graph.ps

Enjoy!

Files