home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / misc / volume7 / bsnews1.1 / rnews.c < prev    next >
C/C++ Source or Header  |  1989-08-05  |  2KB  |  103 lines

  1. /*
  2.  * rnews.c - uux command for bootstrap news
  3.  * copyright 1989 Ronald Florence (ron@mlfarm 7/30/89)
  4.  */
  5.  
  6. #include <stdio.h>
  7. #include <time.h>
  8.  
  9. #ifndef Newsspool
  10. #define Newsspool    "/usr/spool/news/bsnews"
  11. #endif
  12. #ifndef Feeder
  13. #define Feeder         "Usenet"
  14. #endif
  15.  
  16. #define Compress     "/usr/bin/compress -dc > "
  17.  
  18. char      *mktemp(),
  19.         dcomp[40] = Compress;
  20.  
  21. main()
  22. {
  23.   FILE    *nf, *cf;
  24.   char  buf[BUFSIZ],
  25.         *tmpnews = mktemp("newsart.XXXXXX");
  26.   register  c;
  27.   int    new = 1, n;
  28.  
  29.   if (!(nf = fopen(Newsspool, "a")))
  30.     {
  31.       fprintf(stderr, "rnews: can't write to %s\n", Newsspool);
  32.       exit(1);
  33.     }
  34.  
  35.   while (fgets(buf, BUFSIZ, stdin) != NULL)
  36.     {
  37.                 /* batched? */
  38.       if (!strncmp(buf, "#! ", 3))
  39.     {
  40.                 /* compressed? */
  41.       if (!strncmp(buf+3, "cunbatch", 8))
  42.         {
  43.           strcat(dcomp, tmpnews);
  44.           if (!(cf = popen(dcomp, "w")))
  45.         {
  46.           timestamp(nf);
  47.           fprintf(nf, "\nNews lost!  Can't uncompress (rnews).\n\n");
  48.           exit(1);
  49.         }
  50.                 /* uncompress */
  51.           while ((c = getchar()) != EOF)
  52.         putc(c, cf);
  53.           pclose(cf);
  54.                 /* and loop around to unbatch */
  55.           cf = freopen(tmpnews, "r", stdin);
  56.           continue;
  57.         }
  58.                 /* unpack the batch */
  59.       else if (sscanf(buf+3, "rnews %d", &n) == 1)  
  60.         {
  61.           timestamp(nf);
  62.           for (c = 0; c < n; c += strlen(buf))
  63.         {
  64.           if (fgets(buf, BUFSIZ, stdin) == NULL)
  65.             break;
  66.           if (!strncmp(buf, "From ", 5))
  67.             putc('>', nf);
  68.           fputs(buf, nf);
  69.         }
  70.           putc('\n', nf);
  71.           continue;
  72.         }
  73.     }
  74.                 /* it must be unbatched */
  75.       else    
  76.     {
  77.       if (new)
  78.         {
  79.           timestamp(nf);
  80.           new = 0;
  81.         }
  82.       if (!strncmp(buf, "From ", 5))
  83.         putc('>', nf);
  84.       fputs(buf, nf);
  85.     }
  86.     }
  87.   if (!new)
  88.     putc('\n', nf);
  89.   unlink(tmpnews);
  90.   exit(0);
  91. }
  92.  
  93.  
  94. timestamp(newsfile)
  95. FILE  *newsfile;
  96. {
  97.   long    clock, time();
  98.   char    *ctime();
  99.  
  100.   time(&clock);
  101.   fprintf(newsfile, "From %s %s", Feeder, ctime(&clock));
  102. }
  103.