.TITLE INDEX .IDENT /BL1.1/ ; ; This is a completely rewritten version of INDEX designed ; to word with the dynamic memory routines. ; ; J. CLEMENT September 1982 ; ; INDEX COMMAND ; ; LOCAL DATA .psect $TEMP,RW,D,GBL,OVR ; ; Impure data section ; BLINK: .BLKW 1 ; Points back to last item LINK: .BLKW 1 ; Points to current item FLINK: .BLKW 1 ; Points to next item PSTAT: .BLKW 1 ; Page difference STAT: .BLKW 1 ; Status byte STATAD: .BLKW 1 ; Address of status byte CHSAV: .BLKW 1 PAGSAV: .BLKW 1 SPGSAV: .BLKW 1 AINS: .BLKW 1 ; Autoindex switch SUBINX: .BLKW 1 ; Current Subindex count SUBINT: .BLKW 1 ; Total subindex count STRADD: .BLKW 1 ; String address .psect $CODE,ro,i,LCL,con ;+ ; **-INDEX-ADD INDEX ITEM TO INDEX DATA ;- AINDEX::TSTEQB $INXSW,10$ ; INDEXING ENABLED? RETURN ; NO 10$: CALL BRKSV ; Save current loc. in input buffer INCB AINS BR INDEX1 INDEX:: CALL $FRCND ; FORCE TO LOGICAL END OF COMMAND CLRB AINS ; No autoindex INDEX1: CLR BLINK CLR LINK CLR FLINK CLR CHSAV CLR PAGSAV CLR SPGSAV CLR SUBINX ; Clear subindex count CLR SUBINT ; Clear total subindex count MOV #TTBUF,STRADD ; Clear string address MOV #TTBF,R3 ; BUFFER TO GET TITLE BISB #40,$UNLSW ; Disable underlining BISB #40,$OVRSW ; Disable overstriking BISB #40,$AUBRK ; Disable autobreak BISB #40,$IFLSW+1 ; Disable index flag CALL CLRBF ; Clear the buffer MOV PRMRG,-(SP) ; Save right margin MOV PLMRG,R0 ADD #100.,R0 MOV R0,PRMRG ; New temporary right margin TSTEQB AINS,15$ ; No auto index ? INCB RETSW ; Set up return on breakable char CALL SETBF ; Get index term MOV (SP)+,PRMRG ; Restore CLRB RETSW CLR R1 ; Null to chock end CALL PBYT CALL BKUP ; Back up to break BR 18$ ; Got index term 15$: CALL SETBF ; Get index term MOV (SP)+,PRMRG ; Restore TSTEQB $INXSW,10$ ; INDEXING ENABLED? RETURN ; NO 10$: MOV #TTBF,R3 ; Restore buffer address CLR R1 CALL PBYT ; Insert null into title MOV #TTBUF,R2 ; Get buffer address 17$: MOVB (R2)+,R1 ; Get char BEQ 18$ ; Done ? CMPNE R1,$SIFSW,17$ ; Not Subindex flag ? CLRB -1(R2) ; Make flag a null INC SUBINT ; Total number of subindex flags CMP SUBINT,#6 ; Check number BLE 17$ ; Not too many ? MOV #36.,R0 ; Message number to output JMP ILCMA ; too many, give error 18$: BICB #40,$IFLSW+1 ; reenable index flag MOV #INXBF,R3 ; Index buffer TSTEQ XFIRST,STARTX ; not first time for indexing CALL BEGBF ; Set to start of buffer CALL GWRD ; get foreward link MOV R1,FLINK ; foreward link 20$: CALL GETLNK ; Get link and status BCS 100$ ; None so save current entry CALL TSTP ; Skip over page entry BITEQ #X.ENT,STAT,20$ ; No entry to try? CALL TSTS ; Test the string BGT 20$ ; Input string > table entry BNE 100$ ; New entry/ save it 30$: CALL GETLNK ; Get next link BCS 50$ ; At end of table BITNE #X.ENT,STAT,50$ ; End of page numbers only? CALL TSTP ; test page number against table BR 30$ 50$: CLR STAT ; Do not store string, only page numbers JMP KEEP 80$: RETURN 100$: MOV #X.ENT,STAT ; Status/ save all JMP KEEP ; Keep string and page numbers in table ; ; Subroutine to Keep the entry + fill in page number etc. ; STARTX:: CALL CLRBF DEC XFIRST ; set not first MOV #X.ENT,STAT ; first entry status CLR R1 ; clear word CALL PWRD ; for first link BR KEEP1 KEEP: CALL ENDBF ; Get end buffer address KEEP1: MOV BF.FUL(R3),R2 ; Final index MOV BLINK,R1 ; Backward link MOV R2,BLINK ; Now set current entry as backward link CALL FNDBF ; go to it MOV R2,R1 ; last buffer address CALL PWRD ; link it in CALL ENDBF ; back to end buffer 5$: MOV LINK,R1 ; foreward link CALL PWRD ; link it in MOV STAT,R1 ; Initial status CMPNE SUBINX,SUBINT,40$ ; Not at end of subindices ? TSTNEB $CHPSW,20$ ; no chapter print? TSTEQB APNDN,10$ ; No appendix? BIS #X.AP,R1 ; Set appendix status BR 20$ ; no chapter if appendix 10$: TSTEQB CHPTN,20$ ; No chapter? BIS #X.CH,R1 20$: BIS #X.PAG,R1 ; Set for page number TSTEQB SUBPGE,40$ ; No subpage? BIS #X.SPG,R1 40$: MOVB R1,STAT ; Save total status MOV R1,R2 ; Save ADD SUBINX,R1 ; Current subindex number CALL PBYT ; Store status BITEQ #X.AP,R2,50$ ; no appendix? MOVB APNDN,R1 CALL PBYT ; put appendix 50$: BITEQ #X.CH,R2,60$ ; no chapter? MOVB CHPTN,R1 CALL PBYT ; put chapter 60$: BITEQ #X.PAG,R2,70$ ; No page number ? MOV BF.FUL(R3),LINK ; Save link for later MOV PAGENO,R1 BNE 65$ ; Not zero ? INC R1 ; Make it 1 65$: BIS PAGDSP,R1 ; Add on display bits CALL PWRD ; put chapter 70$: BITEQ #X.SPG,R2,80$ ; no subpage? MOVB SUBPGE,R1 CALL PBYT ; put subpage 80$: BITEQB #X.ENT,R2,100$ ; NOT Save entry? MOV STRADD,R2 ; Entry buffer 90$: MOVB (R2)+,R1 ; get byte CALL PBYT ; save it TSTNE R1,90$ ; more to come? CMPEQ SUBINX,SUBINT,100$ ; Finished all levels ? INC SUBINX ; Do next level MOV R2,STRADD ; Next starting address BR KEEP 100$: CALL OUTAD ; Get output address BITEQ #X.PAG,STAT,110$ ; No page number saved ? MOV #INDX,R1 ; Get index flag CALL PBYT ; Into output buffer MOV LINK,R1 ; Link CALL PWRD ; Save it too 110$: RETURN ; ; Subroutine to get next link ; GETLNK: MOV LINK,BLINK MOV FLINK,LINK ; stack the links MOV FLINK,R1 ; next entry BEQ 20$ ; no more CALL FNDBF ; find it CALL GWRD ; get next foreward link BCS 10$ ; end of input MOV R1,FLINK ; next foreward link CALL GBYT ; get status byte MOV R1,STAT ; save status CLC ; Success for next entry 10$: RETURN 20$: SEC ; end of buffer RETURN ; ; Subroutine to compare current page with stored page ; TSTP: MOV STAT,R2 ; get status BITEQ #X.AP,R2,20$ ; no appendix? CALL GBYT ; get appendix BR 40$ 20$: BITEQ #X.CH,R2,40$ ; chapter not exist? CALL GBYT ; Skip over chapter 40$: BITEQ #X.PAG,R2,60$ ; No page number ? CALL GWRD ; get page number 60$: BITEQB #X.SPG,R2,80$ ; no subpage? CALL GBYT ; get subpage 80$: RETURN ; with status EQ,NE ; ; Subroutine to compare input string to table ; TSTS: MOV STAT,R0 ; Get current status BIC #177770,R0 ; Get subentry number CMPNE R0,SUBINX,70$ ; Not same level ? MOV STRADD,R2 ; Input string address 10$: CALL GBYT ; get table entry BIC #^C<177>,R1 ; strip char. CMPNEB GCTABL(R1),#GC.LC,20$ ; Not lower case? SUB #40,R1 ; Convert to upper case 20$: MOVB (R2)+,R0 ; input string char BEQ 50$ ; end of string? BIC #^C<177>,R0 ; strip char. CMPNEB GCTABL(R0),#GC.LC,30$ ; Not lower case? SUB #40,R0 ; Convert to upper case 30$: CMPEQ R0,R1,10$ ; same, continue RETURN 50$: CMPEQ SUBINX,SUBINT,60$ ; End of entire string ? TSTNE R1,60$ ; Not end of entry too ? INC SUBINX ; Count it MOV R2,STRADD ; Save next subentry address MOV #-1,R1 ; Guarantee another compare 60$: CMP R0,R1 ; final compare 70$: RETURN .END