Metropoli BBS
VIEWER: getenv.asm MODE: TEXT (ASCII)
;****************************************************************************
; Filename: GETENV.ASM
;   Author: Adam Seychell
;  Version: 0.0
;  Created: 1995.April.18
;  Updated: -
;****************************************************************************
; Copyright Adam Seychell, 1994-1995.
; All rights reserved.
;****************************************************************************
; Function: char *getenv(char *name);
;  Comment: gets an environment varible.
;    Input: Eax, pointer to string wanted in environment
;   Output: pointer the environemnt's string after the '='character. If could
;           not find name then returns NULL.
;****************************************************************************
Include  STDDEF.INC

    Codeseg

Proc    getenv    ,1
        Push    Edi  Esi
        Mov     Esi,Eax
        Mov     Edi,[environ]           ; Get pointer of pointer array
@@MainLoop:
        Mov     Eax,[Edi]
        Add     Edi,4
        Cmp     [Byte Eax],0            ; check if zero length string.
        jz      @@Error

        Push    Eax
        Mov     Dl,"="
        Call    @strchr
        Pop     Edx
        TestZ   Eax
        jz      @@Error

        Mov     [Byte Eax],0        ; temperarily overwrite "=" with "\0"
        Push    Eax
        Mov     Eax,Esi
        Call    @strcmp
        TestZ   Eax
        Pop     Eax
        Mov     [Byte Eax],"="      ; restore the "=" character
        jnz     @@MainLoop
        Inc     Eax
        Pop     Esi Edi
        Ret
@@Error:
        Clear   Eax
        Pop     Esi Edi
        Ret
Endp  

End
[ RETURN TO DIRECTORY ]