#!/bin/csh -f

# Restore files to their correct state to get timestamps
unzip -o -q ../VMS_LAMPS_20221113.zip
rm -rf index.html LAMPS_*
mv VMS_LAMPS/* .
rmdir VMS_LAMPS/


# rename the contents of [LSLINTERNAL.COM.SRC] to be just
# [LSLINTERNAL.COM], and [LSLSYSTEM.COM.SRC] to be just
# [LSLSYSTEM.COM] for consistency with the other packages.
foreach file ( ` find LAMPS_SRC/LSLINTERNAL/COM/SRC LAMPS_SRC/LSLSYSTEM/COM/SRC -type f ` )
 mv $file $file:h:h/$file:t
end
rmdir LAMPS_SRC/LSLINTERNAL/COM/SRC LAMPS_SRC/LSLSYSTEM/COM/SRC

# Delete some junk
rm LAMPS_SRC/CONVERT/I2DLG/SRC/JNCTEX.F_JMC
rm LAMPS_SRC/CONVERT/I2DXF/SRC/IFF_POLY.BCK
rm LAMPS_SRC/CONVERT/IFF2SIF/SRC/TEXT.SRC_JMC
rm LAMPS_SRC/FLOWLINE/LIBRARY/SRC/FLN_INIT.RFO
rm LAMPS_SRC/IMP/IPATCH/SRC/EDIT_MH.OLD_SRC
rm LAMPS_SRC/IMP/IPATCH/SRC/PRINT_MH.OLD_SRC
rm LAMPS_SRC/IMP/IPATCH/SRC/READ_MH.OLD_SRC
rm LAMPS_SRC/IMP/IPATCH/SRC/TYPE_MH.OLD_SRC
rm LAMPS_SRC/LSLMAINT/OSMHLIB/OSMH_NEW/OSMH_NEW_INI
rm LAMPS_SRC/MATRIX/DTIVIEW/SRC/MODEL_OLD.SRC
rm LAMPS_SRC/POLYGONS/IPOLYGON/SRC/CHECK_COVER_LABEL.OLD_SRC
rm FLOWLINE/COM/FLOWLINEINI.COM_OLD
rm DTMPREPARE/RIV3D/SRC/OLDCHKBOX.SRC
rm DTMPREPARE/RIV3D/SRC/OLDNODHGTS.SRC

# TJL files are editor junk?
rm LAMPS_DOC/PLOTTING/GUIDE/POSTSCRIPT.TJL
rm LAMPS_SRC/LITES2/LITES2/SRC/ANGSQU.TJL
rm LAMPS_SRC/LSLMAINT/GKSMOTIFLIB/SRC/DPS.TJL
rm LAMPS_SRC/LSLMAINT/GKSMOTIFLIB/SRC/GKS2.TJL
rm LAMPS_SRC/LSLMAINT/LDWILDLIB/SRC/LDINIT.TJL

rm -f no_copyright

foreach file ( `find LAMPS_SRC -type f` )

 # Specific files
 switch ( $file:t )
 case 'WIREWRAP.HDR'
  set type='CMN'
  breaksw;
 default:
  # Generic files depending on suffix
  set type = $file:e
  breaksw;
 endsw

 switch ( $type )
 case 'SRC':
 case 'CMN':
 case 'FOR':
 case 'F':
 case 'PAR':
 case 'STR':
 case 'F_ILLINOIS':
 case 'CMN_ILLINOIS':
 case 'F_JMC':
  set comments='C'
  set commentb='C '
  set commente='C'
  breaksw;
 case 'C':
 case 'H':
  set comments='/*'
  set commentb=' '
  set commente=' */'
  breaksw;
 case 'COM':
  set comments='$!'
  set commentb='$! '
  set commente='$!'
  breaksw;
 case 'MAR':
 case 'MAC':
  set comments=';'
  set commentb='; '
  set commente=';'
  breaksw;
 case 'CLD':
  set comments='!'
  set commentb='! '
  set commente='!'
  breaksw;
 case 'CMD':
  set comments=';'
  set commentb='; '
  set commente=';'
  breaksw;
 casde 'PAS':
  set comments='(*'
  set commentb=' '
  set commente=' *)'
  breaksw;
 case 'BCPL_SRC':
 case 'BPL':
  set comments=' //*'
  set commentb=' \/\/'
  set commente=' //*'
  breaksw;
 case 'UIL':
  # recient experience suggests the UIL compiler has 
  # problems with long comments - avoid
  set comments='   /*'
  set commentb=' \*\/\/'
  set commente=' */'
  breaksw;
 case 'MAPID':
 case 'REV':
 case 'UPD':
 case 'CHART':
 case 'TREE':
 case 'RCP':
 case 'RCM':
  continue
  breaksw;
 default:
  echo $file:e >> no_copyright
#  echo $file " : " $file:e
  continue
  breaksw;
 endsw

 echo "$comments
" >tmp
 sed -e "s/^/$commentb/" -e 's/$/\r/' >>tmp <<END_MSG
* This file is part of the LAMPS distribution, released as a software
* preservation project to archive digital history for future historians.
* Copyright (c) 1980-2002 Laser-Scan Ltd, 1Spatial Group Ltd
*
END_MSG
 stat $file |sed -n -e "s/Modify/$commentb* Timestamp of this file for the 2002 release was/p" |sed -e 's/$/\r/' >>tmp
 sed -e "s/^/$commentb/" -e 's/$/\r/' >>tmp <<END_REST_OF_MESSAGE
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see http://www.gnu.org/licenses/.
END_REST_OF_MESSAGE
 echo "$commente
" >>tmp
cat $file >> tmp
mv tmp $file
end

git add LAMPS_SRC

git commit -m 'Add copyright messages' -m 'Also add some missing files.'

cat no_copyright|sort |uniq -c |sort -n
rm no_copyright
