public static function import($source_name, $file = false) { if ($file === false) { $callers = debug_backtrace(); $caller = $callers[0]; $file = $caller['file']; } $relative_dir = dirname($file); $file_base = $relative_dir . '/' . $source_name; if (self::$production) { $basedir = dirname($file_base); $filename = basename($file_base); require_once realpath($basedir . "/.ppp." . $filename . ".php"); } else { $parser = new PPP_Parser(array('init' => false)); $content = $parser->parseFile(realpath($file_base . ".ppp")); eval($content); } }
/** * main * * @access public * @return void */ public function main() { // Load options, and print help if appropriate $config = $this->getopts(array('file:' => 'f:', 'help' => 'h', 'output:' => 'o:')); if ($config['help']) { $this->out($this->help_string); return 0; } // Open input file $input = null; if (empty($config['file'])) { $this->err("-f / --file argument is required!"); return 1; } $input = fopen($config['file'], 'r'); if (!$input) { $this->err("Error reading input from {$config['file']}"); return 1; } // Verify contents of the file $contents = stream_get_contents($input); if (empty($contents)) { $this->err("Cannot parse empty data!"); return 1; } // Create a parser and parse the contents $parser = new PPP_Parser(); $parsed = $parser->parse($contents); // Push output to STDOUT or to file, if provided if (empty($config['output'])) { $this->out($parsed); return 0; } if (file_put_contents($config['output'], $parsed)) { return 0; } else { $this->err("Could not write to output file {$config['output']}"); return 1; } }
<?php function echocolor($text, $color = "normal", $back = 0) { $colors = array('light_red' => "[1;31m", 'light_green' => "[1;32m", 'yellow' => "[1;33m", 'light_blue' => "[1;34m", 'magenta' => "[1;35m", 'light_cyan' => "[1;36m", 'white' => "[1;37m", 'normal' => "[0m", 'black' => "[0;30m", 'red' => "[0;31m", 'green' => "[0;32m", 'brown' => "[0;33m", 'blue' => "[0;34m", 'cyan' => "[0;36m", 'bold' => "[1m", 'underscore' => "[4m", 'reverse' => "[7m"); $out = $colors["{$color}"]; $ech = chr(27) . "{$out}" . "{$text}" . chr(27) . "[0m"; if ($back) { return $ech; } else { echo $ech; } } require 'source/ppp.php'; $parser = new PPP_Parser(); $samples = opendir($sample_dir = dirname(__FILE__) . '/samples'); $output = opendir($output_dir = dirname(__FILE__) . '/output'); $failures = 0; $lines = 0; while ($path = readdir($samples)) { if ($path[0] == '.') { continue; } list($name, $ext) = explode('.', $path); $cur_sample = file_get_contents($sample_dir . '/' . $path); $cur_output = file_get_contents($output_dir . '/' . $name . '.php'); $parsed = $parser->parse($cur_sample); $output_lines = explode("\n", $cur_output); $parsed_lines = explode("\n", $parsed); $line = 0; foreach ($parsed_lines as $p_line) {