home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / unix / volume19 / rkive / part02 / article.c < prev    next >
C/C++ Source or Header  |  1989-06-29  |  5KB  |  179 lines

  1. /*
  2. **                                                                
  3. **  Subsystem:   USENET Sources Archiver             
  4. **  File Name:   article.c               
  5. **                                                        
  6. **  usage: article [ -adnvV ] [-f format ] newsarticle [ ... ]
  7. **
  8. **
  9. ** This software is Copyright (c) 1989 by Kent Landfield.
  10. **
  11. ** Permission is hereby granted to copy, distribute or otherwise 
  12. ** use any part of this package as long as you do not try to make 
  13. ** money from it or pretend that you wrote it.  This copyright 
  14. ** notice must be maintained in any copy made.
  15. **
  16. ** Use of this software constitutes acceptance for use in an AS IS 
  17. ** condition. There are NO warranties with regard to this software.  
  18. ** In no event shall the author be liable for any damages whatsoever 
  19. ** arising out of or in connection with the use or performance of this 
  20. ** software.  Any use of this software is at the user's own risk.
  21. **
  22. **  If you make modifications to this software that you feel 
  23. **  increases it usefulness for the rest of the community, please 
  24. **  email the changes, enhancements, bug fixes as well as any and 
  25. **  all ideas to me. This software is going to be maintained and 
  26. **  enhanced as deemed necessary by the community.
  27. **        
  28. **        Kent Landfield
  29. **        uunet!ssbell!kent
  30. **
  31. **  History:
  32. **    Creation: Tue Feb 21 08:52:35 CST 1989 due to necessity.
  33. **                                                               
  34. */
  35. char sccsid[] = "@(#)article.c    1.1 6/1/89";
  36.  
  37. #include <stdio.h>
  38. #include <ctype.h>
  39. #include <sys/types.h>
  40. #include "article.h"
  41.  
  42. #define ARCHIVE_ONLY  1
  43. #define NO_ARCHIVE   -1
  44.  
  45. #define USAGE  "usage: %s [ -adnvV ] [-f format ] newsarticle [ ... ]\n"
  46.  
  47. char *progname;                 /* name of executable              */
  48. char *format_ptr = NULL;        /* pointer to user supplied format */
  49. int verify_archive = 0;         /* archive verification needed ?   */
  50. FILE *errfp;                    /* standard error file pointer     */
  51. FILE *logfp;                    /* standard output file pointer    */
  52.  
  53. char *strchr();                 /* external function declaration   */
  54.  
  55. main(argc, argv)
  56. int argc;
  57. char **argv;
  58. {
  59.    int c;
  60.    extern char *optarg;
  61.    extern int optind;
  62.  
  63.    progname = argv[0];
  64.    debug = verbose = 0;
  65.    logfp = stdout;
  66.    errfp = stderr;
  67.  
  68.    if (argc > 1) {
  69.       while ((c = getopt(argc, argv, "adnvVf:")) != EOF) {
  70.          switch (c) {
  71.              case 'a':
  72.                  verify_archive = ARCHIVE_ONLY;
  73.                  break;
  74.              case 'd':
  75.                  debug++;
  76.                  break;
  77.              case 'f':
  78.                  format_ptr = optarg;
  79.                  break;
  80.              case 'n':
  81.                  verify_archive = NO_ARCHIVE;
  82.                  break;
  83.              case 'v':
  84.                  verbose++;
  85.                  break;
  86.              case 'V':
  87.                  version();
  88.              default:
  89.                  (void) fprintf(errfp,USAGE, progname);
  90.                  return(1);
  91.          }
  92.       }
  93.    }
  94.  
  95.    if ((optind >= argc) || (argc == 1)) {  /* file from stdin */
  96.         char buf[BUFSIZ];
  97.         while (fgets(buf,sizeof buf,stdin) != NULL) {
  98.                buf[strlen(buf) -1] = '\0';
  99.                article_header(buf);
  100.         }
  101.    }
  102.    else { 
  103.         for (; optind < argc; optind++)    /* process files to print */
  104.              article_header(argv[optind]);
  105.    }
  106.    return(0);                              /* terminate this process */
  107. }
  108.  
  109. article_header(flname)
  110.     char *flname;
  111. {
  112.     char *dp;
  113.     int header_ok = 0;
  114.     char *strcpy();
  115.     FILE *file, *efopen();
  116.  
  117.     int default_format = ARTICLE;
  118.  
  119.     init_article();
  120.  
  121.     file = efopen(flname,"r");
  122.  
  123.     (void) strcpy(article.newsarticle,flname);
  124.  
  125.     while (fgets(s,sizeof s,file) != NULL) {
  126.         /*
  127.         ** Check if the line is not a header line.
  128.         ** Allow 2 lines to go by that are not header
  129.         ** lines. In this manner, the auxilliary sources
  130.         ** headers can be interpreted.
  131.         */
  132.         if (!isalpha(*s) || (strchr(s,':') == NULL)) {
  133.            ++header_ok;
  134.            if (header_ok == 2) {
  135.                /* 
  136.                ** Has the user requested to produce 
  137.                ** only an archive listing ?
  138.                */
  139.                if (verify_archive == ARCHIVE_ONLY) {
  140.                   if (!header.archive_name[0] || !article.description[0])
  141.                        break;
  142.                    default_format = ARCHIVE;
  143.                }
  144.                /* 
  145.                ** Has the user requested to produce 
  146.                ** a listing excluding all archive 
  147.                ** potential members ?
  148.                */
  149.                else if (verify_archive == NO_ARCHIVE) {
  150.                    if (header.archive_name[0] && article.description[0]) 
  151.                        break;
  152.                    default_format = ARTICLE;
  153.                }
  154.                /* 
  155.                ** Print out the information as requested
  156.                */
  157.                format_output(logfp, format_ptr, flname, default_format);
  158.                break;
  159.             }
  160.             continue;
  161.         }
  162.  
  163.         dp = s;
  164.         while (*++dp)
  165.            if (*dp == '\n')
  166.                *dp = '\0';
  167.         /*
  168.         ** Determine the type of the line and then
  169.         ** store the line in its appropriate structure
  170.     ** element for later retrieval.
  171.         */
  172.         store_line();
  173.     }
  174.     (void) fclose(file);
  175.  
  176.     if (verbose)
  177.         dump_article();
  178. }
  179.