A2osX/BIN/X.FILEENUM.S.txt

570 lines
11 KiB
Plaintext
Raw Normal View History

NEW
2019-09-19 15:22:14 +00:00
AUTO 3,1
.LIST OFF
*--------------------------------------
X.MAX.RECURSE .EQ 8
*--------------------------------------
* Uses: (pData)
* hDIRs .BS X.MAX.RECURSE+1
* hDIRENTs .BS X.MAX.RECURSE+1
* Index .BS 1
* hSrcBasePath .BS 1
* hDstBasePath .BS 1 (optional)
* STAT .BS S.STAT
2019-04-30 16:08:47 +00:00
* hFilter .BS 1
*--------------------------------------
2019-04-30 16:08:47 +00:00
* Compare a ZPFileName against hFilter (e.g. '*test?.*')
2018-12-17 15:21:32 +00:00
* CC : match
* CS : no match
*--------------------------------------
2019-04-30 16:08:47 +00:00
FilterMatch >LDA.G index
dec
bne .8 in a subdir, match everything
>LDA.G hFilter
beq .8 No filter....
>SYSCALL GetMemPtr
>STYA ZPPtr2
ldy #S.STAT.FSID
lda (ZPFileStat),y
bne .10 not prodos...
2019-10-12 14:20:09 +00:00
2019-04-30 16:08:47 +00:00
>LDYA ZPPtr2 CI compare
>SYSCALL strupr
2018-12-17 15:21:32 +00:00
2019-10-12 14:20:09 +00:00
.10 lda (ZPPtr2) Get first pattern byte
2018-12-17 15:21:32 +00:00
beq .8 Match always if empty
2019-10-12 14:20:09 +00:00
ldy #0
bra .2
2018-12-17 15:21:32 +00:00
2019-10-12 14:20:09 +00:00
.1 jsr FilterMatch.NextPtr2 get next pattern char
2018-12-17 15:21:32 +00:00
beq .41 end of pattern...
2019-10-12 14:20:09 +00:00
.2 cmp #'*'
2018-12-17 15:21:32 +00:00
beq .5
2019-10-12 14:20:09 +00:00
.3 lda (ZPFileName),y we must match ? or regular char, check if at end of string
2018-12-17 15:21:32 +00:00
beq .9 no char left, exit with error
lda (ZPPtr2) get back pattern char
cmp #'?'
beq .4 no need to compare, any char will match
2019-10-12 14:20:09 +00:00
2018-12-17 15:21:32 +00:00
cmp (ZPFileName),y Regular Char, compare with string at Y
bne .9 no match, exit
2019-10-12 14:20:09 +00:00
.4 iny advance to next char to compare
bra .1 continue if remaining char in pattern
2018-12-17 15:21:32 +00:00
.41 lda (ZPFileName),y end of pattern, but end of string ?
beq .8 yes, string matched entirely
* no, remaining char in string, no match
.9 sec
rts
2019-10-12 14:20:09 +00:00
.5 jsr FilterMatch.NextPtr2 we have '*', last char of pattern ?
2018-12-17 15:21:32 +00:00
beq .8 yes, match everything, including empty string
cmp #'*' another '*' ?
beq .5 yes, '**' = '*', go next char
cmp #'?' '*?' ? we must match a least one char
beq .3
.7 lda (ZPFileName),y we need at least one remaining char in string, check if at end of string
beq .9 no chance to match ? or regular char
iny
lda (ZPPtr2) get again char in pattern
cmp (ZPFileName),y compare with char in string
bne .7 not equal to next non wildcard in pattern
iny
bra .1 go check remaining char in pattern...
2019-10-12 14:20:09 +00:00
.8 clc
FilterMatch.RTS
2018-12-17 15:21:32 +00:00
rts
*--------------------------------------
2019-10-12 14:20:09 +00:00
FilterMatch.NextPtr2
inc ZPPtr2 Make PTR2 advance to next char
bne .1
inc ZPPtr2+1
.1 lda (ZPPtr2)
rts
2019-10-12 14:20:09 +00:00
*--------------------------------------
InitSrcDirYA >SYSCALL RealPath
bcs FilterMatch.RTS
>STYA ZPPtr1
txa
>STA.G hFullPath
ldy #1
lda (ZPPtr1),y
2018-12-20 07:33:10 +00:00
beq .5 we have '/'
>PUSHEA.G STAT
2018-07-20 11:51:08 +00:00
>LDYA ZPPtr1
>SYSCALL Stat
bcs .1 File/DIR does not exists, go extract pattern
2019-04-29 15:47:17 +00:00
.DO X.ENTER.SUBDIR=1
>LDA.G STAT+S.STAT.P.TYPE
2018-12-20 07:33:10 +00:00
cmp #S.FI.T.DIR
bne .4 TYPE not a DIR, extract....
2019-10-12 14:20:09 +00:00
bra .5 TYPE=DIR, do not extract pattern
.ELSE
2019-04-29 15:47:17 +00:00
bra .4
.FIN
2019-10-12 14:20:09 +00:00
.1 jsr GetPtr1Len TYPE is not DIR, check if wc
dey
2019-10-12 14:20:09 +00:00
ldx #0 Init Wildcard count
2019-10-12 14:20:09 +00:00
.2 lda (ZPPtr1),y search backward for a /
cmp #'/'
beq .3
2019-10-12 14:20:09 +00:00
cmp #'?' Test if some wildcard chars....
beq .21
2019-10-12 14:20:09 +00:00
cmp #'*'
bne .22
2019-10-12 14:20:09 +00:00
.21 inx inc wildcard count
.22 dey
bne .2
2019-10-12 14:20:09 +00:00
.3 txa
beq .91 no wc, file not found....
2019-10-12 14:20:09 +00:00
.4 jsr GetPtr1Len Search end of string.....
lda #'/'
2019-10-12 14:20:09 +00:00
.42 dey
cmp (ZPPtr1),y Search backward /
bne .42
2019-10-12 14:20:09 +00:00
tya
sec +1 to skip '/'
adc ZPPtr1
sta ZPPtr2
tay
lda ZPPtr1+1
adc #0
sta ZPPtr2+1
2019-10-12 14:20:09 +00:00
2018-12-20 16:23:43 +00:00
>SYSCALL strdup
bcs .9
txa
>STA.G hFilter
lda #0
sta (ZPPtr2)
2019-10-12 14:20:09 +00:00
.5 >LDYAI 256
2018-07-18 15:30:42 +00:00
>SYSCALL GetMem Get a 256 buffer to store BasePath
bcs .9
>STYA ZPPtr2
txa
>STA.G hSrcBasePath
2019-10-12 14:20:09 +00:00
jsr StrcpyPtr1ptr2
2018-12-20 07:33:10 +00:00
dey
lda #'/'
cmp (ZPPtr2),y
beq .7
iny
sta (ZPPtr2),y
iny
lda #0
sta (ZPPtr2),y
2019-10-12 14:20:09 +00:00
2018-12-20 07:33:10 +00:00
.7 >LDYA ZPPtr2
2018-07-18 15:30:42 +00:00
>SYSCALL OpenDir
bcs .9
2019-10-12 14:20:09 +00:00
ldy #hDIRs
sta (pData),y set hDIRs[0] = Src Hdir
ldy #index
lda #1
sta (pData),y index=hDIRs[0]
jsr .9 Cleanup
clc
rts
2019-10-12 14:20:09 +00:00
.91 lda #MLI.E.FNOTFND
.9 pha
>LDA.G hFullPath
2018-07-18 15:30:42 +00:00
>SYSCALL FreeMem
pla
sec
InitSrcDirYA.RTS
rts
*--------------------------------------
.DO X.COPY.TO.DEST=1
2018-07-18 15:30:42 +00:00
InitDstDirYA >SYSCALL RealPath
bcs InitSrcDirYA.RTS
>STYA ZPPtr1
txa
>STA.G hFullPath
>PUSHEA.G STAT
2018-07-20 11:51:08 +00:00
>LDYA ZPPtr1
>SYSCALL Stat
bcs .1 File/DIR does not exists, go extract DstFileName
2019-10-12 14:20:09 +00:00
>LDA.G STAT+S.STAT.P.TYPE
2018-12-20 07:33:10 +00:00
cmp #S.FI.T.DIR
beq .5 Dst is a directory...no destfilename
2019-10-12 14:20:09 +00:00
.1 jsr GetPtr1Len Search end of string.....
lda #'/'
2019-10-12 14:20:09 +00:00
.2 dey
cmp (ZPPtr1),y Search backward /
bne .2
2019-10-12 14:20:09 +00:00
tya
sec +1 to skip '/'
adc ZPPtr1
sta ZPPtr2
tay
lda ZPPtr1+1
adc #0
sta ZPPtr2+1
2018-12-20 16:23:43 +00:00
>SYSCALL strdup
bcs .9
txa
>STA.G hDstFileName
lda #0
2019-10-03 06:25:27 +00:00
sta (ZPPtr2)
2019-10-12 14:20:09 +00:00
.5 >LDYAI 256
2018-07-18 15:30:42 +00:00
>SYSCALL GetMem Get a 256 buffer to store DstBasePath
bcs .9
2019-10-12 14:20:09 +00:00
>STYA ZPPtr2
txa
>STA.G hDstBasePath
2019-10-12 14:20:09 +00:00
jsr StrcpyPtr1ptr2
dey
lda #'/'
cmp (ZPPtr2),y
beq .7
2019-10-12 14:20:09 +00:00
iny
sta (ZPPtr2),y
iny
lda #0
sta (ZPPtr2),y
.7 jsr .9 Cleanup
clc
.99 rts
.9 pha
>LDA.G hFullPath
2018-07-18 15:30:42 +00:00
>SYSCALL FreeMem
pla
sec
rts
.FIN
*--------------------------------------
GetNextEntry jsr GetEntry
bcs .9
2018-12-19 16:45:09 +00:00
jsr GetFilenameLen Save actual file len for setting up
pha new offset later
lda ZPFileStat
clc
adc #S.STAT
sta ZPFileName
lda ZPFileStat+1
adc /S.STAT
sta ZPFileName+1 Make nDIRENTs[i] point to next DIRENT
2018-12-20 07:33:10 +00:00
jsr GetFilenameLen are we at end of this buffer ?
beq .1 yes, go read next one ...
2018-12-19 16:45:09 +00:00
jsr SetFileStatPtr
2018-11-21 13:08:11 +00:00
jsr GetoDIRENT
pla Get back previous file len
sec
adc (pData),y
sta (pData),y
iny
lda #0
adc (pData),y
sta (pData),y
dey
lda #S.STAT
clc
adc (pData),y
sta (pData),y
iny
lda /S.STAT
adc (pData),y
sta (pData),y
clc
rts
.1 pla
jsr GetEntry.ReadDir
bcs .9
2018-12-19 16:45:09 +00:00
jsr GetFilenameLen
beq GetNextEntry.99
jsr SetFileStatPtr
clc
.9 rts
2018-12-19 16:45:09 +00:00
GetNextEntry.99 sec
rts
*--------------------------------------
2018-11-21 13:08:11 +00:00
GetEntry jsr GethDIRENT
bne .1 we have a buffer to scan
jsr GetEntry.ReadDir First run, get first block
bcs .9 ZPFileName = start of buffer
lda (ZPFileName) Empty !!!
bne .8
2018-12-19 16:45:09 +00:00
sec
rts
2018-07-18 15:30:42 +00:00
.1 >SYSCALL GetMemPtr
>STYA ZPFileName
2018-11-21 13:08:11 +00:00
jsr GetoDIRENT
lda ZPFileName
clc
adc (pData),y
sta ZPFileName
iny
lda ZPFileName+1
adc (pData),y
sta ZPFileName+1 ZPFileName=ZPFileName+oDIRENT
2018-12-19 16:45:09 +00:00
.8 jsr GetFilenameLen
jsr SetFileStatPtr
clc
.9 rts
*--------------------------------------
GetEntry.ReadDir
2018-11-21 13:08:11 +00:00
jsr GethDIRENT
beq .1
2018-11-21 13:08:11 +00:00
pha
lda #0
sta (pData),y reset hDIRENT
pla
2018-07-18 15:30:42 +00:00
>SYSCALL FreeMem discard previous hDIRENT
2018-11-21 13:08:11 +00:00
.1 jsr GethDIR
2018-07-20 11:51:08 +00:00
2018-07-18 15:30:42 +00:00
>SYSCALL ReadDir
bcs .9
>STYA ZPFileName
ldy #index
lda (pData),y
clc
adc #hDIRENTs-1
tay
txa get hDIRENT in A
sta (pData),y
2018-11-21 13:08:11 +00:00
jsr GetoDIRENT
lda #0 and reset offset for this buffer
sta (pData),y
iny
sta (pData),y
clc
.9 rts
*--------------------------------------
EnterSubDirYA >STYA ZPPtr2 save SUBDIR for StrCat
2019-04-29 15:47:17 +00:00
>LDA.G index
cmp #X.MAX.RECURSE
beq .9
ldy #hSrcBasePath
2018-11-21 13:08:11 +00:00
jsr EnterSubDirY
>LDYA ZPPtr1
2018-07-18 15:30:42 +00:00
>SYSCALL OpenDir
bcs .9
pha
2018-11-21 13:08:11 +00:00
>INC.G index
tax
* clc from BCS
adc #hDIRs-1
tay
pla
sta (pData),y
txa make sure hDIRENTs[i] is closed
adc #hDIRENTs-1
tay
lda #0
sta (pData),y
.DO X.COPY.TO.DEST=1
ldy #hDstBasePath
2018-11-21 13:08:11 +00:00
jsr EnterSubDirY
.FIN
clc
.9 rts
2018-11-21 13:08:11 +00:00
EnterSubDirY lda (pData),y
2018-07-18 15:30:42 +00:00
>SYSCALL GetMemPtr
>STYA ZPPtr1 save full path
2018-11-21 13:08:11 +00:00
jsr .1 Make sure ending with /
>PUSHW ZPPtr2
2018-07-16 05:52:52 +00:00
>LDYA ZPPtr1
>SYSCALL StrCat
2019-10-12 14:20:09 +00:00
.1 jsr GetPtr1Len
2018-11-21 13:08:11 +00:00
dey
lda #'/'
2018-11-21 13:08:11 +00:00
cmp (ZPPtr1),y
beq .8
iny
sta (ZPPtr1),y
iny
lda #0
sta (ZPPtr1),y
2018-11-21 13:08:11 +00:00
.8 rts
*--------------------------------------
2018-11-21 13:08:11 +00:00
LeaveSubDir >LDA.G index
beq .9
2018-11-21 13:08:11 +00:00
jsr GethDIRENT.A
beq .1
pha
lda #0
sta (pData),y
pla
2018-07-18 15:30:42 +00:00
>SYSCALL FreeMem
2018-12-20 07:33:10 +00:00
2018-11-21 13:08:11 +00:00
.1 jsr GethDIR
pha
lda #0
sta (pData),y
pla
2018-07-18 15:30:42 +00:00
>SYSCALL CloseDir
2018-11-21 13:08:11 +00:00
>DEC.G index
bne .8
ldy #hSrcBasePath
lda (pData),y
2018-07-18 15:30:42 +00:00
>SYSCALL FreeMem
2018-12-20 07:33:10 +00:00
.DO X.COPY.TO.DEST=1
ldy #hDstBasePath
lda (pData),y
2018-07-18 15:30:42 +00:00
>SYSCALL FreeMem
.FIN
2016-10-30 18:19:43 +00:00
.9 sec
rts
.8 clc
rts
2016-10-30 18:19:43 +00:00
*--------------------------------------
BasePath.. .DO X.COPY.TO.DEST=1
2017-10-04 15:12:03 +00:00
ldy #hDstBasePath
jsr BasePath..1
.FIN
ldy #hSrcBasePath
2019-10-12 14:20:09 +00:00
BasePath..1 lda (pData),y
2018-07-18 15:30:42 +00:00
>SYSCALL GetMemPtr
>STYA ZPPtr1 save full path
2019-10-12 14:20:09 +00:00
jsr GetPtr1Len get len
2017-10-04 15:12:03 +00:00
dey discard ending /
2019-10-12 14:20:09 +00:00
.2 dey
lda (ZPPtr1),y
cmp #'/'
bne .2
2019-10-12 14:20:09 +00:00
iny
lda #0
sta (ZPPtr1),y cut DIR2/ from /dir1/DIR2/
rts
*--------------------------------------
2019-10-12 14:20:09 +00:00
GetPtr1Len ldy #$ff
.1 iny
lda (ZPPtr1),y get len
bne .1
rts
*--------------------------------------
StrcpyPtr1ptr2 ldy #$ff
.1 iny
lda (ZPPtr1),y
sta (ZPPtr2),y
bne .1
rts
*--------------------------------------
2018-12-19 16:45:09 +00:00
GetFilenameLen ldy #$ff
.1 iny
lda (ZPFileName),y
bne .1
tya
rts
*--------------------------------------
SetFileStatPtr sec
adc ZPFileName
sta ZPFileStat
lda ZPFileName+1
adc #0
sta ZPFileStat+1
rts
*--------------------------------------
2018-11-21 13:08:11 +00:00
GethDIR ldy #index
lda (pData),y
clc
adc #hDIRs-1
tay
lda (pData),y
rts
2019-10-03 06:25:27 +00:00
*--------------------------------------
2018-11-21 13:08:11 +00:00
GethDIRENT ldy #index
lda (pData),y
GethDIRENT.A clc
adc #hDIRENTs-1
tay
lda (pData),y
rts
*--------------------------------------
GetoDIRENT ldy #index
lda (pData),y
asl
clc
adc #oDIRENTs-1
tay
rts
*--------------------------------------
MAN
2018-11-20 15:54:49 +00:00
SAVE USR/SRC/BIN/X.FILEENUM.S
2019-04-29 15:47:17 +00:00
LOAD USR/SRC/BIN/CP.S
2018-07-20 11:51:08 +00:00
ASM