[r7647]: sandbox / jlf / samples / pipeline / grep_sources.rex  Maximize  Restore  History

Download this file

30 lines (26 with data), 1.4 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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 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
if \ file~isFile then return .false
name = filespec("name", file~name)~lower
if "makefile"~caselessEquals(name) then return .true
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