+
+ // subdir inside php_pear_dir
+ if (substr($f, 0, $length) == $prefix) {
+ $file_dir = dirname(substr($f, $length));
+ } else {
+ $file_dir = null;
+ }
+
+ foreach (explode(PHP_EOL, file_get_contents($f)) as $line) {
+ // skip comments
+ if (preg_match('/^\s*(#|\/\/|\*|\/\*)/', $line)) {
+ continue;
+ }
+
+ while (preg_match("/(\W|^)(require|include)(_once)?
+ \s* \(? \s*
+ (\"([^\"]*)\"|'([^']*)')
+ \s* \)? \s* ;/x", $line, $m)) {
+
+ if ($m[5] != "") {
+ $x = $m[5];
+ } else if ($m[6] != "") {
+ $x = $m[6];
+ } else {
+ continue 2;
+ }
+
+ if (substr($x, 0, 2) == './' || substr($x, -1) == '$') {
+ continue 2;
+ }
+
+ if (substr($x, -4) != '.php') {
+ continue 2;
+ }
+ $req[$x] = 1;
+ continue 2;
+ }
+
+ if (is_null($file_dir)) {
+ continue;
+ }
+
+ while (preg_match("/(\W|^)(require|include)(_once)?
+ \s* \(? \s* dirname \s* \( \s* __FILE__ \s* \) \s* \. \s*
+ (\"([^\"]*)\"|'([^']*)')
+ \s* \)? \s* ;/x", $line, $m)) {
+
+ if ($m[5] != "") {
+ $x = $m[5];
+ } else if ($m[6] != "") {
+ $x = $m[6];
+ } else {
+ continue 2;
+ }
+
+ if (substr($x, -1) == '$') {
+ continue 2;
+ }
+ if (substr($x, -4) != '.php') {
+ continue 2;
+ }
+
+ $x = "$file_dir/$x";
+ $req[$x] = 1;
+ continue;
+ }
+ }
+ }
+
+ foreach (array_keys($req) as $f) {
+ // skip self deps
+ if (array_key_exists($f, $files)) {
+ continue;
+ }
+ print "pear($f)\n";