[comp.sources.misc] v07i008: News subject index routines

allbery@uunet.UU.NET (Brandon S. Allbery - comp.sources.misc) (06/04/89)

Posting-number: Volume 7, Issue 8
Submitted-by: nelson@uncw.uucp (doom)
Archive-name: nsubj

[PLEASE, people!  This came with no subject line and no information outside
the shar.  This isn't exactly polite.  ++bsa]

#! /bin/sh
# This is a shell archive.  Remove anything before this line, then unpack
# it by saving it into a file and typing "sh file".  To overwrite existing
# files, type "sh file -c".  You can also feed this as standard input via
# unshar, or by typing "sh <file", e.g..  If this archive is complete, you
# will see the following message at the end:
#		"End of archive 1 (of 1)."
# Contents:  MANIFEST Makefile README crontabentry jimsindex.c subj.1
#   subj.c subj.old subjc.8 subjc.c subjn subjn.8
# Wrapped by nelson@uncw on Mon May 22 14:14:03 1989
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'MANIFEST' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'MANIFEST'\"
else
echo shar: Extracting \"'MANIFEST'\" \(486 characters\)
sed "s/^X//" >'MANIFEST' <<'END_OF_FILE'
X   File Name		Archive #	Description
X-----------------------------------------------------------
X MANIFEST                   1	This shipping list
X Makefile                   1	
X README                     1	
X crontabentry               1	
X jimsindex.c                1	
X subj.1                     1	
X subj.c                     1	
X subj.old                   1	
X subjc.8                    1	
X subjc.c                    1	
X subjn                      1	
X subjn.8                    1	
END_OF_FILE
if test 486 -ne `wc -c <'MANIFEST'`; then
    echo shar: \"'MANIFEST'\" unpacked with wrong size!
fi
# end of 'MANIFEST'
fi
if test -f 'Makefile' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'Makefile'\"
else
echo shar: Extracting \"'Makefile'\" \(631 characters\)
sed "s/^X//" >'Makefile' <<'END_OF_FILE'
XCFLAGS=-O #-DSYSV
XSRC= Makefile README subj.1 subjc.8 subjn.8 subj.c \
Xsubj.old subjc.c jimsindex.c subjn crontabentry
XBINDIR=/usr/local/bin
XMANDIR1=/usr/man/man1
XMANDIR8=/usr/man/man8
X
XOBJS=subj.o subjc.o jimsindex.o
X#Sequent users will know what the following line is, others
X#remove the &
XP=&
Xall: $(P) subj subjc
Xsubj: $(P) subj.o jimsindex.o
X	cc -o subj -s subj.o jimsindex.o
Xsubjc: $(P) subjc.o jimsindex.o
X	cc -o subjc -s subjc.o jimsindex.o
Xinstall: subj subjc
X	mv subj $(BINDIR)
X	mv subjc $(BINDIR)
X	cp subj.1 $(MANDIR1)
X	cp subjc.8 $(MANDIR8)
X	cp subjn.8 $(MANDIR8)
Xclean:
X	rm *.o subj subjc
Xshar: 
X	makekit  -m $(SRC)
X	
END_OF_FILE
if test 631 -ne `wc -c <'Makefile'`; then
    echo shar: \"'Makefile'\" unpacked with wrong size!
fi
# end of 'Makefile'
fi
if test -f 'README' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'README'\"
else
echo shar: Extracting \"'README'\" \(1274 characters\)
sed "s/^X//" >'README' <<'END_OF_FILE'
XA couple of handy programs for dealing with subjects in netnews
X("Now where was that article I thought I didn't want to read?").
X"Subj" is a standalone C program which emulates
X% cd <desired_news_directory>;head * | egrep '==>|ubject:'
Xbut is (at least on our machine) faster; plus it puts the filename
Xand the subject-line on the same line.
X"Subjc" is a modified version which accepts a file of file-names
Xand sorta does the same thing.  See the script "subjn" for
Xuse of subjc.  It's an overnight package to put up "/tmp/subjnews"
Xfor later perusal or fgrepping.
X/*Uses the "readdir" stuff of BSD, so probably not very (at all)
Xportable to SYSV.*/
XActually I did go over to a couple of SYSV boxes (3b2/300's
XR2.0 and R3.1) and make it work with SYSV (gad! how long has
Xit been since I had to suffer SYSV?)...  The pertinent 
Xcode is #ifdeffed SYSV.
XThe man pages and Makefile are probably gross overkill for a couple
Xof 50-line programs, but ... just wanted to do it right.  Spent
Xmuch more time on getting the package together than originally
Xspent writing the programs ... but, what the heck ...
XP.S. vi with sw=4, etc.
X-------------
XJim Nelson,UNC-Wilmington,Mathematical Sciences Dept, 919-395-3300
Xnelson@uncw.uucp or nelson@ecsvax.uncecs.edu or nelson@ecsvax.bitnet
END_OF_FILE
if test 1274 -ne `wc -c <'README'`; then
    echo shar: \"'README'\" unpacked with wrong size!
fi
# end of 'README'
fi
if test -f 'crontabentry' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'crontabentry'\"
else
echo shar: Extracting \"'crontabentry'\" \(27 characters\)
sed "s/^X//" >'crontabentry' <<'END_OF_FILE'
X34 7 * * * /usr/uncw/subjn
END_OF_FILE
if test 27 -ne `wc -c <'crontabentry'`; then
    echo shar: \"'crontabentry'\" unpacked with wrong size!
fi
# end of 'crontabentry'
fi
if test -f 'jimsindex.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'jimsindex.c'\"
else
echo shar: Extracting \"'jimsindex.c'\" \(436 characters\)
sed "s/^X//" >'jimsindex.c' <<'END_OF_FILE'
Xjimsindex(a,b)
Xchar *a, *b;
X{
X	int i,j;
X	if(!*a || !*b)return -1;
X	for(i=0;a[i];i++)
X	{
X		for(j=0;;j++)
X		{
X/*			printf("compare %x and %x\n",a[i+j],b[j]);*/
X			if(a[i+j]!=b[j])break;
X		}
X		if(!b[j])return i;
X	}
X	return -1;
X}
X/*
Xchar *x = "Now is the time for all zorkmids";
Xmain()
X{
X	char y[132];
X	int i;
X	for(;;){
X		gets(y);
X		i=jimsindex(x,y);
X		printf("%s,%d\n",x,i);
X		y[0]=0;
X		i=jimsindex(x,y);
X		printf("%s,%d\n",x,i);
X	}
X}
X*/	
END_OF_FILE
if test 436 -ne `wc -c <'jimsindex.c'`; then
    echo shar: \"'jimsindex.c'\" unpacked with wrong size!
fi
# end of 'jimsindex.c'
fi
if test -f 'subj.1' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'subj.1'\"
else
echo shar: Extracting \"'subj.1'\" \(623 characters\)
sed "s/^X//" >'subj.1' <<'END_OF_FILE'
X.TH SUBJ 1 LOCAL
X.SH NAME
Xsubj \- Find "Subject:" line in netnews articles
X.SH SYNOPSIS
X.B subj
X[
X.B -d 
X] 
X.SH DESCRIPTION
X.B Subj
Xfinds "Subject:" lines in all files in a directory.  Finds only
Xfirst match, thus saving time.  The single option -d allows
Xdumping the "Date:" line in addition.
X.SH EXAMPLE
Xcd /usr/spool/news/comp/sources/unix; subj
X.SH BUGS
XA clever combination of head, fgrep, cut, join, etc., probably
Xcould do the same job in a shell script, but, what the heck,
Xit's only fifty or so lines of C code ...
X.SH SEE ALSO
Xsubjc(8), subjn(1)
X.SH AUTHOR
XJim Nelson,  nelson@uncw.uucp  nelson@ecsvax.uncecs.edu
END_OF_FILE
if test 623 -ne `wc -c <'subj.1'`; then
    echo shar: \"'subj.1'\" unpacked with wrong size!
fi
# end of 'subj.1'
fi
if test -f 'subj.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'subj.c'\"
else
echo shar: Extracting \"'subj.c'\" \(1873 characters\)
sed "s/^X//" >'subj.c' <<'END_OF_FILE'
X#include <sys/types.h>
X#include <sys/dir.h>
Xstruct direct zork;
X#include <stdio.h>
X#ifdef SYSV
Xextern char *sys_errlist[];
Xopendir(p)
Xchar *p;
X{
X	int i;
X	extern int errno;
X	extern char *errmsg;
X	i= open(p,0);
X	if(i<0){
X		fprintf(stderr,"errno=%d %s\n",errno,sys_errlist[errno]);
X		fprintf(stderr,"in opendir, i=%d\n",i);
X		exit(7);
X	}
X	return i;
X}
Xunion{
Xstruct direct crundy;
Xchar moobus[17];
X} noogle;
Xstruct direct *readdir(fd)
Xint fd;
X{
X	int i;
X	/*
X	loop:
X	i=read(fd,&(noogle.crundy),sizeof(struct direct));
X
X	if(i<=0)return (struct direct *)0;
X	else
X	{
X	if(noogle.crundy.d_ino==0)goto loop;
X	if(noogle.crundy.d_name[0]=='.')goto loop;
X	*/
X	do{
X	i=read(fd,&(noogle.crundy),sizeof(struct direct));
X
X	if(i<=0)return (struct direct *)0;
X	} while(
X		noogle.crundy.d_ino==0 ||
X		noogle.crundy.d_name[0]=='.'
X		);
X	noogle.crundy.d_name[14]=0;
X	return  &(noogle.crundy);
X}
X#endif
X
X
Xmain(argc,argv)
Xchar **argv;
X{
X
X	char *line, *malloc(), *fgets();
X#ifdef SYSV
X	int dirp, opendir();
X	struct direct *readdir(), *p;
X#else
X	DIR *dirp;
X	struct direct *p;
X#endif
X	FILE *fp;
X	int i, dodate, found, tofind;
X	struct direct dir;
X
X	dodate=0;
X	line = malloc(513);
X	if(line==(char *)0)error(1);
X	if(argc>=2)
X		for(i=1;i<argc;i++)
X		{
X			if(!strcmp(argv[i],"-d"))dodate=1;
X		}
X
X	p= &dir;
X	tofind=1;
X	if(dodate)tofind++;
X	dirp=opendir(".");
X	if(dirp==NULL)error(2);
X	while  (p=readdir(dirp)) {
X		fp=fopen(p->d_name,"r");
X		if(fp==(FILE *)0)error(3);
X		found=0;
X		for(;;){
X			if(fgets(line,132,fp)!=line)break;
X			if(jimsindex(line,"ubject:")>=0)
X			{
X				printf("%s:%s",p->d_name,line);
X				found++;
X				if(found >= tofind)break;
X			}
X			if(dodate)
X				if(jimsindex(line,"Date")>=0)
X				{
X					printf("%s:%s",p->d_name,line);
X					found++;
X					if(found>=tofind)break;
X				}
X		}
X		if(fp)i=fclose(fp);
X		if(i<0)error(4);
X	}
X	exit(0);
X}
Xerror(i)
X{
X	fprintf(stderr,"error %d\n",i);
X	exit(i);
X}
END_OF_FILE
if test 1873 -ne `wc -c <'subj.c'`; then
    echo shar: \"'subj.c'\" unpacked with wrong size!
fi
# end of 'subj.c'
fi
if test -f 'subj.old' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'subj.old'\"
else
echo shar: Extracting \"'subj.old'\" \(318 characters\)
sed "s/^X//" >'subj.old' <<'END_OF_FILE'
X#! /bin/sh
Xcase $1 in
X	"") dir=.;;
X	*) dir=$1;;
Xesac
X	 cd $dir
X	for i in `ls -t`;do
X		if [ -d $i ]
X		then
X			echo ${i}': ****directory****'
X#			cd $i;/bin/sh /usr/uncw/subj
X#			echo ${i}'******end******'
X		fi
X		if [ -f $i ]
X		then
X			echo -n "$i:";head $i|if fgrep ubject
X			then
X			:
X			else
X			echo
X			fi
X		fi
X	done
END_OF_FILE
if test 318 -ne `wc -c <'subj.old'`; then
    echo shar: \"'subj.old'\" unpacked with wrong size!
