#!/bin/sh
#-----------------------------------------------------------------------
#;  Copyright (C) 2025
#;  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: ADVCHK
#-----------------------------------------------------------------------
# Script to run the ADVCHK sequence to test adverb help file references
#-----------------------------------------------------------------------
if [ -f $SYSLOCAL/AIPWD ] ; then
   LPWD=AIPWD
else
   LPWD=PWD
fi
wd=`$LPWD`
case $wd in
  $AIPS_VERSION) echo "advchk: do not run me in $AIPS_VERSION/\*!!!"
                 exit 1;;
esac
echo "advchk: Current directory is $wd; you have 3 seconds to interrupt"
echo "advchk: if this is not where you want to be..."
sleep 3
echo "advchk: Too late!"
#                                       Create ADVCHK.LIS
if [ -f HLPA.LIST ] ; then
    echo "advchk: HLPA.LIST already exists; This is good"
else
    exit 1
fi
if [ "x$HLPFIL" = "x" ] ; then
   echo "advchk: HLPFIL is not defined!  Define your environment!!"
   exit 1
fi
export MYDIR; MYDIR=$wd
rm -f ADVHLP.OUT ADVHLP.SRT ADVCHK.OUT ADVCHK.chk
echo "advchk: Running ADVHLP to get adverb list from help files"
RUN ADVHLP
if [ $? -eq 0 ] ; then
   echo "advchk: Sorting full list"
   sort -d --key=2,2 -o ADVHLP.SRT ADVHLP.OUT
   echo "advchk: Checking for issues, writing ADVCHK.OUT"
   RUN ADVCHK > ADVCHK.OUT
   if [ $? -ne 0 ] ; then
      echo "advchk: Something went a little caca with ADVCHK..."
      exit 1
   fi
else
   echo "advchk: Something went a little caca with ADVHLP..."
   exit 1
fi
echo "advchk: ends with apparent success"
exit 0
