A2osX/SYS/KERNEL.S.ARG.txt
2019-05-25 21:24:07 +02:00

120 lines
2.2 KiB
Plaintext
Raw 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
*/--------------------------------------
* # Args2ArgV
* Expand String and convert to ArgV List
* ## C
* short int args2argv(char* args, char* argv[])
* ## ASM
* `>PUSHW argv`
* `>LDYA args`
* `>SYSCALL Args2ArgV`
* ## RETURN VALUE
* A = Arg count
*\--------------------------------------
ARG.bInQuote .EQ ZPPtr3
*--------------------------------------
K.Args2ArgV jsr K.ExpandStr
bcs .9
>STYA ZPPtr1
stx .80+1
>PULLW ZPPtr2 Get target buffer
ldx #0 Arg Count
stz ARG.bInQuote
.1 jsr MEM.GetCharPtr1
beq .8
cmp #C.SPACE
beq .1 skip leading spaces
.2 cmp #'"' found a quote ?
bne .3
lda ARG.bInQuote
eor #$ff
sta ARG.bInQuote
bra .7 skip quote and check next char
.3 cmp #C.SPACE
bne .6 regular char ...store...
bit ARG.bInQuote
bmi .6 between quotes... store space...
inx Found one arg !!!
lda #0 set this token End
jsr MEM.PutCharPtr2
bra .1
.6 jsr MEM.PutCharPtr2
.7 jsr MEM.GetCharPtr1
bne .2
inx
.8 jsr MEM.PutCharPtr2 set Argv[x] Ending 0
sta (ZPPtr2) set Array Ending 0
phx
.80 lda #$FF SELF MODIFIED
jsr K.FreeMem Discard expanded string
pla get back Arg Count
* clc
rts
.9 >RET 2 Discard target buffer
*/--------------------------------------
* # ArgV
* ## ASM
* **In:**
* A = argument index.
* ## RETURN VALUE
* CC : success
* Y,A = PTR To Arg[A]
* CS : Out Of Bound
*\--------------------------------------
K.ArgV tax save requested arg#
ldy #S.PS.hARGV
lda (pPs),y
jsr K.GetMemPtr
>STYA ZPPtr1
.1 lda (ZPPtr1) end of ARGV[] ?
beq .9 yes, not found....
dex
bmi .7
.3 jsr MEM.GetCharPtr1 skip str
bne .3
jsr MEM.NextCharPtr1 skip \0
bra .1
.7 >LDYA ZPPtr1
.8 clc
rts
.9 lda #E.OOB
sec
rts
*--------------------------------------
MAN
SAVE USR/SRC/SYS/KERNEL.S.ARG
LOAD USR/SRC/SYS/KERNEL.S
ASM