#!/bin/csh

# $Id: addids 19707 2010-10-29 17:59:36Z d3y133 $

# Given a list of files as arguments loop 
# thru them and determine which do not already
# have CVS Id lines.  For each file that does not
# then determine the file type and insert an
# appropriate comment at the top of the file.
#
# Some stupid Fortran compilers are confused by
# comments outside of a subroutine so we need
# insert them after the first complete statement
# including (ugh) comment lines

set path = ($NWCHEM_TOP/src/util $path)
rehash

foreach file ($*)
  grep '$Id' $file >& /dev/null

  set action = $status

  set filetype = `echo $file | awk -f $NWCHEM_TOP/src/util/filetype.awk`

  if ($status != 0) then
    echo Filetype failed completely on $file
    continue
  endif

  if ($filetype == "Unknown") then
    continue
  endif

  if ($action == 0) then
#   echo $filetype $file already contains a CVS Id
    continue
  else if ($action == 1) then
    echo $filetype $file does not contain a CVS Id
  else
    echo $filetype $file ... error
  endif

  cp $file $file.bak
  if ($status != 0) then
    echo Failed to backup $file to $file.bak
    exit 1
  endif

  if ($filetype == "Fortran" || $filetype == "Fortran-header") then
    awk -f $NWCHEM_TOP/src/util/fortranid.awk < $file > tmp.$$
  else if ($filetype == "C"  || $filetype == "C-header") then
    echo '/*$Id: addids 19707 2010-10-29 17:59:36Z d3y133 $*/' > tmp.$$
    cat $file >> tmp.$$
  else if ($filetype == "Makefile") then
    echo '#$Id: addids 19707 2010-10-29 17:59:36Z d3y133 $' > tmp.$$
    cat $file >> tmp.$$
  else
    echo Don\'t know how to put a comment in a $filetype file
  endif

  cp tmp.$$ $file
  /bin/rm -f tmp.$$

endif

  


end


