echo"ERROR: The templates directory "${template_dir}" doesn't exist." 1>&2
exit 1
fi
# set the temporary file location
tmpfile=/tmp/source_file.$$
rm-f${tmpfile}
# check number of lines in the template file
lines=`cat${template_dir}/${header} | wc-l`
# the template file has one empty line at the end, we need to ignore it
lines=`expr${lines} - 1`
# A loop through the all script parameters:
#
# 1. Given a set of source files and a license template header, read a file name of each source file.
# 2. Check if a given file exists. When a directory is encountered, dive in and process all sources in those directories.
# 3. Read each line of the given file and check it for a copyright string.
# 4. If a copyright string found, check the correctness of the years format in the string and replace years with %YEARS%.
# 5. Continue reading the file until the number of lines is equal to the length of the license template header ($lines) and remove a comment prefix for each line.
# 6. Store the result (the license header from a given file) into a temporary file.
# 7. If a temporary file is not empty, compare it with a template file to verify if the license text is the same as in a template.
# 8. Produce a error in case a temporary file is empty, it means we didn't find a copyright string, or it's not correct
#
while["$#"-gt"0"];do
touch${tmpfile}
# In case of the directory as a parameter check recursively every file inside.
if[-d$1];then
curdir=`pwd`
cd$1
echo"*** Entering directory: "`pwd`
echo"***"
files=`ls .`
sh ${script_dir}/${script_name}${first_option}${files}
status=$?
if[${error_status}-ne 1 ];then
error_status=${status}
fi
cd${curdir}
shift
continue
else
echo"### Checking copyright notice in the file: "$1
echo"###"
fi
# Check the existence of the source file.
if[!-f$1];then
echo"ERROR: The source file "$1" doesn't exist." 1>&2
error_status=1
shift
continue
fi
# read the source file and determine where the header starts, then get license header without prefix
counter=0
while read line ;do
# remove windows "line feed" character from the line (if any)