
Simon Nivault <simon.nivault@lrde.epita.fr> writes:
URL: https://svn.lrde.epita.fr/svn/lrde-tools/trunk
ChangeLog: 2007-11-15 Simon Nivault <simon.nivault@lrde.epita.fr>
Tool for checking guards of header files of a project.
* README: Add description. * src/check-guards: New.
Cool!
Index: trunk/src/check-guards =================================================================== --- trunk/src/check-guards (revision 0) +++ trunk/src/check-guards (revision 454) @@ -0,0 +1,39 @@ +#!/bin/sh + +# Utility to check guards of header files. +# Usage : ./check-guards BASE SUB... +# +# - BASE : Specify the root of the project. +# For example, here an header file : +# /home/user/proj1/prj/module1/header.hh +# The path '/home/user/proj1/' should be used +# if the expected guard for this file is +# "PRJ_MODULE1_HEADER_HH". +# Warning! BASE must end with one '/' +# +# - SUB : Specify the element you want to verify. +# Those element can be either directories or files +# and are expected to be located in BASE. +# +############################################################ + +base_dir=$1 +shift +loc=$@ + +for sub in $loc
In fact, you can just write for sub here, and get rid of `loc' (by default, for iterates on `$@' [1]).
+ do + for file in $(find ${base_dir}$sub -name '*.hh') + do + expr1=$(echo "${file##$base_dir}" | tr "[:lower:]" "[:upper:]" | tr "[:punct:]" "_")
It's still nice to use lines smaller than 80 columns (even in shell scripts!). :)
+ expr2=$(cat $file | grep "#ifndef" | grep HH | cut -d ' ' -f 2) + expr3=$(cat $file | grep "# define" | grep HH | cut -d ' ' -f 3) + expr4=$(cat $file | grep "#endif" | grep HH | cut -d ' ' -f 4)
Instead of cat file | cmd ... you can just write cmd <file ... (it saves a fork).
+ if [ "$expr1" = "$expr2" -a "$expr1" = "$expr2" -a "$expr1" = "$expr2" ]; then
Likewise with the 80 columns. Moreover, this lines looks weird. Didn't you want to write if [ "$expr1" = "$expr2" -a \ "$expr1" = "$expr3" -a \ "$expr1" = "$expr4" ]; then instead ?
+ res=OK + else + res="KO, should be $expr1" + fi + echo "${file##$base_dir} : $res" + done +done \ No newline at end of file
Text files shall end with a newline character.
Index: trunk/README =================================================================== --- trunk/README (revision 453) +++ trunk/README (revision 454) @@ -139,6 +139,9 @@ ** src/apatche Send patches to a mailing list.
+** src/check-gards +Check recursivly all the guards of header files.
s/recursivly/recursively/ s/header/C and C++ header/ Thanks for this contribution! :) Notes: [1] See Bash's manual for instance: for name [ in word ] ; do list ; done The list of words following in is expanded, generating a list of items. The variable name is set to each element of this list in turn, and list is executed each time. If the in word is omit- ted, the for command executes list once for each positional parameter that is set (see PARAMETERS below). The return status is the exit status of the last command that executes. If the expansion of the items following in results in an empty list, no commands are executed, and the return status is 0.