;Copyright 2000 - Mark McDonald All rights reserved
; DECLARE: FUNCTION isnull(BYVAL string) AS INTEGER
; DESC:    Returns true if string in null, or contains only spaces or
;          chr$(0)s.
; EXAMP:   IF isnull(String$) THEN ......

Extrn   Get$Loc: Far
Extrn   Rls$Alloc: Far

MCODE Segment Byte
        Assume  CS: MCODE

        Public  isnull

isnull Proc     Far

ARG     ChrString: WORD = Retbytes

        push    BP                      ;
        mov     BP,SP                   ;
        push    DS                      ;

        push    Word Ptr ChrString      ; push string handle
        call    Get$Loc                 ; get location of string
        mov     DS,DX                   ; put segment in DS
        mov     SI,AX                   ; put offset in SI
        mov     AX, 1                   ; assume it's null
        jcxz    Exit                    ; is it null?
        cld                             ; clear direction flag
CheckChar:
        cmp     Byte Ptr DS:[SI], 32    ; is char a space?
        je      NextChar                ; yes, keep looping
        cmp     Byte Ptr DS:[SI], 0     ; is it a 0?
        jne     NotNull                 ; no, exit false
NextChar:
        inc     SI                      ; move to next char
        loop    CheckChar               ;
        jmp     Short Done              ; consider it null
NotNull:
        xor     AX,AX                   ; return false (0)
Done:
        push    AX                      ; save return val
        push    Word Ptr ChrString      ; push string handle
        call    Rls$Alloc               ; release string
        pop     AX                      ; restore return val
Exit:
        pop     DS                      ;
        pop     BP                      ;
        retf    Retbytes                ;
isnull EndP
MCODE EndS
        End