mirror of
https://github.com/A2osX/A2osX.git
synced 2024-11-22 16:31:07 +00:00
401 lines
7.6 KiB
Plaintext
401 lines
7.6 KiB
Plaintext
NEW
|
||
AUTO 3,1
|
||
*/--------------------------------------
|
||
* # Expand
|
||
* ## C
|
||
* `char *expand(const char *str, char *expanded);`
|
||
* ## ASM
|
||
* **In:**
|
||
* `>PUSHW str`
|
||
* `>PUSHW expanded`
|
||
* `>SYSCALL expand`
|
||
* ## RETURN VALUE
|
||
* Y,A = PTR to Expanded String
|
||
* X = hMem to Expanded String (C-String)
|
||
*\--------------------------------------
|
||
.DUMMY
|
||
.OR ZPDRV
|
||
ENV.BufLen .BS 1
|
||
ENV.VarEndChar .BS 1
|
||
ENV.bNoExp .BS 1
|
||
ENV.bExp .BS 1
|
||
.ED
|
||
*--------------------------------------
|
||
K.Expand jsr K.strdup
|
||
bcc .1
|
||
|
||
rts
|
||
|
||
.1 phx Save temp string...
|
||
>STYA TXTPTR
|
||
|
||
stz ENV.BufLen init Expanded String len=0
|
||
stz ENV.bExp No var found yet
|
||
stz ENV.bNoExp Reset no expand flag
|
||
|
||
.10 lda (TXTPTR) End of CSTR?
|
||
beq .80
|
||
|
||
jsr SHARED.TXTPTR.Next
|
||
|
||
.11 cmp #'''
|
||
bne .21
|
||
|
||
lda ENV.bNoExp
|
||
eor #$ff
|
||
sta ENV.bNoExp toggle flag
|
||
bra .10
|
||
|
||
.21 bit ENV.bNoExp
|
||
bpl .23
|
||
|
||
.22 jsr ENV.AddAToBuf
|
||
bra .10
|
||
|
||
.23 cmp #'$' no, found one ?
|
||
bne .22 no, store...
|
||
|
||
ror ENV.bExp Toggle Expanded flag
|
||
lda (TXTPTR)
|
||
bne .30
|
||
|
||
lda #'$' End of string, output $
|
||
bra .22
|
||
|
||
.30 stz ENV.VarEndChar
|
||
cmp #'{' "${VAR]"?
|
||
bne .31
|
||
|
||
dec ENV.VarEndChar "}" expected
|
||
|
||
jsr SHARED.TXTPTR.Next skip "{"
|
||
bra .40
|
||
|
||
.31 jsr ENV.SysVar 0-9 *#?@$!
|
||
bcs .40
|
||
|
||
.35 jsr SHARED.TXTPTR.Next skip $x
|
||
bra .10
|
||
|
||
.40 jsr ENV.ExpandStrVar
|
||
bcc .70
|
||
|
||
.50 ldy ENV.BufLen
|
||
lda /K.Buf256
|
||
>STYA FORPNT
|
||
|
||
ldy #S.PS.hENV
|
||
lda (pPs),y
|
||
|
||
ldx #SYS.GetEnv
|
||
jsr K.SYSCALL.JMPX
|
||
bcs .70
|
||
|
||
ldx ENV.BufLen
|
||
|
||
.51 lda K.Buf256,x
|
||
beq .52
|
||
inx
|
||
bra .51
|
||
|
||
.52 stx ENV.BufLen
|
||
|
||
.70 lda (TXTPTR)
|
||
beq .72
|
||
|
||
jsr SHARED.IsIDValid
|
||
bcs .72
|
||
jsr SHARED.TXTPTR.Next
|
||
bra .70
|
||
|
||
.72 lda ENV.VarEndChar
|
||
bne .35 skip "}" and loop
|
||
|
||
bra .10
|
||
|
||
.80 ldx ENV.BufLen
|
||
stz K.Buf256,x
|
||
|
||
pla discard temp string
|
||
jsr K.FreeMem
|
||
|
||
>LDYAI K.Buf256 dup in case of '' processing
|
||
jsr K.strdup
|
||
bcs .9
|
||
|
||
bit ENV.bExp Did we expand something ?
|
||
bpl .9
|
||
jmp .1
|
||
|
||
* clc
|
||
.9 rts
|
||
*--------------------------------------
|
||
ENV.SysVar jsr ZP.IsDigit $0 ... $9 ?
|
||
bcs .1
|
||
|
||
and #$0f
|
||
|
||
jsr K.ArgV
|
||
bcs .8 Arg# is undefined, do not append anything
|
||
|
||
jsr ENV.AddYAToBuf
|
||
|
||
.8 clc
|
||
rts
|
||
|
||
.1 ldx #ENV.SysVars.Cnt-1
|
||
|
||
.2 cmp ENV.SysVars,x
|
||
beq .3
|
||
dex
|
||
bpl .2
|
||
|
||
sec
|
||
rts
|
||
|
||
.3 txa
|
||
beq ENV.SysVarsAllArgs
|
||
|
||
ldy ENV.SysVars.PS-1,x
|
||
lda (pPS),y
|
||
*--------------------------------------
|
||
ENV.SysVarsNum jsr MATH.A2STR10NP
|
||
ldy #0
|
||
.1 lda A2osX.NumStrBuf,y
|
||
beq ENV.SysVarsNum.8
|
||
iny
|
||
jsr ENV.AddAToBuf
|
||
bra .1
|
||
ENV.SysVarsNum.8
|
||
clc
|
||
rts
|
||
*--------------------------------------
|
||
ENV.SysVarsAllArgs
|
||
lda #1
|
||
jsr K.ArgV
|
||
bcs ENV.SysVarsNum.8
|
||
>STYA ZPPtr3
|
||
|
||
.1 lda (ZPPtr3)
|
||
beq ENV.SysVarsNum.8
|
||
|
||
.2 jsr ENV.AddP3ToBuf
|
||
jsr ENV.NextEnvP3
|
||
lda (ZPPtr3)
|
||
beq ENV.SysVarsNum.8
|
||
lda #C.SPACE
|
||
jsr ENV.AddAToBuf
|
||
bra .2
|
||
*--------------------------------------
|
||
ENV.SysVars .AS "*#?@$!"
|
||
ENV.SysVars.Cnt .EQ *-ENV.SysVars
|
||
ENV.SysVars.PS .DA #S.PS.ARGC,#S.PS.RC,#S.PS.PPID,#S.PS.PID,#S.PS.CPID
|
||
*--------------------------------------
|
||
ENV.ExpandStrVar
|
||
>LDYAI ENV.StrVars
|
||
>STYA ZPPtr3
|
||
ldx #0
|
||
|
||
.1 lda (ZPPtr3)
|
||
beq .9
|
||
|
||
ldy #$ff
|
||
.2 iny
|
||
lda (TXTPTR),y
|
||
beq .3
|
||
|
||
jsr SHARED.IsIDValid
|
||
bcs .3
|
||
|
||
cmp (ZPPtr3),y
|
||
beq .2
|
||
|
||
bra .4
|
||
|
||
.3 lda (ZPPtr3),y
|
||
bne .4
|
||
|
||
jmp (ENV.StrVarsJmp,x)
|
||
|
||
.4 inx
|
||
inx
|
||
jsr ENV.NextEnvP3
|
||
bra .1
|
||
|
||
.9 sec
|
||
rts
|
||
*--------------------------------------
|
||
ENV.StrVars .AZ "LOGNAME"
|
||
.AZ "GECOS"
|
||
.AZ "HOME"
|
||
.AZ "SHELL"
|
||
.AZ "UID"
|
||
.AZ "GID"
|
||
.AZ "PWD"
|
||
.DA #0
|
||
*--------------------------------------
|
||
ENV.StrVarsJmp .DA ENV.StrVarsSession
|
||
.DA ENV.StrVarsSession
|
||
.DA ENV.StrVarsSession
|
||
.DA ENV.StrVarsSession
|
||
.DA ENV.StrVarsUID
|
||
.DA ENV.StrVarsGID
|
||
.DA ENV.StrVarsPWD
|
||
*--------------------------------------
|
||
ENV.StrVarsSession
|
||
jsr ENV.GetSession
|
||
|
||
lda ZPPtr3
|
||
clc
|
||
adc #S.SESSION.NAME
|
||
sta ZPPtr3
|
||
lda ZPPtr3+1
|
||
adc /S.SESSION.NAME
|
||
sta ZPPtr3+1
|
||
|
||
.1 dex
|
||
dex
|
||
bmi ENV.AddP3ToBuf
|
||
|
||
ldy #$ff
|
||
.2 iny
|
||
lda (ZPPtr3),y
|
||
bne .2
|
||
|
||
jsr ENV.NextEnvP3Y
|
||
bra .1
|
||
*--------------------------------------
|
||
ENV.StrVarsUID ldx #S.SESSION.UID
|
||
.HS 2C
|
||
ENV.StrVarsGID ldx #S.SESSION.GID
|
||
|
||
jsr ENV.GetSession
|
||
txa
|
||
tay
|
||
lda (ZPPtr3),y
|
||
jmp ENV.SysVarsNum
|
||
*--------------------------------------
|
||
ENV.StrVarsPWD ldy #S.PS.hCWD
|
||
lda (pPS),y
|
||
jsr K.GetMemPtr
|
||
jmp ENV.AddYAToBuf
|
||
*--------------------------------------
|
||
ENV.GetSession ldy #S.PS.hSID
|
||
lda (pPS),y
|
||
tay
|
||
lda S.Table.hSession-1,y
|
||
jsr K.GetMemPtr
|
||
>STYA ZPPtr3
|
||
rts
|
||
*--------------------------------------
|
||
ENV.AddYAToBuf >STYA ZPPtr3
|
||
*--------------------------------------
|
||
ENV.AddP3ToBuf ldx ENV.BufLen
|
||
ldy #$ff
|
||
dex
|
||
.1 iny
|
||
inx
|
||
lda (ZPPtr3),y
|
||
sta K.Buf256,x
|
||
bne .1
|
||
stx ENV.BufLen
|
||
rts
|
||
*--------------------------------------
|
||
ENV.AddAToBuf ldx ENV.BufLen
|
||
sta K.Buf256,x
|
||
inc ENV.BufLen
|
||
rts
|
||
*--------------------------------------
|
||
ENV.NextEnvP3 jsr ENV.GetP3LenY
|
||
*--------------------------------------
|
||
ENV.NextEnvP3Y tya
|
||
sec
|
||
adc ZPPtr3
|
||
sta ZPPtr3
|
||
bcc .8
|
||
inc ZPPtr3+1
|
||
.8 rts
|
||
*--------------------------------------
|
||
ENV.GetP3LenY ldy #$ff
|
||
.1 iny
|
||
lda (ZPPtr3),y
|
||
bne .1
|
||
rts
|
||
*/--------------------------------------
|
||
* # SetEnv
|
||
* Change or add an environment variable
|
||
* ## C
|
||
* `int setenv(const char *name, const char *value);`
|
||
* ## ASM
|
||
* **In:**
|
||
* `>PUSHW name`
|
||
* `>PUSHW value`
|
||
* `>SYSCALL setenv`
|
||
* ## RETURN VALUE
|
||
*\--------------------------------------
|
||
K.SetEnv
|
||
* >PULLW FORPNT value
|
||
* >PULLW TXTPTR name
|
||
|
||
* ldy #S.PS.hENV
|
||
* lda (pPs),y
|
||
|
||
* jmp K.SYSCALL.JMPX
|
||
*/--------------------------------------
|
||
* # GetEnv
|
||
* searches the environment list to find the environment variable name,
|
||
* and returns a pointer to the corresponding value string.
|
||
* ## C
|
||
* `char *getenv(const char *name, char *value);`
|
||
* ## ASM
|
||
* **In:**
|
||
* `>PUSHW name`
|
||
* `>PUSHW value`
|
||
* `>SYSCALL getenv`
|
||
* ## RETURN VALUE
|
||
* CC : Y,A = PTR to VALUE (C-String)
|
||
* CS : not found
|
||
*\--------------------------------------
|
||
K.GetEnv >PULLW FORPNT value
|
||
* >PULLW TXTPTR name
|
||
*
|
||
* ldy #S.PS.hENV
|
||
* lda (pPs),y
|
||
|
||
* jmp K.SYSCALL.JMPX
|
||
*/--------------------------------------
|
||
* # PutEnv
|
||
* Change or add an environment variable, string is 'NAME=VALUE'
|
||
* ## C
|
||
* `int putenv(char *string);`
|
||
* ## ASM
|
||
* **In:**
|
||
* `>PUSHW string`
|
||
* `>SYSCALL putenv`
|
||
* ## RETURN VALUE
|
||
*\--------------------------------------
|
||
K.PutEnv >PULLW TXTPTR NAME=VALUE
|
||
*/--------------------------------------
|
||
* # UnsetEnv
|
||
* Remove an environment variable
|
||
* ## C
|
||
* `int unsetenv(const char *name);`
|
||
* ## ASM
|
||
* **In:**
|
||
* `>PUSHW name`
|
||
* `>SYSCALL unsetenv`
|
||
* ## RETURN VALUE
|
||
*\--------------------------------------
|
||
K.UnsetEnv
|
||
* >PULLW TXTPTR name
|
||
|
||
ldy #S.PS.hENV
|
||
lda (pPs),y
|
||
|
||
jmp K.SYSCALL.JMPX
|
||
*--------------------------------------
|
||
MAN
|
||
SAVE USR/SRC/SYS/KERNEL.S.ENV
|
||
LOAD USR/SRC/SYS/KERNEL.S
|
||
ASM
|