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

  1.         title    SHOWENV -- getenv demo
  2.     page    55,132
  3.     .286
  4.  
  5. ; SHOWENV.ASM - Demonstrate use of GETENV routine
  6. ;               OS/2 version
  7. ;
  8. ; by Ray Duncan, Copyright (C) 1988 Ziff Davis
  9. ;
  10.  
  11. stdin    equ    0        ; standard input handle
  12. stdout    equ    1        ; standard output handle
  13.  
  14. cr    equ    0dh           ; ASCII carriage return
  15. lf    equ    0ah           ; ASCII line feed
  16.  
  17.     extrn    DosExit:far    ; OS/2 API functions
  18.         extrn    DosRead:far
  19.         extrn    DosWrite:far
  20.  
  21.     extrn    getenv:near    ; returns address of env. string
  22.  
  23. DGROUP    group    _DATA
  24.  
  25. _DATA    segment    word public 'DATA'
  26.  
  27. msg1    db    cr,lf,lf,'Enter name:    '
  28. msg1_len equ $-msg1
  29.  
  30. msg2    db    cr,lf,   'The value is:  '
  31. msg2_len equ $-msg2
  32.  
  33. msg3    db    'not found!'
  34. msg3_len equ $-msg3
  35.  
  36. inbuf    db    64 dup (0)    ; keyboard input buffer
  37. inbuf_len equ $-inbuf
  38.  
  39. rlen    dw    ?        ; receives actual number
  40.                 ; of bytes read
  41.  
  42. wlen    dw    ?        ; receives actual number
  43.                 ; of bytes written
  44.  
  45. _DATA    ends
  46.  
  47.  
  48. _TEXT    segment    word public 'CODE'
  49.  
  50.     assume    cs:_TEXT,ds:DGROUP
  51.  
  52. main    proc    far           ; entry point from OS/2
  53.  
  54.                 ; get env. variable,
  55.                 ; display cue to user...
  56.     push    stdout        ; standard output handle
  57.         push    ds        ; address of message
  58.         push    offset DGROUP:msg1
  59.         push    msg1_len    ; length of message
  60.         push    ds        ; receives bytes written
  61.         push    offset DGROUP:wlen
  62.         call    DosWrite    ; transfer to OS/2
  63.  
  64.                 ; get name of environment
  65.                     ; variable from user...
  66.     push    stdin        ; standard input handle
  67.         push    ds            ; address of input buffer
  68.         push    offset DGROUP:inbuf
  69.         push    inbuf_len    ; length of input buffer
  70.         push    ds            ; receives actual length
  71.         push    offset DGROUP:rlen
  72.     call    DosRead            ; transfer to OS/2
  73.  
  74.     mov    ax,rlen        ; get length of input
  75.     sub    ax,2        ; remove cr-lf characters
  76.     or    ax,ax        ; anything entered?
  77.     jz    main2        ; no, exit
  78.  
  79.     mov    bx,ax        ; append null to string
  80.     mov    byte ptr [bx+inbuf],0
  81.  
  82.                 ; display "The value is:"
  83.     push    stdout        ; standard output handle
  84.         push    ds        ; address of message
  85.         push    offset DGROUP:msg2
  86.         push    msg2_len    ; length of message
  87.         push    ds        ; receives bytes written
  88.         push    offset DGROUP:wlen
  89.         call    DosWrite    ; transfer to OS/2
  90.  
  91.     mov    si,offset inbuf    ; address of ASCIIZ string
  92.     call    strupr        ; fold to upper case
  93.     call    getenv        ; then search environment    
  94.  
  95.     or    ax,ax        ; find anything?
  96.     jz    main1        ; no, display error message
  97.  
  98.                 ; yes, display value of
  99.                     ; environment string
  100.     push    stdout        ; standard output handle
  101.         push    es            ; address of string
  102.         push    di
  103.         push    ax            ; length of string
  104.         push    ds            ; receives bytes written
  105.         push    offset DGROUP:wlen
  106.     call    DosWrite    ; transfer to OS/2    
  107.  
  108.     jmp    main        ; go ask for another
  109.  
  110. main1:                ; env. variable not found
  111.     push    stdout        ; standard output handle
  112.         push    ds        ; address of error message
  113.         push    offset DGROUP:msg3
  114.         push    msg3_len    ; length of message
  115.         push    ds        ; receives bytes written
  116.         push    offset DGROUP:wlen
  117.         call    DosWrite        ; transfer to OS/2
  118.  
  119.     jmp    main        ; go look for another
  120.  
  121. main2:                ; final exit to OS/2
  122.     push    1        ; terminate all threads
  123.         push    0        ; return code = 0
  124.         call    DosExit        ; transfer to OS/2
  125.  
  126. main    endp
  127.  
  128.  
  129. strupr    proc    near        ; convert ASCII string to
  130.                 ;  upper case
  131.                 ; call with DS:SI = string
  132.     push    si        ; save string address
  133.  
  134. strup1:    lodsb            ; next character
  135.     or    al,al        ; found end (null byte) ? 
  136.     jz    strup2        ; yes, jump
  137.     cmp    al,'a'        ; test if in range 'a'-'z'
  138.     jb    strup1        ; skip it if not >= a
  139.     cmp    al,'z'
  140.     ja    strup1        ; skip it if not <= z
  141.                 ; change char to lower case
  142.     sub    byte ptr [si-1],'a'-'A'
  143.     jmp    strup1        ; get another char
  144.  
  145. strup2:    pop    si        ; restore original string
  146.     ret            ; address and return
  147.     
  148. strupr    endp
  149.  
  150. _TEXT    ends
  151.  
  152.     end    main
  153.  
  154.