home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS 1992 June / SIMTEL_0692.cdr / msdos / batutl / echsys10.arc / ENV_SET.ASM < prev    next >
Assembly Source File  |  1989-09-25  |  28KB  |  721 lines

  1.                  PAGE   60,132
  2.  
  3.                  ;Usage is: call envsub  ds:si -> length,string
  4.  
  5.                  ;      length is 1 byte long, <128
  6.                  ;         if high bit on, primary environment is set.
  7.                  ;      string is of form: name=value
  8.  
  9.                  ;   Copyright 1987, A. B. Krueger GPW MI 48236
  10.                  ;   All rights reserved. Contact "ARNY KRUEGER"
  11.                  ;   at the EXEC-PC BBS (414-964-5160) for permission
  12.                  ;   to use commercially.
  13.                  ;
  14.  
  15.                  ;Clone of SET command that demonstrates updating
  16.                  ;      the environment string.
  17.                  ;If there is no secondary command processor, the
  18.                  ;      global environment is updated
  19.                  ;If there is a secondary command processor, then
  20.                  ;      its enviroment is updated
  21.  
  22. sb               segment at 0      ;equates storage blocks and psp's
  23.  
  24. sb_kind          db     ' '        ;type of storage block: 'M' or 'Z'
  25. sb_psp           dw     ?          ;psp segment address
  26. sb_length        dw     ?          ;sb length in paragraphs
  27. sb_head_length   equ    10h        ;length of sb header
  28.                  org    sb_head_length
  29. sb_data          db     ?          ;data in block
  30.  
  31.                  org    0h         ;program segement prefix equates
  32. psp_ret_int      dw     ?          ;int 20h
  33.                  org    2Ch
  34. psp_env          dw     ?          ;segment address of environment
  35.                  org    50h
  36. psp_dos_function dw     ?          ;address of function dispatcher
  37.                  org    80h
  38. psp_parm_string  db     ?          ;1 byte length plus parm string
  39.  
  40. psp_length       equ    100h
  41.  
  42. sb               ends
  43.  
  44. cseg             segment para public
  45.                  assume cs:cseg,ds:cseg,es:sb
  46.                  public env_set
  47.  
  48.                  ;local  data
  49.  
  50. cr               equ    13
  51. lf               equ    10
  52.  
  53. sb_count         dw    0            ;count of sb's encountered
  54. sb_shell         dw    0            ;segment address of shell  sb
  55. sb_shell_env     dw    0            ;segment address of global env sb
  56. sb_secondary     dw    0            ;segment address of secondary command.com
  57. sb_secondary_env dw    0            ;segment address of secondary command env
  58.  
  59. fatal_msg       equ    80h
  60. error_msg       equ    40h
  61. info_msg        equ    20h
  62. msg_flag        db     fatal_msg+error_msg ;+info_msg   ;set flags
  63.                 db     'Copyright 1987, A. B. Krueger GPW MI 48236'
  64. secondary_msg   db     info_msg,'Secondary '
  65. command_found   db     info_msg,'COMMAND.COM found',cr,lf,'$'
  66. bad_dos_msg     db     fatal_msg,'Must be running under DOS 2.0 or above',cr,lf,'$'
  67. bad_sb_msg      db     fatal_msg,'Bad storage block',cr,lf,'$'
  68. bad_env_msg     db     error_msg,'Bad environment block',cr,lf,'$'
  69. command_lost    db     error_msg,'Shell never found',cr,lf,'$'
  70. addbadmsg       db     error_msg,'Environment corrupt',cr,lf,'$'
  71. addmsg          db     info_msg,'Addition requested',cr,lf,'$'
  72. removemsg       db     info_msg,'Removal requested',cr,lf,'$'
  73. env_set_nospace db     error_msg,'No space in environment string',cr,lf,'$'
  74. env_set_syntax  db     error_msg,'Set string syntax error',cr,lf,'$'
  75.  
  76. type_string     proc   near          ;type message at offset in dx
  77.                 push   ax            ;save registers
  78.                 push   cx
  79.                 push   dx
  80.                 push   si
  81.  
  82.                 mov    si,dx         ;get message level
  83.                 lodsb
  84.                 and    al,msg_flag   ;compare to what sells
  85.                 jz     type_ret      ;if not on list, send to bit bucket
  86.  
  87.                 mov    dx,si
  88.                 mov    ax,0900h
  89.                 int    21h
  90. type_ret:
  91.                 pop    si
  92.                 pop    dx
  93.                 pop    cx
  94.                 pop    ax
  95.                 ret
  96. type_string     endp
  97.  
  98. get_first_sb    proc   near       ;get first storage block, point es at it
  99.                 push   ax
  100.                 push   bx
  101.                 mov    ax,5200h
  102.                 int    21h        ;es:bx points to memory block anchor+2
  103.                 dec    bx
  104.                 dec    bx
  105.                 mov    es,es:[bx] ;get first memory block address into es
  106.                 pop    bx
  107.                 pop    ax
  108.                 ret
  109. get_first_sb    endp
  110.  
  111. get_next_sb     proc   near
  112.                 push   ax
  113.                 mov    ax,es             ;get current paragraph
  114.                 add    ax,sb_length      ;add in number of paragraphs
  115.                 inc    ax                ;add 1 for header
  116.                 mov    es,ax             ;set new extra segment address
  117.                 pop    ax
  118.                 ret
  119. get_next_sb     endp
  120.  
  121.  
  122. find_secondary_env proc  near       ;find env sb's for current program sb
  123.                 push   ax           ;pointed to by es
  124.                 push   es
  125.                 mov    ax,es        ;get address of secondary cp's sb
  126.                 inc    ax           ;get its psp address
  127. find_secondary_env_loop:
  128.                 call   get_next_sb  ;get next sb
  129.                 cmp    ax,sb_psp    ;match secondary's psp?
  130.                 jne    find_secondary_env_next    ;if not, skip
  131.  
  132.                 mov    sb_secondary_env,es        ;otherwise, save
  133.                 jmp    find_secondary_env_exit    ;and check no further
  134.                                                   ;lest we trash a .BAT block
  135. find_secondary_env_next:
  136.                 cmp    sb_kind,'Z'                ;last block?
  137.                 jne    find_secondary_env_loop
  138.  
  139. find_secondary_env_exit:
  140.                 pop    es
  141.                 pop    ax
  142.                 ret
  143. find_secondary_env endp
  144.  
  145. command_test    proc   near         ;test program storage block at es:0
  146.                 push   ax
  147.                 push   bx
  148.                 push   cx
  149.                 push   dx
  150.                 push   ds
  151.                 push   es
  152.                 push   si
  153.  
  154.                 cmp    sb_count,2
  155.                 ja     command_second
  156.  
  157.                 mov    dx,offset command_found
  158.                 call   type_string
  159.                 mov    sb_shell,es
  160.                 jmp    command_test_good
  161.  
  162. command_second:
  163.                 cmp    sb_shell,0                       ;did we find shell?
  164.                 je     command_first_bad                ;if not, error
  165.  
  166.                 cmp    word ptr es:psp_env+sb_head_length,0  ;check environment of program
  167.                 je     command_test_good                 ;if no environment, quit
  168.  
  169.                 push   sb_shell
  170.                 pop    ds                               ;ds points to shell
  171.                 mov    al,byte ptr es:sb_head_length+psp_length
  172.                 cmp    al,0E9h                          ;a JMP?
  173.                 jne    command_test_good                ;if not, no harm done
  174.  
  175.                 cmp    al,byte ptr ds:sb_head_length+psp_length   ;check 1st instruction
  176.                 jne    command_first_bad
  177.  
  178.                 mov    si,sb_head_length+psp_length
  179.                 mov    di,sb_head_length+psp_length
  180.                 mov    cx,10      ;look at 10 words of code
  181.                 repz   cmpsw
  182.                 clc
  183.                 jcxz   command_test_found   ;if they all match, fine
  184.  
  185.                 jmp    command_test_good    ;if not, no harm done
  186.  
  187. command_test_found:
  188.                 push   cs
  189.                 pop    ds
  190.                 mov    sb_secondary,es
  191.  
  192.                 mov    ax,es:psp_env+sb_head_length     ;get env address
  193.                 dec    ax                               ;back up over sb header
  194.                 mov    sb_secondary_env,ax              ;and save it
  195.  
  196.                 call   find_secondary_env               ;look for other env's
  197.  
  198.                 mov    dx,offset secondary_msg
  199.                 call   type_string
  200.                 jmp    command_test_good
  201.  
  202. command_first_bad:
  203.                 mov    dx,offset command_lost
  204.                 call   type_string
  205.                 stc
  206.                 jmp    command_test_end
  207.  
  208. command_test_good:
  209.                 clc
  210. command_test_end:
  211.                 pop    si
  212.                 pop    es
  213.                 pop    ds
  214.                 pop    dx
  215.                 pop    cx
  216.                 pop    bx
  217.                 pop    ax
  218.  
  219.                 ret
  220. command_test    endp
  221.  
  222.  
  223.  
  224. prog_test       proc   near         ;test block for program
  225.                 push   ax           ;save registers
  226.                 push   cx
  227.                 push   dx
  228.                 push   es
  229.  
  230.                 mov    ax,sb_psp             ;get PSP of owner
  231.                 cmp    ax,0                  ;if zero, it is free
  232.                 je     prog_exit
  233.  
  234.                 cmp    ax,8                  ;if PSP of owner is at 8
  235.                 je     prog_exit             ;block owned by config.sys
  236.  
  237.                 sub    ax,sb_head_length     ;get address of sb containg program
  238.                 cmp    ax,sb_shell           ;is owner the primary shell?
  239.                 je     prog_exit
  240.                 push   es
  241.                 pop    ax
  242.                 cmp    ax,sb_psp             ;compare to address of owner
  243.                 ja     prog_exit             ;if owner below SB, system-owned
  244.  
  245.                 add    ax,sb_length          ;add in length
  246.                 cmp    ax,sb_psp             ;compare to owner's PSP
  247.                 JB     prog_exit             ;if end below owner PSP, no program
  248.                 cmp    sb_length,10          ;is block long enough to have a psp?
  249.                 jbe    prog_exit             ;if not, no program
  250.  
  251.                 mov    ax,word ptr es:psp_dos_function+sb_head_length
  252.                 cmp    ax,word ptr cs:psp_dos_function   ;check PSP validity
  253.                 jne    prog_exit
  254.  
  255.                 mov    ax,word ptr es:psp_ret_int+sb_head_length
  256.                 cmp    ax,word ptr cs:psp_ret_int     ;check PSP validity
  257.                 jne    prog_exit                ;if invalid, skip looking for env
  258.  
  259.                 call   command_test
  260.                 clc
  261. prog_exit:
  262.  
  263.                 pop    es                       ;restore registers
  264.                 pop    dx
  265.                 pop    cx
  266.                 pop    ax
  267.                 ret
  268.  
  269. prog_test       endp
  270.  
  271. sb_scan         proc   near           ;loop cx storage blocks
  272.  
  273.                 mov    al,sb_kind     ;get storage block type byte
  274.                 cmp    al,04dh        ;ordinary storage block
  275.                 je     sb_scan_got
  276.                 cmp    al,05ah
  277.                 jne    sb_scan_bad
  278.                 mov    cx,1           ;last block
  279.  
  280. sb_scan_got:
  281.                 inc    sb_count              ;count storage blocks
  282.  
  283.                 cmp    sb_count,3            ;blocks 1 and 2 not global env
  284.                 jb     sb_scan_not_global
  285.  
  286.  
  287.                 cmp    sb_count,4            ;blocks 5-up not global env
  288.                 ja     sb_scan_not_global
  289.  
  290.                 cmp    sb_shell_env,0        ;do we have an env yet ?
  291.                 ja     sb_scan_not_global    ; yes, forget this one
  292.  
  293.                 cmp    sb_data,'!'           ;this block an environment ?
  294.                 jb     sb_scan_not_global    ; no, obviously not
  295.  
  296.                 cmp    sb_data,'~'           ;this block an environment ?
  297.                 ja     sb_scan_not_global    ; no, obviously not
  298.  
  299.                 mov    sb_shell_env,es
  300.                 jmp    sb_scan_get
  301.  
  302. sb_scan_not_global:
  303.                 call   prog_test             ;look for program
  304.  
  305.                 loop   sb_scan_get
  306.                 jmp    sb_scan_end
  307.  
  308. sb_scan_get:
  309.                 call   get_next_sb
  310.                 jmp    sb_scan
  311.  
  312. sb_scan_end:
  313.                 clc
  314.                 jmp    sb_scan_exit
  315.  
  316. sb_scan_bad:
  317.                 mov    al,2
  318.                 mov    dx,offset bad_sb_msg
  319.                 stc
  320.  
  321. sb_scan_exit:
  322.                 ret
  323. sb_scan         endp
  324.  
  325.  
  326. sb_anal         proc   near           ;proc to analyze storage blocks
  327.                                       ; to find environment(s)
  328.                 push   ax
  329.                 push   cx
  330.                 push   dx             ;carry flag = error
  331.                 push   es             ;error level in al
  332.                 mov    ah,30h         ;get release number
  333.                 int    21h
  334.                 cmp    al,01h         ;above dos 1.x?
  335.                 jna    sb_bad_dos
  336.  
  337.                 cld                  ;clear direction flag
  338.                 call   get_first_sb
  339.                 mov    cx,9999        ;scan all blocks
  340.                 call   sb_scan
  341.                 jc     sb_send_msg    ;if any errors, exit
  342.  
  343.                 jmp    sb_exit
  344.  
  345. sb_bad_dos:
  346.                 mov    al,1
  347.                 mov    dx,offset bad_dos_msg
  348.                 stc
  349.                 jmp    sb_send_msg
  350.  
  351. sb_bad_env:
  352.                 mov    al,3
  353.                 mov    dx,offset bad_env_msg
  354.                 stc
  355. sb_send_msg:
  356.                 pushf
  357.                 call   type_string
  358.                 popf
  359. sb_exit:
  360.                 pop    es
  361.                 pop    dx
  362.                 pop    cx
  363.                 pop    ax
  364.  
  365.                 ret
  366. sb_anal         endp
  367.  
  368. make_upper     proc    near          ;make cx bytes at es:di upper case
  369.  
  370.                push    ax            ;save registers modified
  371.                push    cx
  372.                push    di
  373.                push    ds
  374.                push    si
  375.  
  376.                push    es
  377.                pop     ds
  378.                mov     si,di
  379. make_upper_loop:
  380.                lodsb                  ;get a byte
  381.                cmp     al,'a'           ;if lower case:
  382.                jb      make_upper_next
  383.                cmp     al,'z'
  384.                ja      make_upper_next
  385.                and     al,255-'a'+'A'   ;make upper case
  386. make_upper_next:
  387.                stosb                  ;store out results
  388.                loop    make_upper_loop
  389.  
  390.                pop     si            ;restore registers
  391.                pop     ds
  392.                pop     di
  393.                pop     cx
  394.                pop     ax
  395.                ret
  396. make_upper     endp
  397.  
  398.  
  399.  
  400. env_var_name  proc     near               ;find environment variable name at
  401.               push     ax                 ;  ds:si, length in cx
  402.               push     bx                 ;at exit, ds:di points to name
  403.               push     di                 ;         name length in cx
  404.               push     es                 ;variable contents length to dx
  405.  
  406.               push     cx                 ;save length and pointer
  407.               push     si                 ;for error exits
  408.  
  409.               jcxz     env_var_name_bad   ;if length is 0, exit
  410.  
  411.  
  412.               push     cs                 ;scan works at es:di
  413.               pop      es
  414.               mov      di,si
  415.               mov      al,' '             ;scan for non-blank
  416.  
  417. env_var_strip:
  418.               repz     scasb              ;look for non-blank
  419.               jcxz     env_var_name_bad   ;if all blank, error!
  420.  
  421.               inc      cx                 ;back up over non-blank character
  422.               dec      di
  423.               mov      si,di              ;save start of non-blank string
  424.               mov      bx,cx              ;save length
  425.  
  426.               repnz    scasb              ;look for a blank
  427.               mov      dx,di              ;save location of ' ' or end
  428.  
  429.               mov      cx,bx              ;reset search length
  430.               mov      di,si              ;reset search pointer
  431.               mov      al,'='             ;search for equals sign
  432.               repnz    scasb
  433.               jne      env_var_name_bad   ;if not found, error
  434.  
  435.               cmp      di,dx              ;compare location of '=' and ' '
  436.               ja       env_var_name_bad   ;found ' ' first? then exit
  437.  
  438.               mov      dx,bx              ;restore search length
  439.               add      dx,si              ;add start
  440.               sub      dx,di              ;subtract where '=' was
  441.  
  442.               pop      ax                 ;pop old si from stack
  443.               pop      ax                 ;pop old cx from stack
  444.  
  445.               mov      cx,di              ;where we found '='
  446.               sub      cx,si              ;subtract string start
  447.               dec      cx                 ;minus 1 for '='
  448.               clc                         ;all is well
  449.               jmp      env_var_name_exit
  450.  
  451. env_var_name_bad:
  452.               pop      si                 ;restore pointer and length
  453.               pop      cx
  454.               xor      dx,dx              ;contents length assumed zero
  455.               stc                         ;problems  - set carry
  456.  
  457. env_var_name_exit:
  458.               pop      es
  459.               pop      di
  460.               pop      bx                 ;restore registers
  461.               pop      ax
  462.               ret
  463.  
  464. env_var_name  endp
  465.  
  466. get_sb_size   proc     near              ;get byte size of sb at es:0 in cx
  467.               push     ax
  468.               mov      ax,sb_length      ;get length of env in paragraphs
  469.               mov      cl,4              ;times 16
  470.               shl      ax,cl
  471.               mov      cx,ax
  472.               pop      ax
  473.               ret
  474. get_sb_size   endp
  475.  
  476. env_var_find  proc     near              ;find environment variable
  477.                                          ;named in ds:si,name length in cx
  478.                                          ;return string start in es:di
  479.                                          ;length of entire string in cx
  480.               push     ax                ;save registers
  481.               push     bx
  482.               push     dx
  483.  
  484.               mov      bx,cx             ;save length of name
  485.               push     es                ;save env block address
  486.               push     ds                ;set  es:di to source string
  487.               pop      es                ;     "
  488.               mov      di,si             ;make name upper case
  489.               call     make_upper        ;altering input string
  490.               pop      es                ;restore es to environment block
  491.  
  492.               call     get_sb_size       ;get size of sb in bytes
  493.  
  494.               mov      di,sb_head_length ;start at data portion of block
  495.               mov      dx,cx             ;save block length
  496.  
  497. env_var_find_loop:
  498.               push     si                ;save string pointers
  499.               push     di
  500.  
  501.               mov      cx,bx             ;compare for length of name
  502.               mov      ah,1              ;say not compare
  503.               repz     cmpsb             ;compare item to name for name length
  504.               jne      env_var_find_next ;if not found, scan on
  505.  
  506.               cmp      byte ptr es:[di],'='   ;check next byte for '='
  507.               jne      env_var_find_next ;if found, go calc length
  508.  
  509.               mov      ah,0              ;say compare ok
  510. env_var_find_next:
  511.               pop      di                ;restore string pointers
  512.               pop      si
  513.  
  514.               xor      al,al             ;look for end of current substring
  515.               mov      cx,dx             ;search remainder of string
  516.               mov      dx,di             ;save search start
  517.               repnz    scasb             ;search for a zero
  518.               jne      env_var_find_end  ;none found, error
  519.  
  520.               cmp      ah,0              ;did original compare fly?
  521.               je       env_var_find_found;if so, then pass length, etc
  522.  
  523.               cmp      byte ptr es:[di],0  ;check next byte for zero
  524.               je       env_var_find_end  ;if found, name not found
  525.  
  526.               mov      dx,cx             ;save length of string remaining
  527.               jmp      env_var_find_loop ;and loop on
  528.  
  529. env_var_find_end:
  530.               xor      cx,cx             ;length = 0, none found
  531.               stc                        ;set error flag
  532.               jmp      env_var_find_exit
  533.  
  534. env_var_find_found:
  535.               mov      cx,di             ;save count of end of string
  536.               mov      di,dx             ;restore search start
  537.               sub      cx,di             ;calc length of search
  538.               dec      cx                ;less length of zero
  539.               clc                        ;no errors
  540.  
  541. env_var_find_exit:
  542.               pop      dx
  543.               pop      bx                ;restore registers
  544.               pop      ax
  545.               ret
  546. env_var_find  endp
  547.  
  548.  
  549. null_var      dw       -1
  550.  
  551. env_var_add   proc near                     ;add  environment variable
  552.                                             ;expression ->ds:si, length in cx
  553.               push    ax                    ;save registers
  554.               push    bx
  555.               push    dx
  556.  
  557.               mov     dx,offset addmsg
  558.               call    type_string
  559.               mov     bx,cx
  560.               push    si
  561.               mov     si,offset null_var  ;send on wild goose chase
  562.               mov     cx,2                ;looking for  x'ffff'
  563.               call    env_var_find        ;es:di points to end of env
  564.               pop     si
  565.               jnc     env_var_add_env_bad
  566.                                           ;es:di now points to end of env
  567.               call    get_sb_size         ;get length of env area in cx
  568.               add     cx,sb_head_length   ;add head length for offsets
  569.               sub     cx,bx               ;deduct length of string
  570.               sub     cx,2                ;deduct length of flag
  571.               cmp     di,cx               ;compare to where we add
  572.               ja      env_var_add_bad     ;if no space, too bad
  573.  
  574.               mov     cx,bx               ;length of string to add
  575.               rep     movsb               ;do the deed
  576.               xor     ax,ax               ;make flag of two zeros
  577.               stosw                       ;add is on
  578.  
  579.               jmp     env_var_add_good
  580.  
  581. env_var_add_env_bad:
  582.               mov     dx,offset addbadmsg
  583.               call    type_string
  584.  
  585. env_var_add_bad:
  586.               stc
  587.               jmp     env_var_add_exit
  588.  
  589. env_var_add_good:
  590.               clc
  591. env_var_add_exit:
  592.               pop     dx                  ;restore registers
  593.               pop     bx
  594.               pop     ax
  595.               ret
  596.  
  597. env_var_add   endp
  598.  
  599.  
  600. env_var_remove proc near                ;remove environment variable
  601.                                         ;at es:di, length in cx
  602.               push    cx
  603.               push    dx
  604.               push    ds
  605.               push    di
  606.               push    si
  607.  
  608.               cld                      ;move left to right
  609.  
  610.               mov     dx,offset removemsg
  611.               call    type_string
  612.  
  613.               inc     cx                  ;add 1 for zero byte
  614.               mov     dx,cx               ;save length of var
  615.               call    get_sb_size         ;cx gets length of env area
  616.               add     cx,sb_head_length   ;add header length for offsets
  617.               sub     cx,di               ;deduct where we start
  618.               sub     cx,dx               ;deduct length of removed variable
  619.  
  620.               mov     si,di               ;move from next variable
  621.               add     si,dx               ;add my length
  622.  
  623.               push    es                  ;do all the work in es:
  624.               pop     ds
  625.  
  626.               rep     movsb               ;do the move
  627.  
  628.               pop     si
  629.               pop     di
  630.               pop     ds
  631.               pop     dx
  632.               pop     cx
  633.               ret
  634. env_var_remove  endp
  635.  
  636.  
  637. env_set       proc    near                ;change environment per ds:si
  638.               push    ax
  639.               push    bx                  ;ds:si points to:
  640.               push    cx                  ; length  db  ?
  641.               push    di
  642.               push    ds                  ; data    db  'name=value'
  643.               push    es
  644.               push    si
  645.               mov sb_count,0              ;count of sb's encountered
  646.               mov sb_shell,0              ;segment address of shell  sb
  647.               mov sb_shell_env,0          ;segment address of global env sb
  648.               mov sb_secondary,0          ;segment address of secondary command.com
  649.               mov sb_secondary_env,0      ;segment address of secondary command env
  650.  
  651.               xor     ax,ax               ;set length of local set string
  652.               lodsb                       ;get length, push di forward
  653.               mov     cx,ax               ;length of set string in cx
  654.               and     cl,0ffh-80h         ;length < 128
  655.               call    sb_anal             ;analyze the storage block chain
  656.                                           ;to find command processor(s)
  657.  
  658.               and     al,80h              ;was use primary switch on?
  659.               jnz     env_set_shell       ;if so, skip secondaries
  660.  
  661.               cmp     sb_secondary_env,0  ;is there a secondary command proc?
  662.               je      env_set_shell       ;if not, use primary
  663.  
  664.               mov     es,sb_secondary_env ;command processor is secondary
  665.               jmp     env_set_command
  666.  
  667. env_set_shell:                            ;command processor is shell
  668.               mov     es,sb_shell_env
  669. env_set_command:
  670.               call    env_var_name        ;find what we want set at call
  671.                                           ;ds:si -> expression, cx has length
  672.                                           ;at return ds:si -> name
  673.                                           ;cx is length of name
  674.               jc      env_set_syntax_err  ;if not found, error
  675.  
  676.               mov     bx,cx               ;calculate new length of set string
  677.               inc     bx                  ;add 1 for '='
  678.               add     bx,dx               ;add length of set string
  679.  
  680.               call    env_var_find        ;find variable in environment block
  681.                                           ;at return, es:di -> start of env str
  682.                                           ;cx is length of env str
  683.               jc      env_set_add         ;if not found, just add
  684.  
  685.               call    env_var_remove      ;remove variable at es:di from env
  686.               cmp     dx,0                ;check out length of data to add
  687.               je      env_set_exit        ;if zero, just exit
  688.  
  689. env_set_add:
  690.               mov     cx,bx               ;restore length of variable
  691.               call    env_var_add         ;add new variable to set string
  692.               jc      env_set_no_space
  693.               jmp     env_set_exit
  694.  
  695. env_set_no_space:
  696.               mov     dx,offset env_set_nospace
  697.               jmp     env_set_type
  698.  
  699. env_set_syntax_err:
  700.               mov     dx,offset env_set_syntax
  701. env_set_type:
  702.               push    cs
  703.               pop     ds
  704.               call    type_string
  705. env_set_error:
  706.               stc
  707. env_set_exit:
  708.               pop     si
  709.               pop     es
  710.               pop     ds
  711.               pop     di
  712.               pop     cx
  713.               pop     bx
  714.               pop     ax
  715.               ret
  716. env_set       endp
  717.  
  718. cseg          ends
  719.               end
  720.  
  721.