#************************************************************************
#*
#*	Copyright (c) 1984, 1991 Micro Focus Ltd.
#*
#*	All  rights reserved.  No part of this program or  publication
#*	may  be  reproduced,  transmitted,  transcribed,  stored  in a
#*	retrieval system,  or translated into any language or computer
#*	language, in any form or by any means, electronic, mechanical,
#*	magnetic,  optical, chemical, manual or otherwise, without the
#*	prior written permission of:
#*
#*	Micro Focus Ltd,
#*	26 West Street, Newbury, Berkshire, United Kingdom.             
#*	(0635) 32646
#*
#*	Filehandler Utilities Demos
#*
#*	Source Module setup	Sccs Identification 1.2
#*
#*	Last Modified on 91/06/10 at 10:48:12
#*
#************************************************************************/

# static	char *SccsId = "@(#)setup	1.2";

#
# COBOL source files
#

CBLFILES="convert1 create edit edit2 info1 info1a info2 info2a rebuild validate validate2 reorg1 reorg2 reorg3"

#
# data files
#

DATAFILES="demofile demofile2 demofile3 demofile4 demofile5 demofile6 demofile7 demofile8 demofile9 demofile10"

#
# index files
#

IDXFILES="demofile demofile2 demofile3 demofile4 demofile5 demofile9 demofile10"

#
# Backup corrupt file
#

BACKUPCORRUPT="badfile badfile.idx"

#
# parameter files
#

PARAMFILES="convert.ind convert.inf convert.lsq convert.rel convert.seq create.cre create.inf edit.edi info1.inf info2.inf validate.inf validate.val reorg.reo"

echo " "
echo "# "
echo "# Filehandler Utilities Demos Setup"
echo "# "
echo " "
echo " "
echo "# Setting up directory for using the demonstration files"
echo " "
echo "# Checking directory contents..."
echo " "

for i in $CBLFILES
do
       if test ! -f $i.cbl
       then
          echo "ERROR: COBOL source file $i.cbl is missing reinstall demos "
          exit 1
       fi
done

for i in $BACKUPCORRUPT
do
       if test ! -f $i
       then
          echo "ERROR: backup corrupt file $i is missing reinstall demos"
          exit 1
       fi
done

for i in $PARAMFILES
do
       if test ! -f $i
       then
          echo "ERROR: Parameter file $i is missing reinstall demos"
          exit 1
       fi
done
echo "# All necessary files are present"
echo " "
echo "# Removing data files..."
echo " "

#
# remove all data files
#

for i in $DATAFILES
do
       rm -f $i
       if test ! $? = 0
       then 
             echo "ERROR: Could not remove datafile $i, check permissions and rerun"
       fi
done

#
# remove all index files
#

for i in $IDXFILES
do
       rm -f $i.idx
       if test ! $? = 0
       then 
             echo "ERROR: Could not remove index file $i.idx, check permissions and rerun"
       fi
done

#
# reinstate corrupt file from its backup
#

echo "# Reinstating corrupt file..."
echo " "
cp badfile corrupt
if test ! $? = 0
then 
       echo " "
       echo "ERROR: Could not copy file badfile to corrupt, check permissions and rerun"
       exit 1
fi

cp badfile.idx corrupt.idx

if test ! $? = 0
then 
       echo " "
       echo "ERROR: Could not copy file badfile.idx to corrupt.idx, check permissions and rerun"
       exit 1
fi

echo "# Compiling COBOL sources..."
echo " "

#
# Compile all COBOL source files
#

for i in $CBLFILES
do
       cob $i.cbl > /dev/null
       if test ! $? = 0
       then
          exit 1
       fi
done

echo "# Compilation Complete"
echo " "
echo "# Setup Complete"
echo " "
echo "# You are now ready to run the demos"
echo " "
