A2osX/BIN/SH.S.CMD.txt
2024-01-05 17:33:57 +01:00

1386 lines
22 KiB
Plaintext
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

NEW
AUTO 3,1
*--------------------------------------
CMD.ALIAS lda (ZPArgVBufPtr)
beq .10
jmp CMD.ALIAS.ADD
.10 >LDA.G hAliases
beq .8
ldy #0
lda #1
.1 >STYA ZPTmpW Save KeyID
>PUSHB.G hAliases
>PUSHW ZPTmpW KeyID
>PUSHW ZPCLBuf
>SYSCALL SListGetByID
bcs .8
>STYA ZPPtr1 NextID
ldy #hAliases
jsr CORE.SListGetData
bcs .9
phx
>PUSHW L.MSG.ALIAS
>PUSHW ZPCLBuf
txa
>SYSCALL GetMemPtr
>PUSHYA
>PUSHBI 4
>SYSCALL PrintF
pla
>SYSCALL FreeMem
>LDYA ZPPtr1
bra .1
.8 clc
.9 rts
*--------------------------------------
CMD.ALIAS.ADD >LDYA ZPArgVBufPtr
>STYA ZPVarNamePtr
jsr CORE.ArgV.Next
beq .9
cmp #'='
bne .99
jsr CORE.ArgV.Next
beq .9
>LDA.G hAliases
bne .1
lda #0
>SYSCALL SListNew
bcs .99
>STA.G hAliases
.1 >PUSHA
>PUSHW ZPVarNamePtr
>PUSHWZ ScopeID
>SYSCALL SListNewKey
bcs .99
>STYA ZPTmpW Save KeyID
>PUSHB.G hAliases
>PUSHW ZPTmpW KeyID
>PUSHW ZPArgVBufPtr DataPtr
>PUSHWZ String Mode
>SYSCALL SListAddData
rts
.9 lda #E.CSYN
sec
.99 rts
*--------------------------------------
CMD.. lda (ZPArgVBufPtr)
beq CMD...9
>LDYA ZPArgVBufPtr
>SYSCALL LoadTxtFile
bcs CMD.SHIFTA.RTS
>LDYA ZPArgVBufPtr Exec . file
CMD..EXEC.YAX jsr CORE.Load.YAX Y,A = Args, X = Code
bcs CMD.SHIFTA.RTS
lda #$C0+C..
jmp STK.Push
CMD...9 jmp CMD.E.CSYN
*--------------------------------------
CMD.NOHUP lda (ZPArgVBufPtr)
beq CMD...9
lda #S.PS.F.NOHUP
tsb CORE.PSFlags
jmp CORE.ExecExtCmd
*--------------------------------------
CMD.SHIFT lda (ZPArgVBufPtr)
beq CMD.SHIFT.1
jsr EXP.GetInt8Exp
bcs CMD.SHIFTA.RTS
.HS B0 BCS
CMD.SHIFT.1 inc
CMD.SHIFTA >SYSCALL Shift
CMD.SHIFTA.RTS rts
*--------------------------------------
CMD.PUSHD >LDA.G PUSHD.STACK
cmp #PUSHD.STACK+PUSHD.STACK.MAX
beq CMD.POPD.CSYN
jsr GetCWD
>SYSCALL StrDup
bcs CMD.POPD.CSYN
>INC.G PUSHD.STACK
tay
txa
sta (pData),y
lda (ZPArgVBufPtr)
bne CMD.CD.0
* clc
.9 rts
*--------------------------------------
CMD.POPD >LDA.G PUSHD.STACK
cmp #PUSHD.STACK
beq CMD.POPD.CSYN
tay
lda (pData),y
jsr CMD.SetCWDA
>DEC.G PUSHD.STACK
clc
CMD.POPD.RTS rts
CMD.POPD.CSYN jmp CMD.E.CSYN
*--------------------------------------
CMD... lda (ZPArgVBufPtr)
bne CMD.POPD.CSYN
>LDYA L.CD..
bra CMD.CD.YA
*--------------------------------------
CMD.CD lda (ZPArgVBufPtr)
beq CMD.CD.HOME
CMD.CD.0 >LDYA ZPArgVBufPtr
bra CMD.CD.YA
CMD.CD.HOME >LDYA L.HOME
CMD.CD.YA >PUSHYA
>PUSHWZ Allocate
>SYSCALL RealPath
bcs CMD.POPD.RTS
>STYA ZPPtr1
stx ZPTmpW Save hMem
ldy #1
lda (ZPPtr1),y
bne .12
txa
jmp CMD.SetCWDA we have '/'
.12 >LDYA ZPPtr1
jsr IO.StatYA
bcs .19
cmp /S.STAT.MODE.DIR
beq .11
lda #MLI.E.INVPATH
.19 pha
lda ZPTmpW
>SYSCALL FreeMem
pla
sec
rts
.11 jsr GetPtr1LenY
dey
lda #'/'
cmp (ZPPtr1),y
beq .14
iny
sta (ZPPtr1),y
iny
lda #0
sta (ZPPtr1),y
.14 lda ZPTmpW
*--------------------------------------
CMD.SetCWDA pha
ldy #S.PS.hCWD
lda (pPS),y
>SYSCALL FreeMem
pla
ldy #S.PS.hCWD
sta (pPS),y
lda #0
* clc
rts
*--------------------------------------
CMD.SET lda (ZPArgVBufPtr)
bne CMD.SET.1
* No arg, print all ENV
>PUSHWZ
>PUSHWZ
>SYSCALL GetEnv
>STYA ZPPtr1
stx ZPTmpW
.1 lda (ZPPtr1)
beq .8 Ending 0 ?
>LDYA ZPPtr1
>SYSCALL PutS
bcs .9
jsr GetPtr1NextString
bra .1
.8 lda ZPTmpW
>SYSCALL FreeMem
* clc
.9 rts
*--------------------------------------
* SET +X VAR = VALUE1 op VALUE2 op VALUE3 ...
*--------------------------------------
CMD.SET.1
.1 jsr CMD.IsSwitch
bcs .6
ldx #SET.VARS-SET.FLAGS-1
.2 cmp SET.FLAGS,x
bne .3
lda SET.VARS,x
eor bState
sta bState
bra .5
.3 dex
bpl .2
.4 cmp #'F'
bne .99
jsr CORE.FUNCRESET
.5 jsr CORE.ArgV.Next
bne .1
clc
rts
*--------------------------------------
.6 >LDYA ZPArgVBufPtr
>STYA ZPVarNamePtr
jsr CORE.ArgV.Next
beq CMD.SET.GET
cmp #'='
bne .99
ldy #1
lda (ZPArgVBufPtr),y
bne .99
jsr CORE.ArgV.Next
beq CMD.SET.UNSET
cmp #'`'
beq CMD.SET.EXEC
jsr EXP.GET
bcc CMD.SET.YA
rts
.99 jmp CMD.E.CSYN
CMD.SET.YA pha
>PUSHW ZPVarNamePtr
pla
>PUSHYA
>SYSCALL SetEnv
rts
CMD.SET.UNSET >PUSHW ZPVarNamePtr
>SYSCALL UnsetEnv
rts
CMD.SET.GET >PUSHW ZPVarNamePtr
>PUSHW ZPCLBuf
>SYSCALL GetEnv
bcs .8
>LDYA ZPCLBuf
>SYSCALL PutS
rts
.8 clc
CMD.SET.RTS rts
*--------------------------------------
CMD.SET.EXEC jsr CORE.ArgV.NextChar skip "`"
jsr IO.Pipe.Out
bcs CMD.SET.RTS
jsr IO.Exec
bcs CMD.SET.RTS
jsr IO.Pipe.In
bcs CMD.SET.RTS
* clc Silent Mode
jsr CL.ReadReset
jmp CMD.READ.VAR
*--------------------------------------
CMD.DATE >PUSHEA.G TimeBuf
>SYSCALL Time
>PUSHW ZPCLBuf
lda (ZPArgVBufPtr)
beq .1
>LDYA ZPArgVBufPtr
bra .2
.1 >LDYA L.FMT.DATE
.2 >PUSHYA
>PUSHEA.G TimeBuf
>SYSCALL StrFTime
CMD.DATE.PRINT >LDYA ZPCLBuf
>SYSCALL PutS
rts
*--------------------------------------
CMD.ECHO stz ZPPtr1 echo -E
stz ZPPtr1+1 echo -N
stz ZPPtr2 index in buffer
lda (ZPArgVBufPtr)
beq .7
.1 jsr CMD.IsSwitch
bcs .3
ldx #0
cmp #'E'
beq .2
inx
cmp #'N'
bne CMD.ECHO.CSYN
.2 ror ZPPtr1,x
bra .6
.3 ldy ZPPtr2
beq .4
lda #C.SPACE
sta (ZPCLBuf),y
inc ZPPtr2
.4 ldy #$ff
.5 iny
lda (ZPArgVBufPtr),y
beq .6
phy
ldy ZPPtr2
sta (ZPCLBuf),y
inc ZPPtr2
ply
bra .5
.6 jsr CORE.ArgV.Next
bne .1
.7 ldy ZPPtr2
bit ZPPtr1+1 -N
bmi .8
lda #C.CR
sta (ZPCLBuf),y
iny
lda #C.LF
sta (ZPCLBuf),y
iny
.8 lda #0
sta (ZPCLBuf),y
>LDYA ZPCLBuf
bit ZPPtr1
bmi .80
jmp IO.OutYA
.80 jmp IO.EscOutYA
.9 rts
CMD.ECHO.CSYN lda #E.CSYN
sec
CMD.ECHO.RTS rts
*--------------------------------------
CMD.READ lda (ZPArgVBufPtr)
beq CMD.ECHO.CSYN
stz ZPVarNamePtr+1
jsr CL.ReadResetV
.1 jsr CMD.IsSwitch
bcs .4
cmp #'S'
bne .2
lda #$ff
>STA.G CL.bSilent
bra .5
.2 cmp #'P'
bne .3
jsr CORE.ArgV.Next
beq CMD.ECHO.CSYN
>LDYA ZPArgVBufPtr
jsr IO.OutYA
bcs CMD.ECHO.RTS
bra .5
.3 cmp #'N'
bne CMD.ECHO.CSYN
jsr CORE.ArgV.Next
beq CMD.ECHO.CSYN
jsr EXP.GetInt8Arg
bcs CMD.ECHO.RTS
>STA.G CL.MaxCnt
bra .5
.4 >LDYA ZPArgVBufPtr
>STYA ZPVarNamePtr
.5 jsr CORE.ArgV.Next
bne .1
lda ZPVarNamePtr+1
beq CMD.ECHO.CSYN
*--------------------------------------
CMD.READ.VAR jsr CL.Reset
.1 >SYSCALL GetChar
bcs CMD.SLEEP.RTS
jsr CL.CHARIN
>LDA.G CL.bReady
bpl .1
lda (ZPCLBuf)
bne .2
jmp CMD.SET.UNSET
.2 >LDYA ZPCLBuf
jmp CMD.SET.YA
*--------------------------------------
CMD.SLEEP lda (ZPArgVBufPtr)
beq CMD.REN.CSYN
jsr EXP.GetInt32Arg
bcs CMD.SLEEP.RTS
>PULLL.G Sleep
CMD.SLEEP.RTS rts
*--------------------------------------
CMD.PAUSE lda #bState.Pause
tsb bState
clc
rts
*--------------------------------------
CMD.MD lda (ZPArgVBufPtr)
beq CMD.REN.CSYN
>PUSHW ZPArgVBufPtr
>PUSHWI S.STAT.MODE.FO+S.STAT.MODE.FG+S.STAT.MODE.FU
>SYSCALL MKDir
rts
*--------------------------------------
CMD.PWD jsr GetCWD
>SYSCALL PutS
rts
*--------------------------------------
CMD.RD lda (ZPArgVBufPtr)
beq CMD.REN.CSYN
jsr IO.StatArgVBufPtr
bcs .99
cmp /S.STAT.MODE.DIR
bne CMD.REN.CSYN
>LDYA ZPArgVBufPtr
>SYSCALL Remove
.99 rts
*--------------------------------------
CMD.REN.CSYN jmp CMD.E.CSYN
CMD.REN lda (ZPArgVBufPtr)
beq CMD.REN.CSYN
jsr CORE.ArgV.Next
lda (ZPArgVBufPtr)
beq CMD.REN.CSYN
>PUSHW ZPArgVBufPrev old path
>PUSHWZ Allocate
>SYSCALL RealPath
bcs CMD.REN.CSYN
>STYA ZPPtr1
stx ZPTmpW
ldy #$ff
.1 iny
lda (ZPPtr1),y
beq .2
cmp #'/'
bne .1
tya
tax
bra .1
.2 ldy #$ff
.3 iny
inx
lda (ZPArgVBufPtr),y
bne .3
txa
tay
lda #0
>SYSCALL GetMem
bcs .90
>STYA ZPPtr2
stx ZPTmpW+1
ldy #$ff
.4 iny
lda (ZPPtr1),y
beq .5
sta (ZPPtr2),y
cmp #'/'
bne .4
tya
inc
tax
bra .4
.5 txa
tay
lda #0
sta (ZPPtr2),y
>PUSHW ZPPtr2
>PUSHW ZPArgVBufPtr
>SYSCALL StrCat
lda ZPTmpW
>SYSCALL FreeMem
lda ZPTmpW+1
sta ZPTmpW
>PUSHW ZPPtr1
>PUSHW ZPPtr2
>SYSCALL Rename
.90 php
pha
lda ZPTmpW
>SYSCALL FreeMem
pla
plp
rts
*--------------------------------------
CMD.FUNCTION lda (ZPArgVBufPtr)
beq .9
jsr STK.GetCtx
bcc .9 No context allowed
>LDA.G hFunctions
bne .1
lda #SL..+SL._
>SYSCALL SListNew
bcs .99
>STA.G hFunctions
.1 >PUSHA
>PUSHW ZPArgVBufPtr
>PUSHWZ ScopeID
>SYSCALL SListNewKey
bcs .99
>STYA ZPTmpW Save KeyID
jsr CORE.ArgV.Next nothing after function name
beq .10
cmp #'{'
bne .9
ldy #1
lda (ZPArgVBufPtr),y
beq .11
.9 jmp CMD.E.CSYN
.99 rts
*--------------------------------------
.10 jsr CORE.GetCharNB
bcs .9
cmp #'{'
bne .9
jsr CORE.GetNextCharNB
bcs .9
.11 >LDYA ZPInputBufPtr
>STYA ZPPtr1
stz ZPPtr2
stz ZPPtr2+1 DataLen
ldx #0 '{' counter
lda (ZPInputBufPtr)
beq .6
.12 cmp #'{'
bne .13
inx
bra .14
.13 cmp #'}'
bne .14
dex
bmi .7
.14 inc ZPPtr2
bne .15
inc ZPPtr2+1
.15 jsr CORE.GetNextChar
bcc .12
.6 txa
bpl .9
.7 jsr CORE.GetNextChar skip ending '}'
>PUSHB.G hFunctions
>PUSHW ZPTmpW KeyID
>PUSHW ZPPtr1 DataPtr
>PUSHW ZPPtr2 DataLen
>SYSCALL SListAddData
bcs .99
>PUSHB.G hFunctions
>PUSHW ZPTmpW KeyID
>PUSHW L.PtrZero DataPtr
>PUSHWI 1 DataLen
>SYSCALL SListAddData Add Ending \0
rts
*--------------------------------------
CMD.CALL jsr CMD.CALL.GETFUNC
bcs CMD.CALL.RTS
>STYA ZPTmpW KeyID
ldy #hFunctions
jsr CORE.SListGetData
bcs CMD.CALL.RTS
>LDYA ZPArgVBufPtr FUNC PARAM1 PARAM2...
jsr CORE.Load.YAX Exec FUNC
bcs CMD.CALL.RTS
lda #$C0+C.CALL
jmp STK.Push
*--------------------------------------
CMD.CALL.GETFUNC
>LDA.G hFunctions
beq CMD.CALL.UNDEF
>PUSHB.G hFunctions
>PUSHW ZPArgVBufPtr
>PUSHWZ ScopeID
>SYSCALL SListLookup
bcc CMD.CALL.RTS
CMD.CALL.UNDEF lda #E.FUNDEF
sec
CMD.CALL.RTS rts
*--------------------------------------
CMD.EXIT lda (ZPArgVBufPtr)
beq .1 no arg, exit 0
jsr EXP.GetInt8Exp
bcs .9
.1 ldy #S.PS.RC
sta (pPS),y
.2 jsr STK.Pull Pull everything until CALL . CL...
bcs .9
cmp #$C0+C.. in CALL, "." or CL context ?
beq CMD.EXIT.FILE
cmp #$C0+C.CALL
beq CMD.EXIT.FILE
cmp #$C0+C.CLEXEC
beq .8
jsr STK.PopCtxA
bcc .2
rts
.8 jsr CMD.EXIT.FILE
lda #bState.ExitOnEOF
tsb bState
clc
.9 rts
*--------------------------------------
CMD.EXIT.FILE jsr STK.PullFree Code buffer
ldy #S.PS.hARGV
lda (pPS),y
>SYSCALL FreeMem ArgV buffer
jsr STK.Pull
ldy #S.PS.hARGV
sta (pPS),y
jsr STK.Pull
ldy #S.PS.ARGC
sta (pPS),y
jsr STK.PullInputBufPtr
jsr STK.Pull
sta ZPInputBuf
jsr STK.Pull
sta ZPInputBuf+1
ldy #S.PS.RC
lda (pPS),y
cmp #1
rts
*--------------------------------------
CMD.BREAK jsr STK.GetCtx Get context in CORE.TestResult
bcs .9
tax
and #$3F
cmp #C.CASE
bne .1
txa
bpl .8 already FALSE
jsr STK.Pull remove C.CASE
jsr STK.Get get SWITCH
bra .7
*--------------------------------------
.1 cmp #C.IF
bne .2
sta (pData),y IF=false to skip until FI
dey get parent context
beq .9
lda (pData),y
and #$3F
.2 cmp #C.WHILE
beq .6
.3 cmp #C.FOR
bne .9
.6 lda (pData),y
.7 and #%01111111
sta (pData),y WHILE/FOR=false, Parent=unchanged
.8 clc
rts
.9 jmp CMD.E.CSYN
*--------------------------------------
* stack-1 hVALUE
* stack SWITCH TOKEN
*--------------------------------------
CMD.SWITCH jsr STK.GetCtx
lda #2
jsr STK.Check
bcs .9
jsr EXP.GET
bcs .9
>SYSCALL StrDup
bcs .9
txa
jsr STK.Push Push EXP hVALUE
lda CORE.TestResult
beq .1
ora #$80
.1 ora #C.SWITCH
jmp STK.Push
.9 rts
*--------------------------------------
CMD.CASE jsr STK.GetCtx Get context in CORE.TestResult
bcs .9
tax
and #$3F
cmp #C.SWITCH
beq .1
cmp #C.CASE
bne .9
txa previous case was true ?
bpl .10
jsr EXP.GET skip expression
bcs .9
rts keep existing context
.10 jsr STK.Pull remove previous C.CASE
bra CMD.CASE
.1 jsr EXP.GET
bcs .9
>PUSHYA
lda (pData)
tay
dey get hVALUE
lda (pData),y
>SYSCALL GetMemPtr
>PUSHYA
>SYSCALL StrCmp
ror CS if !=
and #$80
eor #$80
ora CORE.TestResult
ora #C.CASE
jmp STK.Push
.9
CMD.E.CSYN lda #E.CSYN
sec
rts
*--------------------------------------
CMD.DEFAULT jsr STK.GetCtx Get context in CORE.TestResult
bcs CMD.E.CSYN
and #$3F
cmp #C.SWITCH
beq .1
cmp #C.CASE
bne CMD.E.CSYN
jsr STK.Pull remove C.CASE
.1 jsr STK.Get
and #$C0
ora #C.DEFAULT
jmp STK.Push
*--------------------------------------
CMD.END jsr STK.GetCtx Get context in CORE.TestResult
bcs CMD.E.CSYN
and #$3F
cmp #C.SWITCH
beq .8
cmp #C.CASE
beq .8
cmp #C.DEFAULT
bne CMD.E.CSYN
.8 jmp STK.PopCtx
*--------------------------------------
CMD.FOR jsr STK.GetCtx
lda (ZPArgVBufPtr)
beq CMD.E.CSYN
>LDYA ZPArgVBufPtr
>STYA ZPVarNamePtr
jsr CORE.ArgV.Next
beq CMD.E.CSYN
>PUSHW L.IN
>PUSHW ZPArgVBufPtr
>SYSCALL StrCaseCmp
bcs CMD.E.CSYN
jsr CORE.ArgV.Next
beq CMD.E.CSYN
lda #8 Make sure 8 bytes free on stack
jsr STK.Check
bcs FOR.FILE.9
lda (ZPArgVBufPtr)
cmp #'('
beq CMD.FOR.FILE
cmp #'`'
beq CMD.FOR.EXEC
*--------------------------------------
CMD.FOR.LIST >LDYA ZPArgVBufPtr
>SYSCALL StrDup
bcs FOR.FILE.9
phy
pha
jsr STK.PushInputBufPtr Push CmdPtr AFTER FOR
pla
ply
jsr STK.PushYAX Push listPtr,hList
jsr CORE.PushVarName Push hVARNAME
lda #C.FOR.LIST
jsr STK.Push
lda #C.FOR
jsr STK.Push
jsr CMD.NEXT.LIST.TOKEN
bcc CMD.FOR.LOOP
rts
*--------------------------------------
CMD.FOR.FILE jsr CORE.ArgV.NextChar skip "("
>LDYA ZPArgVBufPtr
ldx #O.RDONLY+O.TEXT
jsr IO.FOpenYAX
bcc CMD.FOR.PUSH
FOR.FILE.9 rts
*--------------------------------------
CMD.FOR.EXEC jsr CORE.ArgV.NextChar skip "`"
jsr IO.Pipe.Out
bcs FOR.FILE.9
jsr IO.Exec
bcs FOR.FILE.9
jsr IO.Pop.Out Restore OUT (NO close)
jsr IO.Pipe.OpenR
bcs FOR.FILE.9
CMD.FOR.PUSH pha save hFILE/hPIPE
jsr STK.PushInputBufPtr Push CmdPtr AFTER FOR
pla
jsr STK.Push push hPIPE for read
jsr CORE.PushVarName Push hVARNAME
* bcs FOR.FILE.9
lda #C.FOR.FILEEXEC
jsr STK.Push
lda #C.FOR
jsr STK.Push
jsr CMD.NEXT.LINE
bcs FOR.FILE.9
CMD.FOR.LOOP ora CORE.TestResult
ora #C.FOR Push FOR
pha
lda (pData)
tay
pla
sta (pData),y
* clc
rts
*--------------------------------------
CMD.NEXT jsr STK.Get Y = StkPtr
bcs .9
and #$3F
cmp #C.FOR
bne .9
dey
lda (pData),y
iny
tax
beq CMD.NEXT.LIST
jmp CMD.NEXT.FILEEXEC
.9 lda #E.NOFOR
sec
rts
*--------------------------------------
* stack-6 CmdPtr
* stack-4 ListPtr
* stack-3 hLIST
* stack-2 hVARNAME
* stack-1 FOR SUB TOKEN
* stack FOR TOKEN
*--------------------------------------
CMD.NEXT.LIST lda (pData),y Y = StkPtr
bpl .1
jsr CMD.NEXT.LIST.TOKEN
bcs .9
bpl .1
lda (pData)
sec
sbc #6
jmp CMD.NEXT.FILEEXEC.LOOPY
.1 lda (pData)
tay
sec
sbc #8
sta (pData)
dey
dey
lda (pData),y hVARNAME
pha
dey
lda (pData),y hLIST
>SYSCALL FreeMem
pla
>SYSCALL FreeMem
* clc
.9 rts
*--------------------------------------
CMD.NEXT.LIST.TOKEN
jsr CMD.NEXT.GetVarNamePtr
dey skip hLIST
dey
lda (pData),y
sta ZPPtr1
dey
lda (pData),y
sta ZPPtr1+1
ldy #0
.10 jsr GetPtr1NextChar
beq .3
cmp #C.SPACE
beq .10
sta (ZPCLBuf),y
iny
.1 jsr GetPtr1NextChar
beq .3
cmp #C.SPACE
beq .3
sta (ZPCLBuf),y
iny
bra .1
.3 lda #0
sta (ZPCLBuf),y
tya
beq .8
>LDYA ZPCLBuf
jsr CMD.SET.YA
bcs .9
lda (pData)
sec
sbc #4
tay
lda ZPPtr1
sta (pData),y
dey
lda ZPPtr1+1
sta (pData),y
lda #$80
clc
.9 rts
.8 jmp CMD.NEXT.END
*--------------------------------------
* stack-4 CmdPtr
* stack-3 hFILE/hPIPE
* stack-2 hVARNAME
* stack-1 FOR SUB TOKEN
* stack FOR TOKEN
*--------------------------------------
CMD.NEXT.FILEEXEC
lda (pData),y Y = StkPtr
bpl CMD.NEXT.FILEEXEC.POP
jsr CMD.NEXT.LINE
bcs CMD.NEXT.FILEEXEC.9
bpl CMD.NEXT.FILEEXEC.POP end of file/pipe
lda (pData)
sec
sbc #4
CMD.NEXT.FILEEXEC.LOOPY
tay
lda (pData),y
sta ZPInputBufPtr
dey
lda (pData),y
sta ZPInputBufPtr+1
clc
CMD.NEXT.FILEEXEC.9
rts
CMD.NEXT.FILEEXEC.POP
lda (pData)
tay
sec
sbc #6
sta (pData)
dey
dey
lda (pData),y hVARNAME
pha
dey
lda (pData),y hFILE/hPIPE
>SYSCALL FClose
pla
>SYSCALL FreeMem
* clc
rts
*--------------------------------------
CMD.NEXT.LINE jsr CMD.NEXT.GetVarNamePtr
dey
lda (pData),y hFILE/hPIPE
>PUSHA
>PUSHW ZPCLBuf
>PUSHWI 256
>SYSCALL FGetS
bcs CMD.NEXT.END
>LDYA ZPCLBuf
jsr CMD.SET.YA
bcs CMD.NEXT.LINE.RTS
lda #$80
* clc
rts
CMD.NEXT.END jsr CMD.SET.UNSET
bcs .9
lda #0
clc keep this CLC for CMD.NEXT.LIST.TOKEN
.9
CMD.NEXT.LINE.RTS
rts
*--------------------------------------
CMD.NEXT.GetVarNamePtr
lda (pData)
dec skip FOR
dec skip SUB TOKEN
tay
lda (pData),y
phy
>SYSCALL GetMemPtr hVARNAME
>STYA ZPVarNamePtr
ply
rts
*--------------------------------------
CMD.WHILE
CMD.IF jsr STK.GetCtx
bit #$40 Parent is true ?
beq .3
jsr EXP.TEST
bcs CMD.NEXT.LINE.RTS
.3 lda CORE.IntCmd
cmp #C.WHILE
bne .8
lda #3
jsr STK.Check
bcs CMD.NEXT.LINE.RTS
>LDYA ZPInputCmdPtr
jsr STK.PushYA Push BEFORE WHILE/IF
.8 lda CORE.TestResult
ora CORE.IntCmd
jmp STK.Push
*--------------------------------------
CMD.LOOP jsr STK.Get
bcs .9
tax
and #$3F
cmp #C.WHILE
bne .9
txa
bmi .8 true, loop
jmp STK.PopCtx false, Discard loop Ptr
.8 jsr STK.Pull
jmp STK.PullInputBufPtr
.9 lda #E.NOWHILE
sec
rts
*--------------------------------------
CMD.ELSE jsr STK.Get
bcs .9
bit #$40 parent is true ?
beq .8 no, skip
tax
and #$3F
cmp #C.IF
bne .9
txa
eor #$80 toggle and store at stack ptr
sta (pData),y
.8 clc
rts
.9
CMD.ELSE.NOIF lda #E.NOIF
sec
rts
*--------------------------------------
CMD.FI jsr STK.Pull
bcs CMD.ELSE.NOIF
and #$3F
cmp #C.IF
bne CMD.ELSE.NOIF
clc
rts
*--------------------------------------
CMD.IsSwitch lda (ZPArgVBufPtr)
cmp #'-'
bne .9
ldy #1
lda (ZPArgVBufPtr),y
beq .9
cmp #'0' is -0 ... -9 ?
bcc .9
cmp #'9'+1
bcc .9
tax
iny
lda (ZPArgVBufPtr),y
bne .9
txa
jmp ToUpperCase
.9 sec
rts
*--------------------------------------
MAN
SAVE usr/src/bin/sh.s.cmd
LOAD usr/src/bin/sh.s
ASM