;*********************************************************************** ; CLRAND - CLEARs a RANDOM FILE ; Purpose: great after you use CREATE and you want the file clean ; Usage: L OPR: ; CLRAND {filespec} ; by Dave Heyliger - AMUS Staff ;*********************************************************************** SEARCH SYS ; search the normals SEARCH SYSSYM SEARCH TRM PHDR -1,0,PH$REE!PH$REU!PH$OPR ;must be in OPR: .OFINI ; define one variable .OFDEF IDDB,D.DDB ; DDB for the file .OFSIZ IMPSIZ ; IMPSIZ is 150 octal bytes GETIMP IMPSIZ,A3 ; A3 points to varibles BYP ; bypass bs LIN ; just a CR? BNE 10$ ; nope TYPECR <Usage: CLRAND {filespec}, where filespec is a random file.> TYPECR < (default extension is .DAT)> EXIT 10$: LEA A1,IDDB(A3) ; point to a DDB MOVB #D$ERC!D$BYP,IDDB+D.FLG(A3) ; set D$ERC bit (trap errors) FSPEC @A1,DAT ; get the filename CMPB IDDB+D.ERR(A3),#D$ESPC ; error? BEQ INERR ; yup CMP IDDB+D.FIL(A3),#0 ; just a ".xxx"? BNE INOK ; nope, ok so far INERR: TYPECR <?Invalid file specification> EXIT ; something was exit INOK: LEA A1,IDDB(A3) ; point to DDB INIT @A1 ; initialize LOOKUP @A1 ; find the file BNE NOFILE ; nope - error CMPW IDDB+D.WRK+6(A3),#-1 ; random file? JEQ AOK ; yup, continue LEA A2,IDDB+D.FIL(A3) ; nope, point to file TYPE <?> ; yes, start error message PFILE @A1 ; type out file TYPECR < is not a random file.> ; and error message EXIT ; then quit NOFILE: TYPECR <?This file does not exist.> EXIT ; other possible error AOK: CRLF ; make sure now.......... TYPE <You are about to zero out all data in this file. Enter Y to confirm: > KBD ; must hit CR for extra safety CTRLC END ; quit on ^C CMPB @A2,#'Y ; yes? JNE END ; nope MOV IDDB+D.WRK(A3),D2 ; D2 holds the number of blocks OPENR @A1 ; open the file READIT: READ @A1 ; get a block LOOP: MOV #128.,D3 ; number of longword clears MOV IDDB+D.BUF(A3),A4 ; A4 points to block 10$: CLR (A4)+ ; zero it out DEC D3 ; one less to do BNE 10$ ; still more to do WRITE @A1 ; write the block DEC D2 ; one less block to do BEQ END ; if zero, we are done INCW IDDB+D.REC+2(A3) ; point to next block BR READIT ; and read it END: EXIT ; back to dot END ; end of source code