tools.grep: adding "grep" tool.
parent
b8cbe9d64d
commit
197b944c7e
|
@ -0,0 +1,15 @@
|
||||||
|
USING: tools.deploy.config ;
|
||||||
|
H{
|
||||||
|
{ deploy-name "grep" }
|
||||||
|
{ deploy-ui? f }
|
||||||
|
{ deploy-c-types? t }
|
||||||
|
{ deploy-console? t }
|
||||||
|
{ deploy-unicode? f }
|
||||||
|
{ "stop-after-last-window?" t }
|
||||||
|
{ deploy-io 3 }
|
||||||
|
{ deploy-reflection 6 }
|
||||||
|
{ deploy-word-props? t }
|
||||||
|
{ deploy-math? t }
|
||||||
|
{ deploy-threads? t }
|
||||||
|
{ deploy-word-defs? t }
|
||||||
|
}
|
|
@ -0,0 +1,31 @@
|
||||||
|
|
||||||
|
USING: kernel fry io io.files io.encodings.ascii sequences
|
||||||
|
regexp command-line namespaces ;
|
||||||
|
|
||||||
|
IN: tools.grep
|
||||||
|
|
||||||
|
! TODO: getopt
|
||||||
|
! TODO: color
|
||||||
|
! TODO: case-insensitive
|
||||||
|
|
||||||
|
: grep-lines ( regexpt -- )
|
||||||
|
'[ dup _ matches? [ print ] [ drop ] if ] each-line ;
|
||||||
|
|
||||||
|
: grep-file ( pattern filename -- )
|
||||||
|
ascii [ grep-lines ] with-file-reader ;
|
||||||
|
|
||||||
|
: grep-usage ( -- )
|
||||||
|
"Usage: factor grep.factor <pattern> [<file>...]" print ;
|
||||||
|
|
||||||
|
: run-grep ( -- )
|
||||||
|
command-line get [
|
||||||
|
grep-usage
|
||||||
|
] [
|
||||||
|
unclip ".*" dup surround <regexp> swap [
|
||||||
|
grep-lines
|
||||||
|
] [
|
||||||
|
[ grep-file ] with each
|
||||||
|
] if-empty
|
||||||
|
] if-empty ;
|
||||||
|
|
||||||
|
MAIN: run-grep
|
Loading…
Reference in New Issue