This commit is contained in:
burniouf 2022-10-10 13:58:50 +02:00
parent 127ebe266a
commit a66047ccd5
3 changed files with 114 additions and 46 deletions

View File

@ -24,6 +24,27 @@ exists, thus return value is limited to
whether or not a valid argument was whether or not a valid argument was
given. given.
# GREP
Print lines that match patterns
## Arguments
**-H**
Help screen
**-I**
Ignoce case
**-N**
Print line number
**-Q**
Quiet mode
**-S**
Silent mode
**-V**
Invert match
## Return Value
if **-Q** specified, always 0
otherwise, 0 if a match found, E.NOKEY if not
# MKDIR # MKDIR
Create directories Create directories

Binary file not shown.

View File

@ -4,7 +4,26 @@ NEW
.OP 65C02 .OP 65C02
.OR $2000 .OR $2000
.TF bin/grep .TF bin/grep
*-------------------------------------- */-------------------------------------
* # GREP
* Print lines that match patterns
* ## Arguments
* **-H**
* Help screen
* **-I**
* Ignoce case
* **-N**
* Print line number
* **-Q**
* Quiet mode
* **-S**
* Silent mode
* **-V**
* Invert match
* ## Return Value
* if **-Q** specified, always 0
* otherwise, 0 if a match found, E.NOKEY if not
*\-------------------------------------
.INB inc/macros.i .INB inc/macros.i
.INB inc/a2osx.i .INB inc/a2osx.i
.INB inc/kernel.i .INB inc/kernel.i
@ -14,20 +33,27 @@ NEW
.DUMMY .DUMMY
.OR ZPBIN .OR ZPBIN
ZS.START ZS.START
ArgIndex .BS 1
ArgPattern .BS 1
ZPPtr1 .BS 2 ZPPtr1 .BS 2
ZPPatternPtr .BS 2 ZPPatternPtr .BS 2
ZPBufPtr .BS 2 ZPBufPtr .BS 2
ArgIndex .BS 1
ArgPattern .BS 1
hFile .BS 1 hFile .BS 1
hBuf .BS 1 hBuf .BS 1
LineNum .BS 2 LineNum .BS 2
char .BS 1 char .BS 1
bIgnoreCase .BS 1 bIgnoreCase .BS 1
bLineNum .BS 1 bLineNum .BS 1
bQuiet .BS 1
bSilent .BS 1
bInvertMatch .BS 1 bInvertMatch .BS 1
bFound .BS 1
ZS.END .ED ZS.END .ED
*-------------------------------------- *--------------------------------------
* File Header (16 Bytes) * File Header (16 Bytes)
@ -59,18 +85,22 @@ CS.INIT clc
rts rts
*-------------------------------------- *--------------------------------------
CS.RUN jsr CS.RUN.CheckArgs CS.RUN jsr CS.RUN.CheckArgs
bcs CS.RUN.LOOP.RTS bcs .99
stz LineNum >LDYAI 256
stz LineNum+1 >SYSCALL GetMem
bcs .99
CS.RUN.LOOP >SLEEP >STYA ZPBufPtr
stx hBuf
.1 >SLEEP
>PUSHB hFile >PUSHB hFile
>PUSHW ZPBufPtr >PUSHW ZPBufPtr
>PUSHWI 256 >PUSHWI 256
>SYSCALL FGetS >SYSCALL FGetS
bcs .9 bcs .7
inc LineNum inc LineNum
bne .2 bne .2
@ -79,20 +109,30 @@ CS.RUN.LOOP >SLEEP
.2 jsr CS.RUN.PRINT .2 jsr CS.RUN.PRINT
bcc CS.RUN.LOOP bcc .1
rts rts
.9 cmp #MLI.E.EOF .7 cmp #MLI.E.EOF
bne .99 bne .98
lda #0 Exit with no Error lda bQuiet
bmi .8
.99 sec bit bFound
CS.RUN.LOOP.RTS rts bmi .8
lda #E.NOKEY
sec
rts
.8 lda #0 Exit with no Error
.98 sec
.99 rts
*-------------------------------------- *--------------------------------------
CS.RUN.CheckArgs CS.RUN.CheckArgs
jsr CS.RUN.NextArg jsr CS.RUN.NextArg
bcs .4 bcs .7
lda (ZPPtr1) lda (ZPPtr1)
cmp #'-' cmp #'-'
@ -116,31 +156,36 @@ CS.RUN.CheckArgs
sta hFile sta hFile
bra CS.RUN.CheckArgs bra CS.RUN.CheckArgs
*--------------------------------------
.1 ldy #1 .1 ldy #1
lda (ZPPtr1),y lda (ZPPtr1),y
beq .97
ldx #OptionList.Cnt-1 .2 ldx #OptionList.Cnt-1
.2 cmp OptionList,x .3 cmp OptionList,x
beq .3 beq .4
dex dex
bpl .2 bpl .3
bra .97 bra .97
.3 txa .4 txa
lsr lsr
beq .98 beq .98 -H or -h
tax tax
lda #$80 sec
sta bIgnoreCase-1,x ror bIgnoreCase-1,x
bra CS.RUN.CheckArgs iny
lda (ZPPtr1),y
bne .2
.4 lda hFile bra CS.RUN.CheckArgs
bne .80 *--------------------------------------
.7 lda hFile
bne .8
ldy #S.PS.hStdIn ldy #S.PS.hStdIn
lda (pPS),y lda (pPS),y
@ -157,17 +202,10 @@ CS.RUN.CheckArgs
lda (pPS),y lda (pPS),y
sta hFile sta hFile
.80 >LDYAI 256 .8 clc
>SYSCALL GetMem
bcs .9
>STYA ZPBufPtr
stx hBuf
* clc
.9 rts .9 rts
*--------------------------------------
.97 lda #E.SYN .97 lda #E.SYN
.98 pha .98 pha
@ -239,7 +277,14 @@ CS.RUN.PRINT >LDYA ZPBufPtr
eor bInvertMatch eor bInvertMatch
bpl .8 bpl .8
lda bLineNum sec
ror bFound
lda bQuiet
ora bSilent
bmi .8
bit bLineNum
bpl .7 bpl .7
>PUSHW L.MSG.NUMLINE >PUSHW L.MSG.NUMLINE
@ -286,16 +331,18 @@ CS.DOEVENT sec
*-------------------------------------- *--------------------------------------
CS.END CS.END
*-------------------------------------- *--------------------------------------
OptionList .AS "HhIiNnVv" OptionList .AS "HhIiNnQqSsVv"
OptionList.Cnt .EQ *-OptionList OptionList.Cnt .EQ *-OptionList
*-------------------------------------- *--------------------------------------
MSG.USAGE .AS "Usage : GREP <pattern> <File> or CMD|GREP <pattern>\r\n" MSG.USAGE .CS "Usage : GREP <pattern> <File> or CMD|GREP <pattern>\r\n"
.AS " -H : This help screen\r\n" .CS " -H : This help screen\r\n"
.AS " -I : Ignore Case\r\n" .CS " -I : Ignore Case\r\n"
.AS " -N : Print line Number\r\n" .CS " -N : Print line Number\r\n"
.AS " -V : Invert Match" .CS " -Q : Quiet Mode\r\n"
MSG.CRLF .AZ "\r\n" .CS " -S : Silent Mode\r\n"
MSG.NUMLINE .AZ "%5D:" .CS " -V : Invert Match"
MSG.CRLF .CZ "\r\n"
MSG.NUMLINE .CZ "%5D:"
*-------------------------------------- *--------------------------------------
.DUMMY .DUMMY
.OR 0 .OR 0