.title lines - Routines to read/write lines of text from a ; standard Pascal file unit using Pascal RTL routines. ; Written by Ned Freed, 11-Apr-1984, revised for RFA operations, 28-May-1985 ; getline code borrowed with permission - Chris Yoder, 12-May-1988 $RABDEF ; Define RAB symbols for RMS $RMSDEF $DEVDEF .psect $LOCAL, PIC,USR,CON,REL,LCL,NOSHR,NOEXE,RD, WRT,NOVEC,LONG buffer: .blkb 1026 .psect $CODE, PIC,USR,CON,REL,LCL, SHR, EXE,RD,NOWRT,NOVEC,LONG ; getline reads a line from a Pascal file. If EOF is detected, getline signals ; this by returning a value of FALSE. All other errors are reported with ; LIB$SIGNAL. ; Call: getline (pfv, linebuffer, linelength, start); ; Equivalent ISO standard Pascal code: (Note: This is NOT the proper ; declaration under VMS for getline! See TERDEF.PAS for the proper one.) ; function getline (var f : text; ; var linebuffer : packed array [lower..upper : integer] of char; ; var linelength : integer; start : integer) : boolean; ; ; var ; index : integer; ; ; begin (* getline *) ; linelength := 0; ; if eof (f) then getline := false else begin ; index := start; ; while not eoln (f) and (index <= upper) do begin ; linelength := succ (linelength); linebuffer[index] := f^; ; get (f); index := succ (index); ; end; (* while *) ; readln (f); getline := true; ; end; ; end; (* getline *) .entry getline,^m movl 4(ap),r2 ; Get PFV address bbs #48,(r2),1$ ; See if PFV is valid ; Pascal's buffer is empty -- we can read the next record directly with RMS ; and save a lot of overhead. movl r2,-(sp) ; Save address of PFV calls #1,g^pas$rab ; And convert to RAB movl r0,r3 ; Save RAB address movl 8(ap),r1 ; Get address of string descr. movw rab$w_usz(r3),r4 ; Save old buffer size movl rab$l_ubf(r3),r5 ; Save old buffer address clrl r0 ; Default is no offset cmpl (ap),#3 ; See if enough args are there bleq 11$ ; Skip if not subw3 #1,@16(ap),r0 ; Otherwise get offset 11$: subw3 r0,(r1),rab$w_usz(r3) ; And install the new one addl3 r0,4(r1),rab$l_ubf(r3) ; And install the new address $get rab=(r3) ; Read a record movb #rab$c_seq,rab$b_rac(r3) ; Reset to sequential mode movw r4,rab$w_usz(r3) ; Restore changed fields movl r5,rab$l_ubf(r3) ; of size and address blbc r0,6$ ; See if an error occurred movzwl rab$w_rsz(r3),@12(ap) ; No error, set the length movl #1,r0 ; Indicate success ret ; And return 6$: cmpl r0,#rms$_eof ; See if this is end of file beql 7$ ; If it is just indicate it pushl r0 ; Otherwise signal error calls #1,g^lib$signal ; With LIB$SIGNAL ret ; If Pascal has something in its buffer we must read it using Pascal's own ; routines. 1$: bbs #49,(r2),2$ ; See if there is anything 7$: clrl r0 ; No, set false clrl @12(ap) ; And zero length ret ; And return 2$: movl 8(ap),r3 ; Fetch address of string movzwl (r3),-(sp) ; And pass along length movl r2,-(sp) ; The length of the PFV pushab buffer ; And finally pass along buffer calls #3,g^pas$read_varying ; Read it movl r2,-(sp) ; Eat up to end of line calls #1,g^pas$readln2 ; By calling READLN movzwl buffer,@12(ap) ; Return the length movc3 buffer,buffer+2,@4(r3) ; And copy back result movl #1,r0 ; Return true ret .end