home *** CD-ROM | disk | FTP | other *** search
/ rtsi.com / 2014.01.www.rtsi.com.tar / www.rtsi.com / OS9 / OSK / TELECOM / UUCPbb_2_1_src.lzh / UUCPBB21 / procart.c < prev    next >
Text File  |  1994-09-25  |  7KB  |  205 lines

  1. /* procart.c - Process a single article into one or more news groups.
  2.     Copyright (C) 1994 Brad Spencer
  3.  
  4.     This file is part of the OS-9 UUCP package, UUCPbb.
  5.  
  6.     This program is free software; you can redistribute it and/or modify
  7.     it under the terms of the GNU General Public License as published by
  8.     the Free Software Foundation; either version 2 of the License, or
  9.     (at your option) any later version.
  10.  
  11.     This program is distributed in the hope that it will be useful,
  12.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.     GNU General Public License for more details.
  15.  
  16.     You should have received a copy of the GNU General Public License
  17.     along with this program; if not, write to the Free Software
  18.     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19.  
  20.     The author of UUCPbb, Bob Billson, can be contacted at:
  21.     bob@kc2wz.bubble.org  or  uunet!kc2wz!bob  or  by snail mail:
  22.     21 Bates Way, Westfield, NJ 07090
  23. */
  24.  
  25. #include "uucp.h"
  26. #include "rnews.h"
  27. #include "mbuf.h"
  28.  
  29. extern char *junk;
  30. extern char *space;
  31. struct mbuf *mwrite();
  32. extern int debuglvl;
  33.  
  34. int free();
  35.  
  36. int procart (fd, initalbuf, initng, gh, origlength)
  37. FILE *fd;
  38. char *initalbuf, *initng;
  39. struct mbuf *gh;
  40. long origlength;
  41. {
  42.      char lbuf[512];
  43.      char *newsgroups = NULL, *refline = NULL;
  44.      int gotgroup = FALSE, r;
  45.      struct mbuf *mh = NULL, *mp = NULL;
  46.      register struct mbuf *gg;
  47.  
  48.      /* A inital newsgroup may be forced onto this article */
  49.      if (*initng != '\0')
  50.           newsgroups = initng;
  51.  
  52.      mp = mwrite (mp, &mh, initalbuf, strlen (initalbuf) + 1);
  53.  
  54.      while (feof (fd) == 0)
  55.        {
  56.           if (gotgroup == FALSE)
  57.             {
  58.                getline (fd, initalbuf);
  59.  
  60.                if (debuglvl > 8)
  61.                     lineis (lbuf, initalbuf);
  62.  
  63.                mp = mwrite (mp, &mh, initalbuf, strlen (initalbuf) + 1);
  64.  
  65.                if (*initng == '\0')
  66.                  {
  67.                     if (strncmp (mp->cbuf, "Newsgroups: ", 12) == 0)
  68.                       {
  69.                          newsgroups = &mp->cbuf[12];
  70.  
  71.                          if (debuglvl > 1)
  72.                            {
  73.                               sprintf (lbuf, "Newsgroup: %s", newsgroups);
  74.                               log (lbuf);
  75.                            }
  76.  
  77.                          if (refline != NULL)
  78.                               gotgroup = TRUE;
  79.                       }
  80.                  }
  81.  
  82.                /* Bob says that tabs need to be eaten from References: lines
  83.                 */
  84.               if (strncmp (mp->cbuf, "References: ", 12) == 0)
  85.                 {
  86.                    refline = mp->cbuf;
  87.                    fixref (refline);
  88.  
  89.                    if (debuglvl > 2)
  90.                      {
  91.                         sprintf (lbuf, "Reference line is: '%s'", refline);
  92.                         log (lbuf);
  93.                      }
  94.  
  95.                    if (newsgroups != NULL)
  96.                         gotgroup = TRUE;
  97.                  }
  98.  
  99.                if (mp->cbuf[0] == '\0')
  100.                  {
  101.                     if (newsgroups == NULL)
  102.                       {
  103.                          if (debuglvl > 1)
  104.                               log ("No newsgroup given, junking article");
  105.  
  106.                          newsgroups = junk;
  107.                       }
  108.                     gotgroup = TRUE;
  109.                  }
  110.             }
  111.           else
  112.             {
  113.                if (gotgroup == TRUE)
  114.                  {
  115.                     openarts (gh, newsgroups);
  116.  
  117.                     if (origlength != -1)
  118.                          if ((origlength - 1) > 0)
  119.                               extendfile (gh, origlength, lbuf);
  120.  
  121.                     /* Write the inital few lines to the file(s) */
  122.                     for (gg = gh; gg != NULL; gg = gg->mbuf_next)
  123.                          if (((struct groups *)gg->cbuf)->artfd != NULL)
  124.                               for (mp = mh; mp != NULL; mp = mp->mbuf_next)
  125.                                    fprintf (((struct groups *)gg->cbuf)->artfd,"%s\n", mp->cbuf);
  126.  
  127.                     gotgroup++;
  128.                  }
  129.  
  130.                if ((r = fread (initalbuf, 1, BIGBUF-1, fd)) < 0)
  131.                     log ("procart: read error");
  132.  
  133.                if (debuglvl > 8)
  134.                  {
  135.                     sprintf (lbuf, "read: %d", r);
  136.                     log (lbuf);
  137.                  }
  138.                crlf (initalbuf, r);
  139.  
  140.                /* Write a just-read block */
  141.                for (gg = gh;  gg != NULL;  gg = gg->mbuf_next)
  142.                     if (((struct groups *)gg->cbuf)->artfd != NULL)
  143.                          fwrite (initalbuf, 1, r,((struct groups *)gg->cbuf)->artfd);
  144.             }
  145.        }
  146.  
  147.      /* Close all the open files */
  148.      for (gg = gh; gg != NULL; gg = gg->mbuf_next)
  149.           if (((struct groups *)gg->cbuf)->artfd != NULL)
  150.             {
  151.                fclose (((struct groups *)gg->cbuf)->artfd);
  152.                ((struct groups *)gg->cbuf)->artfd = NULL;
  153.             }
  154.  
  155.      /* free the mbuf list, use 'free' because the cbufs are simple */
  156.      if (mh != NULL)
  157.           mfree (mh, free);
  158. }
  159.  
  160.  
  161.  
  162. /* This next bit is a attempt to lessen the disk fragmentation that seems to
  163.    occur when spooling news.  It seeks to the maximum length that a article
  164.    may be and then writes a byte.  It then rewinds.  Hopefully, contiguous
  165.    blocks will be allocated */
  166.  
  167. int extendfile (gh, origlength, lbuf)
  168. struct mbuf *gh;
  169. long origlength;
  170. char lbuf[];
  171. {
  172.      register struct mbuf *gg;
  173.  
  174.      for (gg = gh; gg != NULL; gg = gg->mbuf_next)
  175.           if (((struct groups *)gg->cbuf)->artfd != NULL)
  176.             {
  177.                if (lseek (fileno (((struct groups *)gg->cbuf)->artfd),
  178.                                   origlength-1, 0) == -1)
  179.                  {
  180.                     sprintf (lbuf, "Couldn't seek %ld %d",
  181.                                    origlength-1, errno);
  182.                     log (lbuf);
  183.                  }
  184.  
  185.                write (fileno (((struct groups *)gg->cbuf)->artfd), space, 1);
  186.  
  187.                if (lseek (fileno (((struct groups *)gg->cbuf)->artfd), 0L, 0)
  188.                       == -1)
  189.                  {
  190.                     sprintf (lbuf, "Couldn't seek back %ld %d",
  191.                                    origlength, errno);
  192.                     log (lbuf);
  193.                  }
  194.             }
  195. }
  196.  
  197.  
  198.  
  199. int lineis (lbuf, initalbuf)
  200. char lbuf[], *initalbuf;
  201. {
  202.      strncat (strcpy (lbuf, "LINE IS '"), initalbuf, 20);
  203.      log (lbuf);
  204. }
  205.