From de5cb6329b4e6a4c409d1418f16a3488a53ca953 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Sun, 27 Nov 2011 11:29:44 -0500 Subject: This is what was deployed on the lnns server --- shell/bin/grep.php | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 shell/bin/grep.php (limited to 'shell/bin/grep.php') diff --git a/shell/bin/grep.php b/shell/bin/grep.php new file mode 100644 index 0000000..c73b911 --- /dev/null +++ b/shell/bin/grep.php @@ -0,0 +1,52 @@ + $line_contents) { + if (preg_match($pattern,$line_contents)>0) { + if ( + (self::flag($flags,'r') && !self::flag($flags,'h')) // recursive + || (self::flag($flags,'H')) // or explicit + ) { echo htmlentities($file).': '; } + if (self::flag($flags,'n')) { echo $line_number.': '; } + echo htmlentities($line_contents)."\n"; + } + } + } + + public static function main($args, $env) { + $me = array_shift($args); + $flags = ''; + while (substr($args[0],0,1) == '-') { + $flags .= array_shift($args); + } + $flags = preg_replace('/[ -]/','',$flags); + $pattern = array_shift($args); + foreach ($args as $file) { + if (self::flag($flags,'r')) { self::recurse_grep($pattern, $file, $flags); } + else { self::grep($pattern, $file, $flags); } + } + } +} -- cgit v1.2.3