From 476f98ab1be38f58cbe51b3184406c86ce52c9dc Mon Sep 17 00:00:00 2001 From: Albert Cheng Date: Wed, 14 Feb 2007 16:33:49 -0500 Subject: [svn-r13307] Improvement Separated the file type guessing from UNKNOWN_TYPE into a function itself to be used by other routines later. Added debug printing feature. --- bin/chkcopyright | 85 +++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 60 insertions(+), 25 deletions(-) diff --git a/bin/chkcopyright b/bin/chkcopyright index 3428457..6893255 100755 --- a/bin/chkcopyright +++ b/bin/chkcopyright @@ -83,6 +83,18 @@ EOF } +# Print Debug output +# +PRINTDEBUG() +{ + if [ -n "$VERBOSE" ]; then + echo $* + else + : # noop + fi +} + + # Generate various styles of Copyright notices # BUILDCOPYRIGHT() @@ -590,6 +602,43 @@ VMSCMD_FILE() } +# Guess the type of file. +# Inspect the first 5 lines to guess what type of file it is. +# +GUESS_File_Type() +{ + if [ $# -ne 1 ]; then + echo "wrong number of arguments($#)" + return + fi + f=$1 + # Now guess the file type. + head -5 < $f > $tmpfile + if head -1 < $tmpfile | grep '^#!' > /dev/null; then + # First line is "#!". It is likely a shell script or similar type. + echo SHELL_FILE + elif grep '\/\*' < $tmpfile > /dev/null; then + # Found some lines containing '/*'. It may be a C/C++ style file. + echo C_SOURCE + elif grep '^!' < $tmpfile > /dev/null; then + # Some lines start with a "!". It may be a Fortran 9X style file. + echo FORTRAN_SOURCE + elif grep '^#' < $tmpfile > /dev/null; then + # Some lines start with a "#". It may be a shell like type. + # Put this after C_SOURCE which may have #define and such lines. + echo SHELL_FILE + elif grep -i '^' < $tmpfile > /dev/null || \ + grep '^