home *** CD-ROM | disk | FTP | other *** search
/ ftp.barnyard.co.uk / 2015.02.ftp.barnyard.co.uk.tar / ftp.barnyard.co.uk / cpm / walnut-creek-CDROM / ENTERPRS / CPM / UTILS / S / ZCNFG21.LZH / CFGLIB.LZH / GETZFS.Z80 < prev    next >
Text File  |  1992-11-03  |  10KB  |  327 lines

  1. ;routine to perform parse of [DU/DIR:]FN[.FT]
  2. ;date: 09/18/91
  3. ;author: A.E. Hawley
  4. ;version 1.3    previous: v 1.2, 10/19/88
  5.  
  6. ;v 1.5 10/25/91
  7. ; added logic to decrement default DRive in SCAN: if it
  8. ; is 0ffh. This records the occurrence of a lone ':'.
  9. ; Also added error handling after the call to DIRSCN so
  10. ; a bogus value is not put into BC!
  11. ;v 1.4 09/12/91
  12. ; corrected SCAN to store the error flag!
  13. ; corrected main routine to properly test error flag!
  14. ; added code in main routine to store User at FCB+13
  15. ;v 1.3 09/08/91
  16. ; Modified DUSCN so that default DU passed in BC
  17. ; is not tested for out-of-range values. Such values
  18. ; can then be used to test for presence of user
  19. ; supplied D or U, and defaults provided separately.
  20. ; If BC contains legal values, operation is unchanged.
  21. ;v 1.2 10/19/88
  22. ; Modified delimiter list to include '/'
  23. ; Default D/U are passed in BC rather than an external.
  24. ; Uses ALL 8080 registers, no Z80 special registers
  25.  
  26.     PUBLIC    dirscn,duscn,fname
  27.     GLOBAL    fill,ifcb,inifcb,mpy16,pkgoff,radbin
  28.     GLOBAL    rten1,sdelm,sksp,ucase
  29.  
  30. ;-----------------------------------------
  31.  
  32. ;entry-    HL -> Token to be parsed as Z3 filespec
  33. ;    DE -> FCB drive byte
  34. ;    B  =  Default Drive
  35. ;    C  =  Default User
  36.  
  37. ;exit-    HL -> Delimiter which terminated the parse
  38. ;    DE    is preserved
  39. ;    BC =  D/U, with defaults replaced by explicit D or U
  40. ;    (caller is responsible for legality of defaults)
  41. ;    if BC=-1 on entry, a parsed colon decrements B allowing
  42. ;    detection of an FS of form ':[FN.FT]' (10/25/91)
  43. ;    FCB drive byte, FN, FT, map fields initialized
  44. ;    FCB-1 = FCB+13 = Default or declared User area
  45. ;    NZ = Error, FCB+15 contains error flag
  46. ;    Z  = no error
  47. ;    A  = number of '?' in fn/ft. (wildcard count)
  48.  
  49. ;-----------------------------------------
  50.  
  51. fname:    push    de        ; Save pointer while initializing
  52.     ld    (tempusr),bc    ; Initialize temporary DU
  53.  
  54.     call    inifcb        ; Initialize FCB
  55.     pop    de
  56.  
  57.     push    de
  58.     call    scan        ; parse token into the FCB
  59. ;on return, A=number of '?' encountered
  60.     pop    de        ;->fcb
  61.  
  62.     push    hl        ; Initialize fcb-1, fcb with bc
  63.     ld    h,d
  64.     ld    l,e
  65.     ld    (hl),b        ; Drive
  66.     dec    hl
  67.     ld    (hl),c        ; User
  68.  
  69.     ld    hl,13
  70.     add    hl,de        ;-> Z3 User byte
  71.     ld    (hl),c
  72.     inc    hl
  73.     inc    hl        ;->error flag
  74.     inc    (hl)
  75.     dec    (hl)        ;returns Z if no errors
  76.     pop    hl        ;->next char after token
  77.     ret            ;return NZ if bad du or wildcards
  78.  
  79. ;-----------------------------------------
  80.  
  81. ; This routine processes a token pointed to by HL.  It attempts
  82. ; to interpret the token according to the form [DU:|DIR:]NAME.TYP and places
  83. ; the corresponding values into the FCB pointed to by DE.
  84. ; On entry, HL->token, DE->target fcb, BC=current DU (1..16,0..32)
  85. ; On exit, HL points to the delimiter encountered at the end of the token.
  86. ; The Z flag is set if a wild card was detected in the token, and A=? count.
  87. ; The drive byte is initialized, and the S1 byte contains the user number.
  88. ; BC contains the Drive/User.
  89. ; ERROR conditions: on a bad directory reference, the RC byte in the FCB
  90. ; will be set to NZ. (usually 0FFh)
  91.  
  92. scan:
  93.     call    scanf8        ; Extract possible file name
  94.     cp    ':'        ; Was terminating character a colon?
  95.     jr    nz,scant    ; If not, go on to extract file type
  96.     inc    hl        ; Point to character after colon
  97.  
  98. ; Code for resolving directory specifications returns
  99. ; with a nonzero value and NZ flag setting
  100. ; if the DU/DIR specification cannot be resolved.
  101.  
  102.     push    hl
  103.     push    de
  104.     ld    bc,(tempusr)    ; Preset C to current user, B to current drive
  105.     ld    a,b
  106.     inc    a        ; -1 default?
  107.     jr    nz,scan1    ; no, don't disturb it
  108.     dec    b        ; else make it 0FEh to show colon present    
  109.     ld    (tempusr),bc    ; and save it
  110. scan1:    call    duscn        ;check for DU form
  111.     jr    z,gotit
  112.     pop    de        ;not DU, check for DIR
  113.     pop    hl
  114.     push    hl
  115.     push    de
  116.     call    dirscn        ;returns nz if bad dir|no ndir|not Z3
  117.     jr    nz,scan3    ;not found, BC destroyed
  118.  
  119. gotit:    ld    (tempusr),bc
  120. scan3:    pop    de        ; Get FCB pointer back
  121.     ld    b,a        ; save error flag
  122.     push    de        ;clear FN field after du/dir scan use
  123.     inc    de        ;12/04/87
  124.     call    ifcb        ; ret A=B=0, Z
  125.     pop    de
  126.  
  127.     ld    hl,15
  128.     add    hl,de        ; point to RC byte of the FCB
  129.     ld    (hl),b        ; Store error flag there (NZ if error)
  130.     ld    a,(tempdr)    ; Set designated drive
  131.     ld    (de),a        ; ..into FCB
  132.     pop    hl        ; Restore pointer to token string
  133.                 ;..and save error flag pointer
  134.     call    scanf8        ; Scan for file name
  135.  
  136. ; Process the file type specification in the token
  137.  
  138. scant:
  139.     ld    a,(hl)        ; Get ending character of file name field
  140.     ex    de,hl        ; Switch FCB pointer into HL
  141.     ld    bc,8        ; Offset to file type field
  142.     add    hl,bc
  143.     ex    de,hl        ; Switch pointers back
  144.  
  145.     cp    '.'        ; See if file type specified
  146.     jr    nz,scant2    ; If not, skip over file type parsing
  147.  
  148.     inc    hl        ; Point to character after '.'
  149.     push    de        ; Save pointer to FCB file type
  150.     ld    b,3        ; Maximum characters in file type
  151.     call    scanfield    ; Parse file type into FCB
  152.     pop    de
  153.  
  154. scant2:    call    scanf3        ; Skip to next delimiter or line end
  155.  
  156. ; Set zero flag if '?' in filename.typ
  157. qmcnt    equ    $+1        ; Pointer for in-the-code modification
  158.     ld    a,0        ; Number of question marks
  159.     or    a        ; Set zero flag
  160.     ld    bc,(tempusr)    ; return DU in BC
  161.     ret
  162.  
  163. ;-----------------------------------------
  164.  
  165. ; This routine invokes SCANFIELD for a file name field.  It initializes the
  166. ; question mark count and preserves the FCB pointer.
  167.  
  168. scanf8:
  169.     xor    a        ; Initialize question mark count
  170.     ld    (qmcnt),a
  171.     push    de        ; Save pointer to FCB
  172.     ld    b,8        ; Scan up to 8 characters
  173.     call    scanfield
  174.     pop    de        ; Restore pointer to FCB
  175.     ret
  176.  
  177. ; This routine scans a command-line token pointed to by HL for a field whose
  178. ; maximum length is given by the contents of the B register.  The result is
  179. ; placed into the FCB buffer pointed to by DE.  Wild cards of '?' and '*' are
  180. ; expanded.  On exit, HL points to the terminating delimiter.
  181.  
  182. scanfield:
  183.     call    sdelm        ; Done if delimiter encountered
  184.     ret    z
  185.     inc    de        ; Point to next byte in FCB
  186.     cp    '*'        ; Is character a wild card?
  187.     jr    nz,scanf1    ; Continue if not
  188.  
  189.     ld    a,'?'        ; Process '*' by filling with '?'s
  190.     ld    (de),a
  191.     call    qcountinc    ; Increment count of question marks
  192.     jr    scanf2        ; Skip so HL pointer left on '*'
  193.  
  194. scanf1:                ; Not wildcard character '*'
  195.     call    ucase        ; make sure it's upper case ascii
  196.     ld    (de),a        ; Store character in FCB
  197.     inc    hl        ; Point to next character in command line
  198.     cp    '?'        ; Check for question mark (wild)
  199.     call    z,qcountinc    ; Increment question mark count
  200. scanf2:
  201.     djnz    scanfield    ; Decrement char count until limit reached
  202. scanf3:
  203.     call    sdelm        ; Skip until delimiter
  204.     ret    z        ; Zero flag set if delimiter found
  205.     inc    hl        ; Pt to next char in command line
  206.     jr    scanf3
  207.  
  208.  
  209. ; Subroutine to increment the count of question mark characters in the
  210. ; parsed file name.
  211.  
  212. qcountinc:
  213.     push    hl
  214.     ld    hl,qmcnt    ; Point to count
  215.     inc    (hl)        ; Increment it
  216.     pop    hl
  217.     ret
  218.  
  219. ;-----------------------------------------
  220.  
  221. ; This code attempts to interpret the token in the FCB pointed to by register
  222. ; pair DE as a DIR (named directory) prefix.  If it is successful, the drive
  223. ; and user values are stored in TEMPDR and TEMPUSR, and the zero flag is set.
  224.  
  225. dirscn:
  226.     inc    de        ; Point to first byte of directory form
  227.  
  228.     ex    de,hl        ; Switch pointer to FCB to HL
  229.  
  230.     ld    de,15h        ; Offset to NDR address
  231.     push    hl        ; Preserve pointer to FCB
  232.     call    pkgoff        ; Get NDR address from ENV into DE
  233.     pop    hl
  234.     jr    z,direrr    ; Branch if no NDR implemented
  235.  
  236. dirsc1:
  237.     ld    a,(de)        ; Get next character
  238.     or    a        ; Zero if end of NDR
  239.     jr    z,direrr
  240.     inc    de        ; Point to name of directory
  241.     inc    de
  242.     push    hl        ; Save pointer to name we are looking for
  243.     push    de        ; Save pointer to NDR entry
  244.     ld    b,8        ; Number of characters to compare
  245.  
  246. dirsc2:
  247.     ld    a,(de)
  248.     cp    (hl)
  249.     jr    nz,dirsc3    ; If no match, quit and go on to next DIR
  250.     inc    hl        ; Point to next characters to compare
  251.     inc    de
  252.     djnz    dirsc2        ; Count down
  253.  
  254. dirsc3:
  255.     pop    de        ; Restore pointers
  256.     pop    hl
  257.     jr    z,dirsc4    ; Branch if we have good match
  258.  
  259.     ex    de,hl        ; Advance to next entry in NDR
  260.     ld    bc,16        ; 8 bytes for name + 8 bytes for password
  261.     add    hl,bc
  262.     ex    de,hl
  263.     jr    dirsc1    ; Continue comparing
  264.  
  265. dirsc4:            ; Match found
  266.     ex    de,hl        ; Switch pointer to NDR entry into HL
  267.     push    hl        ; ..and save it for later
  268.     dec    hl        ; Point to user corresponding to the DIR
  269.     ld    c,(hl)        ; Get user value into C
  270.     dec    hl        ; Point to drive
  271.     ld    b,(hl)        ; Get it into B
  272.     pop    hl
  273.     ret
  274.  
  275. ;-----------------------------------------
  276.  
  277. direrr:                ; Error exit for dirscn, duscan
  278. duerr:    or    0ffh        ; Return NZ to show failure
  279.     ret
  280.  
  281. ;-----------------------------------------
  282.  
  283. ; This code attempts to interpret the token in the FCB pointed to by register
  284. ; pair DE as a DU (drive/user) prefix.  If it is successful, the drive and
  285. ; user values are stored in TEMPDR and TEMPUSR, and the zero flag is set.
  286. ; Entry- BC = default drive, user
  287.  
  288. duscn:
  289.     ex    de,hl        ; Switch FCB pointer to HL
  290.     inc    hl        ; Point to first byte of file name in FCB
  291.  
  292.     ld    a,(hl)        ; Get possible drive specification
  293.     sub    'A'        ; Otherwise convert to number 0..15
  294.     jr    c,duscn1    ; If < 0, leave B as is
  295.     cp    16
  296.     jr    nc,duscn1    ; If > 15, leave B as is
  297.     ld    b,a        ; Otherwise use value given
  298.     inc    hl        ; ..and point to next character
  299.     inc    b        ; Shift drive to range 1..16
  300.  
  301. duscn1:    ld    a,(hl)        ; Get possible user specification
  302.     cp    ' '
  303.     ret    z        ; if none present, leave C as is
  304.     push    bc        ; Save DU values in BC
  305.     call    rten1        ; Get specified decimal user number into BC
  306.     pop    hl        ; Restore values to HL
  307.     jr    c,duerr        ; Return NZ if invalid decimal conversion
  308.     ld    a,b        ; Get high byte of result
  309.     or    a        ; Make sure it is zero
  310.     ret    nz        ; If not, return NZ to show bad user number
  311.     ld    a,31
  312.     sub    c        ; if CY set, then number > 31
  313.     sbc    a,a        ; propagate CY into A and set flags
  314.     ret    nz        ; NZ = bad user number
  315.     ld    b,h        ; DU value is now in BC
  316.     xor    a        ; Set Z to flag success
  317.     ret
  318.  
  319. ;-----------------------------------------
  320.  
  321. tempusr:            ;temporary local values
  322.     db    0
  323. tempdr:
  324.     db    0
  325.  
  326.     end
  327.