#!/bin/bash
#
#


#------
#   Build the sed editing script.
#------
YEAR=`date | awk '{print $6}'`
echo "it is now $YEAR"

echo "s/Copyright (c) 20[0-9][0-9] QUALCOMM/Copyright (c) ${YEAR} QUALCOMM/g" >temp-sed-edit

#------
#   Get list of all affected source files.
#------
FILE_LIST=`grep -l -r "Copyright (c) 20[0-9][0-9] QUALCOMM" *`
echo ${FILE_LIST}

p4 edit $FILE_LIST

#------
#   Loop through all affected files
#------
for file in $FILE_LIST
do
    echo "editing $file..."
    TEMP_NAME="${file}.preserve"
    if test -f $TEMP_NAME
    then
        echo "  >>> file $TEMP_NAME exists! <<<"
        exit 1
    fi
    mv $file $TEMP_NAME

    sed -f temp-sed-edit $TEMP_NAME > $file
done

for file in $FILE_LIST
do
    TEMP_NAME="${file}.preserve"
    rm $TEMP_NAME
done

p4 revert -a $FILE_LIST
rm temp-sed-edit

