#!/bin/sh
#-----------------------------------------------------------------------
#;  Copyright (C) 1995, 2003, 2024
#;  Associated Universities, Inc. Washington DC, USA.
#;
#;  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; either version 2 of
#;  the License, or (at your option) any later version.
#;
#;  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, write to the Free
#;  Software Foundation, Inc., 675 Massachusetts Ave, Cambridge,
#;  MA 02139, USA.
#;
#;  Correspondence concerning AIPS should be addressed as follows:
#;         Internet email: aipsmail@nrao.edu.
#;         Postal address: AIPS Project Office
#;                         National Radio Astronomy Observatory
#;                         520 Edgemont Road
#;                         Charlottesville, VA 22903-2475 USA
#-----------------------------------------------------------------------
# Usage: SHOPH
#-----------------------------------------------------------------------
# Script to run the SHOPH sequence to test help file shopping lists
# - the ZZ*.HLP files used by ABOUT - against the current help files.
#-----------------------------------------------------------------------
if [ -f $SYSLOCAL/AIPWD ] ; then
   LPWD=AIPWD
else
   LPWD=PWD
fi
wd=`$LPWD`
case $wd in
  $AIPS_VERSION) echo "shoph: do not run me in $AIPS_VERSION/\*!!!"
                 exit 1;;
esac
echo "shoph: Current directory is $wd; you have 3 seconds to interrupt"
echo "shoph: if this is not where you want to be..."
sleep 3
echo "shoph: Too late!"
#                                       Create SHOPH.LIS
if [ -f SHOPH.LIS ] ; then
   echo "shoph: SHOPH.LIS already exists; Please mv or rm!"
   exit 1
elif [ "x$HLPFIL" = "x" ] ; then
   echo "shoph: HLPFIL is not defined!  Define your environment!!"
   exit 1
fi
echo "HLPFIL" >SHOPH.LIS
nf=`ls $HLPFIL/*.HLP | tee -a SHOPH.LIS | wc -l`
echo "shoph: Created SHOPH.LIS with $nf help files"
export MYDIR; MYDIR=$wd
rm -f SHOPA.LIS SHOPA.OUT shopping.list ZZ*.HLP ZZ*.TMP ZZ*.TEX
cp SHOPH.LIS SHOPA.LIS
echo "shoph: Running SHOPA to get list from help files"
RUN SHOPA
if [ $? -eq 0 ] ; then
   echo "shoph: Sorting full list"
   sort +0 -4 -u -f -o shopping.sort SHOPA.OUT
   echo "shoph: Converting to ZZ*.HLP and checking for changes"
   RUN SHOPH
   if [ $? -ne 0 ] ; then
      echo "shoph: Something went a little caca with SHOPH..."
      exit 1
   fi
else
   echo "shoph: Something went a little caca with SHOPA..."
   exit 1
fi
echo "shoph: ends with apparent success"
exit 0
