home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / misc / volume1 / 8706 / 4 < prev    next >
Encoding:
Text File  |  1993-09-02  |  5.2 KB  |  203 lines

  1. Article 84 of comp.sources.misc:
  2. Relay-Version: version B 2.10.3 alpha 5/22/85; site osu-eddie.UUCP
  3. Path: osu-eddie!cbosgd!ihnp4!ptsfa!ames!necntc!ncoast!allbery
  4. From: paul@nessus.UUCP (/dev/null)
  5. Newsgroups: comp.sources.misc
  6. Subject: grabheaders - update to news/misc submission
  7. Message-ID: <2713@ncoast.UUCP>
  8. Date: 25 Jun 87 01:41:54 GMT
  9. Date-Received: 26 Jun 87 05:10:13 GMT
  10. Sender: allbery@ncoast.UUCP
  11. Lines: 185
  12. Keywords: news grabheaders misc utility
  13. Approved: allbery@ncoast.UUCP
  14. X-Archive: comp.sources.misc/8706/4
  15.  
  16. The following program was originally distributed with news2.11 in the
  17. misc directory.  I have updated it so that it will work with USG machines
  18. and also the new history file format.  I have also added some comments
  19. to the start of the program so that one doesn't have to have ESP to make
  20. it run.
  21.  
  22. Why is this program useful?
  23.  
  24. It is often nice to be able to get all of the message headers from news
  25. so that one can produce nice statistics (i.e. Rick Adams' usenet activity
  26. reports).  This program will dump all of the headers it can get to stdout.
  27.  
  28. It has only been tested on a System V release 2.0 system running news 2.11.
  29. Please inform me if you have problems running under bsd [do you know anyone
  30. doing an Intel 386 bsd port?] or any other configuration.
  31.  
  32.                         Paul Traina
  33.                         paul@nessus.uucp
  34.  
  35. -*- cut here for maximum consumer satisfaction -*-
  36. /*
  37.  *    grabheaders: dump to stdout the headers of all the news-items
  38.  *             available through the history database.
  39.  *
  40.  *    Original Author: ?? (distributed in news2.11/misc directory)
  41.  *    Kludgemonger:     Paul Traina (paul@nessus.UUCP / pst@ai.ai.mit.edu)
  42.  *
  43.  *    This program has been kludged a tad to:
  44.  *    1) work on USG systems
  45.  *    2) work with the new "hashed" history file
  46.  *
  47.  *    If your news history file is "hashed" (in news 2.11, the history
  48.  *    file has been broken into 10 smaller files and stored in "history.d")
  49.  *    then you should compile this with -DHASHED.  Otherwise the program
  50.  *    will assume you are using an old version of news that has one file
  51.  *    just called "history".  This may also be true of systems that run
  52.  *    with DBM (? I don't know ?).
  53.  *
  54.  *    If you are running a USG machine (SystemV), then add -DUSG to
  55.  *    the compile line -- this will:
  56.  *        a) define index -> strchr
  57.  *        b) add timeb information
  58.  *
  59.  *    You will also need (if your system does not have them directly
  60.  *    in some library) fdate.o and getdate.o.  These are supplied
  61.  *    with the news distribution (ftime.c and getdate.y).
  62.  *
  63.  *    This has only been tested on news2.11 patch level 8 with a
  64.  *    system running System V release 2.0.  Please notify me of
  65.  *    any problems you may have.
  66.  *
  67.  */
  68.  
  69. #include <sys/types.h>
  70. #include <stdio.h>
  71. #include <sys/stat.h>
  72. #include <ctype.h>
  73. #include <sys/time.h>
  74.  
  75. #ifdef HASHED
  76. #define HISTDIR    "/usr/lib/news/history.d"
  77. #else
  78. #define HISTORY    "/usr/lib/news/history"
  79. #endif
  80.  
  81. #define SPOOL    "/usr/spool/news"
  82.  
  83. #ifndef USG
  84. #include <sys/timeb.h>
  85. #else
  86. struct timeb
  87. {
  88.     time_t    time;
  89.     unsigned short millitm;
  90.     short    timezone;
  91.     short    dstflag;
  92. };
  93. #define index strchr
  94. #define rindex strrchr
  95. #endif
  96.  
  97. #define DAYSEC (24L*60L*60L)
  98.  
  99.  
  100. main()
  101. {
  102.     FILE *infile;
  103.  
  104. #ifdef HASHED
  105.     char histfile[15];    /* name of current history file */
  106.     int  histindex;
  107.  
  108.     for (histindex = 0; histindex < 10; histindex++) {
  109.       sprintf(histfile, "%s/%01d", HISTDIR, histindex);
  110.       infile = fopen(histfile, "r");
  111.       getheaders(infile, histfile);
  112.     }
  113. #else
  114.     infile = fopen(HISTORY, "r");
  115.     getheaders(infile, HISTORY);
  116. #endif
  117. }
  118.  
  119. getheaders(Hfile, name)
  120. FILE *Hfile;
  121. char *name;
  122. {
  123.     FILE *Afile;
  124.     char buffer[BUFSIZ], datestr[BUFSIZ];
  125.     char *index();
  126.     struct stat stbuf;
  127.     struct timeb now;
  128.     long t;
  129.  
  130.     if (Hfile == NULL) {
  131.         perror(name);
  132.         exit(1);
  133.     }
  134.  
  135.     if (chdir(SPOOL) < 0) {
  136.         perror(SPOOL);
  137.         exit(1);
  138.     }
  139.  
  140.     (void) ftime(&now);
  141.  
  142.     while (fgets(buffer, BUFSIZ, Hfile) != NULL) {
  143.         register char *p, *file;
  144.  
  145.         p = index(buffer, '\t');
  146.         if (p == NULL)
  147.             continue;
  148.         file = index(p+1, '\t');
  149.         if (file == NULL || file[1] == '\n')
  150.             continue;
  151.         *file = '\0';
  152.         t = getdate(p, &now);
  153.         /* if ( (t+DAYSEC*14L) < now.time)
  154.             continue; */
  155.         strcpy(datestr, p);
  156.         p = file;
  157.         while (*++p != ' ' && *p != '\n')
  158.             if (*p == '.')
  159.                 *p = '/';
  160.         *p = '\0';
  161.         file++;
  162.         if (       strncmp(file, "net", 3)  && strncmp(file, "mod", 3)
  163.             && strncmp(file, "comp", 4) && strncmp(file, "sci", 3)
  164.             && strncmp(file, "news", 4) && strncmp(file, "rec", 3)
  165.             && strncmp(file, "talk", 4) && strncmp(file, "misc", 4)
  166.             && strncmp(file, "soc", 3)
  167.             )
  168.             continue;
  169.         Afile = fopen(file, "r");
  170.         if (Afile == NULL)
  171.             continue;
  172.         while (fgets(buffer, BUFSIZ, Afile) != NULL &&
  173.             buffer[0] != '\n') {
  174.         if (strncmp(buffer, "From: ", 5) == 0) {
  175.             register char *cp = index(buffer, '@');
  176.             if (cp)
  177.                 while (*++cp && *cp != '.' && *cp != ' ')
  178.                     if (isupper(*cp))
  179.                         *cp = tolower(*cp);
  180.                 cp--;
  181.                 while (*++cp && *cp != ' ')
  182.                     if (islower(*cp))
  183.                         *cp = toupper(*cp);
  184.             }
  185.             fputs(buffer, stdout);
  186.         }
  187.         fstat(fileno(Afile), &stbuf);
  188.         printf("Date-Received: %s\n", datestr);
  189.         printf("Bytes: %ld\n\n", stbuf.st_size - ftell(Afile));
  190.         fclose(Afile);
  191.     }
  192.     printf("\n");
  193.     fclose(Hfile);
  194. }
  195. -*- this is the end -- STOP YOUR CUT NOW SILLY! -- fnord -*-
  196.  
  197. -- 
  198. arpa:    pst@ai.ai.mit.edu
  199. bitnet: paul%nessus@sbitp
  200. uucp:   {ucbvax|sdcsvax|pyramid}!ucsbcsl!nessus!paul
  201.  
  202.  
  203.