SEQ better handling of invalid args and now supports -H to avoid undesired behavior

This commit is contained in:
Brian J. Bernstein 2023-01-10 20:43:53 -05:00
parent 0ac5def14f
commit d3c8805e40

View File

@ -47,6 +47,7 @@ wFirst .BS 2 ; arg variable - starting count
wIncr .BS 2 ; arg variable - increment
wLast .BS 2 ; arg variable - ending count
bFormat .BS 1 ; flag that the format -f option was specified
bHelp .BS 1 ; flag that the help -h option was specified
ZPPtrFormat .BS 2 ; pointer to format -f string
bString .BS 1 ; flag that the string -s option was specified
ZPPtrString .BS 2 ; pointer to string -s string
@ -116,10 +117,13 @@ CS.RUN
.10 >STYA ZPPtr1 ; ArgV pointer was in Y,A so stick into ZPPtr1
lda (ZPPtr1)
cmp #'-' ; does arg have a hyphen?
bne .11 ; if not, check for string args
bne .11 ; if not, check for string/numeric args
jsr CS.RUN.CheckOpt ; if it had a hyphen, check and set arg if recognized
bcc .1 ; if we recognized the arg, then loop again to check next
bcs .9 ; if we didn't recognize the arg, go to usage and exit
bit bHelp ; was the arg 'Help'?
bpl .1 ; no, loop again to check next
jmp .9 ; it was, so display usage and exit
*--- Checking of argument -F ----------
@ -144,7 +148,7 @@ CS.RUN
*--- Checking of argument -T ----------
.13 bit bTerminating ; did we just see the -t option?
bpl .2 ; no, jump to the next arg flag
bpl .2 ; no, jump to numeric processing
lda ArgIndex ; yes, then get the pointer to the arg string
>SYSCALL ArgV ; and set it to the pointer for the -t
>STYA ZPPtrTerm ; string storage
@ -153,6 +157,21 @@ CS.RUN
jmp .1 ; and then go process the next arg
*--- Display usage and error out ------
.9
>PUSHW L.MSG.USAGE ; push address for usage text
>PUSHBI 0
>SYSCALL PrintF ; print usage message
lda #E.SYN ; set OS return code as Syntax Error
sec ; indicate we don't want CS.RUN called again
rts ; return to OS
*--- Successful exit ------------------
.99
lda #0 ; set OS return code to success
sec ; indicate we don't want CS.RUN called again
rts ; return to OS
*--- Processing numerical args --------
.2 lda ArgIndex
>SYSCALL ArgV ; check for an arg at index in A
@ -389,18 +408,18 @@ CS.CmpFirstLast >PUSHW wFirst ; using FPU macro, so push first,
*--------------------------------------
CS.END
*--------------------------------------
MSG.USAGE .CS "Usage : SEQ [first [incr]] last\r\n"
.CS " -F numeric format\r\n"
.CS " -S string separator\r\n"
.CZ " -T terminating string\r\n"
MSG.USAGE .CS "Usage : SEQ [options] [first [incr]] last\r\n"
.CS " -F fmt : numeric format\r\n"
.CS " -S sep : string separator\r\n"
.CZ " -T trm : terminating string\r\n"
MSG.MSG.NEWLINE .CZ "\r\n"
*--------------------------------------
FMT.FORMAT .AZ "%I"
FMT.STRING .AZ "\r\n"
FMT.TERM .AZ ""
*--------------------------------------
OptionList .AS "FfSsTt"
OptionVars .DA #bFormat,#bFormat,#bString,#bString,#bTerminating,#bTerminating
OptionList .AS "FfSsTtHh"
OptionVars .DA #bFormat,#bFormat,#bString,#bString,#bTerminating,#bTerminating,#bHelp,#bHelp
*--------------------------------------
* Per Process DATA segment (0 filled before INIT)
*--------------------------------------