GSoC/GCI Archive
Google Code-in 2013 BRL-CAD

Write script to detect preprocessor include guard discrepancies

completed by: Peter Amidon

mentors: Sean

BRL-CAD source code currently has over 450 C header (include) files. Header files usually include a preprocessor block that ensures the header is only included once. It usually looks something like this:

#ifndef THIS_HEADER
#define THIS_HEADER
... file contents ...

#endif /* THIS_HEADER */

This tasks basically involves writing a script that will detect whether a header file has a header guard and, if it does, whether the name matches our header name convention.

Your job is to write a script that detects any discrepancies, based on the file name, for all of our headers. Our convention should be {SUBPATH_}FILENAME_H where SUBPATH indicates the subdirectory where the header resides minus the first directory; and FILENAME_H is the name of the file with punctuation and spaces converted to underscores.

Some examples:

  • include/bu.h becomes just BU_H
  • src/libbu/anim.h becomes LIBBU_ANIM_H
  • src/conv/iges/iges.h becomes CONV_IGES_IGES_H

Suggest using the VM if you're not on Linux, but this command will locate all of the header files for you from the top of a source tree checkout:

find . \( -not -regex '.*src/other.*' -not -regex '.*svn.*' -not -regex '.*cmake.*' \) -name \*.h

You can use any language you like to write your script. We have numerous POSIX shell scripts that you can reference in our sh/ directory of a source tree.

Obtain our trunk sources from a Subversion checkout or VM from Sourceforge. Submit your script, which should just run with minimal fuss (no external dependencies preferred) on our source tree.