#!/bin/csh -ef
# $Id: list_paths,v 1.1.2.1 2013/12/18 17:47:54 Niki.Zadeh Exp $
#-----------------------------------------------------------------------
#              list_paths: CVS administrative script
#
# AUTHOR: V. Balaji (vb@gfdl.gov)
#         SGI/GFDL Princeton University
#
# 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.
#
# For the full text of the GNU General Public License,
# write to: Free Software Foundation, Inc.,
#           675 Mass Ave, Cambridge, MA 02139, USA.
#-----------------------------------------------------------------------
# script to be run from the CVSROOT/modules file to create path lists
# $1 contains the name of the archive being checked out
# this script creates two files:
# path_names contains all the source files ( *.{c,C,f,F,fh,f90,F90,h,H,inc} )
# path_names.html contains all the doc files ( *.{html,ps,txt}, README, readme )
# NOTE: if these files exist, they are appended to.
#       This is necessary, since for aliases that checkout multiple
#       directories you need to keep the results from earlier checkouts.
#       This could yield unexpected results if you use the same working
#       directory for different experiments using different modules. You
#       must remove these files if beginning a fresh experiment.

set argv = (`getopt o: $*`)
set out = "$cwd/path_names"
#---------------------------------------------------
while ("$argv[1]" != "--")
    switch ($argv[1])
        case -o:
            set out = $argv[2]; shift argv; breaksw
    endsw
    shift argv
end
shift argv
#---------------------------------------------------

unset noclobber
if( $?DEBUG )echo Running $0 in $cwd, args $*

set src = "$out.src.tmp" 
set doc = "$out.doc.tmp"
set outdoc = "$out.html"

touch $out	# create the file if it doesn't exist
cp $out $src
find $* -type f \
 \( -name \*.c   \
 -o -name \*.C   \
 -o -name \*.f   \
 -o -name \*.fh  \
 -o -name \*.F   \
 -o -name \*.f90 \
 -o -name \*.F90 \
 -o -name \*.h   \
 -o -name \*.H   \
 -o -name \*.inc \
 \) -print >> $src

sed 's:.*/\(.*\):\0 \1:' $src | nl | sort --key 3 -u | sort -n | awk '{print $2}' > $out
echo "A list of the files you checked out is in the file $out ..."

touch $doc	# create the file if it doesn't exist
find $* -type f \
 \( -name \*.html \
 -o -name \*.ps   \
 -o -name \*.txt  \
 -o -name \*.pdf  \
 -o -name \*.jpg  \
 -o -name readme  \
 -o -name read_me \
 -o -name README  \
 \) -print > $src
if ( -z $src ) then
   rm -f $doc $src
   exit
endif
# $src has non-zero size (i.e some doc exists)
cat $src >> $doc

#write path_names.html file
echo "<title>Documentation in current working directory</title>"           > $outdoc
echo "<h1>Documentation in current working directory</h1>"                >> $outdoc
sort -u $doc | awk '{print "<p><a href=\"" $1 "\">" $1 "</a>"}'           >> $outdoc
echo '<p><hr><small>This file was automatically generated by list_paths.' >> $outdoc
echo '$Revision: 1.1.2.1 $ $Date: 2013/12/18 17:47:54 $'                 >> $outdoc

rm -f $doc $src
