#!/bin/sh
# $Header: newsgroups.SH,v 4.3 85/05/01 11:43:27 lwall Exp $
# 
# $Log:	newsgroups.SH,v $
# Revision 4.3  85/05/01  11:43:27  lwall
# Baseline for release with 4.3bsd.
# 

export PATH || (echo "OOPS, this isn't sh.  Desperation time.  I will feed myself to sh."; sh $0; kill $$)

: syntax: newsgroups [pattern] [pipeflag]

: System Dependencies

: You might want to change pager to a "make column" program if you have one.
: On the other hand, if your kernel does paging, cat would probably do.
pager="/usr/ucb/more"
active="/tmp/active.$$"

: End of system dependencies, hopefully

/news/lib/getactive $active

if /bin/test $# -ge 2 ; then
    pager=/bin/cat
else
    /bin/echo "Completely unsubscribed newsgroups:"
fi

dotdir=${DOTDIR-${HOME-$LOGDIR}}

: Throwing .newsrc into the pot twice is a lovely hack to prevent
: bogus newsgroups from showing up as unsubscribed.

/bin/cat $dotdir/.newsrc $dotdir/.newsrc $active | \
/bin/sed	-e '/^options/d' \
	-e '/^[	 ]/d' \
	-e '/^control/d' \
	-e '/^to\./d' \
	-e 's/^\([^ !:]*\)[ !:].*$/\1/' \
	-e "/.*$1/p" \
	-e 'd' | \
/bin/sort | /usr/bin/uniq -u | $pager
if /bin/test $# -ge 2 ; then
    exit
fi
/bin/echo -n "[Type return to continue] "
read tmp
/bin/echo ""
/bin/echo "Unsubscribed but mentioned in .newsrc:"
/bin/sed < $dotdir/.newsrc \
	-e "/$1.*!/"'s/^\([^!]*\)!.*$/\1/p' \
	-e 'd' | \
/bin/sort | $pager
