tools.grep: adding "grep" tool.

db4
John Benediktsson 2015-04-01 14:41:41 -07:00
parent b8cbe9d64d
commit 197b944c7e
2 changed files with 46 additions and 0 deletions

View File

@ -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 }
}

View File

@ -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