mirror of
https://github.com/myvesta/vesta
synced 2025-07-05 20:41:53 -07:00
myvesta php replacement for gnu 'grep' (but without regular expression)
This commit is contained in:
parent
2f37124545
commit
888db2bc72
4 changed files with 140 additions and 6 deletions
|
@ -11,7 +11,7 @@ stream_set_blocking(STDIN, false);
|
|||
$myvesta_stdin='';
|
||||
$myvesta_f = fopen( 'php://stdin', 'r' );
|
||||
while( $myvesta_line = fgets( $myvesta_f ) ) {
|
||||
$myvesta_stdin .= $myvesta_line;
|
||||
$myvesta_stdin .= $myvesta_line;
|
||||
}
|
||||
fclose( $myvesta_f );
|
||||
|
||||
|
@ -27,13 +27,36 @@ if (!function_exists($func)) {
|
|||
if (!function_exists($func)) myvesta_throw_error(2, 'Function does not exists');
|
||||
}
|
||||
|
||||
$insert_stdin_at_position=false;
|
||||
if ($func=="myvesta_grep") $insert_stdin_at_position=1;
|
||||
|
||||
$params=array();
|
||||
|
||||
if ($myvesta_stdin!='') $params[]=$myvesta_stdin;
|
||||
$added=0;
|
||||
$stdin_content='';
|
||||
$myvesta_stdin_return_not_found=false;
|
||||
if ($myvesta_stdin!='' && $insert_stdin_at_position===false) {$params[]=$myvesta_stdin; $added++;}
|
||||
|
||||
for ($i=2; $i<$counter; $i++) {
|
||||
$argv[$i]=myvesta_fix_backslashes($argv[$i]);
|
||||
if ($insert_stdin_at_position!==false && $myvesta_stdin=='') if ($insert_stdin_at_position==$added) {$stdin_content=$argv[$i]; $added++; continue;}
|
||||
$params[]=$argv[$i];
|
||||
$added++;
|
||||
}
|
||||
if ($insert_stdin_at_position!=false) {
|
||||
if ($myvesta_stdin=='') {
|
||||
$file_or_stdin=$stdin_content;
|
||||
if (!file_exists($file_or_stdin)) {
|
||||
$myvesta_stdin_return_not_found=true;
|
||||
$myvesta_stdin='';
|
||||
} else {
|
||||
$myvesta_stdin=file_get_contents($file_or_stdin);
|
||||
}
|
||||
}
|
||||
if (isset($params[$insert_stdin_at_position])) array_splice($params, $insert_stdin_at_position, 0, array($myvesta_stdin));
|
||||
else $params[$insert_stdin_at_position]=$myvesta_stdin;
|
||||
}
|
||||
//print_r($params); exit;
|
||||
|
||||
$r=call_user_func_array($func, $params);
|
||||
if (is_bool($r)) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue