#!/bin/sh
# Fix up the @since tags
# @author: Christopher Hylands
# @version: $Id: fixsince 47892 2008-01-24 01:28:30Z cxh $
#
# There are several cases
# 1. The file is new between releases and has no tag
# 2. The file is new between releases and has the wrong tag
# 3. An old file has the incorrect tag

# The first thing to do is to generate a list of new files
# by running diff between the old release and the new release

oldVersion=6.0.2
newVersion=7.0.devel

diffOutput=/tmp/fixsince.diffOutput.$$
diffOutput=/tmp/pt.diffs
if [ ! -f $diffOutput ]; then
    echo "Generating $diffOutput, this will take awhile"
    diff -r $PTII/adm/dists/ptII$oldVersion \
	$PTII/adm/dists/ptII$newVersion > $diffOutput
fi
ls -l $diffOutput

newJavaFiles=/tmp/fixsince.newJavaFiles
if [ ! -f $newJavaFiles ]; then
    echo "Creating $newJavaFiles"
    egrep "^Only in ${PTII}/adm/dists/ptII${newVersion}/" $diffOutput |
        egrep '.java$' |
        sed -e 's/Only in //' -e 's@: @/@' |
	grep -v DEThreadActor.java > $newJavaFiles 
fi
ls -l $newJavaFiles

if [ ! -f $newJavaFiles ]; then
    echo "$0: Can't find $newJavaFiles to determine which files are new, exiting"
    exit 9 
fi

files=`cat $newJavaFiles`
for file in $files
do
  grep @since $file >& /dev/null 
  retval=$?
  tmpfile=/tmp/fixsince.tmpfile
  tmpfile2=/tmp/fixsince.tmpfile2
  if [ $retval = 1 ]; then
    echo "$file does not have an @since tag"
    awk '{  if ($0 ~ /@version/) {
	       print $0
	       print "@since Ptolemy II 6.1"
	    } else {
	       print $0
            }
         }' <$file >$tmpfile
  else
    echo $file  
    sed -e 's/@since.*/@since Ptolemy II 6.1/' \
	$file > $tmpfile

  fi
  sed -e 's/Copyright (c) 200[0-9]-200[0-9]/Copyright (c) 2008/' \
      -e 's/Copyright (c) 199[0-9]-200[0-9]/Copyright (c) 2008/' \
      -e 's/Copyright (c) 200[0-6]/Copyright (c) 2008/' \
	< $tmpfile > $tmpfile2
    diff $file $tmpfile2

  # If everything looks alright, edit /tmp//fixsince.newJavaFiles and
  # remove the leading adm/dists/ptIIX.Y.devel and then uncomment the
  # lines below and rerun in $PTII
   
  #cp $tmpfile2 $file
  #cvs commit -m "This file is new since Ptolemy 6.1, so the copyright and @since tag should reflect that." $file
done
