From:	MERC::"uunet!VM1.NoDak.EDU!ANU-NEWS" 29-JUN-1992 13:14:00.67
To:	Multiple recipients of list ANU-NEWS <ANU-NEWS@VM1.NoDak.EDU>
CC:	
Subj:	Re: NNTP -- please be quiet

In article <1992Jun29.144250.26626@julian.uwo.ca>,
 reggers@julian.uwo.ca (Reg Quinton) writes:
> 1. Newsrc.old:
> My users aren't at all happy about this new feature, perhaps it should be
> conditionalized on some profile setting or environment variable?

Here is some code was posted the the newsgroup some time ago changing this
behavior by Harry Flowers.
--
USmail: Bob Sloane, University of Kansas Computer Center, Lawrence, KS, 66045
E-mail: sloane@kuhub.cc.ukans.edu, sloane@ukanvax.bitnet, AT&T: (913)864-0444

From: Harry Flowers <flowers@memstvx1.memst.edu>
Subject: Bugfix: corrupted NEWSRC./NEWSRC.OLD problem

Okay, here's a patch to V6.1a4 NEWSRC.C to change the behavior; now, it
will not make any .OLD files, but, if it encounters an error when updating
the NEWSRC file, it will retain the old one and issue an error for the user.
The status given will be "1" if the error was encountered when writing the
file, and "-1" if the error occurred in flushing the buffers on the close.
I've tested it, and I haven't been able to get NEWS to leave a corrupted
NEWSRC file with this fix.  Hopefully, this will make it into the V6.1
distribution.  If you have any problems with this fix, please let me know.

To apply this patch:   $ UPATCH NEWSRC.C <NEWSRC_C.PAT
where UPATCH is defined to call the Un*x-like patch program.

