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);
43 function error($fmt) {
44 trigger_error(call_user_func_array("sprintf", func_get_args()));
47 function stdin_is_readable() {
48 $r = [STDIN
]; $w = $e = [];
49 return stream_select($r, $w, $e, 0);
52 function is_gitignored($file) {
55 if (!isset($gitignore)) {
56 if (is_readable(".gitignore")) {
57 $gitignore = explode("\n", `find | git check
-ignore
--stdin`
);
63 return in_array($file, $gitignore);
68 function xmllist(SimpleXmlElement
$dir, $p = ".", &$a = null) {
70 $p = trim($p, "/") . "/" . trim($dir["name"], "/") . "/";
71 foreach ($dir as $file) {
72 switch ($file->getName()) {
74 xmllist($file, $p, $a);
77 $a[] = sprintf("%s/%s", trim($p, "/"), trim($file["name"]));
80 error("Unknown content type: %s", $file->getName());
87 function dirlist($dir, $p = null) {
88 $p = implode("/", array_filter([trim($p, "/"), trim($dir, "/")]));
89 foreach (scandir($p) as $file) {