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
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
Create directories

Binary file not shown.

View File

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