4 ini_set("log_errors", false);
5 ini_set("display_errors", true);
8 if ($argv[1] === "-") {
13 } elseif (stdin_is_readable()) {
14 $file = "php://stdin";
16 $file = "./package.xml";
19 if (($xml = simplexml_load_file($file))) {
20 $xml_files = xmllist($xml->contents
[0]);
22 while ($dir = array_shift($dirs)) {
23 foreach (dirlist($dir) as $file) {
24 if (is_gitignored($file)) {
28 if (!in_array($file, $xml_files)) {
29 echo "Missing file $file\n";
32 $base = basename($file);
33 if ($base{0} !== ".") {
34 array_push($dirs, $file);
39 foreach ($xml_files as $file) {
40 if (!file_exists($file)) {
41 echo "Extraneous file $file\n";
48 function error($fmt) {
49 trigger_error(call_user_func_array("sprintf", func_get_args()));
52 function stdin_is_readable() {
53 $r = [STDIN
]; $w = $e = [];
54 return stream_select($r, $w, $e, 0);
57 function is_gitignored($file) {
60 if (!isset($gitignore)) {
61 if (is_readable(".gitignore")) {
62 $gitignore = explode("\n", `find | git check
-ignore
--stdin`
);
68 return in_array($file, $gitignore);
73 function xmllist(SimpleXmlElement
$dir, $p = ".", &$a = null) {
75 $p = trim($p, "/") . "/" . trim($dir["name"], "/") . "/";
76 foreach ($dir as $file) {
77 switch ($file->getName()) {
79 xmllist($file, $p, $a);
82 $a[] = sprintf("%s/%s", trim($p, "/"), trim($file["name"]));
85 error("Unknown content type: %s", $file->getName());
92 function dirlist($dir, $p = null) {
93 $p = implode("/", array_filter([trim($p, "/"), trim($dir, "/")]));
94 foreach (scandir($p) as $file) {