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.


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


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 {" >
$ ./parse some_source_file.c >>
$ echo "}" >>
$ dot -Tps -o
$ gv

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 {" >
$ for i in *.c ;do ./parse $i >> ;done
$ for i in *.h ;do ./parse $i >> ;done
$ echo "}" >>
$ dot -Tps -o
$ gv