.title rsxopn open file for reading .ident /4.0.01/ .psect $code .enabl gbl inpbuf = inbuf bf$pnt = bufpnt er$sav = errsav by$cnt = recount bl$num = blknum io$sta = iostat .mcall fdbdf$ ,fdat$a ,fdrc$a ,fdop$a ,fdbf$a ,fdbk$a .mcall qiow$ ,dir$ ,finit$ ,exit$s ,fsrsz$ .mcall csi$ ,csi$1 ,csi$2 .mcall opns$r ,open$w ,ofnb$r ,opnt$d ,close$ .mcall get$ ,put$ ,read$ ,write$ ,wait$ ,fdbk$r .mcall fdat$r ,fdof$l .mcall alun$s ,fdop$r fdof$l .mcall nmblk$ rsxdef: nmblk$ ,,,SY,0 .macro moverr err mov err ,-(sp) call seterr .endm moverr .sbttl open for input fsize = 60. .psect $code ; $ O P E N ; ; @r5 .asciz of filespec ; 2(r5) channel number $open:: save ; save registers please tst 2(r5) beq 96$ clr er$sav ; assume no errors yet. sub #fsize ,sp ; use stack for filename. mov sp ,r2 ; set up a pointer now. clrb @r2 ; zap the new name mov @r5 ,r1 ; point to input filename. clr r0 ; count length here 10$: cmpb @r1 ,#'/ ; hit any switches yet ? beq 20$ ; yes, stop copying then. inc r0 ; increment the length. cmp r0 ,#fsize-2 ; overflow the tiny buffer? bhis 20$ ; yep movb (r1)+ ,(r2)+ ; no, continue copying name. bne 10$ ; no end in sight yet 20$: clrb @r2 ; insure null terminated. mov sp ,r2 ; point back to start of name. .len r2 ; get the file spec length mov r0 ,r1 ; anything there at all ? beq 120$ ; oops csi$1 #csiblk,r2,r1 ; now do the first scan. bcs 120$ ; oops csi$2 #csiblk,OUTPUT ; finish up the scan please bcs 120$ ; oops mov 2(r5) ,r1 ; channel number to use beq 30$ ; channel 0 ? asl r1 ; times 2 please mov r1 ,r2 clr bf$pnt(r1) ; init single char pointer call 200$ opns$r rwfdbl(r1),2(r5),,,buflst(r1),#512. mov rwfdbl(r1),r1 ; preset fdb address bcc 30$ ; oops call 400$ br 100$ 30$: clr f.nrbd(r1) ; need to have this zapped. mov f.hibk+2(r1),opnsiz ; save size of the file movb f.racc(r1),filmod(r2) ; save read/write get/put mode mov f.rsiz(r1),mx$siz(r2) ; save max recordsize please movb f.rtyp(r1),rc$fmt+0(r2) ; save record type movb f.ratt(r1),rc$fmt+1(r2) ; save record attributes mov f.efbk+2(r1),la$blk(r2) ; save last block mov f.ffby(r1),la$byt(r2) ; save first free byte clrb vfc$(r2) ; no vertical forms control mov #77777 ,bufpnt(r2) ; overflow the buffer pointer clr bl$num(r2) ; no reads yet clr rd$siz(r2) ; no read sizes clr rm$siz(r2) ; no rms/fcs record sizes clr io$sta(r2) ; call setprt bitb #fd.dir ,f.rctl(r1) ; directory orientated dev? beq 90$ ; no movb #dkhnd ,io$sta(r2) ; yes, stuff correct handler idx 90$: bis #10000 ,io$sta(r2) 95$: add #fsize ,sp ; pop tiny work buffer. 96$: unsave ; pop temps and exit clc ; return ; bye 100$: moverr f.err(r1) ; get the error code please. 110$: add #fsize ,sp ; unsave ; bye sec return 120$: moverr # ; null filename passed ! br 110$ ; exit 200$: alun$s 2(r5),#"SY,#0 ; insure lun defaults to sy: return 400$: tst f.fnb+n.stat(r1) ; if .parse crapped then the status bne 410$ ; field will be zapped on VMS AME. movb #ie.bnm ,f.err(r1) ; if so, stuff a bad name error in. sec ; and say we failed return 410$: clc ; success return .sbttl read/write default protection and file owner ; input: r2 = channel number times 2 .mcall qiow$s setprt: save clr -(sp) ; get set to read the owner clr -(sp) ; address to return it mov inpprm+0,-(sp) ; function codes mov sp ,r1 ; point to parameter block cmp -(sp) ,-(sp) ; allocate a place to store mov sp ,6(sp) ; the owner and protection asr r2 qiow$s #io.rat,r2,#20,,,,<#0,r1> mov (sp)+ ,opfilo ; save the file owner first mov (sp)+ ,opnpro ; save the file prot code add #6 ,sp ; pop parameter block unsave ; pop temps and exit return inpprm: .byte -1,4 ; read file owner and protection ;- .word 0 ; to be filled in ;- .word 0 ; end of it .end