#!/bin/ksh
#
# $Revision: 1.2 $ $Date: 2012-07-26 17:11:47-04 $
# $Source: /home/vogelke/bin/RCS/addmtime,v $
# $Host: sys7.com $
# $UUID: bb38ca26-5c76-3577-92cb-4a94e7eb27cd $
#
#<addmtime: prepend modtime to build files, restore original modtime.

PATH=/opt/sfw/bin:/usr/sfw/bin:/bin:/usr/bin
export PATH

# Save arg list.

case "$#" in
    0) echo need a file; exit 1 ;;
    *) argv="$*" ;;
esac

# Write the modtime for each file to a new copy,
# rename it, and reset the modtime.

for file in $argv
do
    set X $(stat -c '%y' $file)
    shift
    case "$#" in
        0) continue ;;
        *) ts="$*" ;;
    esac

    (date -d "$ts"; echo; cat $file) > $file.n
    touch -d "$ts" $file.n && mv $file.n $file
done

exit 0