fi
# end of 'subj.old'
fi
if test -f 'subjc.8' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'subjc.8'\"
else
echo shar: Extracting \"'subjc.8'\" \(722 characters\)
sed "s/^X//" >'subjc.8' <<'END_OF_FILE'
X.TH SUBJC 1 LOCAL
X.SH NAME
Xsubjc \- Find "Subject:" line in netnews articles
X.SH SYNOPSIS
X.B subjc filename
X.SH DESCRIPTION
X.B Subjc
Xfinds "Subject:" lines in all files in a file of filenames.
XFinds only
Xfirst match, thus saving time.
X.SH EXAMPLE
X.sp
X#!/bin/sh
X.sp
X/usr/bin/find /usr/spool/news -type f -print >/tmp/sub1jnews
X.sp
Xdate > /tmp/subjnews
X.sp
X/usr/local/bin/subjc /tmp/sub1jnews | /usr/bin/sort >> /tmp/subjnews
X.sp
Xrm -f /tmp/sub1jnews
X.SH BUGS
XA clever combination of head, fgrep, cut, join, etc., probably
Xcould do the same job in a shell script, but, what the heck,
Xit's only fifty or so lines of C code ...
X.SH SEE ALSO
Xsubj(1), subjn(1)
X.SH AUTHOR
XJim Nelson,  nelson@uncw.uucp  nelson@ecsvax.uncecs.edu
END_OF_FILE
if test 722 -ne `wc -c <'subjc.8'`; then
    echo shar: \"'subjc.8'\" unpacked with wrong size!
