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