$! ------------------ CUT HERE -----------------------
$ v='f$verify(f$trnlnm("SHARE_VERIFY"))'
$!
$! This archive created by VMS_SHARE Version 7.2-007  22-FEB-1990
$!   On  7-MAY-1992 09:40:37.61   By user FLOWERS
$!
$! This VMS_SHARE Written by:
$!    Andy Harper, Kings College London UK
$!
$! Acknowledgements to:
$!    James Gray       - Original VMS_SHARE
$!    Michael Bednarek - Original Concept and implementation
$!
$! TO UNPACK THIS SHARE FILE, CONCATENATE ALL PARTS IN ORDER
$! AND EXECUTE AS A COMMAND PROCEDURE  (  @name  )
$!
$! THE FOLLOWING FILE(S) WILL BE CREATED AFTER UNPACKING:
$!       1. NEWSRC_C.PAT;1
$!
$set="set"
$set symbol/scope=(nolocal,noglobal)
$f=f$parse("SHARE_TEMP","SYS$SCRATCH:.TMP_"+f$getjpi("","PID"))
$e="write sys$error  ""%UNPACK"", "
$w="write sys$output ""%UNPACK"", "
$ if f$trnlnm("SHARE_LOG") then $ w = "!"
$ ve=f$getsyi("version")
$ if ve-f$extract(0,1,ve) .ges. "4.4" then $ goto START
$ e "-E-OLDVER, Must run at least VMS 4.4"
$ v=f$verify(v)
$ exit 44
$UNPACK: SUBROUTINE ! P1=filename, P2=checksum
$ if f$search(P1) .eqs. "" then $ goto file_absent
$ e "-W-EXISTS, File ''P1' exists. Skipped."
$ delete 'f'*
$ exit
$file_absent:
$ if f$parse(P1) .nes. "" then $ goto dirok
$ dn=f$parse(P1,,,"DIRECTORY")
$ w "-I-CREDIR, Creating directory ''dn'."
$ create/dir 'dn'
$ if $status then $ goto dirok
$ e "-E-CREDIRFAIL, Unable to create ''dn'. File skipped."
$ delete 'f'*
$ exit
$dirok:
$ w "-I-PROCESS, Processing file ''P1'."
$ if .not. f$verify() then $ define/user sys$output nl:
$ EDIT/TPU/NOSEC/NODIS/COM=SYS$INPUT 'f'/OUT='P1'
PROCEDURE Unpacker ON_ERROR ENDON_ERROR;SET(FACILITY_NAME,"UNPACK");SET(
SUCCESS,OFF);SET(INFORMATIONAL,OFF);f:=GET_INFO(COMMAND_LINE,"file_name");b:=
CREATE_BUFFER(f,f);p:=SPAN(" ")@r&LINE_END;POSITION(BEGINNING_OF(b));
LOOP EXITIF SEARCH(p,FORWARD)=0;POSITION(r);ERASE(r);ENDLOOP;POSITION(
BEGINNING_OF(b));g:=0;LOOP EXITIF MARK(NONE)=END_OF(b);x:=ERASE_CHARACTER(1);
IF g=0 THEN IF x="X" THEN MOVE_VERTICAL(1);ENDIF;IF x="V" THEN APPEND_LINE;
MOVE_HORIZONTAL(-CURRENT_OFFSET);MOVE_VERTICAL(1);ENDIF;IF x="+" THEN g:=1;
ERASE_LINE;ENDIF;ELSE IF x="-" THEN IF INDEX(CURRENT_LINE,"+-+-+-+-+-+-+-+")=
1 THEN g:=0;ENDIF;ENDIF;ERASE_LINE;ENDIF;ENDLOOP;t:="0123456789ABCDEF";
POSITION(BEGINNING_OF(b));LOOP r:=SEARCH("`",FORWARD);EXITIF r=0;POSITION(r);
ERASE(r);x1:=INDEX(t,ERASE_CHARACTER(1))-1;x2:=INDEX(t,ERASE_CHARACTER(1))-1;
COPY_TEXT(ASCII(16*x1+x2));ENDLOOP;WRITE_FILE(b,GET_INFO(COMMAND_LINE,
"output_file"));ENDPROCEDURE;Unpacker;QUIT;
$ delete/nolog 'f'*
$ CHECKSUM 'P1'
$ IF CHECKSUM$CHECKSUM .eqs. P2 THEN $ EXIT
$ e "-E-CHKSMFAIL, Checksum of ''P1' failed."
$ ENDSUBROUTINE
$START:
$ create 'f'
X*** $1$DUA7:`5BANU.NEWS61A4.NEWS_SRC`5DNEWSRC.C;168
X--- newsrc.c
X**************
X*** 32,37
X `20
X  #include "newsinclude.h"
X  #include "newsextern.h"
X `20
X `20
X  time_t sys_reg_time = (time_t) 0;
X--- 32,38 -----
X `20
X  #include "newsinclude.h"
X  #include "newsextern.h"
X+ #include signal
X `20
X  time_t sys_reg_time = (time_t) 0;
X `20
X**************
X*** 33,39
X  #include "newsinclude.h"
X  #include "newsextern.h"
X `20
X-`20
X  time_t sys_reg_time = (time_t) 0;
X `20
X  extern int profile_flags, kid_valid;
X--- 34,39 -----
X  #include "newsextern.h"
X  #include signal
X `20
X  time_t sys_reg_time = (time_t) 0;
X `20
X  extern int profile_flags, kid_valid;
X**************
X*** 522,528
X    int f_itm,
X        l_itm,
X        i = 1,
X!       g;
X    ITM_PTR l_ia;
X    GRP_PTR l_ga;
X  #if USEDOTNEWSRC
X--- 522,529 -----
X    int f_itm,
X        l_itm,
X        i = 1,
X!       g,
X!       bad_file;
X    ITM_PTR l_ia;
X    GRP_PTR l_ga;
X  #if USEDOTNEWSRC
X**************
X*** 716,722
X    kill_write(newsrc);
X    profile_write(newsrc);
X    putlc = 0;
X!   fclose(newsrc); newsrc = 0;
X `20
X    rename(n_r_n,n_r_c);`09`09/* rename tmp to newsrc name */
X    while (!delete(n_r_n));       /* delete all tmp versions */
X--- 717,731 -----
X    kill_write(newsrc);
X    profile_write(newsrc);
X    putlc = 0;
X!   bad_file = (ferror(newsrc) `7C fclose(newsrc));  /* get status & close f
Vile */
X!   newsrc = 0;
X!   if (bad_file) `7B`09/* if any error occured writing or flushing, abort *
V/
X!     sprintf(err_oline,"ERROR: unable to update NEWSRC; status %d",bad_file
V);
X!     write_err_line(err_oline);`09/* show the error */
X!     while (!delete(n_r_n));`09/* cleanup tmp files */
X!     sleep(5);`09`09`09/* give some time to see the error msg */
X!     return(bad_file);`09`09/* return with status */
X!     `7D
X `20
X    rename(n_r_n,n_r_c);`09`09/* rename tmp to newsrc name */
X    while (!delete(n_r_n));       /* delete all tmp versions */
X**************
X*** 720,747
X `20
X    rename(n_r_n,n_r_c);`09`09/* rename tmp to newsrc name */
X    while (!delete(n_r_n));       /* delete all tmp versions */
X- /************************************************************************/
X- /* a new bittlet of code to perform the analogue of rn's .newsrc ->`09*/
X- /* .oldnewsrc: rename older newsrc to newsrc.old and purge that`09`09*/
X- /* this does the required thing, but the code isn't yet robust enough`09*/
X- /* to post`09`09`09`09`09`09`09`09*/
X- /************************************************************************/
X-   strcpy(n_r_n,n_r_c);          /* fin with tmp name - copy newsrc name */
X-   sprintf(err_oline,"n_r_n is %s",n_r_n);
X-   err_line(err_oline);
X-   if (n_r_n`5Bstrlen(n_r_n)-1`5D == '.')
X-      strcat(n_r_n,"old");`09/* make up `60save' version name */
X-   else
X-      strcat(n_r_n,".old");
X-   strcat(n_r_c,";-1");`09`09/* point to next older version */
X-   rename(n_r_c,n_r_n);`09`09/* rename next older version to .old */
X-   strcat(n_r_n,";-2");`09`09/* potentially retain two versions of .old */
X-   while (!delete(n_r_n));`09/* purge .old/keep=2 */
X-   while (!delete(n_r_c));       /* purge newsrc file */
X-   n_r_c`5Bstrlen(n_r_c)-3`5D = '\0'; /* rename newsrc to version 1 */
X- /************************************************************************/
X- /* end of patched bit of code`09`09`09`09`09`09*/
X- /************************************************************************/
X    strcpy(n_r_n,n_r_c);          /* fin with tmp name - save newsrc name */
X    strcat(n_r_c,";-1");          /* purge newsrc file */
X    while (!delete(n_r_c));
X--- 729,734 -----
X `20
X    rename(n_r_n,n_r_c);`09`09/* rename tmp to newsrc name */
X    while (!delete(n_r_n));       /* delete all tmp versions */
X    strcpy(n_r_n,n_r_c);          /* fin with tmp name - save newsrc name */
X    strcat(n_r_c,";-1");          /* purge newsrc file */
X    while (!delete(n_r_c));
$ CALL UNPACK NEWSRC_C.PAT;1 1159636939
$ v=f$verify(v)
$ EXIT
$! ------------------ CUT HERE -----------------------
--
Harry Flowers                           Internet: FLOWERS@MEMSTVX1.MEMST.EDU
Memphis State University                & Bitnet: FLOWERS@MEMSTVX1
