FILEENUM : Fixed another memory leak in leaveSubDir

This commit is contained in:
Rémy GIBERT 2016-11-01 22:37:12 +01:00
parent 5f87674616
commit 3b311a9645
6 changed files with 403 additions and 562 deletions

View File

@ -7,571 +7,44 @@ AUTO 6
.OP 65C02
.OR $2000
.TF /A2OSX.BOOT/BIN/CP
*--------------------------------------
* -R recurse
* -Y no confirm
* -C continue on error
*--------------------------------------
.INB /A2OSX.DEV/INC/MACROS.I
.INB /A2OSX.DEV/INC/A2OSX.I
*--------------------------------------
MAX.RECURSE .EQ 8
COPY.BUF.SIZE .EQ 4096
X.DELETE.SOURCE .EQ 0
*--------------------------------------
ZPPtr1 .EQ ZPBIN
ZPPtr2 .EQ ZPBIN+2
ZPPtr3 .EQ ZPBIN+4
.INB BIN/X.CPMV.S
*--------------------------------------
* File Header (16 Bytes)
*--------------------------------------
CS.START cld
jmp (.1,x)
.DA #$61 6502,Level 1 (65c02)
.DA #1 BIN Layout Version 1
.DA 0
.DA CS.END-CS.START Code Length To Relocate
.DA DS.END-DS.START Data Segment to Allocate
.DA 0
.DA 0
*--------------------------------------
* Relocation Table
*--------------------------------------
.1 .DA CS.INIT
.DA CS.RUN
.DA CS.DOEVENT
.DA CS.QUIT
L.MSG.USAGE .DA MSG.USAGE
L.MSG.CP .DA MSG.CP
L.MSG.OK .DA MSG.OK
L.MSG.ERR .DA MSG.ERR
L.FullSrcPath .DA FullSrcPath
L.FullDstPath .DA FullDstPath
L.FINFO .DA FINFO
.DA 0
*--------------------------------------
CS.INIT ldy #hS.LISTDIR.IDX
tya
sta (pData),y
ldy #S.PS.hARGS
lda (pPs),y
bne .1
>LDYA L.MSG.USAGE
>SYSCALL PStrOutYA
lda #SYSMGR.ERRSYN
sec
.99 rts
.1 >PUSHA
>PUSHBI $20 Push SEP=' '
>PUSHBI 0
>SYSCALL PStrGetTkn
bcs .99
sta hSrcPath
stx hDstPath
>SYSCALL GetMemPtrA
>STYA ZPPtr1
stz FullSrcPath
ldy #1
lda (ZPPtr1),y
cmp #'/'
beq .2
jsr CS.INIT.SrcPfx
.2 lda (ZPPtr1)
tay
clc
adc FullSrcPath
sta FullSrcPath
tax
.3 lda (ZPPtr1),y
sta FullSrcPath,x
dex
dey
bne .3
>LDYA L.FullSrcPath
jsr NewDirListYA
bcs .99
lda hDstPath
bne .4
jsr CS.INIT.DstPfx
bra .7
.4 >SYSCALL GetMemPtrA
>STYA ZPPtr1
stz FullDstPath
ldy #1
lda (ZPPtr1),y
cmp #'/'
beq .5
jsr CS.INIT.DstPfx
.5 lda (ZPPtr1)
tay
clc
adc FullDstPath
sta FullDstPath
tax
.6 lda (ZPPtr1),y
sta FullDstPath,x
dex
dey
bne .6
.7 >LDYA L.FullDstPath
>SYSCALL MLIGetFileInfoYA
bcs .71 File not found....must be /path/file
>STYA ZPPtr3
ldy #S.FINFO.TYPE
lda (ZPPtr3),y
cmp #$f Directory ?
bne .71
ldy FullDstPath
lda FullDstPath,y
cmp #'/'
beq .71
inc FullDstPath
iny
lda #'/'
sta FullDstPath,y
.71 lda FullDstPath
sta (pData)
tay
.8 lda FullDstPath,y
sta (pData),y
dey
bne .8
lda (pPs)
ora #S.PS.F.EVENT Now accept events
sta (pPs)
clc
rts
*--------------------------------------
CS.INIT.SrcPfx ldy #S.PS.hPREFIX
lda (pPs),y
>SYSCALL GetMemPtrA
>STYA ZPPtr2
lda (ZPPtr2)
sta FullSrcPath
tay
.1 lda (ZPPtr2),y
sta FullSrcPath,y
dey
bne .1
rts
*--------------------------------------
CS.INIT.DstPfx ldy #S.PS.hPREFIX
lda (pPs),y
>SYSCALL GetMemPtrA
>STYA ZPPtr2
lda (ZPPtr2)
sta FullDstPath
tay
.1 lda (ZPPtr2),y
sta FullDstPath,y
dey
bne .1
rts
*--------------------------------------
CS.RUN ldy #bCANCEL
lda (pData),y
beq .98
sec
rts
.98 ldy #bSTOP
lda (pData),y
beq .1
clc
.99 rts
.1 jsr GetDirList
bcs .99
>SYSCALL ListDirNextA
bcc .15
jsr CloseDirList
rts if not back to first level, CC, if CS, quit!
.15 pha
>SYSCALL GetMemPtrA
>STYA ZPPtr1
lda (ZPPtr1) get File type/len
and #$E0
cmp #$E0 Volume ($F) or Dir ($E) HEADER ?
bne .10
jmp .8
.10 lda (ZPPtr1)
and #$0F
sta (ZPPtr1) Adjust Filename len
jsr GetDirList
>SYSCALL GetMemPtrA
>STYA ZPPtr2
ldy #S.LISTDIR.hPATH get Src path
lda (ZPPtr2),y
>SYSCALL GetMemPtrA
>STYA ZPPtr2
lda (ZPPtr2)
tay
tax
.11 lda (ZPPtr2),y
sta FullSrcPath,y
dey
bne .11
ldy #0
.12 inx append filename
iny
lda (ZPPtr1),y
sta FullSrcPath,x
tya
cmp (ZPPtr1)
bne .12
stx FullSrcPath
lda (pData)
tay
tax
.2 lda (pData),y copy dest path
sta FullDstPath,y
dey
bne .2
ldy #0
.3 inx append filename
iny
lda (ZPPtr1),y
sta FullDstPath,x
tya
cmp (ZPPtr1)
bne .3
stx FullDstPath
>PUSHW L.FullDstPath
>PUSHW L.FullSrcPath
>LDYA L.MSG.CP
>SYSCALL PStrOutYA
jsr CS.RUN.COPY
bcs .5
>LDYA L.MSG.OK
bra .7
.5 >PUSHA
>LDYA L.MSG.ERR
.7 >SYSCALL PStrOutYA
.8 pla
>SYSCALL FreeMemA
clc
rts
*--------------------------------------
CS.RUN.COPY >LDYA L.FullSrcPath
>SYSCALL MLIGetFileInfoYA
bcs .9
>STYA ZPPtr1
ldy #S.FINFO-1 Save File info for applying to new file later
.1 lda (ZPPtr1),y
sta FINFO,y
dey
bpl .1
lda FINFO+S.FINFO.TYPE
cmp #$f dir ?
bne .2
jsr CS.RUN.COPY.DIR
bcc .3
rts
.2 jsr CS.RUN.COPY.FILE
bcc .3
rts
.3 >PUSHW L.FullDstPath
>PUSHW L.FINFO
>SYSCALL MLISetFileInfo
.9 rts
*--------------------------------------
CS.RUN.COPY.DIR >LDYA L.FullDstPath
>SYSCALL MLICreateDirYA
bcc .10
cmp #$47
bne CS.RUN.COPY.ERR CS
.10 ldx FullSrcPath
inx
lda #'/'
sta FullSrcPath,x
stx FullSrcPath
>LDYA L.FullSrcPath
jsr NewDirListYA
bcs .9
lda FullDstPath
inc
sta (Pdata)
tay
lda #'/'
sta (Pdata),y
dey
.1 lda FullDstPath,y
sta (Pdata),y
dey
bne .1
clc
.9 rts
CS.RUN.COPY.ERR sec
CS.RUN.COPY.RTS rts
*--------------------------------------
CS.RUN.COPY.FILE
>PUSHW FINFO+S.FINFO.AUXTYPE
>PUSHB FINFO+S.FINFO.TYPE
>PUSHBI $C3 R/W, we will setup attrs later
>PUSHW L.FullDstPath
>SYSCALL MLICreateFile
bcc .10
cmp #$47
bne CS.RUN.COPY.ERR
.10 >LDYA L.FullSrcPath
>SYSCALL MLIOpenYA
bcs CS.RUN.COPY.RTS
sta hSrcFile
stx hSrcBuf
>LDYA L.FullDstPath
>SYSCALL MLIOpenYA
bcs .19
sta hDstFile
stx hDstBuf
>PUSHWI COPY.BUF.SIZE
>PUSHBI 0
>SYSCALL GetMem
.19 bcs .98
>STYA ZPPtr2
stx hCopyBuf
.2 >PUSHWI COPY.BUF.SIZE
>PUSHW ZPPtr2
>PUSHB hSrcFile
>SYSCALL MLIRead
bcs .97
>STYA ZPPtr3 Bytes Read
>PUSHYA
>PUSHW ZPPtr2
>PUSHB hDstFile
>SYSCALL MLIWrite
lda ZPPtr3
cmp #COPY.BUF.SIZE
lda ZPPtr3+1
sbc /COPY.BUF.SIZE
bcs .2
jsr .97
clc
rts
.97 pha
lda hCopyBuf
>SYSCALL FreeMemA
pla
.98 pha
lda hSrcFile
>SYSCALL MLICloseA
lda hSrcBuf
>SYSCALL FreeMemA
pla
.99 pha
lda hDstFile
>SYSCALL MLICloseA
lda hDstBuf
>SYSCALL FreeMemA
pla
sec
rts
*--------------------------------------
CS.DOEVENT ldy #S.EVT.hDEV is Event from active IN device?
lda (pEvent),y
ldy #S.PS.hINDEV
cmp (pPs),y
bne .9
lda (pEvent)
and #S.EVT.F.KEY is it a KEY event?
beq .9
ldy #S.EVT.DATAHI is it an O or SAPPLE key ?
lda (pEvent),y
bne .9
ldy #S.EVT.DATALO
lda (pEvent),y
cmp #$03 Ctrl-C
bne .1
lda #$FF
ldy #bCANCEL
sta (pData),y
bra .8
.1 cmp #$13 Ctrl-S
bne .8
ldy #bSTOP
lda (pData),y
eor #$FF
sta (pData),y
.8 clc
rts
.9 sec
rts
*--------------------------------------
CS.QUIT jsr CloseDirList
bcc CS.QUIT
lda hSrcPath
beq .1
>SYSCALL FreeMemA
.1 lda hDstPath
beq .8
>SYSCALL FreeMemA
.8 clc
rts
*--------------------------------------
* PRIVATE
*--------------------------------------
NewDirListYA >SYSCALL ListDirInitYA
bcs .9
tax
ldy #hS.LISTDIR.IDX
lda (pData),y
inc
cmp #hS.LISTDIR.IDX+MAX.RECURSE+1
beq .9 CS
sta (pData),y
tay
txa
sta (pData),y
clc
.9 rts
*--------------------------------------
CloseDirList jsr GetDirList
bcs .9
>SYSCALL ListDirCloseA
ldy #hS.LISTDIR.IDX
lda (pData),y
tay
lda #0
sta (pData),y
tya
ldy #hS.LISTDIR.IDX
dec
sta (pData),y
cmp #hS.LISTDIR.IDX
beq .9 CS
lda (pData)
tay
.1 dey
lda (pData),y
cmp #'/'
bne .1
tya
sta (pData) cut DIR2/ from /dir1/DIR2/
clc
.9 rts
*--------------------------------------
GetDirList ldy #hS.LISTDIR.IDX
lda (pData),y
cmp #hS.LISTDIR.IDX
beq .9 CS
tay
lda (pData),y
clc
.9 rts
.INB BIN/X.FILEENUM.S
*--------------------------------------
CS.END
MSG.USAGE >PSTR "Usage : CP [-R -C] <Src file/Dir, *,? wildcards allowed> [Dest Dir]\n -R recurse subdirs\n -C resume on error\n"
MSG.CP >PSTR "cp: %S to %S "
MSG.OK >PSTR "[Ok]\n"
MSG.ERR >PSTR "[%h]\n"
hSrcPath .BS 1
hDstPath .BS 1
FullSrcPath .BS 64
FullDstPath .BS 64
FINFO .BS S.FINFO
hSrcFile .BS 1
hSrcBuf .BS 1
hDstFile .BS 1
hDstBuf .BS 1
hCopyBuf .BS 1
*--------------------------------------
OptionList >PSTR "CRY"
OptionVars .DA #bContinue,#bRecurse,#bNoConfirm
*--------------------------------------
MSG.USAGE >CSTR "Usage : CP [Src File/Dir, *,? wildcards allowed]\n -C : Continue on error\n -R : Recurse subdirectories\n -Y : Dont't prompt for override\n"
MSG.DIR >CSTR "CP Dir :%S to %S..."
MSG.FILE >CSTR "CP File:%S%S to %S..."
MSG.OK >CSTR "[OK]\n"
MSG.ERR >CSTR "[%h]\n"
*--------------------------------------
STAT .BS S.STAT
ArgCount .BS 1
*--------------------------------------
.DUMMY
.OR 0
DS.START
DstPath .BS 64 (pData)
hS.LISTDIR.IDX .BS 1
hS.LISTDIRS .BS MAX.RECURSE
bSTOP .BS 1
Index .BS 1
hDIRs .BS MAX.RECURSE
hDIRENTs .BS MAX.RECURSE
oDIRENTs .BS MAX.RECURSE*2
hBasePath .BS 1
hFilter .BS 1
bCANCEL .BS 1
bRECURSE .BS 1
bCONTINUEONERR .BS 1
bSTOP .BS 1
bContinue .BS 1
bRecurse .BS 1
bNoConfirm .BS 1
DS.END
.ED
*--------------------------------------

