Diff of /sandbox/jlf/samples/pipeline/grep_sources.rex [r7646] .. [r7647]  Maximize  Restore

Switch to side-by-side view

--- a/sandbox/jlf/samples/pipeline/grep_sources.rex
+++ b/sandbox/jlf/samples/pipeline/grep_sources.rex
@@ -1,22 +1,13 @@
-/*
-Description :
-    For each source file found in the current directory and its subdirectories (recursively),
-    list the lines which contain the requested string.
-    The last line gives the number of matches.
-Usage :
-    cd <the root directory of the source files"
-    rexx grep_sources "my string"    -- case sensitive by default
-    rexx grep_sources "-i my string" -- for a case insensitive grep
-*/
-
+if arg() <> 1 then do ; call help ; return ; end
 use strict arg string
+string = string~strip -- You need that !!! you have a trailing space when redirecting like that : grep_sources mystring > results.txt
 caseless = ""
 if string~left(3) == "-i " then do
     caseless = "caseless"
     string = string~substr(4)
 end
 
-"."~pipe(.filetree recursive | .select {isSourceFile(value)} | .getFiles mem | .all[string] caseless | .console | .lineCount | .console)
+"."~pipe(.filetree recursive memorize | .select {isSourceFile(item)} | .fileLines memorize | .all[string] caseless | .console {dataflow["fileTree"]~item":"index item} | .lineCount | .console)
 
 ::routine isSourceFile
     use strict arg file -- a .File object
@@ -26,5 +17,14 @@
     ext = filespec("extension", name)~lower
     return "am c cls cpp def fnc frm h hpp html mak orx readme rc rex sgml txt xml"~caselessWordPos(ext) <> 0
 
+::routine help
+    say 'Description :'
+    say '    For each source file found in the current directory and its subdirectories (recursively),'
+    say '    list the lines which contain the requested string.'
+    say '    The last line gives the number of matches.'
+    say 'Usage :'
+    say '    cd <the root directory of the source files>'
+    say '    rexx grep_sources "my string"    -- case sensitive by default'
+    say '    rexx grep_sources "-i my string" -- for a case insensitive grep'
 
 ::requires "pipeline/pipe_extension.cls"

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks