home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / PPOS2.ZIP / GETENV2.ASM < prev    next >
Assembly Source File  |  1988-10-07  |  2KB  |  70 lines

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