home *** CD-ROM | disk | FTP | other *** search
- Article 84 of comp.sources.misc:
- Relay-Version: version B 2.10.3 alpha 5/22/85; site osu-eddie.UUCP
- Path: osu-eddie!cbosgd!ihnp4!ptsfa!ames!necntc!ncoast!allbery
- From: paul@nessus.UUCP (/dev/null)
- Newsgroups: comp.sources.misc
- Subject: grabheaders - update to news/misc submission
- Message-ID: <2713@ncoast.UUCP>
- Date: 25 Jun 87 01:41:54 GMT
- Date-Received: 26 Jun 87 05:10:13 GMT
- Sender: allbery@ncoast.UUCP
- Lines: 185
- Keywords: news grabheaders misc utility
- Approved: allbery@ncoast.UUCP
- X-Archive: comp.sources.misc/8706/4
-
- The following program was originally distributed with news2.11 in the
- misc directory. I have updated it so that it will work with USG machines
- and also the new history file format. I have also added some comments
- to the start of the program so that one doesn't have to have ESP to make
- it run.
-
- Why is this program useful?
-
- It is often nice to be able to get all of the message headers from news
- so that one can produce nice statistics (i.e. Rick Adams' usenet activity
- reports). This program will dump all of the headers it can get to stdout.
-
- It has only been tested on a System V release 2.0 system running news 2.11.
- Please inform me if you have problems running under bsd [do you know anyone
- doing an Intel 386 bsd port?] or any other configuration.
-
- Paul Traina
- paul@nessus.uucp
-
- -*- cut here for maximum consumer satisfaction -*-
- /*
- * grabheaders: dump to stdout the headers of all the news-items
- * available through the history database.
- *
- * Original Author: ?? (distributed in news2.11/misc directory)
- * Kludgemonger: Paul Traina (paul@nessus.UUCP / pst@ai.ai.mit.edu)
- *
- * This program has been kludged a tad to:
- * 1) work on USG systems
- * 2) work with the new "hashed" history file
- *
- * If your news history file is "hashed" (in news 2.11, the history
- * file has been broken into 10 smaller files and stored in "history.d")
- * then you should compile this with -DHASHED. Otherwise the program
- * will assume you are using an old version of news that has one file
- * just called "history". This may also be true of systems that run
- * with DBM (? I don't know ?).
- *
- * If you are running a USG machine (SystemV), then add -DUSG to
- * the compile line -- this will:
- * a) define index -> strchr
- * b) add timeb information
- *
- * You will also need (if your system does not have them directly
- * in some library) fdate.o and getdate.o. These are supplied
- * with the news distribution (ftime.c and getdate.y).
- *
- * This has only been tested on news2.11 patch level 8 with a
- * system running System V release 2.0. Please notify me of
- * any problems you may have.
- *
- */
-
- #include <sys/types.h>
- #include <stdio.h>
- #include <sys/stat.h>
- #include <ctype.h>
- #include <sys/time.h>
-
- #ifdef HASHED
- #define HISTDIR "/usr/lib/news/history.d"
- #else
- #define HISTORY "/usr/lib/news/history"
- #endif
-
- #define SPOOL "/usr/spool/news"
-
- #ifndef USG
- #include <sys/timeb.h>
- #else
- struct timeb
- {
- time_t time;
- unsigned short millitm;
- short timezone;
- short dstflag;
- };
- #define index strchr
- #define rindex strrchr
- #endif
-
- #define DAYSEC (24L*60L*60L)
-
-
- main()
- {
- FILE *infile;
-
- #ifdef HASHED
- char histfile[15]; /* name of current history file */
- int histindex;
-
- for (histindex = 0; histindex < 10; histindex++) {
- sprintf(histfile, "%s/%01d", HISTDIR, histindex);
- infile = fopen(histfile, "r");
- getheaders(infile, histfile);
- }
- #else
- infile = fopen(HISTORY, "r");
- getheaders(infile, HISTORY);
- #endif
- }
-
- getheaders(Hfile, name)
- FILE *Hfile;
- char *name;
- {
- FILE *Afile;
- char buffer[BUFSIZ], datestr[BUFSIZ];
- char *index();
- struct stat stbuf;
- struct timeb now;
- long t;
-
- if (Hfile == NULL) {
- perror(name);
- exit(1);
- }
-
- if (chdir(SPOOL) < 0) {
- perror(SPOOL);
- exit(1);
- }
-
- (void) ftime(&now);
-
- while (fgets(buffer, BUFSIZ, Hfile) != NULL) {
- register char *p, *file;
-
- p = index(buffer, '\t');
- if (p == NULL)
- continue;
- file = index(p+1, '\t');
- if (file == NULL || file[1] == '\n')
- continue;
- *file = '\0';
- t = getdate(p, &now);
- /* if ( (t+DAYSEC*14L) < now.time)
- continue; */
- strcpy(datestr, p);
- p = file;
- while (*++p != ' ' && *p != '\n')
- if (*p == '.')
- *p = '/';
- *p = '\0';
- file++;
- if ( strncmp(file, "net", 3) && strncmp(file, "mod", 3)
- && strncmp(file, "comp", 4) && strncmp(file, "sci", 3)
- && strncmp(file, "news", 4) && strncmp(file, "rec", 3)
- && strncmp(file, "talk", 4) && strncmp(file, "misc", 4)
- && strncmp(file, "soc", 3)
- )
- continue;
- Afile = fopen(file, "r");
- if (Afile == NULL)
- continue;
- while (fgets(buffer, BUFSIZ, Afile) != NULL &&
- buffer[0] != '\n') {
- if (strncmp(buffer, "From: ", 5) == 0) {
- register char *cp = index(buffer, '@');
- if (cp)
- while (*++cp && *cp != '.' && *cp != ' ')
- if (isupper(*cp))
- *cp = tolower(*cp);
- cp--;
- while (*++cp && *cp != ' ')
- if (islower(*cp))
- *cp = toupper(*cp);
- }
- fputs(buffer, stdout);
- }
- fstat(fileno(Afile), &stbuf);
- printf("Date-Received: %s\n", datestr);
- printf("Bytes: %ld\n\n", stbuf.st_size - ftell(Afile));
- fclose(Afile);
- }
- printf("\n");
- fclose(Hfile);
- }
- -*- this is the end -- STOP YOUR CUT NOW SILLY! -- fnord -*-
-
- --
- arpa: pst@ai.ai.mit.edu
- bitnet: paul%nessus@sbitp
- uucp: {ucbvax|sdcsvax|pyramid}!ucsbcsl!nessus!paul
-
-
-