home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 11 Util / 11-Util.zip / OS2ENV.ZIP / GETENV2.ASM < prev    next >
Assembly Source File  |  1989-03-15  |  2KB  |  58 lines

  1. ;----------------------------------------------------------------------
  2. ; GETENV --- Return address and length of variable portion of environment
  3. ;            string OS/2 version using DosScanEnv
  4. ;
  5. ; Copyright (c) 1989 Ziff Communications Co.
  6. ; PC Magazine * Ray Duncan
  7. ;
  8. ; Call with:    DS:SI = ASCIIZ env. variable name
  9. ; Returns:      ES:DI = address of env. variable
  10. ;               AX    = length (0 = not found)
  11. ; Uses:         nothing
  12. ;----------------------------------------------------------------------
  13.         .286
  14.         extrn   DosScanEnv:far  ; OS/2 API function
  15.  
  16. _TEXT   segment word public 'CODE'
  17.         assume  cs:_TEXT
  18.                                 ; local variables...
  19. valptr  equ     [bp-4]          ; receives pointer to env. value string
  20.         public  getenv          ; make visible to Linker
  21.  
  22. getenv  proc    near
  23.  
  24.         enter   4,0             ; allocate local variable
  25.         push    cx              ; save register
  26.                                 ; call OS/2 to search environment block...
  27.         push    ds              ; address of name string
  28.         push    si
  29.         push    ss              ; address to receive 
  30.         lea     ax,valptr       ; pointer to value string
  31.         push    ax
  32.         call    DosScanEnv      ; transfer to OS/2
  33.         or      ax,ax           ; env. variable found?
  34.         jz      get1            ; jump if it exists
  35.  
  36.         xor     ax,ax           ; else return length=0
  37.         jmp     get2
  38.  
  39. get1:   les     di,dword ptr valptr  ; load value string addr.
  40.  
  41.         mov     cx,-1           ; find length of string
  42.         cld                     ; by scanning for null
  43.         xor     al,al
  44.         repnz scasb
  45.         not     cx
  46.         dec     cx              ; and let AX = length,
  47.         mov     ax,cx           ; ES:DI = address
  48.         mov     di,word ptr valptr
  49. get2:                           ; common exit point
  50.         pop     cx              ; restore registers
  51.         leave                   ; discard local variables
  52.         ret                     ; return to caller
  53.  
  54. getenv  endp
  55.  
  56. _TEXT   ends
  57.         end
  58.