.TITLE SRDSRT-SORT THE DIRECTRY .IDENT -6.4- ; DEC-83 .ENABL LC ; ; MODIFICATIONS: ; ; CEF001 -- 1-June-83 ; ADD .PSECTS ; ; ; VERSION 6.4 - 07-Nov-83 (;BT003 and ;DJS001) ; ; Bob Turkelson ; SRD Working Group ; ; Use additional LUN for reading headers. For directories too ; large to fit into memory, the directory is kept open while ; processing it in pieces. Thus the directory LUN can not be ; re-used for reading the headers. ; Issue a fatal message if write-back is specified and the ; directory is too large to fit into memory. Determined before ; any directory sorting is done, to save the sorting time. ; (Previously a directory write-back cancelled warning was ; issued, but the last piece of the directory was written ; anyway, wiping out most of the directory.) ; Add sort by date capability. Merged from Henry Tumblin's ; version of SRD (which does not appear on the SIG tapes). ; Allow specification of major and minor sort keys in any order ; in the /SR:x:x:x switch, also allowing the sort to be either ; ascending or descending for any key (file name, type, version ; date). Ascending and descending capability adopted from ; changes by Dave Sides (Sachs/Freeman Assoc., Inc., c/o ; JHU/Applied Physics Laboratory)(;DJS001). Ideas for ; specifying sort keys came from the version of SRD in the ; U. S. Forest Service collection of programs appearing on the ; Spring 1982 SIG tape. The implementation here is quite ; different. ; ;+ ; ; **SRD--SORT DIRECTORY ; ; THIS MODULE SORTS THE DIRECTORY ; ; ; DUKE001 -- 19-NOV-79,-5.0-, HENRY R. TUMBLIN ; MOVED COMPRESS INTO SRDSUB AS A SUBROUTINE ; ; THIS TASK WILL SORT A RSX11/IAS DIRECTORY ; THEN CREATE A LISTING WITH SEVERAL SELECTION OPTIONS ; ; ; ;- ; .PSECT SRDATA,D,RW,LCL,REL,CON ;BT003 ; SYSTEM MACRO CALLS ;**-1 ; .MCALL CALLR,WRITE$,WAIT$,CLOSE$,QIOW$,DIR$ ;BT003 ; ;**-1 ; LOCAL MACRO ; .MACRO C$MP ARG,DIR ;DJS001 .IF IDN DIR ASC ; Is the order ascending? ;DJS001 CMP ARG(R3),ARG(R4) ; SEE WHICH IS BIGGER ;DJS001 BHI EXCHNG ; IF HI EXCHANGE POINTERS ;DJS001 BLO CONTINUE ; IF LO, CONTINUE ;DJS001 .IFF ; Else... ;DJS001 .IF IDN DIR DSC ; Is the order descending? ;DJS001 CMP ARG(R3),ARG(R4) ; SEE WHICH IS SMALLER ;DJS001 BLO EXCHNG ; IF LO EXCHANGE POINTERS ;DJS001 BHI CONTINUE ; IF HI, CONTINUE ;DJS001 .IFF ; Else... ;DJS001 .ERROR ; Illegal value for direction argument. ;DJS001 .ENDC ;DJS001 .ENDC ;DJS001 .ENDM ;DJS001 ; ;BT003 READAT: QIOW$ IO.RAT,HDRLUN,EFN1,,IOSB$,,<0,ATTLST> ;BT003 ATTLST: .BYTE -15,43 ; Read creation date ;BT003 .WORD DTBUF ; Buffer to receive date/time ;BT003 .WORD 0 ; End of attribute list ;BT003 DTBUF: ;BT003 RVNO: .BLKW 1 ; Revision number ;BT003 RVDATE: .BLKB 7 ; Revision date ;BT003 .BLKB 6 ; Revision time ;BT003 CRDATE: .BLKB 7 ; Creation date ;BT003 .BLKB 6 ; Creation time ;BT003 .BLKB 7 ; Expiration date ;BT003 .EVEN ;BT003 SRTORD: .BLKW 6 ; Addresses for ordered sort ;BT003 ; ;BT003 .PSECT SRDCOD,I,RO,LCL,CON,REL ;BT003 ; ;BT003 ; ;**-5 SRDSRT:: ;BT003 BIT #WBSW,SWMS2$ ; Requested to write back directory? ;BT003 BEQ 5$ ; EQ - no, proceed ;BT003 CMPB #IE.EOF,F.ERR+UFDFDB ; Has entire directory been read? ;BT003 BEQ 5$ ; EQ - yes, proceed ;BT003 FERR WBCAN ; Issue fatal error (without sorting) to ;BT003 ; ; prevent last piece of directory being ;BT003 ; ; written later ;BT003 5$: MOV F.BKDS+2+UFDFDB,R1 ; Point at end of buffer ;BT003 ;**-1 MOV DIRBF$,R2 ; POINT AT TOP OF DIRECTORY CALL SRDCOM ; COMPRESS WHAT WE HAVE. .ENABL LSB BIT #DATSRT,FLAGS$ ; Sorting by date? ;BT003 BEQ 10$ ; EQ - no ;BT003 CALL GETDAT ; Read in file headers to get dates ;BT003 ; ;BT003 ; AT THIS POINT, THE DIRECTORY IS DENSE, AND ; R1=LOGICAL END OF DIRECTORY ; R2=FIRST ENTRY ; ; NOW WE SORT THE ENTRIES ; 10$: BIT #SRSW,SWMS2$ ; SORT IT ??? BNE 100$ ; NE - yes ;BT003 JMP WBACK ; Otherwise, check for write-back ;BT003 100$: MOV #SRTORD,R3 ; Point to table to put sort code addresses ;BT003 MOV #SKBUF$,R5 ; Point to start of sort key buffer ;BT003 110$: CMPB (R5),#'T ; Sort on file type? ;BT003 BNE 130$ ; NE - no ;BT003 TSTB (R5)+ ; Point to field for descending ;BT003 CMPB (R5)+,#'D ; Descending file type? ;BT003 BEQ 120$ ; EQ - yes ;BT003 MOV #STA,(R3)+ ; Ascending file type ;BT003 BR 250$ ; Proceed to next sort key ;BT003 120$: MOV #STD,(R3)+ ; Descending file type ;BT003 BR 250$ ; Proceed to next sort key ;BT003 130$: CMPB (R5),#'N ; Sort on file name? ;BT003 BNE 150$ ; NE - no ;BT003 TSTB (R5)+ ; Point to field for descending ;BT003 CMPB (R5)+,#'D ; Descending file type? ;BT003 BEQ 140$ ; EQ - yes ;BT003 MOV #SNA,(R3)+ ; Ascending file name ;BT003 BR 250$ ; Proceed to next sort key ;BT003 140$: MOV #SND,(R3)+ ; Descending file name ;BT003 BR 250$ ; Proceed to next sort key ;BT003 150$: CMPB (R5),#'V ; Sort on file version? ;BT003 BNE 170$ ; NE - no ;BT003 TSTB (R5)+ ; Point to field for descending ;BT003 CMPB (R5)+,#'D ; Descending file version? ;BT003 BEQ 160$ ; EQ - yes ;BT003 MOV #SVA,(R3)+ ; Ascending file version ;BT003 BIS #ASCVER,FLAGS$ ; Set ascending version flag ;BT003 BIT #PUSW,SWMSK$ ; Selecting obsolete versions? ;BT003 BNE 250$ ; NE - yes ;BT003 BIS #OVDSVA,FLAGS$ ; No, set for ascending, highest versions ;BT003 BR 250$ ; Proceed to next sort key ;BT003 160$: MOV #SVD,(R3)+ ; Descending file version ;BT003 BIT #PUSW,SWMSK$ ; Selecting obsolete versions? ;BT003 BEQ 250$ ; EQ - no ;BT003 BIS #OVDSVA,FLAGS$ ; No, set for descending, lowest versions ;BT003 BR 250$ ; Proceed to next sort key ;BT003 170$: CMPB (R5),#'D ; Sort on file date? ;BT003 BNE 190$ ; NE - no ;BT003 TSTB (R5)+ ; Point to field for descending ;BT003 CMPB (R5)+,#'D ; Descending date? ;BT003 BEQ 180$ ; EQ - yes ;BT003 MOV #SDA,(R3)+ ; Ascending date ;BT003 BR 250$ ; Proceed to next sort key ;BT003 180$: MOV #SDD,(R3)+ ; Descending date ;BT003 BR 250$ ; Proceed to next sort key ;BT003 190$: TST (R5)+ ; Future ;BT003 250$: TST (R5) ; At end of sort keys? ;BT003 BNE 110$ ; No, process next one ;BT003 CLR (R3) ; Signal end of address table ;BT003 15$: ;BT003 MOV R2,R3 ; COPY ADDRESS OF CURRENT TOP ;**-1 MOV R3,R4 ; AGAIN 20$: ADD #D.SIZ,R4 ; POINT AT NEXT ITEM CMP R4,R1 ; WATCH FOR END BHIS 40$ ; BR WHEN ALL DONE MOV #SRTORD,R5 ; Point to table of addresses of sort code ;BT003 JMP @(R5)+ ; Check the first field for sorting ;BT003 NXTFLD: TST (R5) ; Are we at the end of the table? ;BT003 BEQ CONTINUE ; EQ - yes ;BT003 JMP @(R5)+ ; Check the next field for sorting ;BT003 EXCHNG: MOV R4,R3 ;BT003 CONTINUE: BR 20$ ;BT003 STA: C$MP D.TYP,ASC ; Ascending file type ;BT003 BR NXTFLD ; Proceed to next sort key ;BT003 STD: C$MP D.TYP,DSC ; Descending file type ;BT003 BR NXTFLD ; Proceed to next sort key ;BT003 SNA: C$MP D.FNAM,ASC ; Ascending file name ;BT003 C$MP D.FNAM+2,ASC ;BT003 C$MP D.FNAM+4,ASC ;BT003 BR NXTFLD ; Proceed to next sort key ;BT003 SND: C$MP D.FNAM,DSC ; Descending file name ;BT003 C$MP D.FNAM+2,DSC ;BT003 C$MP D.FNAM+4,DSC ;BT003 BR NXTFLD ; Proceed to next sort key ;BT003 SVA: C$MP D.VER,ASC ; Ascending file version ;BT003 BR NXTFLD ; Proceed to next sort key ;BT003 SVD: C$MP D.VER,DSC ; Descending file version ;BT003 BR NXTFLD ; Proceed to next sort key ;BT003 SDA: C$MP D.FLEV,ASC ; Ascending date ;BT003 BR NXTFLD ; Proceed to next sort key ;BT003 SDD: C$MP D.FLEV,DSC ; Descending date ;BT003 BR NXTFLD ; Proceed to next sort key ;BT003 ; ;**-15 ; COME HERE AFTER A SCAN COMPLETE ; 40$: CMP R2,R3 ; MAKE SURE IT CHANGED BNE 45$ ; BR IF EXCHANGE REQUIRED ADD #D.SIZ,R2 ; ADVANCE TO NEXT ENTRY BR 60$ 45$: MOV #8.,R4 ; SET LOOP COUNT 50$: MOV (R2),-(SP) ; PUSH 1 MOV (R3),(R2)+ ; COPY NEW OVER OLD MOV (SP)+,(R3)+ ; NOW PUT SOB R4,50$ ; 60$: CMP R2,R1 ; SEE IF DONE BLO 15$ ; LO - no, more to do ;BT003 .DSABL LSB ;**-1 ; ; DIRECTORY IS SORTED, NOW WRITE BACK ; WBACK: MOV #WBTRY,R4 ; Re-try loop count ;BT003 CLR R5 ;**-1 BIT #WBSW,SWMS2$ ;WRITE-BACK REQUESTED? BEQ 90$ ;BR IF NO ;**-5 65$: CMP DIRBF$,R1 ; DOES THE DIRECTORY HAVE ANYTHING IN IT? BHIS 100$ ; NO -- DON'T WRITE. BIT #DATSRT,FLAGS$ ; Doing a date sort? ;BT003 BEQ 68$ ; EQ - no ;BT003 CALL CLRDAT ; Clear temporary dates out of header ;BT003 68$: ;BT003 CLR R5 MOV #1,F.EFBK+2+UFDFDB ;RESET END-OF-FILE MOV DIRBF$,F.BKDS+2+UFDFDB ;POINT I-O BUFFER TO TOP MOV #1,F.VBN+2+UFDFDB ;AND ALSO VIRT. BLK NUMBER 70$: WRITE$ #UFDFDB ;WRITE OUT A BLOCK BCS 85$ ; ERROR WAIT$ #UFDFDB ; WAIT FOR COMPLETION BCS 85$ 75$: ADD #512.,F.BKDS+2+UFDFDB ;ADJ. BUFFER TO NEXT BLK CMP F.BKDS+2+UFDFDB,R1 ;SEE IF WE'RE PAST END OF DATA BLO 70$ ; CHECK FOR ERROR & RETRY IF NEEDED TST R5 BEQ 100$ ; NO ERRORS THIS TIME SOB R4,65$ BR 100$ ; Close UFD & return 85$: DIAG WBERR INC R5 BR 75$ 90$: CMPB #IE.EOF,F.ERR+UFDFDB ; DONE WITH DIRECTORY ?? BNE 110$ ; If NE no - just return ; 100$: CLOSE$ #UFDFDB ; Close the UFD ; 110$: MOV R1,F.BKDS+2+UFDFDB ; POINT AT END OF BUFFER RETURN ; and return ; ;BT003 ;+ ;BT003 ; This routine will fill in the file date in ;BT003 ; the file system level location in the file ID in ;BT003 ; the directory entry. On ODS-1 systems, this location ;BT003 ; is always zero. ;BT003 ;- ;BT003 GETDAT: MOV R0,-(SP) ; Save registers ;BT003 MOV R1,-(SP) ; ... ;BT003 MOV R2,-(SP) ; ... ;BT003 MOV R2,R3 ; Point to start of directory ;BT003 10$: CMP R3,R1 ; At end yet ? ;BT003 BHIS 90$ ; HIS - then all thru ;BT003 MOV R1,-(SP) ; Save pointer ;BT003 MOV R3,READAT+Q.IOPL ; Set file ID pointer ;BT003 DIR$ #READAT ; Read attributes ;BT003 CMPB IOSB$,#IS.SUC ; Did it succeed ? ;BT003 BEQ 20$ ; EQ - yes ;BT003 DIAG BADDS ; Unable to read file dates ;BT003 CLR R2 ; Set to zero ;BT003 BR 30$ ;BT003 20$: MOV #CRDATE,R1 ; Point to creation date string ;BT003 BIT #RDSW,SWMS2$ ; Use revision date? ;BT003 BEQ 25$ ; EQ - no ;BT003 TST RVNO ; Ever revised? ;BT003 BEQ 25$ ; EQ - no, use creation date ;BT003 MOV #RVDATE,R1 ; Point to revision date string ;BT003 25$: CALL CVDATE ; Convert date (return value in R2) ;BT003 BCC 30$ ; CC - then read OK ;BT003 DIAG BADDS ; File header date corrupt ;BT003 CLR R2 ; Set to zero ;BT003 30$: MOV R2,D.FLEV(R3) ; Insert date into directory ;BT003 MOV (SP)+,R1 ; Restore pointer ;BT003 ADD #D.SIZ,R3 ; Point to next entry ;BT003 BR 10$ ; And loop ;BT003 90$: MOV (SP)+,R2 ; Restore registers ;BT003 MOV (SP)+,R1 ; ... ;BT003 MOV (SP)+,R0 ; ... ;BT003 RETURN ;BT003 ; ;BT003 ;+ ;BT003 ; This routine will zero the file level number in the ;BT003 ; directory entry. This is required before the directory is ;BT003 ; written back to disk. ;BT003 ;- ;BT003 CLRDAT: MOV DIRBF$,R3 ; Point to start ;BT003 10$: CMP R3,R1 ; At end of buffer ? ;BT003 BHIS 90$ ; HIS - then all thru ;BT003 CLR D.FLEV(R3) ; Reset file level # ;BT003 ADD #D.SIZ,R3 ; Point to next entry ;BT003 BR 10$ ; And loop ;BT003 90$: RETURN ;BT003 ;BT003 .END