mirror of
https://github.com/A2osX/A2osX.git
synced 2025-02-21 06:29:08 +00:00
752 lines
13 KiB
Plaintext
752 lines
13 KiB
Plaintext
NEW
|
||
AUTO 3,1
|
||
.LIST OFF
|
||
*--------------------------------------
|
||
X.MAX.RECURSE .EQ 8
|
||
*--------------------------------------
|
||
* Uses:
|
||
* (ZP)
|
||
* ZPPtr1 .BS 2
|
||
* ZPPtr2 .BS 2
|
||
* ZPFileName .BS 2
|
||
* ZPFileStat .BS 2
|
||
* (pData)
|
||
* Index .BS 1
|
||
* pDIRs .BS X.MAX.RECURSE*2
|
||
* pDIRENTs .BS X.MAX.RECURSE*2
|
||
* oDIRENTs .BS X.MAX.RECURSE*2
|
||
* STATBUF .BS S.STAT
|
||
* pSrcBasePath .BS 2
|
||
* pDstBasePath .BS 2 (optional)
|
||
* pInclude .BS 2
|
||
* pIgnore .BS 2
|
||
*--------------------------------------
|
||
X.Quit jsr X.LeaveSubDir
|
||
bcc X.Quit
|
||
|
||
.DO X.COPY.TO.DEST=1
|
||
|
||
ldy #pDstFileName+1
|
||
jsr .7
|
||
|
||
ldy #pDstBasePath+1
|
||
jsr .7
|
||
|
||
.FIN
|
||
|
||
ldy #pSrcBasePath+1
|
||
jsr .7
|
||
|
||
ldy #pInclude+1
|
||
jsr .7
|
||
|
||
ldy #pIgnore+1
|
||
|
||
.7 lda (pData),y
|
||
beq .9
|
||
|
||
pha
|
||
dey
|
||
lda (pData),y
|
||
tay
|
||
pla
|
||
|
||
>LIBC Free
|
||
|
||
.9 clc
|
||
rts
|
||
*--------------------------------------
|
||
* Compare a ZPFileName against pInclude (e.g. '*test?.*')
|
||
* CC : match
|
||
* CS : no match
|
||
*--------------------------------------
|
||
X.IncludeMatch >LDA.G index
|
||
dec
|
||
bne X.FilterMatch.CLCRTS in a subdir, match everything
|
||
|
||
clc
|
||
.HS B0 BCS
|
||
|
||
X.IgnoreMatch sec
|
||
ldy #pInclude+1
|
||
bcc .11
|
||
|
||
iny
|
||
iny pIgnore
|
||
|
||
.11 lda (pData),y
|
||
beq X.FilterMatch.RTS No filter....exit with passed carry
|
||
|
||
sta ZPPtr2+1
|
||
dey
|
||
lda (pData),y
|
||
sta ZPPtr2
|
||
|
||
ldy #S.STAT.FSID
|
||
lda (ZPFileStat),y if 0, Regular ProDOS....
|
||
pha save FSID for comparing later
|
||
bne .10
|
||
|
||
>LDYA ZPPtr2 ... so CI compare
|
||
>LIBC StrUpr
|
||
|
||
.10 plx get back FSID
|
||
|
||
lda (ZPPtr2) Get first pattern byte
|
||
beq .8 Match always if empty
|
||
|
||
ldy #0
|
||
bra .2
|
||
|
||
.1 jsr X.FilterMatch.NextPtr2 get next pattern char
|
||
beq .41 end of pattern...
|
||
|
||
.2 cmp #'*'
|
||
beq .5
|
||
|
||
.3 lda (ZPFileName),y we must match ? or regular char, check if at end of string
|
||
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
|
||
|
||
jsr X.FilterMatch.CmpPtr2CharPtr1Y Regular Char, compare with string at Y
|
||
bne .9 no match, exit
|
||
|
||
.4 iny advance to next char to compare
|
||
bra .1 continue if remaining char in pattern
|
||
|
||
.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
|
||
|
||
.5 jsr X.FilterMatch.NextPtr2 we have '*', last char of pattern ?
|
||
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
|
||
jsr X.FilterMatch.CmpPtr2CharPtr1Y compare with char in string
|
||
bne .7 not equal to next non wildcard in pattern
|
||
|
||
iny
|
||
bra .1 go check remaining char in pattern...
|
||
|
||
.8
|
||
X.FilterMatch.CLCRTS
|
||
clc
|
||
X.FilterMatch.RTS
|
||
rts
|
||
*--------------------------------------
|
||
X.FilterMatch.CmpPtr2CharPtr1Y
|
||
lda (ZPFileName),y
|
||
phx
|
||
plx
|
||
bne .1 Foreign FS or ProDOS.FX : CS compare
|
||
|
||
jsr X.ToUpper
|
||
|
||
.1 cmp (ZPPtr2)
|
||
rts
|
||
*--------------------------------------
|
||
X.FilterMatch.NextPtr2
|
||
inc ZPPtr2 Make PTR2 advance to next char
|
||
bne .1
|
||
|
||
inc ZPPtr2+1
|
||
|
||
.1 lda (ZPPtr2)
|
||
rts
|
||
*--------------------------------------
|
||
X.InitSrcDirYA >STYA ZPPtr1
|
||
|
||
X.InitSrcDirPtr1
|
||
jsr X.InitGetBuf Get a 256 buffer to store BasePath
|
||
bcs .99
|
||
|
||
>STYA.G pSrcBasePath
|
||
|
||
ldy #1
|
||
lda (ZPPtr2),y ZPPtr2 = Expand(ZPPtr1)
|
||
beq .8 we have '/'
|
||
|
||
jsr X.Init.Stat
|
||
bcs .1 File/DIR does not exists, go extract pattern
|
||
|
||
.DO X.ENTER.SUBDIR=1
|
||
|
||
>LDA.G STATBUF+S.STAT.MODE+1
|
||
and #$F0
|
||
cmp /S.STAT.MODE.DIR
|
||
bne .7 Not a dir....
|
||
|
||
jsr X.GetPtr2Len
|
||
|
||
dey
|
||
lda #'/'
|
||
cmp (ZPPtr2),y
|
||
beq .8
|
||
|
||
iny
|
||
sta (ZPPtr2),y
|
||
iny
|
||
lda #0
|
||
sta (ZPPtr2),y
|
||
|
||
bra .8 TYPE=DIR, do not extract pattern
|
||
|
||
.ELSE
|
||
|
||
bra .7
|
||
|
||
.FIN
|
||
|
||
.1 cmp #MLI.E.INVPATH
|
||
bne .98
|
||
|
||
jsr X.GetPtr2Len TYPE is not DIR, check if wc
|
||
|
||
dey
|
||
|
||
ldx #0 Init Wildcard count
|
||
|
||
.2 lda (ZPPtr2),y search backward for a /
|
||
cmp #'/'
|
||
beq .6
|
||
|
||
cmp #'?' Test if some wildcard chars....
|
||
beq .3
|
||
|
||
cmp #'*'
|
||
bne .4
|
||
|
||
.3 inx inc wildcard count
|
||
|
||
.4 dey
|
||
bne .2
|
||
|
||
.6 txa
|
||
beq .97 no wc, file not found....
|
||
|
||
.7 jsr X.InitSplitBuf
|
||
bcs .99
|
||
|
||
>STYA.G pInclude
|
||
|
||
.8 >LDYA ZPPtr2
|
||
>LIBC OpenDir
|
||
bcs .99
|
||
|
||
phy
|
||
|
||
ldy #pDIRs+1
|
||
sta (pData),y set hDIRs[0] = Src Hdir
|
||
dey
|
||
pla
|
||
sta (pData),y
|
||
|
||
lda #1
|
||
>STA.G index index=hDIRs[0]
|
||
|
||
* clc
|
||
|
||
rts
|
||
|
||
.97 lda #MLI.E.INVPATH
|
||
.98 sec
|
||
.99 rts
|
||
*--------------------------------------
|
||
.DO X.RESET.SRC.DIR=1
|
||
X.ResetSrcDir jsr X.GetpDIR
|
||
|
||
>LIBC CloseDir
|
||
|
||
>LDYA.G pSrcBasePath
|
||
>LIBC OpenDir
|
||
bcs .9
|
||
|
||
pha
|
||
phy
|
||
|
||
>LDA.G index
|
||
asl
|
||
* clc
|
||
adc #pDIRs-2
|
||
tay
|
||
|
||
pla
|
||
sta (pData),y
|
||
iny
|
||
pla
|
||
sta (pData),y
|
||
|
||
* clc
|
||
.9 rts
|
||
.FIN
|
||
*--------------------------------------
|
||
.DO X.COPY.TO.DEST=1
|
||
X.InitDstDirYA >STYA ZPPtr1
|
||
|
||
X.InitDstDirPtr1
|
||
jsr X.InitGetBuf Get a 256 buffer to store BasePath
|
||
bcs .99
|
||
|
||
>STYA.G pDstBasePath
|
||
|
||
jsr X.Init.Stat
|
||
bcs .1 File/DIR does not exists, go extract DstFileName
|
||
|
||
>LDA.G STATBUF+S.STAT.MODE+1
|
||
and #$F0
|
||
cmp /S.STAT.MODE.DIR
|
||
beq .8 Dst is a directory...no hDstFileName
|
||
|
||
.1 jsr X.InitSplitBuf
|
||
bcs .99
|
||
|
||
>STYA.G pDstFileName
|
||
|
||
.8 jmp X.NormalizePtr2
|
||
|
||
.99 rts
|
||
|
||
.FIN
|
||
*--------------------------------------
|
||
X.InitGetBuf >LDYAI 256
|
||
>LIBC Malloc Get a 256 buffer to store BasePath
|
||
bcs .99
|
||
|
||
>STYA ZPPtr2
|
||
|
||
>SS
|
||
>PUSHW ZPPtr1
|
||
>PUSHW ZPPtr2
|
||
>LIBC RealPath
|
||
>SR
|
||
bcs .98
|
||
|
||
>LDYA ZPPtr2
|
||
|
||
* clc
|
||
|
||
rts
|
||
|
||
.98 pha
|
||
>LDYA ZPPtr2
|
||
>LIBC Free
|
||
pla
|
||
|
||
sec
|
||
|
||
.99 rts
|
||
*--------------------------------------
|
||
X.Init.Stat >SS
|
||
>PUSHW ZPPtr2
|
||
>PUSHEA.G STATBUF
|
||
>LIBC Stat
|
||
>SR
|
||
rts
|
||
*--------------------------------------
|
||
X.InitSplitBuf jsr X.GetPtr2Len Search end of string.....
|
||
|
||
lda #'/'
|
||
|
||
.1 dey
|
||
cmp (ZPPtr2),y Search backward /
|
||
bne .1
|
||
|
||
tya
|
||
sec +1 to skip '/'
|
||
adc ZPPtr2
|
||
sta ZPPtr1
|
||
|
||
lda ZPPtr2+1
|
||
adc #0
|
||
sta ZPPtr1+1
|
||
|
||
lda (ZPPtr1)
|
||
beq .8 path is /dir/
|
||
|
||
>LDYA ZPPtr1
|
||
>LIBC StrDup
|
||
bcs .99
|
||
|
||
pha
|
||
|
||
lda #0
|
||
sta (ZPPtr1)
|
||
|
||
pla Y,A = pStr
|
||
|
||
.8 clc
|
||
|
||
.99 rts
|
||
*--------------------------------------
|
||
X.GetNextEntry jsr X.GetEntry
|
||
bcs .9
|
||
|
||
jsr X.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
|
||
|
||
jsr X.GetFilenameLen are we at end of this buffer ?
|
||
beq .1 yes, go read next one ...
|
||
|
||
jsr X.SetFileStatPtr
|
||
|
||
>LDA.G index
|
||
asl
|
||
* clc
|
||
adc #oDIRENTs-2
|
||
tay
|
||
|
||
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 X.GetEntry.ReadDir
|
||
bcs .9
|
||
|
||
jsr X.GetFilenameLen
|
||
sec
|
||
beq .9
|
||
|
||
jsr X.SetFileStatPtr
|
||
|
||
clc
|
||
.9 rts
|
||
*--------------------------------------
|
||
X.GetEntry jsr X.GetpDIRENT
|
||
cmp #0
|
||
bne .1 we have a buffer to scan
|
||
|
||
jsr X.GetEntry.ReadDir First run, get first block
|
||
bcs .9 ZPFileName = start of buffer
|
||
|
||
lda (ZPFileName) Empty !!!
|
||
bne .8
|
||
|
||
sec
|
||
rts
|
||
*--------------------------------------
|
||
.1 >STYA ZPFileName
|
||
|
||
>LDA.G index
|
||
asl
|
||
* clc
|
||
adc #oDIRENTs-2
|
||
tay
|
||
|
||
lda ZPFileName
|
||
clc
|
||
adc (pData),y
|
||
sta ZPFileName
|
||
|
||
iny
|
||
|
||
lda ZPFileName+1
|
||
adc (pData),y
|
||
sta ZPFileName+1 ZPFileName=ZPFileName+oDIRENT
|
||
|
||
.8 jsr X.GetFilenameLen
|
||
|
||
jsr X.SetFileStatPtr
|
||
|
||
clc
|
||
.9 rts
|
||
*--------------------------------------
|
||
X.GetEntry.ReadDir
|
||
jsr X.GetpDIRENT
|
||
cmp #0
|
||
beq .1
|
||
|
||
>LIBC Free discard previous pDIRENT
|
||
|
||
jsr X.ResetpDIRENT
|
||
|
||
.1 jsr X.GetpDIR
|
||
|
||
>LIBC ReadDir
|
||
bcs .9
|
||
|
||
>STYA ZPFileName
|
||
|
||
>LDA.G index
|
||
asl
|
||
* clc
|
||
adc #pDIRENTs-2
|
||
tay
|
||
|
||
lda ZPFileName
|
||
sta (pData),y
|
||
iny
|
||
lda ZPFileName+1
|
||
sta (pData),y
|
||
|
||
>LDA.G index
|
||
asl
|
||
* clc
|
||
adc #oDIRENTs-2
|
||
tay
|
||
|
||
lda #0 and reset offset for this buffer
|
||
sta (pData),y
|
||
iny
|
||
sta (pData),y
|
||
clc
|
||
.9 rts
|
||
*--------------------------------------
|
||
X.EnterSubDirYA >STYA ZPPtr1 save SUBDIR for StrCat
|
||
|
||
>LDA.G index
|
||
cmp #X.MAX.RECURSE
|
||
beq .9
|
||
|
||
ldy #pSrcBasePath
|
||
jsr X.EnterSubDirY
|
||
>LDYA ZPPtr2
|
||
>LIBC OpenDir
|
||
bcs .9
|
||
|
||
pha
|
||
phy
|
||
>INC.G index
|
||
asl
|
||
* clc
|
||
adc #pDIRs-2
|
||
tay
|
||
pla
|
||
sta (pData),y
|
||
iny
|
||
pla
|
||
sta (pData),y
|
||
|
||
jsr X.ResetpDIRENT make sure pDIRENTs[i] is closed
|
||
|
||
.DO X.COPY.TO.DEST=1
|
||
ldy #pDstBasePath
|
||
jsr X.EnterSubDirY
|
||
.FIN
|
||
|
||
clc
|
||
.9 rts
|
||
*--------------------------------------
|
||
X.EnterSubDirY lda (pData),y
|
||
sta ZPPtr2
|
||
iny
|
||
lda (pData),y
|
||
sta ZPPtr2+1 save full path
|
||
|
||
>SS
|
||
>PUSHW ZPPtr2
|
||
>PUSHW ZPPtr1
|
||
>LIBC StrCat
|
||
>SR
|
||
|
||
X.NormalizePtr2 jsr X.GetPtr2Len
|
||
|
||
dey
|
||
lda #'/'
|
||
cmp (ZPPtr2),y
|
||
beq .8
|
||
|
||
iny
|
||
sta (ZPPtr2),y
|
||
|
||
iny
|
||
lda #0
|
||
sta (ZPPtr2),y
|
||
|
||
.8 clc
|
||
rts
|
||
*--------------------------------------
|
||
X.LeaveSubDir >LDA.G index
|
||
beq .3
|
||
|
||
jsr X.GetpDIRENT.A
|
||
cmp #0
|
||
beq .1
|
||
|
||
>LIBC Free
|
||
|
||
jsr X.ResetpDIRENT
|
||
|
||
.1 jsr X.GetpDIR
|
||
cmp #0
|
||
beq .2
|
||
|
||
>LIBC CloseDir
|
||
|
||
.2 >DEC.G index
|
||
bne .8
|
||
|
||
.3 >LDYA.G pSrcBasePath
|
||
cmp #0
|
||
beq .4
|
||
|
||
>LIBC Free
|
||
|
||
>STZ.G pSrcBasePath+1
|
||
|
||
.4 .DO X.COPY.TO.DEST=1
|
||
>LDYA.G pDstBasePath
|
||
cmp #0
|
||
beq .5
|
||
|
||
>LIBC Free
|
||
|
||
>STZ.G pDstBasePath+1
|
||
|
||
.FIN
|
||
|
||
.5 sec
|
||
rts
|
||
|
||
.8 clc
|
||
rts
|
||
*--------------------------------------
|
||
X.BasePath.. .DO X.COPY.TO.DEST=1
|
||
|
||
ldy #pDstBasePath
|
||
jsr X.BasePath..1
|
||
.FIN
|
||
ldy #pSrcBasePath
|
||
|
||
X.BasePath..1 lda (pData),y
|
||
sta ZPPtr2
|
||
iny
|
||
lda (pData),y
|
||
sta ZPPtr2+1 save full path
|
||
|
||
jsr X.GetPtr2Len get len
|
||
|
||
dey discard ending /
|
||
|
||
.2 dey
|
||
lda (ZPPtr2),y
|
||
cmp #'/'
|
||
bne .2
|
||
|
||
iny
|
||
lda #0
|
||
sta (ZPPtr2),y cut DIR2/ from /dir1/DIR2/
|
||
|
||
rts
|
||
*--------------------------------------
|
||
X.ToUpper cmp #'a'
|
||
bcc .8
|
||
|
||
cmp #'z'+1
|
||
bcs .8
|
||
|
||
eor #$20
|
||
|
||
.8 rts
|
||
*--------------------------------------
|
||
X.GetPtr2Len ldy #$ff
|
||
|
||
.1 iny
|
||
|
||
lda (ZPPtr2),y get len
|
||
bne .1
|
||
|
||
rts
|
||
*--------------------------------------
|
||
X.GetFilenameLen
|
||
ldy #$ff
|
||
|
||
.1 iny
|
||
lda (ZPFileName),y
|
||
bne .1
|
||
|
||
tya
|
||
rts
|
||
*--------------------------------------
|
||
X.SetFileStatPtr
|
||
sec
|
||
adc ZPFileName
|
||
sta ZPFileStat
|
||
lda ZPFileName+1
|
||
adc #0
|
||
sta ZPFileStat+1
|
||
rts
|
||
*--------------------------------------
|
||
X.GetpDIR >LDA.G index
|
||
|
||
asl
|
||
* clc
|
||
adc #pDIRs-2
|
||
tay
|
||
lda (pData),y
|
||
pha
|
||
iny
|
||
lda (pData),y
|
||
ply
|
||
rts
|
||
*--------------------------------------
|
||
X.GetpDIRENT >LDA.G index
|
||
|
||
X.GetpDIRENT.A asl
|
||
* clc
|
||
adc #pDIRENTs-2
|
||
tay
|
||
lda (pData),y
|
||
pha
|
||
iny
|
||
lda (pData),y
|
||
ply
|
||
rts
|
||
*--------------------------------------
|
||
X.ResetpDIRENT >LDA.G index
|
||
asl
|
||
* clc
|
||
adc #pDIRENTs-2
|
||
tay
|
||
lda #0
|
||
sta (pData),y
|
||
iny
|
||
sta (pData),y
|
||
rts
|
||
*--------------------------------------
|
||
MAN
|
||
SAVE usr/src/shared/x.fileenum.s
|
||
LOAD usr/src/bin/cp.s
|
||
ASM
|