#! /bin/sh
###=====================================================================
### Read the contents of a .jar-lst file, extracting the latest file
### time, and then use it to reset the modification times of the
### associated archive and .html files.  The times of directory files
### and the MANIFEST.MF file are ignored, since they are modified during
### the creation of the .jar archive.
###
### An older version of this file used the .tar-lst file, but that lacks
### the seconds data from the time stamp.  This version for .jar-lst
### files is somewhat more complex, but at least recovers fully accurate
### time stamps.
###
### Usage:
###	./set-archive-times-2.sh jar-lst-file(s)
###
### Any files specified on the command line which are not .jar-lst files
### are silently ignored.
###
### [19-Jan-2000]
###=====================================================================

for f in "$@"
do
	g=`basename $f .jar-lst`
	if test $g != $f
	then
		cmd=`awk '
		$NF == "META-INF/MANIFEST.MF" { next }
		$NF ~ "/$" { next }
		NF == 8 {
			monthnum = (int(index("Jan.Feb.Mar.Apr.May.Jun.Jul.Aug.Sep.Oct.Nov.Dec.",$3)/4) + 1);
			YMDHMS = sprintf("%04d-%02d-%02d%s",$7,monthnum,$4,$5);
			if (YMDHMS > Last_YMDHMS) Last_YMDHMS = YMDHMS
		}
		END {print "touch -m -t " substr(Last_YMDHMS,1,4) \
			substr(Last_YMDHMS,6,2) substr(Last_YMDHMS,9,2) \
			substr(Last_YMDHMS,11,2) substr(Last_YMDHMS,14,2) \
			"." substr(Last_YMDHMS,17,2)}' $f`
		for e in arc arc-lst html jar jar-lst tar.gz tar-lst zip zip-lst zoo zoo-lst
		do
			if test -f $g.$e
			then
				echo $cmd $g.$e
				eval $cmd $g.$e
			fi
		done
	fi
done
