A2osX/SYS/KERNEL.S.ENV.txt

401 lines
7.6 KiB
Plaintext
Raw Normal View History

2017-12-22 21:24:30 +00:00
NEW
2019-05-25 19:24:07 +00:00
AUTO 3,1
*/--------------------------------------
2020-01-17 11:23:11 +00:00
* # Expand
* ## C
* `char *expand(const char *str, char *expanded);`
* ## ASM
2018-06-14 15:31:36 +00:00
* **In:**
2020-01-20 07:23:51 +00:00
* `>PUSHW str`
2020-01-17 11:23:11 +00:00
* `>PUSHW expanded`
* `>SYSCALL expand`
2018-10-11 15:23:06 +00:00
* ## RETURN VALUE
* Y,A = PTR to Expanded String
2020-01-17 11:23:11 +00:00
* X = hMem to Expanded String (C-String)
*\--------------------------------------
2019-01-04 13:17:31 +00:00
.DUMMY
.OR ZPDRV
ENV.BufLen .BS 1
2019-09-09 15:38:37 +00:00
ENV.VarEndChar .BS 1
2019-01-04 13:17:31 +00:00
ENV.bNoExp .BS 1
2019-07-22 06:31:01 +00:00
ENV.bExp .BS 1
2019-01-04 13:17:31 +00:00
.ED
*--------------------------------------
2020-01-17 11:23:11 +00:00
K.Expand jsr K.strdup
2020-01-16 14:55:21 +00:00
bcc .1
2020-01-17 07:31:00 +00:00
2020-01-16 14:55:21 +00:00
rts
2020-01-18 19:37:32 +00:00
.1 phx Save temp string...
2020-01-16 14:55:21 +00:00
>STYA TXTPTR
2019-09-09 15:38:37 +00:00
stz ENV.BufLen init Expanded String len=0
2019-07-22 06:31:01 +00:00
stz ENV.bExp No var found yet
stz ENV.bNoExp Reset no expand flag
2020-01-15 16:43:23 +00:00
.10 lda (TXTPTR) End of CSTR?
2019-09-09 15:38:37 +00:00
beq .80
2020-01-15 16:43:23 +00:00
jsr SHARED.TXTPTR.Next
2019-09-10 10:22:57 +00:00
.11 cmp #'''
bne .21
2017-10-27 14:56:46 +00:00
lda ENV.bNoExp
eor #$ff
sta ENV.bNoExp toggle flag
2019-09-10 10:22:57 +00:00
bra .10
2017-10-27 14:56:46 +00:00
.21 bit ENV.bNoExp
bpl .23
.22 jsr ENV.AddAToBuf
2019-09-10 10:22:57 +00:00
bra .10
2019-09-09 15:38:37 +00:00
.23 cmp #'$' no, found one ?
bne .22 no, store...
2019-07-22 06:31:01 +00:00
ror ENV.bExp Toggle Expanded flag
2020-01-15 16:43:23 +00:00
lda (TXTPTR)
2019-09-10 10:22:57 +00:00
bne .30
2019-10-12 14:20:09 +00:00
2019-09-09 15:38:37 +00:00
lda #'$' End of string, output $
bra .22
2019-10-12 14:20:09 +00:00
2019-09-10 10:22:57 +00:00
.30 stz ENV.VarEndChar
cmp #'{' "${VAR]"?
bne .31
2019-09-09 15:38:37 +00:00
dec ENV.VarEndChar "}" expected
2020-01-15 16:43:23 +00:00
jsr SHARED.TXTPTR.Next skip "{"
2019-09-09 15:38:37 +00:00
bra .40
2019-10-12 14:20:09 +00:00
2020-01-22 13:26:40 +00:00
.31 jsr ENV.SysVar 0-9 *#?@$!
2020-01-17 07:31:00 +00:00
bcs .40
2020-01-15 16:43:23 +00:00
.35 jsr SHARED.TXTPTR.Next skip $x
2019-09-09 15:38:37 +00:00
bra .10
2019-10-12 14:20:09 +00:00
2019-09-10 06:28:08 +00:00
.40 jsr ENV.ExpandStrVar
2019-09-10 10:22:57 +00:00
bcc .70
2020-01-14 15:26:24 +00:00
2020-01-22 13:26:40 +00:00
.50 ldy ENV.BufLen
lda /K.Buf256
>STYA FORPNT
2020-02-06 16:23:59 +00:00
ldy #S.PS.hENV
lda (pPs),y
ldx #SYS.GetEnv
jsr K.SYSCALL.JMPX
2019-09-10 10:22:57 +00:00
bcs .70
2020-01-14 15:26:24 +00:00
2020-01-22 13:26:40 +00:00
ldx ENV.BufLen
2020-01-17 16:12:24 +00:00
2020-01-22 13:26:40 +00:00
.51 lda K.Buf256,x
beq .52
inx
bra .51
2020-01-17 16:12:24 +00:00
2020-01-22 13:26:40 +00:00
.52 stx ENV.BufLen
2020-01-17 16:12:24 +00:00
2020-01-15 16:43:23 +00:00
.70 lda (TXTPTR)
2019-09-10 10:22:57 +00:00
beq .72
2020-01-15 16:43:23 +00:00
2019-09-10 10:22:57 +00:00
jsr SHARED.IsIDValid
2020-01-15 16:43:23 +00:00
bcs .72
jsr SHARED.TXTPTR.Next
bra .70
.72 lda ENV.VarEndChar
2020-01-22 13:26:40 +00:00
bne .35 skip "}" and loop
2019-09-10 10:22:57 +00:00
2020-01-22 13:26:40 +00:00
bra .10
2019-10-12 14:20:09 +00:00
2020-01-16 14:55:21 +00:00
.80 ldx ENV.BufLen
stz K.Buf256,x
2019-10-12 14:20:09 +00:00
2020-01-18 19:37:32 +00:00
pla discard temp string
2020-01-16 14:55:21 +00:00
jsr K.FreeMem
2019-10-12 14:20:09 +00:00
2020-01-16 14:55:21 +00:00
>LDYAI K.Buf256 dup in case of '' processing
jsr K.strdup
bcs .9
2019-10-12 14:20:09 +00:00
bit ENV.bExp Did we expand something ?
2020-01-16 14:55:21 +00:00
bpl .9
jmp .1
* clc
.9 rts
2020-01-17 11:23:11 +00:00
*--------------------------------------
2020-01-22 13:26:40 +00:00
ENV.SysVar jsr ZP.IsDigit $0 ... $9 ?
bcs .1
2020-01-16 07:33:14 +00:00
2020-01-22 13:26:40 +00:00
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
2018-06-28 15:26:34 +00:00
dex
2020-01-22 13:26:40 +00:00
bpl .2
2020-01-16 07:33:14 +00:00
2020-01-17 11:23:11 +00:00
sec
rts
2020-01-16 07:33:14 +00:00
2020-01-22 13:26:40 +00:00
.3 txa
2020-01-17 11:23:11 +00:00
beq ENV.SysVarsAllArgs
2018-06-28 15:26:34 +00:00
2020-01-17 11:23:11 +00:00
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
2020-01-16 07:33:14 +00:00
2020-01-17 11:23:11 +00:00
.1 lda (ZPPtr3)
beq ENV.SysVarsNum.8
2020-01-15 09:50:04 +00:00
2020-01-17 11:23:11 +00:00
.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
2020-01-16 14:55:21 +00:00
ldx #0
2020-01-15 09:50:04 +00:00
2020-01-17 11:23:11 +00:00
.1 lda (ZPPtr3)
beq .9
2020-01-15 09:50:04 +00:00
2020-01-17 11:23:11 +00:00
ldy #$ff
.2 iny
lda (TXTPTR),y
beq .3
2020-01-15 09:50:04 +00:00
2020-01-17 11:23:11 +00:00
jsr SHARED.IsIDValid
bcs .3
2020-01-15 09:50:04 +00:00
2020-01-17 11:23:11 +00:00
cmp (ZPPtr3),y
beq .2
2020-01-15 09:50:04 +00:00
2020-01-17 11:23:11 +00:00
bra .4
2018-06-28 15:26:34 +00:00
2020-01-17 11:23:11 +00:00
.3 lda (ZPPtr3),y
bne .4
2020-01-15 09:50:04 +00:00
2020-01-17 11:23:11 +00:00
jmp (ENV.StrVarsJmp,x)
2020-01-15 09:50:04 +00:00
2020-01-17 11:23:11 +00:00
.4 inx
2018-06-28 15:26:34 +00:00
inx
2020-01-17 11:23:11 +00:00
jsr ENV.NextEnvP3
bra .1
2019-12-02 16:47:53 +00:00
2020-01-17 11:23:11 +00:00
.9 sec
rts
*--------------------------------------
ENV.StrVars .AZ "LOGNAME"
.AZ "GECOS"
.AZ "HOME"
.AZ "SHELL"
.AZ "UID"
.AZ "GID"
2020-02-04 14:35:48 +00:00
.AZ "PWD"
2020-01-17 11:23:11 +00:00
.DA #0
*--------------------------------------
ENV.StrVarsJmp .DA ENV.StrVarsSession
.DA ENV.StrVarsSession
.DA ENV.StrVarsSession
.DA ENV.StrVarsSession
.DA ENV.StrVarsUID
.DA ENV.StrVarsGID
2020-02-04 14:35:48 +00:00
.DA ENV.StrVarsPWD
2020-01-17 11:23:11 +00:00
*--------------------------------------
ENV.StrVarsSession
2020-02-04 14:35:48 +00:00
jsr ENV.GetSession
lda ZPPtr3
2020-01-17 11:23:11 +00:00
clc
adc #S.SESSION.NAME
sta ZPPtr3
2020-02-04 14:35:48 +00:00
lda ZPPtr3+1
2020-01-17 11:23:11 +00:00
adc /S.SESSION.NAME
sta ZPPtr3+1
2020-01-16 14:55:21 +00:00
2020-01-17 11:23:11 +00:00
.1 dex
dex
2020-01-22 13:26:40 +00:00
bmi ENV.AddP3ToBuf
2018-06-28 15:26:34 +00:00
2020-01-17 11:23:11 +00:00
ldy #$ff
.2 iny
lda (ZPPtr3),y
bne .2
2018-06-28 15:26:34 +00:00
2020-01-17 11:23:11 +00:00
jsr ENV.NextEnvP3Y
bra .1
*--------------------------------------
2020-02-04 14:35:48 +00:00
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
*--------------------------------------
2020-01-22 13:26:40 +00:00
ENV.AddYAToBuf >STYA ZPPtr3
2020-01-17 11:23:11 +00:00
*--------------------------------------
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
2018-06-28 15:26:34 +00:00
rts
2020-02-05 06:46:52 +00:00
*--------------------------------------
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
2018-06-28 15:26:34 +00:00
*/--------------------------------------
* # SetEnv
2018-09-06 15:36:44 +00:00
* Change or add an environment variable
* ## C
* `int setenv(const char *name, const char *value);`
* ## ASM
2018-06-14 15:31:36 +00:00
* **In:**
2020-01-17 07:31:00 +00:00
* `>PUSHW name`
2018-09-06 15:36:44 +00:00
* `>PUSHW value`
* `>SYSCALL setenv`
2018-10-11 15:23:06 +00:00
* ## RETURN VALUE
*\--------------------------------------
2020-02-06 16:23:59 +00:00
K.SetEnv
* >PULLW FORPNT value
* >PULLW TXTPTR name
2020-02-03 15:17:34 +00:00
2020-02-06 16:23:59 +00:00
* ldy #S.PS.hENV
* lda (pPs),y
* jmp K.SYSCALL.JMPX
*/--------------------------------------
2018-06-21 15:12:10 +00:00
* # GetEnv
2018-09-06 15:36:44 +00:00
* searches the environment list to find the environment variable name,
* and returns a pointer to the corresponding value string.
* ## C
2020-01-15 07:10:24 +00:00
* `char *getenv(const char *name, char *value);`
2018-09-06 15:36:44 +00:00
* ## ASM
2018-06-14 15:31:36 +00:00
* **In:**
2020-01-15 07:10:24 +00:00
* `>PUSHW name`
* `>PUSHW value`
2018-10-11 15:23:06 +00:00
* `>SYSCALL getenv`
* ## RETURN VALUE
2018-09-06 15:36:44 +00:00
* CC : Y,A = PTR to VALUE (C-String)
2016-08-17 06:25:58 +00:00
* CS : not found
*\--------------------------------------
2020-01-15 09:50:04 +00:00
K.GetEnv >PULLW FORPNT value
2020-02-06 16:23:59 +00:00
* >PULLW TXTPTR name
*
* ldy #S.PS.hENV
* lda (pPs),y
2020-02-02 14:58:01 +00:00
2020-02-06 16:23:59 +00:00
* 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
*/--------------------------------------
2018-06-21 15:12:10 +00:00
* # UnsetEnv
2018-09-06 15:36:44 +00:00
* Remove an environment variable
* ## C
* `int unsetenv(const char *name);`
* ## ASM
2018-06-14 15:31:36 +00:00
* **In:**
2020-01-17 11:23:11 +00:00
* `>PUSHW name`
2018-09-06 15:36:44 +00:00
* `>SYSCALL unsetenv`
2018-10-11 15:23:06 +00:00
* ## RETURN VALUE
*\--------------------------------------
2020-02-06 16:23:59 +00:00
K.UnsetEnv
* >PULLW TXTPTR name
2020-01-17 13:25:59 +00:00
2020-02-05 06:46:52 +00:00
ldy #S.PS.hENV
2020-02-03 15:17:34 +00:00
lda (pPs),y
2020-02-06 16:23:59 +00:00
jmp K.SYSCALL.JMPX
2016-08-17 06:25:58 +00:00
*--------------------------------------
2015-03-14 21:48:35 +00:00
MAN
2018-11-17 17:17:13 +00:00
SAVE USR/SRC/SYS/KERNEL.S.ENV
LOAD USR/SRC/SYS/KERNEL.S
2015-03-14 21:48:35 +00:00
ASM