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

Consistent preprocessor include guards for all include/ headers (78 headers)

completed by: Peter Amidon

mentors: Sean

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

... file contents ...

#endif /* THIS_HEADER */

This tasks basically involves editing that THIS_HEADER string so that it's using a consistent naming convention. Some of our files use a convention like __FILE_H__ while others use FILE_H or FILE_H__ and others still using some other convention.

Your job is to make them all the same, based on the file name, for all headers in the include/ directory. 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/whatever.h becomes LIBBU_WHATEVER_H
  • src/conv/step/step.h becomes CONV_STEP_STEP_H


  • include/

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 | grep include

This is a lot of edits, but they are very simple edits. You don't even really need to understand C to do this task, but it might help you go a little faster. You're welcome to write a script or not.

You do need to be able to first compile BRL-CAD successfully so you can recompile during/after your edits and know whether you changed anything wrong.

Obtain our trunk sources from a Subversion checkout or VM from Sourceforge. Submit a patch file of all your changes: svn diff > my_patch.diff