home *** CD-ROM | disk | FTP | other *** search
/ Groovy Bytes: Behind the Moon / groovybytes.iso / GROOVY / SND_TOOL / FUNK108A.ZIP / DOS32V30.ZIP / PAL / VARIOUS / GETENV.ASM < prev    next >
Encoding:
Assembly Source File  |  1995-05-20  |  1.4 KB  |  55 lines

  1. ;****************************************************************************
  2. ; Filename: GETENV.ASM
  3. ;   Author: Adam Seychell
  4. ;  Version: 0.0
  5. ;  Created: 1995.April.18
  6. ;  Updated: -
  7. ;****************************************************************************
  8. ; Copyright Adam Seychell, 1994-1995.
  9. ; All rights reserved.
  10. ;****************************************************************************
  11. ; Function: char *getenv(char *name);
  12. ;  Comment: gets an environment varible.
  13. ;    Input: Eax, pointer to string wanted in environment
  14. ;   Output: pointer the environemnt's string after the '='character. If could
  15. ;        not find name then returns NULL.
  16. ;****************************************************************************
  17. Include  STDDEF.INC
  18.  
  19.     Codeseg
  20.  
  21. Proc    getenv    ,1
  22.         Push    Edi  Esi
  23.         Mov    Esi,Eax
  24.     Mov    Edi,[environ]        ; Get pointer of pointer array
  25. @@MainLoop:
  26.     Mov    Eax,[Edi]
  27.     Add    Edi,4
  28.     Cmp    [Byte Eax],0        ; check if zero length string.
  29.     jz      @@Error
  30.  
  31.     Push    Eax
  32.     Mov    Dl,"="
  33.     Call    @strchr
  34.     Pop    Edx
  35.     TestZ    Eax
  36.     jz      @@Error
  37.  
  38.     Mov    [Byte Eax],0        ; temperarily overwrite "=" with "\0"
  39.     Push    Eax
  40.     Mov    Eax,Esi
  41.     Call    @strcmp
  42.     TestZ    Eax
  43.     Pop    Eax
  44.     Mov    [Byte Eax],"="        ; restore the "=" character
  45.     jnz     @@MainLoop
  46.     Inc    Eax
  47.         Pop     Esi Edi
  48.         Ret
  49. @@Error:
  50.     Clear   Eax
  51.         Pop     Esi Edi
  52.     Ret
  53. Endp  
  54.  
  55. End