#!/bin/csh -f
#>
#> PACT-INFO - display info about the installed PACT
#>
#> Usage: pact-info [-c] [-t] [-h] [-d] [-e] [-i] [-l] [-m] [-s]
#>
#> Options:
#>          c - Display the source repository commit log
#>          t - Display info for the Version Tags
#>
#>          h - Display the help package
#>
#>          d - Display info for the documents
#>          e - Display info for the executables
#>          i - Display info for the include (header) files
#>          l - Display info for the libraries
#>          m - Display info for the manager script files
#>          s - Display info for the source files
#>
#>          (default) - Display info for the sources, executables,
#>                      libraries and documents.
#>
#
# Modification History:
#   07-07-94  Jan Moura, LLNL:  Added separate options and tags.
#   09-01-94  Jan Moura, LLNL;  Added display of commit log.
#
####################
# include "cpyright.h"
#

# see PCD for the reason for this
set Here = `pwd` ; cd ; set RealHome = `pwd` ; cd $Here ; unset $Here

set UserDir   = `pwd | sed "s|$RealHome|$home|"`
set HelpCode    = $UserDir/$0
set CvsOpt    = ""

set SCSRepository = ""
set SRCDate       = ""

set All = "seld"

set ROOT   = `./pwhich ultra`
set BINDIR = $ROOT:h
set CVSROOTDir = ""
set SrcDir = ""
set BinDir = ""
set LibDir = ""
set IncDir = ""
set MgrDir = ""
set DocDir = ""
set Tags = ""

while ("$1" =~ -*)
   set All = ""
   switch ($1)
      case -c*:
              set CVSROOTDir = `echo $CVSROOT/CVSROOT`
              breaksw

      case -h*:                                  #print Usage:
	      goto Help

      case -d*:
              set DocDir = /SRC/docs/pact
              breaksw

      case -e*:
              set BinDir = "$BINDIR"
              breaksw

      case -i*:
              set IncDir = ( "$BINDIR:h""/include" )
              breaksw

      case -l*:
              set LibDir = ( "$BINDIR:h""/lib" )
              breaksw

      case -m*:
	      set MgrDir = "$UserDir"
              breaksw

      case -s*:
	      if ($?CVSROOT) then
		 set SrcDir = `echo $CVSROOT`
		 set SrcDir = $SrcDir:h/src
	      endif
              breaksw

      case -t*:
                                    # define the Source Control System
              source $UserDir/pact-scs
              set Tags = "-T -a"
              breaksw
              
      default:
 	      goto Help
   endsw
   shift
end

if ($All != "") then
   if ($?CVSROOT) then
      set SrcDir = `echo $CVSROOT`
      set SrcDir = $SrcDir:h/src
   endif
   set BinDir = "$BINDIR"
   set LibDir = ( "$BINDIR:h""/lib" )
   set IncDir = ( "$BINDIR:h""/include" )
   set DocDir = /SRC/docs/pact
endif

if (`uname -s` == "SunOs") then
   set FLAGS  = -lg
else
   set FLAGS  = -l
endif

set Libs = `cat pact.lib`
set Incs = `cat pact.include`
set Bins = ( `cat pact.bin` `cat pact.script` )
set Mgrs = `cat pact.manager`
set Docs = `cat pact.doc`
set Pact = `cat pact.Pact`

echo ""
echo `date`
echo ""

