From ea9707ccdf1b77d9444c1317a5240219a44b6c65 Mon Sep 17 00:00:00 2001 From: Albert Cheng Date: Tue, 1 Nov 2005 11:59:59 -0500 Subject: [svn-r11652] Purpose: Improvement Description: The copyright notice of some files may contain some white spaces such as tabs, trailing blanks and \r (common in Windows files). Diff will flag them as not matching. Could not just use -b or -w of diff because it will ignore embedded spaces and could not handle \r anyway. Solution: Added a RINSE function will remove all \r and trailing spaces and expand tabs to proper number of spaces. Now, diff can compare without worry of cosmetic white spaces. Platforms tested: heping, applying on a Windows/copy_hdf.bat file. --- bin/chkcopyright | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/bin/chkcopyright b/bin/chkcopyright index aa4098f..ccd3fe2 100755 --- a/bin/chkcopyright +++ b/bin/chkcopyright @@ -257,6 +257,19 @@ PARSE_OPTION() } +# Rinse the file by, +# removing all \r which is often present in Windows files; +# replace tabs with equivalent spaces; +# removing all trailing spaces. +# $1 is the file to be rinsed. +RINSE() +{ + rf=$1 + cp $rf $tmpfile + dos2unix < $tmpfile | expand | sed -e 's/ *$//' > $rf +} + + # Match Copyright notice. # $1 file which contains the expected copyright notice. # $2 file in which to look for the copyright notice. @@ -277,6 +290,7 @@ MATCH_COPYRIGHT() nlines=`wc -l < ${COPYRIGHTFILE}| tr -d ' '` head -$NUMBEGINLINES < $f | sed -n -e "/${COPYRIGHTSTR}/"',$p' | \ head -${nlines} > ${EXTRACTEDFILE} + RINSE ${EXTRACTEDFILE} $DIFF ${EXTRACTEDFILE} ${COPYRIGHTFILE} >/dev/null 2>&1 if test $? -eq 0; then echo PASSED @@ -331,7 +345,8 @@ HTML_FILE() COPYRIGHTFILE=$HTM_COPYRIGHT # Must use stdin for wc to prevent filename from popping up. nlines=`wc -l < ${COPYRIGHTFILE}| tr -d ' '` - sed -n -e '/^$/p' < $f | head -${nlines} > ${EXTRACTEDFILE} + sed -n -e '/^/p' < $f | head -${nlines} > ${EXTRACTEDFILE} + RINSE ${EXTRACTEDFILE} $DIFF ${EXTRACTEDFILE} ${COPYRIGHTFILE} >/dev/null 2>&1 if test $? -ne 0; then # show the differences @@ -501,8 +516,8 @@ while read file; do # Ignore binary data files continue ;; - *.zip | *.dsp | *.dsw) - # Ignore Windows binary files + *.zip | *.dsp | *.dsw | *.js) + # Ignore Windows binary or special files. continue ;; *CVS/* ) -- cgit v0.12