home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Usenet 1994 October
/
usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso
/
misc
/
volume7
/
nsubj
/
subj.c
< prev
next >
Wrap
C/C++ Source or Header
|
1989-06-03
|
2KB
|
113 lines
#include <sys/types.h>
#include <sys/dir.h>
struct direct zork;
#include <stdio.h>
#ifdef SYSV
extern char *sys_errlist[];
opendir(p)
char *p;
{
int i;
extern int errno;
extern char *errmsg;
i= open(p,0);
if(i<0){
fprintf(stderr,"errno=%d %s\n",errno,sys_errlist[errno]);
fprintf(stderr,"in opendir, i=%d\n",i);
exit(7);
}
return i;
}
union{
struct direct crundy;
char moobus[17];
} noogle;
struct direct *readdir(fd)
int fd;
{
int i;
/*
loop:
i=read(fd,&(noogle.crundy),sizeof(struct direct));
if(i<=0)return (struct direct *)0;
else
{
if(noogle.crundy.d_ino==0)goto loop;
if(noogle.crundy.d_name[0]=='.')goto loop;
*/
do{
i=read(fd,&(noogle.crundy),sizeof(struct direct));
if(i<=0)return (struct direct *)0;
} while(
noogle.crundy.d_ino==0 ||
noogle.crundy.d_name[0]=='.'
);
noogle.crundy.d_name[14]=0;
return &(noogle.crundy);
}
#endif
main(argc,argv)
char **argv;
{
char *line, *malloc(), *fgets();
#ifdef SYSV
int dirp, opendir();
struct direct *readdir(), *p;
#else
DIR *dirp;
struct direct *p;
#endif
FILE *fp;
int i, dodate, found, tofind;
struct direct dir;
dodate=0;
line = malloc(513);
if(line==(char *)0)error(1);
if(argc>=2)
for(i=1;i<argc;i++)
{
if(!strcmp(argv[i],"-d"))dodate=1;
}
p= &dir;
tofind=1;
if(dodate)tofind++;
dirp=opendir(".");
if(dirp==NULL)error(2);
while (p=readdir(dirp)) {
fp=fopen(p->d_name,"r");
if(fp==(FILE *)0)error(3);
found=0;
for(;;){
if(fgets(line,132,fp)!=line)break;
if(jimsindex(line,"ubject:")>=0)
{
printf("%s:%s",p->d_name,line);
found++;
if(found >= tofind)break;
}
if(dodate)
if(jimsindex(line,"Date")>=0)
{
printf("%s:%s",p->d_name,line);
found++;
if(found>=tofind)break;
}
}
if(fp)i=fclose(fp);
if(i<0)error(4);
}
exit(0);
}
error(i)
{
fprintf(stderr,"error %d\n",i);
exit(i);
}