if ($SrcDir != "") then

   set STDOUT = $cwd/src.count
   rm -f $STDOUT
   touch $STDOUT

   cd $SrcDir

   echo PACT sources reside in $SrcDir
   set ACSrc = ""
   foreach i ($Pact)
      set ACSrc = ( $ACSrc `find $i -name "*.[ch]" -print` )
   end
   wc -l $ACSrc | tail -1 | awk '{ printf "%8d\tlines C source (A)\n", $1 }' >>& $STDOUT

   touch foobar
   set AFSrc = ""
   foreach i ($Pact)
      set AFSrc = ( $AFSrc `find $i -name "*.f" -print` )
   end
   wc -l $AFSrc | tail -1 | awk '{ printf "%8d\tlines F77 source (A)\n", $1 }' >>& $STDOUT
   rm foobar
 

   set SSrc = ""
   set SSrc = ( $SSrc `find panacea -name "*.scm" -print` )
   set SSrc = ( $SSrc `find scheme -name "*.scm" -print` )
   set SSrc = ( $SSrc `find sx -name "*.scm" -print` )
   set SSrc = ( $SSrc `find ultra -name "*.scm" -print` )
   wc -l $SSrc | tail -1 | awk '{ printf "%8d\tlines SCHEME source\n", $1 }' >>& $STDOUT

   set PSrc = ""
   set PSrc = ( $PSrc `find manager -name "pre-Make" -print` )
   foreach i ($Pact)
      set PSrc = ( $PSrc `find $i -name "pre-Make" -print` )
   end
   wc -l $PSrc | tail -1 | awk '{ printf "%8d\tlines pre-Make file\n", $1 }' >>& $STDOUT

   cd manager
   wc -l $Mgrs | tail -1 | awk '{ printf "%8d\tlines Manager source\n", $1 }' >>& $STDOUT

   cd ..
   awk '    { lines = lines + $1 \
              print } \
        END { printf "Total maintained source is %d lines\n", lines }' $STDOUT

   rm -f $STDOUT

endif


if ($BinDir != "") then
   echo ""
   echo PACT executables reside in $BinDir
   cd $BinDir
   ls $FLAGS $Bins | awk '    { bytes = bytes + $5 \
                              printf "%8d\t%s %s %s\t%s\n", $5, $6, $7, $8, $9 } \
                        END { printf "Total space for executables is %d bytes\n\n", bytes }'
endif


if ($LibDir != "") then
   echo ""
   echo PACT libraries reside in $LibDir
   cd $LibDir
   ls $FLAGS $Libs | awk '    { bytes = bytes + $5 \
                              printf "%8d\t%s %s %s\t%s\n", $5, $6, $7, $8, $9 } \
                        END { printf "Total space for libraries is %d bytes\n\n", bytes }'
endif


if ($IncDir != "") then
   echo ""
   echo PACT headers reside in $IncDir
   cd $IncDir
   ls $FLAGS $Incs | awk '    { bytes = bytes + $5 \
                              printf "%8d\t%s %s %s\t%s\n", $5, $6, $7, $8, $9 } \
                        END { printf "Total space for headers is %d bytes\n\n", bytes }'
endif


if ($MgrDir != "") then
   echo ""
   echo PACT manager scripts reside in $MgrDir
   cd $MgrDir
   ls $FLAGS $Mgrs | awk '    { bytes = bytes + $5 \
                              printf "%8d\t%s %s %s\t%s\n", $5, $6, $7, $8, $9 } \
                        END { printf "Total space for manager scripts is %d bytes (~%d lines)\n\n", bytes, bytes/26 }'
endif


if ($DocDir != "") then
   echo ""
   echo PACT FAQ files and postscript documents reside in $DocDir
   cd $DocDir
   ls $FLAGS $Docs | awk '    { bytes = bytes + $5 \
                                printf "%8d\t%s %s %s\t%s\n", $5, $6, $7, $8, $9 } \
                          END { printf "Total space for FAQ and ps docs is %d bytes (~%d pages)\n\n", bytes, bytes/3668 }'
endif

if ("$Tags" != "") then
   echo ""
   echo "PACT revision tags (cvs history -T -a):"
   eval "($History $Tags | tail -20 )"
endif

if ("$CVSROOTDir" != "")then
   echo ""
   echo "PACT commit log:"
   eval "more $CVSROOTDir/commitlog"
endif

exit($status)


#................................................... help package
Help:
  awk '($1 == "#>") {print}' $HelpCode      #print Usage:
  exit(1)
