function adjusted_name($script_name, $adjust_for_regression = 0) { global $subject_dir; phc_assert($subject_dir !== "", "subject_dir must be defined before this function is called"); // we need the prefix for the check if ($adjust_for_regression) { // add the size-dependent suffix if (is_labelled($script_name, "size-dependent")) { if (is_32_bit()) { $script_name .= ".32bit"; } else { $script_name .= ".64bit"; } } } // remove the prefix $prefix = $subject_dir; $prefix = preg_replace("/\\//", "\\/", $prefix); $script_name = preg_replace("/{$prefix}/", "", $script_name); return $script_name; }
function get_all_scripts_in_dir($directory) { phc_assert($directory != '', "Cant search blank directory"); phc_assert(preg_match("/\\/\$/", $directory), "directory '{$directory}' must end in a '/'"); $command = "find -L {$directory} -name \"*.php\""; $result = explode("\n", trim(`{$command}`)); if (count($result) == 1 && $result[0] == "") { return array(); } # I have no idea why, but on OSX `find` returns two forward-slashes in some # cases, and PHP won't open directories structured like that. foreach ($result as &$line) { $line = preg_replace("!//!", "/", $line); } return $result; }
function get_annotations($subject) { $out = file_get_contents($subject); $available = get_available_annotations(); $triples = array(); // match the annotations $lines = split("\n", $out); $pregs = array("/#(.*)\$/", "/\\/\\/(.*)\$/", "/\\/\\*(.*)\\*\\//"); foreach ($lines as $line) { foreach ($pregs as $preg) { if (preg_match("{$preg}", $line, $line_match)) { if (preg_match("/\\s*\n\t\t\t\t\t\t\t\t{\t\t\t\t\t\t# start matching string\n\t\t\t\t\t\t\t\t\t\\s*\n\t\t\t\t\t\t\t\t\t(\\S+\t\t\t\t# start match with name\n\t\t\t\t\t\t\t\t\t\\s*\n\t\t\t\t\t\t\t\t\t(\\(.*?\\))?\t\t# match optional argument\n\t\t\t\t\t\t\t\t\t:\n\t\t\t\t\t\t\t\t\t\\s*\n\t\t\t\t\t\t\t\t\t\\S.*\\S)\t\t\t# end match with value\n\t\t\t\t\t\t\t\t\t\\s*\n\t\t\t\t\t\t\t\t}\t\t\t\t\t\t# finish match\n\t\t\t\t\t\t\t\\s*/x", $line_match[1], $comment_match)) { $triples[] = $comment_match[1]; } } } } // Extract the annotations, adding dependencies and options. $result = array(); while (count($triples) > 0) { $triple = array_shift($triples); // match "name (options): value preg_match("/^\n\t\t\t\t\t\t(\\S+)\t\t\t\t# match name\n\t\t\t\t\t\t\\s*\n\t\t\t\t\t\t(?:\t\t\t\t# dont put this group into the result\n\t\t\t\t\t\t\t\\(\n\t\t\t\t\t\t\t\t(.*?)\t\t# match options, but not the brackets\n\t\t\t\t\t\t\t\\)\t\n\t\t\t\t\t\t)?\t\t\t\t\t# options is optional\n\t\t\t\t\t\t:\n\t\t\t\t\t\t\\s*\n\t\t\t\t\t\t(\\S.*\\S)\t\t\t# match value\n\t\t\t\t\t\t\\s*\n\t\t\t\t\t\$/x", $triple, $triple_match); $name = $triple_match[1]; $options = parse_options($triple_match[2]); $value = $triple_match[3]; phc_assert(isset($available[$name]), "Annotation {$name} not available, in {$subject}"); $available[$name]->add_value($options, $value); $result[$name] = $available[$name]; $triples = array_merge($available[$name]->get_dependencies(), $triples); } // Add default that hasnt been added. foreach ($available as $name => $annotation) { if (count($annotation->values) == 0 && $annotation->get_default_value() !== NULL) { $annotation->add_value($annotation->get_default_options(), $annotation->get_default_value()); $result[] = $annotation; } } return $result; }
function get_all_scripts_in_dir($directory) { phc_assert($directory != '', "Cant search blank directory"); phc_assert(preg_match("/\\/\$/", $directory), "directory '{$directory}' must end in a '/'"); $command = "find -L {$directory} -name \"*.php\""; $result = split("\n", trim(`{$command}`)); if (count($result) == 1 && $result[0] == "") { return array(); } return $result; }