.title getlin ;+ ; n = getlin(buf, int) ; ; gets the next line from int into buf (characters up to and ; including a NEWLINE character) ; ; if a read error or end-of-file occurs, EOF is returned ;- ap=%5 buf=2 int=4 ; ; .psect $r.roi,con,ro,rel,lcl,i .enabl lsb getlin:: mov @int(ap),r0 ; rat4 unit number call r$gfbk ; get RFDB address in r1 bcs 100$ ; c set => invalid unit bit #rf.clo,(r1) ; is the file open? bne 100$ ; NO, error bit #rf.raw,(r1) ; rawmode terminal? bne 100$ ; YES, getlin error on raw tty bit #rf.mod,(r1) ; input mode? bne 5$ ; YES cmpb #rdwr$r,r.acc(r1) ; opened at READWRITE? bne 100$ ; NO, error clr r.byte(r1) ; no bytes left in record bis #rf.mod,(r1) ; set to input mode 5$: mov buf(ap),r3 ; address of user buffer clr r4 ; initialize counter 10$: call r$cget ; get next character into r0 bcs 100$ ; c set => error or EOF movb r0,(r3)+ ; move character into user buf inc r4 ; increment counter cmpb r0,#newlin ; NEWLINE character? beq 20$ ; YES, done cmp r4,#511. ; buffer full? blt 10$ ; NO, get next character 20$: cmp r4,#1 ; only one character? beq 30$ ; YES cmpb -2(r3),#'@ ; escaped NEWLINE? bne 30$ ; NO cmp (ap),#3 ; called from prompt? bne 30$ ; NO sub #2,r3 ; point at '@' dec r4 ; decrease character count movb #' ,(r3)+ ; @n => BLANK bit #rf.tty,(r1) ; is it a terminal? beq 10$ ; NO, just read next record mov #4,r0 ; number of characters to put mov 6(ap),r2 ; address of string mov r1,-(sp) ; save RFDB address mov @int(ap),r1 ; lun to use call r$rput ; put secondary prompt mov (sp)+,r1 ; restore RFDB address br 10$ ; get some more characters 30$: clrb (r3) ; terminate with EOS mov r4,r0 ; return count in r0 return 100$: cmp r0,#tmo ; did it timeout? beq 110$ ; YES, return(TMO) mov #eof,r0 ; return EOF 110$: return .end