fi
# end of 'subjc.8'
fi
if test -f 'subjc.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'subjc.c'\"
else
echo shar: Extracting \"'subjc.c'\" \(743 characters\)
sed "s/^X//" >'subjc.c' <<'END_OF_FILE'
X#include <stdio.h>
X#define SZ 512 /*line lengths*/
Xmain(argc,argv)
Xchar *argv[];
X{
X	FILE *fn, *fp;
X	char *line, *file, *fgets(), *malloc();
X	int i,k;
X
X	line = malloc(SZ+1);
X	if(line==(char *)0)exit(1);
X	file = malloc(SZ+1);
X	if(file==(char *)0)exit(2);
X
X	if(argc>=2)fn=fopen(argv[1],"r");
X	else exit(3);
X	if(fn==(FILE *)0)exit(1);
X	while( fgets(file,SZ,fn)==file){
X		for(i=0;file[i]&&i<SZ;i++)if(file[i]=='\n')file[i]=0;
X		fp=fopen(file,"r");
X		if(fp==NULL){
X			printf("cannot open: %s\n",file);
X			exit(2);
X		}
X		for(i=0;i<40;i++){
X			if( fgets(line,SZ,fp)!=line)break;
X			if(*line)
X				if( (k=jimsindex(line,"ubject:"))>0)
X				{
X					printf("%s\t%s",file+15,line+k+7);
X					break;
X				}
X		}
X		if(fp!=NULL){i=fclose(fp);if(i<0)exit(4);}
X	}
X}
END_OF_FILE
if test 743 -ne `wc -c <'subjc.c'`; then
    echo shar: \"'subjc.c'\" unpacked with wrong size!
