.TITLE LENGTH .IDENT /1.C/ .ENABL LC ; ; Title: Routine to determine length of character string ; ; Routine Name: FORTRAN entry point - LENGTH ; MACRO-11 entry points - $SCAN, .SCAN ; ; File Name: LENGTH.MAC ; ; Author: B.Hillam ; ; Description: ; These routines scan a character string for a null, and return the ; number of characters preceding that null. A maximum string length ; may be specified : if not, the routines scan only 256. characters. ; ; Latest Modification: ; 1 17-OCT-79 Original ; EDW 1.B 14-MAY-82 Get RO PSECT's right ; EDW 1.C 27-OCT-82 Change name to LENGTH to avoid F77 clash on LEN ; ; External Routines called: NONE ; ; Restrictions: ; If a maximum string length is not specified or is <= 0, ; only 256. characters will be checked. ; ; Calling Sequence: ; ; Parameters enclosed in [] are optional, and may be omitted. ; ; FORTRAN CALL : N = LENGTH (ARRAY[,[MAXLEN]]) ; ; INPUTS : ; ARRAY LOGICAL*1 one-dimensional array containing string whose ; length is required, terminated by a null. ; MAXLEN INTEGER*2 value specifying maximum string length to check. ; If this parameter is omitted, is zero or is negative, 256. ; is used as a maximum length. ; OUTPUTS : ; LENGTH INTEGER*2 return via fumction name (answer in R0) = length ; of input string, excluding trailing null. ; ; MACRO-11 CALL : ; INPUTS : ; .SCAN entry point : R0 = maximum length of string. ; $SCAN entry point : Maximum string length = 256. R0 ignored. ; Both entry points : R1 = start address of string ; OUTPUTS: ; R0 preserved ; R1 preserved ; R2 = Length of string ;END .ENABL LSB .PSECT PURE.I,RO,I .SCAN:: MOV R0,-(SP) ;Save maximum string length BLE 1$ ;If < or = 0, use 256. BR 2$ $SCAN:: MOV R0,-(SP) ;Save R0 1$: MOV #256.,R0 ;Check a maximum of 256. characters 2$: MOV R1,-(SP) ;Save start address of string CLR R2 ;Clear string character count 3$: TSTB (R1)+ ;Check for a null BEQ 4$ ;EQ if one found INC R2 ;Count the characters SOB R0,3$ ;Continue for 256 maximum. 4$: MOV (SP)+,R1 ;Restore buffer pointer MOV (SP)+,R0 ; RTS PC .DSABL LSB ; NULARG=-1 ; ARRAY=2 MAXLEN=4 ; ; FORTRAN entry point ; LENGTH::MOV ARRAY(R5),R1 ;Get the start address of the string CMPB (R5),#2 ;Is there a MAXLEN parameter ? BLT 1$ ;LT if no. CMP MAXLEN(R5),#NULARG ;Is it null ? BNE 2$ ;NE if no 1$: CLR R0 ;Set to check for maximum of 256. characters BR 3$ 2$: MOV @MAXLEN(R5),R0 ;Get the specified maximum length 3$: CALL .SCAN ;Scan the string MOV R2,R0 ;INTEGER*2 function return via R0 RTS PC ; .END