home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / unix_c / usenet / bncvt.c < prev    next >
C/C++ Source or Header  |  1989-03-21  |  4KB  |  114 lines

  1. 31-Oct-85 07:53:26-MST,4174;000000000001
  2. From: "Carl S. Gutekunst" <csg@pyramid.uucp>
  3. Newsgroups: net.sources
  4. Subject: bncvt -- filter bnproc batches to unbatch
  5. Date: 31 Oct 85 03:12:27 GMT
  6. Followup-To: net.sources.bugs
  7. Keywords: news bnproc unbatch bncvt
  8. To:       unix-sources@BRL-TGR.ARPA
  9.  
  10. /*===========================================================================**
  11. **              BBBBBBB   NN    NN    CCCCC   VV    VV  TTTTTTTT             **
  12. **              BB    BB  NNN   NN   CC   CC  VV    VV     TT                **
  13. **              BB    BB  NNNN  NN  CC        VV    VV     TT                **
  14. **              BBBBBBB   NN NN NN  CC        VV    VV     TT                **
  15. **              BB    BB  NN  NNNN  CC         VV  VV      TT                **
  16. **              BB    BB  NN   NNN   CC   CC    VVVV       TT                **
  17. **              BBBBBBB   NN    NN    CCCCC      VV        TT                **
  18. **===========================================================================**
  19. **  Copyright (C) 1985 by PYRAMID TECHNOLOGY CORPORATION, Mountain View, CA  **
  20. **===========================================================================**
  21. ** Permission is granted to freely use and distribute this software, as long **
  22. ** as no attempt is made to profit from it, and this notice is included.     **
  23. **===========================================================================**
  24. **
  25. ** ** bncvt.c -- utility to filter bnproc news batches to unbatch.
  26. **
  27. **    Written in a fit of desperation by Carl S. Gutekunst
  28. **
  29. ** ** Decsription:
  30. **
  31. **    This filter accepts uncompressed news batches in "bnproc" format and
  32. **    writes them out in "unbatch" format. Using 2.10.3 news, its output can
  33. **    be piped directly into rnews.
  34. **
  35. **    The filter also adjusts for the bnproc "article eater" bug, which threw
  36. **    off the article byte count and caused rnews to discard entire articles.
  37. **
  38. ** ** Execution (for 2.10.3 netnews):
  39. **
  40. **    uncompress | bncvt | rnews
  41. **
  42. ** ** Generation:
  43. **
  44. **    cc bncvt.c -o bncvt -s -O
  45. **
  46. ** ** $Log:    bncvt.c,v $
  47. **    Revision 1.1  85/10/30  19:07:13  csg
  48. **    Initial version, written in a fit of desperation by Carl S. Gutekunst.
  49. **    
  50. **===========================================================================*/
  51.  
  52. #include <stdio.h>
  53.  
  54. #define LINESIZE 128            /* Size of the input line buffer     */
  55.  
  56. static char RCSid[] = "$Header: bncvt.c,v 1.1 85/10/30 19:07:13 csg Rel $";
  57.  
  58. main ()
  59. {
  60.    char linebuf[LINESIZE], *lp;        /* Single line buffer, and pointer   */
  61.    int expected, nbytes;        /* Bytes expected and read so far    */
  62.  
  63.    nbytes = expected = 0;
  64.    while (fgets (linebuf, LINESIZE, stdin) != NULL)
  65.    {
  66.       /*
  67.        * Check for an article eater. This is a DEL character, either 0x7F or
  68.        * 0xFF, in the first column preceeding a new article byte count. It
  69.        * usually throws off the byte count, so we have to add some padding
  70.        * to keep rnews from losing sync (and discarding the next article).
  71.        */
  72.  
  73.       if ((linebuf[0] & 0x7F) == 0x7F)
  74.       {
  75.      if (expected > 0)
  76.         while (nbytes++ < expected)
  77.            putc ('\0', stdout);
  78.       }
  79.  
  80.       /*
  81.        * If we aren't expecting text, then we're expecting an article byte
  82.        * count. This is a left-justified integer, immediately followed by a
  83.        * newline. We ignore leading article-eater DEL characters.
  84.        */
  85.  
  86.       if (nbytes >= expected)
  87.       {
  88.      nbytes = expected = 0;
  89.      lp = linebuf;
  90.      while ((*lp & 0x7F) == 0x7F)
  91.         ++lp;
  92.      while (*lp >= '0' && *lp <= '9')
  93.         expected = expected * 10 + (*lp++ - '0');
  94.  
  95.      if (*lp == '\n' && expected > 0)
  96.         printf ("#! rnews %d\n", expected);
  97.      else
  98.      {  fprintf (stderr, "Sync->%s", linebuf);
  99.         expected = 0;
  100.      }
  101.       }
  102.  
  103.       /*
  104.        * Another normal line of text: write it out.
  105.        */
  106.  
  107.       else
  108.       {
  109.      fputs (linebuf, stdout);
  110.      nbytes += strlen (linebuf);
  111.       }
  112.    }
  113. }
  114.