.TITLE LESCSQ .ENABL LC ; ; AUTHOR: S.C. Cribbs (Technical Services Branch) ; Atomic Energy of Canada Ltd. Pinawa, Manitoba ; 83/05/14 ; ; ; Look for Escape Sequences ; ; Called by FORTRAN: I = LESCSQ(STRING) ; ; where STRING - Character string which returns received input ; I - -1 = Time out (no response received) ; 0 = Invalid Escape sequence detected ; >0 = Number of characters in Escape sequence ; ; NOTE: When an invalid character sequence is detected, ; all characters preceeding and the offending character are returned ; in ASCIZ format in vector STRING. If only an character is ; received before timeout occurs, the character will be ; returned as an ASCIZ string in STRING and an invalid sequence detected ; code will be returned. If no input at all is received, STRING will ; contain a null string. The timeout period has been defined ; (in TCFLIO.MAC) as 0.2 seconds for those systems supporting .TWAIT ; (FB or XM monitors) or .MRKT under the SJ monitor. For systems ; with no LTC, timeout is a simulated 1 second (on a LSI-11/2), but is ; easily modified before program assembly. ; .GLOBL LESCSQ ;Entry point .GLOBL TSET,TRESET,IGTC .PSECT USER$I RW,I,LCL,REL,CON LESCSQ: TST (R5)+ ;Skip over FORTRAN argument count MOV @R5,R4 ;Load address of buffer "STRING" CLRB (R4)+ ;Define the default 2 character CLRB -(R4) ; null value for STRING CLR R3 ;Assume no CSI string will be found JSR PC,TSET ;Define required terminal settings 1$: CALL IGTC ;Get a character from terminal BCS TMOERR ;Error return indicates time out CMPB #33,R0 ;Was character received an "ESCAPE"? BNE ILLERR ;No, take error exit 2$: MOVB R0,(R4)+ ;Load character into user's buffer CALL IGTC ;Get another character from terminal BCS TMOERR ;Error return indicates time out CMPB #40,R0 ;< Legal minimum for ESC. sequence? BGT ILLERR ;Yes, abort subroutine CMPB #176,R0 ;> Legal maximum for ESC. sequence? BLT ILLERR ;Yes, abort subroutine .PAGE TST R3 ;Is this a control sequence? BNE 3$ ;Yes, apply appropriate tests CMPB #60,R0 ;< Legal minimum "FINAL CHARACTER"? BGT 2$ ;Must be an "INTERMEDIATE CHARACTER" CMPB #133,R0 ;Is this a "CONTROL SEQUENCE INTRODUCER"? BNE FINAL ;No, must be the end of ESC. sequence MOV #1,R3 ;Set "CSI" string found flag MOV #1,R2 ;Define "CSI" parameter wanted now BR 2$ ;Look for next character 3$: CMPB #100,R0 ;> valid "CSI" parameter code? BLT FINAL ;Yes, must be "CSI FINAL CHARACTER" CMPB #60,R0 ;Is it within parameter code range? BLE 4$ ;Yes, check it further CLR R2 ;Define: no more parameters allowed BR 2$ ;Look for next character 4$: TST R2 ;Is a parameter acceptable here? BEQ ILLERR ;No, abort subroutine BR 2$ ;Look for next character FINAL: MOVB R0,(R4)+ ;Store it in the user's buffer CLRB @R4 ;Returned string is in ASCIZ format SUB @R5,R4 ;Determine count of chars. received MOV R4,-(SP) ;Return the count as the function value BR TRMNTE ;Restore terminal's original characteristics ILLERR: MOVB R0,(R4)+ ;Load character into user's buffer CLRB @R4 ;Returned string is in ASCIZ format ILLE1: CLR -(SP) ;Indicate illegal sequence found BR TRMNTE ;Restore terminal's original characteristics TMOERR: CMP @R5,R4 ;Any characters received? BNE ILLE1 ; if so, mark as an illegal string MOV #-1,-(SP) ;Indicate no response from terminal TRMNTE: JSR PC,TRESET ;Reset terminal to user's settings MOV (SP)+,R0 ;Load returned function value RETURN ;Return to caller .END