; Maximal string length package - version 23.12.88

               XDEF    LinkTop
               XDEF    ComalStr
               XDEF    MaxLen

               include 'ram:package.i'

; Initialisation section
               MOVE.L  D0,A0                  ; Address of package structure
               MOVE.L  #LinkTop,PckTopId(A0)  ; Address of top-link
               MOVE.L  PckCmlStr(A0),ComalStr ; Address of Comal structure
               CLR.W   D0                     ; No error
               RTS

; String max function
MaxLen:        MOVE.W  -2(A5),D1       ; Get type
               CMP.B   #strg,D1        ; String ?
               BNE.S   ARGERR          ; No -> error
               MOVE.L  -12(A5),A2      ; Get address of string var
               BTST    #POINTERBIT,D1  ; Pointer ?
               BEQ.S   MaxLen1         ; No -> branch
               MOVE.L  (A2),A2         ; Pointer -> get data address
MaxLen1:       MOVE.W  (A2),D2         ; Get maximal string length
               EXT.L   D2              ; Extend to long
               CLR.L   D3              ; Result is an integer
               RTS                     ; Return

; Error
ARGERR:        MOVEQ   #76,D0          ; Type error
               MOVE.L  ComalStr,A0     ; Get address of Comal structure
               JMP     CMLRET(A0)      ; Return error

               SECTION MaxLenData,DATA

MaxLenLink:    DC.L    0
               DC.L    MaxLenName
               DC.W    shortcode       ; Short integer function
               DC.W    1               ; One argument
               DC.W    strgref         ; REF - text
               DC.L    MaxLen          ; Rutine address
MaxLenName:    DC.B    'MAXLEN',0

               CNOP    0,2
LinkTop:       DC.L    MaxLenLink

               SECTION MaxLenBlock,BSS
;
; Internal workspace
;
ComalStr:      DS.L    1               ; Pointer to Comal structure

               END 
