#!/bin/sh
#############################################################################
##
#W  maketoc          GAP share package 'atlasrep'               Thomas Breuer
##
#H  @(#)$Id: maketoc,v 1.13 2001/02/27 15:08:55 gap Exp $
##
#Y  Copyright (C)  2001,  Lehrstuhl D fuer Mathematik,  RWTH Aachen,  Germany
##
##  This script produces the file 'pkg/atlasrep/gap/atlasprm.g'
##  of {\GAP}~4 from the data on a remote server.
##
##  It must be called from the directory 'pkg/atlasrep',
##  in the form `etc/maketoc <gap>' or `etc/maketoc <gap> -v'
##  or `etc/maketoc <gap> -v -test',
##  where <gap> must be a command to call {\GAP}~4,
##  and the options `-v' and `-test' mean verbose output and the execution
##  of some consistency checks, respectively.
##


#############################################################################
##
##  The output is written to 'OUTFILE', whose string version is 'OUTNAME'.
##  'TMPFILE' is an intermediate file.
##  The old version of 'OUTFILE' is saved in 'OLDFILE'.
##
OUTFILE=gap/atlasprm.g
OUTNAME="gap/atlasprm.g"
TMPFILE=gap/atlasprm.new
OLDFILE=gap/atlasprm.old

rm -rf $TMPFILE


#############################################################################
##
##  Copy the header of the old file with the remote table of contents.
##
awk -v "OUTNAM=$OUTNAME" \
    'BEGIN {
         while ( getline < OUTNAM && $0 !~ /do not edit/ ) {
             print $0;
         }
         print $0;
         printf( "##\n\n" );
     }' > $TMPFILE


#############################################################################
##
##  Create the current remote table of contents, using the server data.
##
$1 -q <<EOF
RequirePackage( "atlasrep" );
AtlasOfGroupRepresentationsToDoInMakeTOC( [ "$2", "$3$" ], "$TMPFILE" );
quit;
EOF


#############################################################################
##
##  Add the info about the end of the file ...
##
echo '#############################################################################' >> $TMPFILE
echo '##' >> $TMPFILE
echo '#E' >> $TMPFILE
echo '' >> $TMPFILE


#############################################################################
##
##  Save the old version of the file, and replace it by the new version.
##
mv $OUTFILE $OLDFILE
mv $TMPFILE $OUTFILE


#############################################################################
##
##  Print the differences between old and new version.
##
diff -u $OLDFILE $OUTFILE


#############################################################################
##
#E

