home *** CD-ROM | disk | FTP | other *** search
/ back2roots/padua / padua.7z / padua / uucp / auucp+-1.02 / fuucp_plus_src.lzh / sendbatch.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-11-21  |  3.1 KB  |  161 lines

  1. /*
  2. **  sendbatch.c - written by Ingo Feulner, Copyright (C) 1990.
  3. **
  4. **  12-Jul-90  first version
  5. **   1-Oct-90  corrected some known bugs
  6. **
  7. */
  8.  
  9.  
  10. #include <string.h>
  11. #include <stdlib.h>
  12. #include <stdio.h>
  13.  
  14. #include "unix.h"
  15. #include "config.h"
  16.  
  17. #define VERDATE " 1.02 (1 Oct 90) "
  18.  
  19. static char *version20 = "$VER: sendbatch" VERDATE "\n\r";
  20.  
  21. #ifndef TRUE
  22. #define  TRUE     1
  23. #define  FALSE    0
  24. #endif
  25.  
  26. void main(int argc, char *argv[])
  27. {
  28.   /* Werte fⁿr 'getopt()' */
  29.   extern char *optarg;
  30.   extern int optind;
  31.   signed char c;
  32.  
  33.   FILE *tmp;
  34.  
  35.   char *tempfile  = "T:sendbatch.tmpXXXXXXXX";
  36.   char *ftempfile = "T:sendbatch.finalXXXXXXXX";
  37.   char command[256];
  38.   char batch[256];
  39.   char acctest[256];
  40.   char node[20];
  41.  
  42.   char compress = FALSE;
  43.  
  44.   long maxlength = 0;
  45.  
  46.  
  47.  
  48.   while((c = getopt(argc, argv, "acl:")) > 0)
  49.   {
  50.     switch(c)
  51.     {
  52.       case 'c':
  53.         compress = TRUE;
  54.         break;
  55.       case 'l':
  56.         maxlength = atol(optarg);
  57.         break;
  58.       case '?':
  59.     (void)fprintf(stderr, "AmigaUUCP Plus: sendbatch" VERDATE "\n");
  60.     (void)fprintf(stderr, "Copyright (C) 1990 Ingo Feulner\n\n");
  61.         (void)fprintf(stderr, "Usage: %s [-c] [-l<maxlength>] system\n", argv[0]);
  62.         exit(1);
  63.         break;
  64.       default:
  65.         (void)fprintf(stderr, "Unknown option '%c'\n", c);
  66.         exit(1);
  67.         break;
  68.     }
  69.   }
  70.  
  71.   mktemp(tempfile);
  72.   mktemp(ftempfile);
  73.  
  74.   (void)strcpy(node, argv[optind]);
  75.  
  76.   (void)strcpy(batch, node);
  77.   (void)strcat(batch, ".nbatch");
  78.  
  79.   (void)strcpy(acctest, GetConfigDir(UUNEWS));
  80.   (void)strcat(acctest, batch);
  81.  
  82.   if((tmp = fopen(acctest, "r")) == NULL)
  83.   {
  84.     (void)strcat(acctest, ".work");
  85.     if((tmp = fopen(acctest, "r")) == NULL)
  86.     {
  87.       /* No news to batch, so exit quietly */
  88.       (void)remove(tempfile);
  89.       (void)remove(ftempfile);
  90.       exit(0);
  91.     }
  92.     else
  93.       fclose(tmp);
  94.   }
  95.   else
  96.     fclose(tmp);
  97.  
  98.  
  99.   if((tmp = fopen(ftempfile, "w")) == NULL)
  100.   {
  101.     (void)fprintf(stderr, "Can't open tempfile\n");
  102.     exit(1);
  103.   }
  104.  
  105.  
  106.   if(compress == TRUE)
  107.   {
  108.     (void)fprintf(tmp, "#! cunbatch\n");
  109.     fclose(tmp); /* wichtig! */
  110.  
  111.     (void)sprintf(command, "batch >%s %s %ld",
  112.                   tempfile, batch, (maxlength > 0) ? maxlength : 1000000);
  113.  
  114.     if(system(command))
  115.     {
  116.       (void)fprintf(stderr, "batch failed.\n");
  117.       exit(1);
  118.     }
  119.  
  120.  
  121.     (void)sprintf(command, "compress <%s >>%s", tempfile, ftempfile);
  122.  
  123.     if(system(command))
  124.     {
  125.       (void)fprintf(stderr, "compress failed.\n");
  126.       exit(1);
  127.     }
  128.  
  129.  
  130.     (void)sprintf(command, "uux %s \"%s!rnews\"", ftempfile, node);
  131.  
  132.     if(system(command))
  133.     {
  134.       (void)fprintf(stderr, "uux failed.\n");
  135.       exit(1);
  136.     }
  137.   }
  138.   else
  139.   {
  140.     fclose(tmp);
  141.  
  142.     (void)sprintf(command, "batch >%s %s %ld", ftempfile, batch,
  143.                                     (maxlength > 0) ? maxlength : 1000000);
  144.  
  145.     if(system(command))
  146.     {
  147.       (void)fprintf(stderr, "batch failed.\n");
  148.       exit(1);
  149.     }
  150.  
  151.     (void)sprintf(command, "uux %s \"%s!rnews\"", ftempfile, node);
  152.     if(system(command))
  153.     {
  154.       (void)fprintf(stderr, "uux failed.\n");
  155.       exit(1);
  156.     }
  157.   }
  158.   (void)remove(tempfile);
  159.   (void)remove(ftempfile);
  160. }
  161.