Checking file header with Adacontrol


Many times you want to make sure that your code has correct comment block at the beginning of the source code file. This comment block can contain the source code license, copyright information, the name of the author, or description of the file.

Adacontrol can help you here with its header_comments rule. For example:

check header_comments (minimum, 10);
search header_comments (model, "licenseheader.pat");

The first line checks that the header comments is at least 10 lines long. The second line compares the header comments against a pattern file "licenseheader.pat", which contains a template how the header block should look like, and warns if the header does not match to the file.

Example pattern file could be something like this:

*
^-- My Ada Program$
^--$
^-- Copyright \(c\) 20.+$
^--$
^-- Permission to use, copy, modify, and distribute this software for any$
^-- purpose with or without fee is hereby granted, provided that the above$
^-- copyright notice and this permission notice appear in all copies.$
^--$
^-- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES$
^-- WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF$
^-- MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR$
^-- ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES$
^-- WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN$
^-- ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF$
^-- OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.$

The pattern file syntax is explained in the Adacontrol User Manual (basically each line is a regular expression).