fi
# end of 'subjc.c'
fi
if test -f 'subjn' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'subjn'\"
else
echo shar: Extracting \"'subjn'\" \(182 characters\)
sed "s/^X//" >'subjn' <<'END_OF_FILE'
X#!/bin/sh
X/usr/bin/find /usr1/NET/News -type f -print >/tmp/sub1jnews
Xdate > /tmp/subjnews
X/usr/local/bin/subjc /tmp/sub1jnews | /usr/bin/sort >> /tmp/subjnews
Xrm -f /tmp/sub1jnews
X
END_OF_FILE
if test 182 -ne `wc -c <'subjn'`; then
    echo shar: \"'subjn'\" unpacked with wrong size!
fi
# end of 'subjn'
fi
if test -f 'subjn.8' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'subjn.8'\"
else
echo shar: Extracting \"'subjn.8'\" \(453 characters\)
sed "s/^X//" >'subjn.8' <<'END_OF_FILE'
X.TH SUBJN 1 LOCAL
X.SH NAME
Xsubjn \- Find "Subject:" line in netnews articles
X.SH SYNOPSIS
X.B subjn filename
X.SH DESCRIPTION
X.B Subjn
Xis a shell script driver for subjc, which see.
X.SH BUGS
XA clever combination of head, fgrep, cut, join, etc., probably
Xcould do the same job in a shell script, but, what the heck,
Xit's only fifty or so lines of C code ...
X.SH SEE ALSO
Xsubjc(1), subj(1)
X.SH AUTHOR
XJim Nelson,  nelson@uncw.uucp  nelson@ecsvax.uncecs.edu
END_OF_FILE
if test 453 -ne `wc -c <'subjn.8'`; then
    echo shar: \"'subjn.8'\" unpacked with wrong size!
fi
# end of 'subjn.8'
fi
echo shar: End of archive 1 \(of 1\).
cp /dev/null ark1isdone
MISSING=""
for I in 1 ; do
    if test ! -f ark${I}isdone ; then
	MISSING="${MISSING} ${I}"
    fi
done
if test "${MISSING}" = "" ; then
    echo You have the archive.
    rm -f ark[1-9]isdone
else
    echo You still need to unpack the following archives:
    echo "        " ${MISSING}
fi
##  End of shell archive.
exit 0