home *** CD-ROM | disk | FTP | other *** search
/ Phoenix CD 2.0 / Phoenix_CD.cdr / 02a / pushpath.zip / PUSHPATH.ASM < prev    next >
Assembly Source File  |  1987-02-28  |  4KB  |  79 lines

  1. ;program pushpath.  Reads the current path specification.
  2. ;Adds a carriage return the end of it.  Writes the number of
  3. ;bytes including the carriage return at the beginning of it.
  4. ;Appends it to file E:\Path.dat, creating the file if necessary.
  5. ;Idea is that PopPath will read the file and reset the path.
  6.  
  7. cseg      segment   para  public   'code'
  8. push      proc      far
  9.           assume    cs:cseg, ds:cseg, es:cseg, ss:cseg
  10.           org       100H                ;for com file
  11. start:    push      ds
  12.           mov       ds, ds:002ch        ;seg. address of environment
  13.           mov       si,0                ;and its offset
  14. search:   mov       di, offset pathflag ;look for 'PATH='
  15.           mov       cx,5                ;length pathflag
  16. repe      cmpsb                         ;see if pathflag in env
  17.           je        grab                ;found pathflag
  18. ;if here, entry does not begin with pathflag.  Look for
  19. ;the zero marking the end of the entry
  20. findzero: lodsb                         ;look for zero
  21.           cmp       al,0                ;is it zero?
  22.           je        zero                ;found a zero.  A second?
  23.           jmp       findzero            ;loop till found
  24. zero:     cmp       byte ptr ds:[si], 0          ;second zero?
  25.           je        nofind              ;path not in environment
  26.           jmp       search              ;keep looking
  27. ;here we found the path.  Need to save it.
  28. grab:     mov       cx,0                ;need counter
  29.           mov       di, offset string
  30. grabit:   lodsb
  31.           cmp       al,0                ;look for end of path entry
  32.           je        haveit              ;got to end of pathspec
  33.           inc       cl                  ;count characters
  34.           stosb                         ;store the path spec
  35.           jmp       grabit              ;loop to get full pathspec
  36. haveit:   inc       cl                  ;count includes final cr
  37.           mov       al,cl
  38.           mov       di, offset output
  39.           stosb
  40.           pop       ds
  41.           push      cx                  ;save length
  42. ;now mess around with the file
  43.           mov       ah, 3DH             ;function call, open file
  44.           mov       dx, offset file     ;address of fname
  45.           mov       al, 2               ;open for read,write
  46.           int       21H                 ;open it
  47.           mov       bx,ax               ;save handle
  48.           jnc       cont                ;branch if successful
  49.           mov       ah, 3CH             ;if no file, create it
  50.           mov       cx, 0               ;no attribute.
  51.           int       21H                 ;do it
  52.           mov       bx,ax               ;file handle to bx
  53. cont:     mov       al,2                ;setup move to EOF
  54.           xor       cx,cx               ;zero cx -moving to at EOF
  55.           xor       dx,dx               ;zero dx-no offset
  56.           mov       ah, 42H             ;function call, move pointer
  57.           int       21H                 ;move it
  58. ;now write the path spec out, with length and cr
  59.           pop       cx                  ;get string length back
  60.           inc       cl                  ;outputting string + its length
  61.           mov       dx, offset output   ;set up right
  62.           mov       ah, 40H             ;function call, write string
  63.           int       21H                 ;do it
  64. ;now close the file. Handle should still be in bx
  65.           mov       ah, 3EH             ;function call, close
  66.           int       21H                 ;do it
  67.           jmp       quit
  68. nofind:   pop       ds
  69. quit:     int       20H                 ;return to DOS
  70. push      endp
  71. file      db        'C:\PATH.DAT'
  72. endz      db        2    dup(0)
  73. pathflag  db        'PATH='
  74. output    db        0
  75. string    db        128 dup (0dh)
  76.           cseg      ends
  77.           end       start
  78. 
  79.