home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / unix_c / mail / undgstfy.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-03-21  |  4.8 KB  |  199 lines

  1. /*    Modified 1/27/88 to handle more types of digests and
  2.     a compile-time option added (LONGNAME) which will cause
  3.     the default output file name to be <digest-name>.VOL.NUM
  4.     rather than the VOL.NUM form described below.
  5.  
  6.     This has been tested with the Info-IBM, Info-Kermit, and
  7.     Info-CPM Digest formats.
  8.  
  9.     This program should be called 'UNDIGEST' rather than 'DIGEST'
  10.     as it is below since there is a companion program in the
  11.     Simtel20 PD2:<UNIX.MAIL> directory (digest.c) that
  12.     creates a Digest file from individual messages.
  13.  
  14.     The original documentation below has NOT been modified to
  15.     reflect these changes.
  16.  
  17.                     David Brown
  18.                     jdb@ncsc.arpa
  19. */
  20. /*
  21. DIGEST:  (version 3) November, 1984
  22.  
  23. NAME: 
  24.     Digest  - reformats the ailist digest for use with "mail -f"
  25.  
  26. SYNOPSIS:
  27.     digest file [file] 
  28.  
  29. DESCRIPTION:
  30.  
  31. digest takes the file name  given  in  first  argument  and  places  the
  32. reformatted  file  in  the  second argument, if given. If no output file
  33. (2nd argument) is given, the output will be placed into a  default  file
  34. whose  name  is of the form VOL.NUM where VOL and NUM are the volume and
  35. number of the ailist digest fed in (e.g. 2.144,etc.).
  36.  
  37. A few notes:
  38.     (1) if only one argument is given, it is assumed to be the
  39.         input file.  If no args are given, you get prompted for
  40.         for the input file, and the output is sent to the default
  41.         file construction.
  42.  
  43.     (2) This has been tested only for use with the specific ailist/human-
  44.         nets format now in use.  I will soon get around to adding
  45.         code to this program to handle other formats.  When I do,
  46.         I will send it along.
  47.  
  48.     (3) The input to this program must be A SINGLE AILIST 
  49.         OR HUMAN-NETS DIGEST.  If you have been stuffing all 
  50.         your ailist digests into a single file, running this pgm 
  51.         on that file will yield  incorrect and unpredictable results.  
  52.         The pgm is best  used to manage the incoming stuff.
  53.  
  54.     (4) the input file is left untouched (i.e. is not removed)
  55.  
  56.     (5) digest does not work with piped input (a bug, sorry).
  57.         This has meant for me that I stick the day's ailist digest
  58.         into a temp file when I receive it over "mail", and then
  59.         later "digest" this temp file to get it into a suitable
  60.         form for "mail -f".
  61.  
  62. BUGS:
  63.     If there are ailist sub-entries which do not have a DATE:
  64.     field in the header, they will be appended to the entry
  65.     prior.  
  66.  
  67. Any questions, suggestions or problems, etc. should be sent to 
  68.  
  69. douglas stumberger
  70. department of computer science
  71. 111 Cumington Street
  72. boston, ma. 02215
  73.  
  74. csnet: des@bostonu
  75. bitnet: csc10304@bostonu
  76.  
  77. */
  78.  
  79. #include <stdio.h>
  80.  
  81. main(argc,argv)
  82.     int argc; char *argv[] ;
  83. {
  84.     FILE *fpr, *fpw ;
  85.     char *lead, *fromline, temp[81], fname[81] ,
  86.         digest[81],vol[50],num[5] ;
  87.     register int done=0, gl ;
  88.     
  89.     if (argc > 3) {
  90.         printf("Usage: %s file [file]\n",argv[0]) ;
  91.         exit(0);
  92.     }
  93.     if (argc == 1) { 
  94.         printf("What file is the digest in? > ") ;
  95.         scanf("%s",fname) ;
  96.     }
  97.     else 
  98.         strcpy(fname,argv[1]) ;
  99.     
  100.     if ((fpr = fopen(fname,"r")) == NULL) {
  101.         printf("%s: No such file\n",fname) ;
  102.         exit(0) ;
  103.     }
  104.  
  105. #ifdef DEBUG
  106.     printf(" input file name is <%s>\n",fname) ;
  107. #endif
  108.  
  109.     lead = (char *) calloc(90,sizeof(char)) ;  
  110.  
  111.     get_line(fpr,lead) ;        /* get the first line of file */
  112.  
  113.     fromline = (char *) malloc(strlen(lead)+1) ;
  114.     strcpy(fromline,lead) ;
  115.  
  116.     if (argc != 3) {   /* no output file given - 
  117.                 find out vol/num for filename */
  118.  
  119.         while ((lead[0] != '-') && (!done)) {
  120. #ifdef DEBUG
  121. printf("Scanning:%s",lead);
  122. #endif
  123.             sscanf(lead,"%s %s",digest,temp) ;
  124.             if (!strcmp(temp,"Digest")) {
  125. #ifdef DEBUG
  126. printf("\nFound a match\n");
  127. #endif
  128.                    sscanf(lead,"%*s %*s %*s %*s %*s %*s %*s %s %*c %*s %s",
  129.                    vol,num) ;
  130.                done++ ;
  131.             }
  132.             get_line(fpr,lead) ;
  133.         }
  134.  
  135.         strcat(digest,".") ;        
  136. #ifndef LONGNAME
  137.         digest[0]='\0';
  138. #endif
  139.         strcat(digest,vol) ;
  140.         strcat(digest,".") ;
  141.         strcat(digest,num) ;
  142.     }
  143.     else 
  144.         strcpy(digest,argv[2]) ;    /* output filename is third argument */
  145.  
  146.  
  147. #ifdef DEBUG
  148.         printf("output file is <%s>",digest) ;
  149. #endif
  150.  
  151.     fclose(fpr) ;            
  152.  
  153. #ifdef DEBUG
  154.         printf(" input file is <%s>\n",fname) ;
  155. #endif
  156.  
  157.     if ((fpr = fopen(fname,"r")) == NULL) {
  158.         printf("\nERROR: File will not rewind\n") ;
  159.         exit(0) ;
  160.     }
  161.  
  162.     if ((fpw = fopen(digest,"w")) == NULL) {
  163.         printf("\nERROR: Output File will not open\n") ;
  164.         exit(0) ;
  165.     }
  166.  
  167.     get_line(fpr,lead) ;        /* copy the ailist header */
  168.  
  169.     while (lead[0] != '-') {    /* i.e.  Law's message of the topics */
  170.         fprintf(fpw,"%s",lead) ;
  171.         get_line(fpr,lead) ;
  172.     }
  173.  
  174.     gl = get_line(fpr,lead) ;    /* do the body of the digest */
  175.     while (gl != EOF) {
  176.         sscanf(lead,"%s",temp) ;
  177.         if (!strcmp (temp,"Date:"))
  178.             fprintf(fpw,"%s",fromline) ;
  179.         fprintf(fpw,"%s",lead) ;
  180.         gl = get_line(fpr,lead) ;
  181.     }
  182.  
  183.     printf("Re-formatted digest now in file <%s>\n",digest) ;
  184.     }    
  185.  
  186.  
  187. get_line (fp,s)
  188.     FILE *fp;    char *s;
  189. {
  190.     register int c,i=0 ;
  191.  
  192.     while ((c != '\n') && (c != EOF)) {
  193.         c = getc(fp) ;
  194.         *(s+i++) = c ;
  195.     }
  196.     *(s+i++) = '\0' ;
  197.     return(c) ;
  198. }
  199.