home *** CD-ROM | disk | FTP | other *** search
/ back2roots/padua / padua.7z / padua / uucp / duucp-1.17 / AU-117b4-src.lha / src / util / uuarchive.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-12-24  |  1.6 KB  |  84 lines

  1. /*
  2.  *  UUARCHIVE
  3.  *
  4.  *  UUARCHIVE infile outfile
  5.  *
  6.  *  Appends infile to outfile then deletes infile.  Removes any uuencoded
  7.  *  files from infile (by looking for the begin line and deleting the
  8.  *  contents).
  9.  *
  10.  *  Usually used with dmail, dmail archives to a temporary file anything
  11.  *  you send out, then appends the temporary file to your mbox via this
  12.  *  command when it quits.  Thus, distributions you send out do not
  13.  *  get archived.
  14.  */
  15.  
  16. #include <stdlib.h>
  17. #include <string.h>
  18. #include <stdio.h>
  19. #include "version.h"
  20.  
  21. IDENT(".01");
  22.  
  23. char Buf[2048];
  24.  
  25. int ScanArchive(FILE *fi, FILE *fo);
  26. int isoct(char c);
  27.  
  28. int
  29. main (int ac, char **av)
  30. {
  31.     FILE *fi;
  32.     FILE *fo;
  33.  
  34.     if (ac != 3) {
  35.     puts("UUARCHIVE infile outfile");
  36.     exit(1);
  37.     }
  38.     if (fi = fopen(av[1], "r")) {
  39.     if (fo = fopen(av[2], "a")) {
  40.         int r = ScanArchive(fi, fo);
  41.         fclose(fi);
  42.         fclose(fo);
  43.         if (r >= 0)
  44.         remove(av[1]);
  45.     } else {
  46.         printf("unable to create/append %s\n", av[2]);
  47.     }
  48.     } else {
  49.     printf("unable to open %s\n", av[1]);
  50.     }
  51.     return(0);
  52. }
  53.  
  54. int
  55. ScanArchive (FILE *fi, FILE *fo)
  56. {
  57.     while (fgets(Buf, sizeof(Buf), fi)) {
  58.     if (strncmp(Buf, "begin ", 6) == 0 && isoct(Buf[6]) && isoct(Buf[7]) && isoct(Buf[8]) && Buf[9] == ' ') {
  59.         fputs(Buf, fo);
  60.         fprintf(fo, "** DELETED FOR ARCHIVE **\n");
  61.         while (fgets(Buf, sizeof(Buf), fi)) {
  62.         if (strncmp(Buf, "From ", 5) == 0)
  63.             break;
  64.         if (Buf[0] == '\n')
  65.             break;
  66.         if (strncmp(Buf, "end", 3) == 0)
  67.             break;
  68.         }
  69.     }
  70.     fputs(Buf, fo);
  71.     }
  72.     if (ferror(fi) || ferror(fo))
  73.     return(-1);
  74.     return(1);
  75. }
  76.  
  77. int
  78. isoct(char c)
  79. {
  80.     if (c >= '0' && c <= '7')
  81.     return(1);
  82.     return(0);
  83. }
  84.