View File

@ -111,7 +111,7 @@ CS.INIT >SYSCALL GetArgC
*--------------------------------------
CS.RUN ldy #bCANCEL
lda (pData),y
bmi .99
bmi .92
ldy #bSTOP
lda (pData),y
@ -151,16 +151,16 @@ CS.RUN ldy #bCANCEL
bcs .99
.91 jsr LeaveSubDir
bcs .99
bcs .92
jsr BasePath..
.8 clc
rts
.99 lda #0
.92 lda #0
sec
rts
.99 rts
*--------------------------------------
CS.RUN.DEV ldy #bLong
lda (pData),y

View File

@ -0,0 +1,53 @@
PR#3
PREFIX /A2OSX.SRC
NEW
INC 1
AUTO 6
.LIST OFF
.OP 65C02
.OR $2000
.TF /A2OSX.BOOT/BIN/MV
*--------------------------------------
.INB /A2OSX.DEV/INC/MACROS.I
.INB /A2OSX.DEV/INC/A2OSX.I
*--------------------------------------
X.DELETE.SOURCE .EQ 1
*--------------------------------------
.INB BIN/X.CPMV.S
*--------------------------------------
.INB BIN/X.FILEENUM.S
*--------------------------------------
CS.END
*--------------------------------------
OptionList >PSTR "CRY"
OptionVars .DA #bContinue,#bRecurse,#bNoConfirm
*--------------------------------------
MSG.USAGE >CSTR "Usage : MV [Src File/Dir, *,? wildcards allowed]\n -C : Continue on error\n -R : Recurse subdirectories\n -Y : Dont't prompt for override\n"
MSG.DIR >CSTR "MV Dir :%S to %S..."
MSG.FILE >CSTR "MV File:%S%S to %S..."
MSG.OK >CSTR "[OK]\n"
MSG.ERR >CSTR "[%h]\n"
*--------------------------------------
STAT .BS S.STAT
ArgCount .BS 1
*--------------------------------------
.DUMMY
.OR 0
DS.START
Index .BS 1
hDIRs .BS MAX.RECURSE
hDIRENTs .BS MAX.RECURSE
oDIRENTs .BS MAX.RECURSE*2
hBasePath .BS 1
hFilter .BS 1
bCANCEL .BS 1
bSTOP .BS 1
bContinue .BS 1
bRecurse .BS 1
bNoConfirm .BS 1
DS.END
.ED
*--------------------------------------
MAN
SAVE BIN/MV.S
ASM

