.TITLE DBSMAK ... Database File Initializer .IDENT /300482/ .ENABL LC ; ; ; ; Written by Ray Di Marco ; 30-Apr-82 ; ; ;_____________________________________________________________________________ ; ; ; This is the main module for the DBSMNG cusp DBSMAK, that is used to create ; and initialize a set of database files. The program is created by linking ; this module with the database library, DBSLIB, and optionally with the user ; template. If the template is not linked in the user will be asked for the ; name of the file that holds the template (in .SAV format) when the program ; is executed. ; ; This program when run results in the three database files (viz .DAT, .KEY ; and .PAR) files being created and initialized. For large database (over 1000 ; entries,) a little patience is needed as it takes 40 to 50 seconds to ; initialize the data file! ; ; This program can be envoked as a CUSP from a DBSMNG MENU program, and will ; accept commands via core common. ; ; .SBTTL Declarations ; .MCALL .PRINT,.EXIT ; Error Aborting .MCALL FILSPT ; File support .MCALL .PUSH,.POP ; stacking ; FILSPT ; Initialize file support ; .GLOBL FORM$$ ; address template .GLOBL $$FORM ; pointer to template .GLOBL DBSLDR ; template loader ; .GLOBL CON.ST,CON.EX ; CONIO .GLOBL FILINT,FIL.DW,FIL.KW,FIL.PW ; FILEIO .GLOBL KEY$$B ; KEYGEN .GLOBL FIL.NW ; FILSPT .GLOBL FRM.ZP ; FRMIO ; ; .PSECT CODE ; open code area ; ====== ==== ; .SBTTL Macro Definitions ; ; .MACRO LOAD OFF,REG MOV $$FORM,REG MOV OFF(REG),REG .ENDM LOAD ; .MACRO PRINT STR=R0 .GLOBL CON.LO MOV STR,R0 CALL CON.LO .ENDM PRINT ; .MACRO GTLIN BUF=R0,STR .IF NB,STR .GLOBL CON.LO MOV STR,R0 CALL CON.LO .ENDC MOV BUF,R0 .GLOBL CON.LI CALL CON.LI .ENDM GTLIN ; .SBTTL Main Code ; ; ; If TEMPLATE not linked in with the program use DBSLDR to load the template. ; If the template was linked in, $$FORM. If have to load the template ; ourselves we must store the load address (returned in R0 by DBSLDR) in ; $$FORM as its needed later. ; START: CALL CON.ST ; ensure CONIO inited TST $$FORM ; template linked in? BNE 100$ ; yes -> skip GTLIN #BUF,#PRMT ; get TEMPLATE name MOV #BUF,R0 ; R0 -> name CALL DBSLDR ; load template MOV R0,$$FORM ; set up pointer ; ; ; Have to work out sizes of the files we must create, using facts that a) the ; parameter file is of one block, b) the key file holds 16 keys per block, c) ; the number of blocks in the data file depends on the number of records and ; the blocking factor. ; 100$: LOAD 14,R1 ; R1 = number of records INC R1 ; allow for header MOV R1,R2 ; R2 = number of key records LOAD 12,R0 ; R0 = blocking factor BGT 120$ ; positive -> 120$ CMP R0,#-1 ; is it -1 or 0? BLT 140$ ; no -> goto 140$ MOV #1,R0 ; yes -> same as +1 120$: MUL R0,R1 ; R1 = number blocks needed BR 170$ ; exit 140$: INC R0 ; R0 = divisor (ie BF=-2->-1) ASH R0,R1 ; R1 = number blocks needed INC R1 ; allow 1 extra for luck 170$: ADD #15.,R2 ; R2 = number of blocks ... ASH #-4,R2 ; .... in KEY file ADD #3,R2 ; ensure that have a .. BIC #3,R2 ; .... multiple of 4 ; ; Can now create files, using sizes worked out above. Note that 10000$ will ; enter the files in the dirrectory so can then use normal DBS routines. ; PRINT #M.ENTER ; indicate function LOAD 16,R5 ; R5 -> FDBPAR MOV #1,FDB.BL(R5) ; set up file size CALL 10000$ ; enter file LOAD 20,R5 ; R5 = FDBDAT MOV R1,FDB.BL(R5) ; set up file size CALL 10000$ ; enter file LOAD 22,R5 ; R5 = FDBKEY MOV R2,FDB.BL(R5) ; set up file size CALL 10000$ ; enter file ; ; ; As the database files are now in the dirrectory, we can now access them ; using the normal DBSMNG file I/O modules. Access files! ; CALL FILINT ; Init DBS file I/O ; ; Initialize PARAMETER file. All except first word (cn) must be 0! ; PRINT #M.INTP ; indicate phase LOAD 16,R0 ; R0 -> FDBPAR MOV FDB.BF(R0),R3 ; R3 -> PARBUF MOV R3,R0 ; R0 -> BUFFER MOV #400,R1 ; R1 = counter 1100$: CLR (R0)+ ; clear out SOB R1,1100$ ; ... parameter block MOV #1,0(R3) ; cn = 1 CALL FIL.PW ; output parameter block ; ; Zero out the KEY file. ; PRINT #M.INTK ; indicate phase MOV #KEY$$B,R0 ; R0 -> key buffer MOV #16.,R1 ; R1 = counter 2100$: CLR (R0)+ ; initialize keys SOB R1,2100$ ; loop LOAD 14,R0 ; R0 = number of records INC R0 ; allow for header 2200$: CALL FIL.KW ; output key SOB R0,2200$ ; loop till all done CALL FIL.KW ; initialize header ; ; Zero out the data file. ; PRINT #M.INTD ; indicate phase MOV $$FORM,R0 ; R0 -> RDT MOV (R0),R5 ; R5 -> record buffer CALL FRM.ZP ; zero out buffer LOAD 14,R0 ; R0 = number of records INC R0 ; allow for header 3200$: CALL FIL.DW ; output record SOB R0,3200$ ; loop till all done CALL FIL.DW ; initialize header ; ; All done. Say so and then exit. ; PRINT #M.DONE ; tell done JMP CON.EX ; exit ; ; ; This routine is called with R5 holding the address of a FDB. It enters ; the file in the dirrectory and the resets the FDB to its initial state. ; 10000$: PURGE ; ensure channel free BIS #F.NERR,FDB.FL(R5) ; no auto-error messages CALL FIL.NW ; enter file BCS 10100$ ; error -> skip .PUSH FDB.RQ(R5) ; save RQ value MOV #400,FDB.RQ(R5) ; want to I/O 400 words MOV FDB.NB(R5),R0 ; R0 = number blocks in file DEC R0 ; R0 = address of last block WRITE BLOCK=R0,ERROR=10100$ ; write out last block CLOSE ; make permanent PURGE ; ensure free .POP FDB.RQ(R5) ; restore RQ value CLR FDB.BL(R5) ; reset block pointer CLR FDB.FL(R5) ; reset flags RETURN ; exit 10100$: PRINT #M.FERR ; tell errored STATUS ; show cause .EXIT ; abort ; ; .SBTTL Data structures and messages ; ; .PSECT DATA ; open data area ; ====== ==== ; ; $$FORM: .WORD FORM$$ ; points to FDTs BUF: .BLKB 100 ; input buffer PRMT: .ASCII /DBSMAK RDM300482/<15><12> .ASCII / Enter name of TEMPLATE: /<200> M.ENTE: .ASCIZ / creating database files/ M.INTP: .ASCIZ / initializing PAR file../ M.INTK: .ASCIZ / initializing KEY file../ M.INTD: .ASCIZ / initializing DAT file../ M.DONE: .ASCIZ / Database now setup!/ M.FERR: .ASCII /DBSMAK-fatal-file creation failure!/<15><12><11><200> .END START