#!/bin/sh
#
# fol -- list the followups to the current article ($A).
#
# Invoke from "readnews" or "vnews" as "!fol" or "!fol -v".
# This may be compatible with other UNIX news readers as is, or with some
# minor modifications.
#
# If invoked as "fol -v" (or with any other argument) you are placed
# in "view" on the followups, if there are any.
#
# This is for netnews users who have ants in their pants wanting to followup
# to a post, but want to be sure nobody else has said the same thing first :-).
# It is written in boring but ubiquitous Bourne Shell for maximum portability.
#
# Written 5/2/90 by Dan Levy, ttbcad!levy, AT&T Bell Labs
#

PATH=/usr/5bin:/bin:/usr/bin:/usr/ucb/bin:$PATH; export PATH

echo	#in case not already at the left margin

if test -z "$A"
then
	echo \$A is null or not set >&2
	exit 1
elif test ! -f "$A" -o ! -r "$A"
then
	echo File \$A="'$A'" not found or unreadable >&2
	exit 1
fi

case $A in
	/*)	;;
	*)	echo File \$A="'$A'" not a full path name >&2
		exit 1
		;;
esac

F=`basename $A`

if expr $F : '[1-9][0-9]*$' >/dev/null
then
	:
else
	echo FILE \$A="'$A'" does not have numeric basename >&2
	exit 1
fi

D=`dirname $A`

cd $D || exit 1

M=`grep '^Message-ID:' $A | line | (read M I R; echo $I)`

if test -z "$M"
then
	echo FILE \$A="'$A'" has no Message-ID in it >&2
	exit 1
fi

echo Looking for followups to $F in this news group

L=`ls | awk '($1 + 0 > '$F')' | sort -n`
FU=`grep "^References:" $L /dev/null |
	awk -F: '(index($0,"'$M'") > 1) { print $1 }`

if test -n "$FU"
then
	echo Followups to $F in this news group: $FU
	if test $# -ne 0
	then
		echo Type return to enter \"view\" on followups:
		read x
		view $FU
	fi
else
	echo No followups to $F found in this news group
fi

exit 0