View File

@ -146,7 +146,6 @@ CS.RUN ldy #bCANCEL
lda (pData),y
bpl .8
ldy #hBasePath
lda (pData),y
>SYSCALL GetMemPtrA

313
BIN/X.CPMV.S.txt Normal file
View File

@ -0,0 +1,313 @@
PR#3
PREFIX /A2OSX.SRC
NEW
INC 1
AUTO 6
.LIST OFF
*--------------------------------------
MAX.RECURSE .EQ 8
*--------------------------------------
ZPPtr1 .EQ ZPBIN
ZPPtr2 .EQ ZPBIN+2
*--------------------------------------
* File Header (16 Bytes)
*--------------------------------------
CS.START cld
jmp (.1,x)
.DA #$61 6502,Level 1 (65c02)
.DA #1 BIN Layout Version 1
.DA 0
.DA CS.END-CS.START Code Length To Relocate
.DA DS.END-DS.START Data Segment to Allocate
.DA 0
.DA 0
*--------------------------------------
* Relocation Table
*--------------------------------------
.1 .DA CS.INIT
.DA CS.RUN
.DA CS.DOEVENT
.DA CS.QUIT
L.MSG.USAGE .DA MSG.USAGE
L.MSG.DIR .DA MSG.DIR
L.MSG.FILE .DA MSG.FILE
L.MSG.OK .DA MSG.OK
L.MSG.ERR .DA MSG.ERR
L.STAT .DA STAT
.DA 0
*--------------------------------------
CS.INIT >SYSCALL GetArgC
sta ArgCount
cmp #1
beq .99
.1 dec ArgCount
beq .5
lda ArgCount
>SYSCALL GetArgA
>STYA ZPPtr1
lda (ZPPtr1)
cmp #2
bne .4
ldy #1
lda (ZPPtr1),y
cmp #'-'
bne .4
iny
lda (ZPPtr1),y
ldx OptionList
.2 cmp OptionList,x
beq .3
dex
bne .2
lda #SYSMGR.ERRSYN
sec
rts
.3 ldy OptionVars-1,x
lda #$80
sta (pData),y
bra .1
.4 >LDYA ZPPtr1
jsr InitSrcDirYA
bcs .9
bra .1 scan for any other args
.5 ldy #index
lda (pData),y
beq .99
.8 lda (pPs)
ora #S.PS.F.EVENT Now accept events
sta (pPs)
clc
rts
.99 >LDYA L.MSG.USAGE
>SYSCALL PrintFYA
lda #SYSMGR.ERRSYN
sec
.9 rts
*--------------------------------------
CS.RUN ldy #bCANCEL
lda (pData),y
bmi .99
ldy #bSTOP
lda (pData),y
bmi .8
jsr GetNextEntry
bcs .9
ldy #hFilter
lda (pData),y
beq .4 No filter....
>SYSCALL GetMemPtrA
>PUSHYA
>PUSHW ZPPtr1
>SYSCALL PStrMatch
bcs .8 no match, skip....
.4 ldy #S.STAT.PRODOS.DRIVE
lda (ZPPtr2),y ProDOS Device ?
bne .5
ldy #S.STAT.PRODOS.TYPE
lda (ZPPtr2),y
cmp #$0F Directory ?
bne .6
jmp CS.RUN.DIR
.5 jmp CS.RUN.DEV
.6 jmp CS.RUN.FILE
.9 jsr LeaveSubDir
bcs .99
ldy #bRecurse
lda (pData),y
bpl .8
ldy #hBasePath
lda (pData),y
>SYSCALL GetMemPtrA
>PUSHYA
>LDYA L.MSG.DIR
>SYSCALL PrintFYA
jsr CS.RUN.DELETE.DIR
jsr CS.RUN.PRINT.RC
jsr BasePath..
.8 clc
rts
.99 lda #0
sec
rts
*--------------------------------------
CS.RUN.DEV >PUSHW ZPPtr1
>LDYA L.MSG.FILE
>SYSCALL PrintFYA
bcs .9
ldy #bRecurse
lda (pData),y
bpl .8
jsr CS.RUN.PRINT.FILE
bcs .9
lda #0
clc
jsr CS.RUN.PRINT.RC
>LDYA ZPPtr1
jmp EnterSubDirYA
.8 clc
.9 rts
*--------------------------------------
CS.RUN.DIR ldy #bRecurse
lda (pData),y
bpl .8
ldy #1
lda (ZPPtr1),y
cmp #'.'
beq .8
>LDYA ZPPtr1
jmp EnterSubDirYA
.8 clc
.9 rts
*--------------------------------------
CS.RUN.FILE jsr CS.RUN.PRINT.FILE
bcs .9
jsr CS.RUN.DELETE.FILE
jsr CS.RUN.PRINT.RC
.9 rts
*--------------------------------------
CS.RUN.PRINT.FILE
>PUSHW ZPPtr1
ldy #hBasePath
lda (pData),y
>SYSCALL GetMemPtrA
>PUSHYA
>LDYA L.MSG.FILE
>SYSCALL PrintFYA
rts
*--------------------------------------
CS.RUN.DELETE.DIR
jsr CS.RUN.GET.BASE.PATH
bra CS.RUN.DELETE
*--------------------------------------
CS.RUN.DELETE.FILE
jsr CS.RUN.GET.BASE.PATH
>PUSHW ZPPtr1
>PUSHWI UsrBuf256
>SYSCALL PStrCat
CS.RUN.DELETE >LDYAI UsrBuf256
>SYSCALL RemoveYA
rts
*--------------------------------------
CS.RUN.GET.BASE.PATH
ldy #hBasePath
lda (pData),y
>SYSCALL GetMemPtrA
>PUSHYA
>PUSHWI UsrBuf256
>SYSCALL PStrCpy
rts
*--------------------------------------
CS.RUN.PRINT.RC pha
php
bcs .1
>LDYA L.MSG.OK
bra .8
.1 >PUSHA
>LDYA L.MSG.ERR
.8 >SYSCALL PrintFYA
bcs .9
plp
ldy #bContinue
lda (pData),y
eor #$80
asl
pla
rts
.9 plx
plx
rts
*--------------------------------------
CS.DOEVENT ldy #S.EVT.hDEV is Event from active IN device?
lda (pEvent),y
ldy #S.PS.hINDEV
cmp (pPs),y
bne .9
lda (pEvent)
and #S.EVT.F.KEY is it a KEY event?
beq .9
ldy #S.EVT.DATAHI is it an O or SAPPLE key ?
lda (pEvent),y
bne .9
ldy #S.EVT.DATALO
lda (pEvent),y
cmp #$03 Ctrl-C
bne .1
lda #$FF
ldy #bCANCEL
sta (pData),y
bra .8
.1 cmp #$13 Ctrl-S
bne .8
ldy #bSTOP
lda (pData),y
eor #$FF
sta (pData),y
.8 clc
rts
.9 sec
rts
*--------------------------------------
CS.QUIT jsr LeaveSubDir
bcc CS.QUIT
ldy #hFilter
lda (pData),y
beq .3
>SYSCALL FreeMemA
.3 clc
rts
*--------------------------------------
MAN
SAVE BIN/X.CPMV.S

View File

@ -279,12 +279,16 @@ LeaveSubDir ldy #index
lda (pData),y
dec
sta (pData),y
beq .9
clc
rts
bne .8
ldy #hBasePath
lda (pData),y
>SYSCALL FreeMemA
.9 sec
rts
.8 clc
rts
*--------------------------------------
BasePath.. ldy #hBasePath
lda (pData),y
@ -308,4 +312,3 @@ BasePath.. ldy #hBasePath
*--------------------------------------
MAN
SAVE BIN/X.FILEENUM.S