#! /bin/sh
# -*- mode: sh; coding: utf-8 -*-
#
# tla-last-modified
#
# Copyright (C) 2004-2005 Elmar Hoffmann
#
# tla-last-modified extracts the last modification date of a given
# file from a ChangeLog generated by tla.
#
#
# 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.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
#

set -e

CHANGELOG="ChangeLog"

if [ $# -eq 2 ]; then
    CHANGELOG="$2"
elif [ $# -ne 1 ]; then
    echo "Usage: $(basename $0) FILE [CHANGELOG]"
    exit 1
fi

# escape file name
file=`echo $1 | sed 's,\(\.\|\+\|/\),\\\\\1,g'`

sed -n "
# copy date to hold space
s/^\([0-9]\+-[0-9]\+-[0-9]\+ [0-9]\+:[0-9]\+:[0-9]\+ GMT\)\t.*\$/\1/
T nodate
h
b next
: nodate

# check if file is in list of modified files
/^ *\(new\|modified\) files:$/b files
b next
: files
n
/$file/b print
b next

# print date from hold space
: print
g
p
q
: next
" ${CHANGELOG}
