home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / jsage / znode3 / uploads / zf11src.lbr / ZFSUBS6.ZZ0 / ZFSUBS6.Z80
Encoding:
Text File  |  1992-10-01  |  5.1 KB  |  211 lines

  1. .printx    Reading ZFSUBS6.Z80
  2. ;==========================================================================
  3. ;
  4. ;  ZFSUBS6.Z80 - Tagged File List Read/Write Routines
  5. ;
  6. ;==========================================================================
  7.  
  8. ; In order to preserve the list of tagged files between ZFILER shell
  9. ; invocations, the name of each tagged file is written to a temporary
  10. ; text file, ZFILER.TAG.  When ZFILER is re-invoked, it looks for the
  11. ; tag file and, if possible, soft tags all previously tagged files.  The
  12. ; tag file is then erased.
  13.  
  14. ; ZFILER.TAG text file lines are 13 character long -- an 11 character file
  15. ; name and <cr><lf>.  EOF is 1Ah.
  16.  
  17.  
  18. ; READTAGS -
  19. ; Read temporary file with previously tagged file names, then softag files
  20. ; which still exist. This routine is called when ZFILER invoked as a shell
  21. ; by ZCPR3.
  22. ;
  23. ;    Since these operations are (ideally) transparent to the user,
  24. ;    they quit without comment on i/o errors.
  25. ;
  26. readtags:
  27.     ld    a,(savtfla)    ; Option enabled?
  28.     or    a
  29.     ret    z        ; No
  30.  
  31.     call    retud        ; Save current DIR
  32.     ld    (dirsav),bc
  33.     call    gettagdu    ; Log in ZFILER.TAG DIR and point to FCB1
  34.     call    fi0$open    ; Open file for byte input
  35.     jr    nz,rdtex    ; No file
  36.  
  37.     ld    hl,(ring)    ; Init to start of ring
  38.     ld    (ringpos),hl
  39. rdtloop:
  40.     call    tagget        ; Get next name
  41.     jr    z,rdtloop1    ; EOF
  42.     call    rdtmat        ; Match to current file ring
  43.     jr    rdtloop        ; Keep going to EOF
  44. rdtloop1:
  45.     call    fi0$close    ; Close input file
  46.     ld    de,fcb        ; Delete it
  47.     call    f$delete    ; Yes
  48. rdtex:
  49.     ld    bc,(dirsav)    ; Get back DIR we started in
  50.     call    logud
  51.     ret
  52.  
  53. ;
  54. ; Get next name
  55. ;
  56. tagget:
  57.     ld    hl,namebuf    ; Buffer to receive name
  58.     ld    b,13        ; Get FilenameTyp<CR><LF>
  59. tagget1:
  60.     call    f0$get
  61.     cp    1ah
  62.     ret    z
  63.     call    caps        ; In case file not made by ZFILER
  64.     ld    (hl),a
  65.     inc    hl
  66.     djnz    tagget1
  67.     ret
  68.  
  69. ;
  70. ; Match saved tagged file name to ring.
  71. ;   Since ring may have changed, there is no guarantee of a match.
  72. ;   Search starts at last matched position and wraps around.
  73. ; If match found, softag it.
  74. ;
  75. rdtmat:
  76.     ld    hl,(ringpos)    ; Keep starting position
  77.     ld    (sringpos),hl
  78.     ex    de,hl        ; To DE
  79.     jr    rdt2
  80.  
  81. rdtend:
  82.     ld    hl,(ring)    ; Wrap search to start of ring
  83.     ld    (ringpos),hl
  84.     jr    rdt1a
  85. rdt1:
  86.     call    incringpos    ; Advance to next element
  87. rdt1a:    ex    de,hl        ; Ring pointer to DE
  88.     ld    hl,(sringpos)    ; Are we back to starting position?
  89.     call    cmpdehl
  90.     ret    z        ; If so, quit with no match
  91.  
  92. rdt2:
  93.     ld    hl,(ringend)
  94.     call    cmpdehl        ; End of ring?
  95.     jr    z,rdtend    ; Yes, reset to start
  96.     ld    hl,namebuf-1    ; Point to current file name from list
  97.     call    fmatch        ; Do we have a match?
  98.     jr    nz,rdt1        ; No, try again
  99.  
  100. ; We found it
  101.     ld    hl,tagoff    ; Offset to tag byte
  102.     add    hl,de        ; DE still has ring position
  103.     ld    (hl),stagch    ; Soft tag this file
  104.     call    incringpos    ; Ready for next
  105.     ret
  106.  
  107. ;--------------------------------------------------------------------------
  108.  
  109. ; WRITETAGS - Write tagged file names to temporary file
  110. ; This routine is called on Z command or Macro run.
  111. ;   If tag save option on ..
  112. ;     If any files tagged ..
  113. ;    Make output file
  114. ;    Write each tagged file name to it
  115. ;    Close file
  116. ;
  117. writetags:
  118.     ld    a,(savtfla)    ; Option enabled?
  119.     or    a
  120.     ret    z        ; No
  121.  
  122.     xor    a
  123.     ld    (wtagflag),a    ; Reset output flag
  124.  
  125.     ld    hl,(ringpos)    ; Save entry ring pos
  126.     ld    (sringpos),hl
  127.     ld    hl,(ring)    ; Init to start of ring
  128.     ld    de,-eltsiz    ; Back up one
  129.         add    hl,de
  130.     ld    (ringpos),hl
  131.     call    wtagloop    ; Put tagged file names
  132.     ld    hl,(sringpos)    ; Restore entry ring pos
  133.     ld    (ringpos),hl
  134.     ld    a,(wtagflag)    ; Anything written?
  135.     or    a
  136.     call    nz,fo0$close    ; ..close output file
  137.     ret
  138. ;
  139. wtagloop:
  140.     call    ringinc        ; Advance pointer, get possible tag
  141.         ret    z        ; End of ring
  142.     cp    tagch        ; Tagged?
  143.     jr    nz,wtagloop    ; No
  144.     call    tagput        ; Yes, write name to output
  145.     jr    z,wtagloop    ; Write OK
  146.     ret            ; Write error
  147.  
  148. ;
  149. ; Write a tagged file's name to output
  150. ;   RET NZ on write error
  151. ;
  152. tagput:
  153.     ld    a,(wtagflag)    ; Have we opened file?
  154.     or    a
  155.     jr    nz,tagput1    ; Yes
  156.  
  157.     call    gettagdu    ; Log in ZFILER.TAG DU
  158.     call    fo0$open    ; Open for byte output
  159.     ret    nz        ; No room
  160.     or    -1
  161.     ld    (wtagflag),a    ; Set output open flag
  162. tagput1:
  163.     ld    b,11        ; Put FilenameTyp
  164.     ld    hl,(ringpos)
  165.     inc    hl        ; ->first char of name
  166. tagput2:
  167.     ld    a,(hl)
  168.     and    7fh        ; No need to incude attribits
  169.     call    f0$put
  170.     ret    nz        ; Output error
  171.     inc    hl
  172.     djnz    tagput2
  173.  
  174.     ld    a,cr        ; Append <CR><LF>
  175.     call    f0$put
  176.     ret    nz
  177.     ld    a,lf
  178.     call    f0$put
  179.     ret
  180.  
  181. ;--------------------------------------------------------------------------
  182. ; Common Subroutines
  183. ;
  184. ; Locate DIR for .TAG file
  185. ;   Here we just use the same DIR as for ZEX batch file
  186. ;   Move tag file name to fcb1 and init
  187. ;   RET  DE .FCB1
  188. ;
  189. gettagdu:
  190.     ld    bc,(batdu)    ; Fixed DU for batch file
  191.     ld    a,(batrootadr)    ; See if using root instead
  192.     or    a
  193.     call    nz,root        ; If using root directory, find it
  194.     call    logud
  195.     call    resdma        ; Make sure DMA at TBUF
  196.     ld    hl,tagfile    ; Move tag file to an fcb
  197.     ld    de,fcb+1
  198.     ld    bc,11
  199.     ldir
  200.     ld    de,fcb
  201.     call    initfcb        ; Initialize it
  202.     ret
  203.  
  204. ;
  205.     dseg
  206. namebuf        ds    13    ; Filename input buffer
  207. wtagflag    ds    1    ; Output open flag
  208. dirsav        ds    2    ; DU on entry
  209.     cseg
  210. ;
  211.