[net.news.sa] Fix to "/usr/lib/news/batch".

stephen@dcl-cs.UUCP (Stephen J. Muir) (09/01/85)

The program "/usr/lib/news/batch" is called from "/usr/lib/news/sendbatch" with
two arguments -- the file to batch and the maximum size of the output file.

What was happening is that "batch" exited AFTER the output file size had been
exceeded instead of just before.  So, if we use a batching size of 50000 and
the file size was at 49983, say, and the next article was 70000 bytes, we would
end up with a file of 119983 bytes.  With this patch, it would stop at 49983
and the next article would become the first (in this case only) one of the next
batch.

The above is not QUITE true -- the "batch" program doesn't make allowances for
the "#! rnews <size>" lines when calculating the size of the output file (it
didn't do that previously either).  This is not important enough for me to be
bothered to fix it.
----------------------------------- cut here ----------------------------------
*** batch.c.old	Sun Sep  1 17:24:50 1985
--- batch.c	Sun Sep  1 17:24:54 1985
***************
*** 85,92
  	else
  		maxbytes = 100000000L; /* backwards compatible */
  	nbytes = 0;
! 	while ((fdstatus = fgets(fname, sizeof fname, fd)) != NULL
! 	    && nbytes < maxbytes) {
  		cp = index(fname, '\n');
  		if (cp)
  			*cp = '\0';

--- 85,91 -----
  	else
  		maxbytes = 100000000L; /* backwards compatible */
  	nbytes = 0;
! 	while ((fdstatus = fgets(fname, sizeof fname, fd)) != NULL) {
  		cp = index(fname, '\n');
  		if (cp)
  			*cp = '\0';
***************
*** 96,101
  			continue;
  		}
  		fstat(fileno(nfd), &sbuf);
  		printf("#! rnews %ld\n", sbuf.st_size);
  		n = 0;
  		while ((c = getc(nfd)) != EOF) {

--- 95,105 -----
  			continue;
  		}
  		fstat(fileno(nfd), &sbuf);
+ 		if (cp)
+ 			*cp = '\n';	/* dcl-cs!stephen */
+ 		nbytes += sbuf.st_size;
+ 		if (nbytes > maxbytes && nbytes != sbuf.st_size)
+ 			break;	/* dcl-cs!stephen */
  		printf("#! rnews %ld\n", sbuf.st_size);
  		n = 0;
  		while ((c = getc(nfd)) != EOF) {
***************
*** 103,109
  			n++;
  		}
  		fclose(nfd);
- 		nbytes += sbuf.st_size;
  		if (n != sbuf.st_size) { /* paranoia */
  			logerr("%s, expected %ld bytes, got %ld", fname,
  				n, sbuf.st_size);

--- 107,112 -----
  			n++;
  		}
  		fclose(nfd);
  		if (n != sbuf.st_size) { /* paranoia */
  			logerr("%s, expected %ld bytes, got %ld", fname,
  				n, sbuf.st_size);
-- 
UUCP:	...!seismo!mcvax!ukc!dcl-cs!stephen
DARPA:	stephen%lancs.comp@ucl-cs	| Post: University of Lancaster,
JANET:	stephen@uk.ac.lancs.comp	|	Department of Computing,
Phone:	+44 524 65201 Ext. 4599		|	Bailrigg, Lancaster, UK.
Project:Alvey ECLIPSE Distribution	|	LA1 4YR