home *** CD-ROM | disk | FTP | other *** search
/ OpenStep 4.2J (Developer) / os42jdev.iso / NextDeveloper / Source / GNU / uucp / Uucp.framework / contrib / uucomp.shar / uucomp-1.1 / uucomp.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-12-20  |  3.4 KB  |  137 lines

  1. /*
  2.  * uucomp - compress outgoing news/mail
  3.  * 
  4.  * usage: uucomp C.*
  5.  * 
  6.  * This works for Taylor uucp (available from prep.ai.mit.edu:/pub/gnu/uucp*),
  7.  * but I don't promise it works for anyone else's uucp package.  Basically, this
  8.  * is a quick-n-dirty hack to get compressed mail and news to a uucp site.  This
  9.  * becomes important when you're on the other end of a 1200 baud packet radio
  10.  * link, where the throughput can be 60 CPS (or lower).  It also tends to hide
  11.  * any nasties that people might want to say to you, since the packets *are*
  12.  * public readable.  Yes, I looked at uubatch, but it was too complicated for
  13.  * me to figure out <grin>, and it didn't work with Taylor-uucp.  This is almost
  14.  * too simple to work...
  15.  * 
  16.  * To use this little guy, do something like this in the .bashrc or .profile
  17.  * or .cshrc of the uucp's login shell:
  18.  * 
  19.  * cd /usr/spool/uucp/<wherever the C. and D. files are kept>
  20.  * /usr/bin/uucomp C.*
  21.  * exec /usr/lib/uucp/uucico
  22.  * 
  23.  * This program was written by Ed Carp (erc@apple.com).  It can be used for any
  24.  * non-commercial purpose.  This software is freely redistributable.
  25.  */
  26.  
  27. /*
  28.  * 
  29.  * Copyright 1993 by Ed Carp (erc@apple.com)  All rights reserved.
  30.  * 
  31.  * Permission is hereby granted for any non-commercial use of this
  32.  * program, as long as this copyright notice remains intact.  Commercial
  33.  * users may contact me - I'm easy.
  34.  * 
  35.  */
  36.  
  37. #include <stdio.h>
  38. #include "uucomp.h"
  39. #undef NULL
  40. #define NULL (0)
  41. main (argc, argv)
  42. int argc;
  43. char **argv;
  44. {
  45.   int i, j, sw, ctr = 0, errflag = 0, mctr = 0, nctr = 0, skipctr = 0;
  46.   char scr[64], rcmd[10], line[1024], lineout[1024];
  47.   char *strtok (), *ptr, *lineptr, compfile[32];
  48.   FILE *in;
  49.  
  50.   printf ("uucomp 1.1 08/04/93 ... by erc@apple.com\nscanning %d files.", argc - 1);
  51.   for (i = 1; i < argc; i++)
  52.   {
  53.     if (strncmp (argv[i], "C.", 2) != 0)
  54.     {
  55.       skipctr++;
  56.       continue;
  57.     }
  58.     if ((in = fopen (argv[i], "r+")) == (FILE *) NULL)
  59.     {
  60.       skipctr++;
  61.       continue;
  62.     }
  63.     fgets (line, 1022, in);
  64.     if(*line != 'E')
  65.     {
  66.       skipctr++;
  67.       continue;
  68.     }
  69.     line[strlen (line) - 1] = NULL;
  70.     rewind (in);
  71.     *lineout = NULL;
  72.     lineptr = line;
  73.     sw = errflag = 0;
  74.     printf (".");
  75.     fflush (stdout);
  76.     for (j = 0;; j++)
  77.     {
  78.       ptr = strtok (lineptr, " ");
  79.       if (ptr == NULL)
  80.     break;
  81.       lineptr = NULL;
  82.       if (j == 1)
  83.       {
  84.     if (access (ptr, 4) == EOF)
  85.     {
  86. #ifdef DEBUG
  87.       printf ("skip: file '%s' doesn't exist\n", ptr);
  88. #endif
  89.       errflag = 1;
  90.       break;               /*
  91.                         * skip it if the data file isn't
  92.                         * there yet 
  93.                         */
  94.     }
  95.     strcpy (compfile, ptr);
  96.       }
  97.       if (j == 9)
  98.       {
  99.     if (strcmp (ptr, "rmail") != 0 && strcmp (ptr, "rnews") != 0)
  100.     {
  101. #ifdef DEBUG
  102.       printf ("skip: '%s' wrong command\n", ptr);
  103. #endif
  104.       errflag = 1;
  105.       break;
  106.     }
  107.     if (strcmp (ptr, "rmail") == 0)
  108.       mctr++;
  109.     if (strcmp (ptr, "rnews") == 0)
  110.       nctr++;
  111.     sw = 1;
  112.     strcat (lineout, "c");
  113.       }
  114.       strcat (lineout, ptr);
  115.       strcat (lineout, " ");
  116.     }
  117.     if (errflag == 1)
  118.     {
  119.       skipctr++;
  120.       fclose (in);
  121.       continue;
  122.     }
  123.     fprintf (in, "%s\n", lineout);
  124.     fclose (in);
  125.     sprintf (line,
  126.          "%s -fc > /tmp/uucomp.%d < %s;cp /tmp/uucomp.%d %s",
  127.          COMPRESS, getpid (), compfile, getpid (), compfile);
  128.     system (line);
  129.     ctr++;
  130.   }
  131.   sprintf (line, "/tmp/uucomp.%d", getpid ());
  132.   unlink (line);
  133.   printf ("\n%d skipped, %d compressed (%d mail, %d news).\n",
  134.       skipctr, ctr, mctr, nctr);
  135.   exit (0);
  136. }
  137.