Subversion Repositories oidplus

Rev

Rev 557 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
557 daniel-mar 1
#!/usr/bin/env php
88 daniel-mar 2
<?php
3
 
511 daniel-mar 4
/*
5
 * OIDplus 2.0
6
 * Copyright 2019 - 2021 Daniel Marschall, ViaThinkSoft
7
 *
8
 * Licensed under the Apache License, Version 2.0 (the "License");
9
 * you may not use this file except in compliance with the License.
10
 * You may obtain a copy of the License at
11
 *
12
 *     http://www.apache.org/licenses/LICENSE-2.0
13
 *
14
 * Unless required by applicable law or agreed to in writing, software
15
 * distributed under the License is distributed on an "AS IS" BASIS,
16
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
 * See the License for the specific language governing permissions and
18
 * limitations under the License.
19
 */
20
 
499 daniel-mar 21
# Source:
22
# https://svn.viathinksoft.com/cgi-bin/viewvc.cgi/vgwhois/trunk/maintenance/qa-monitor/syntax/global-syntax-check?revision=HEAD&view=markup
88 daniel-mar 23
 
24
error_reporting(E_ALL | E_NOTICE | E_STRICT | E_DEPRECATED);
25
 
26
$silent = ($argc >= 2) && ($argv[1] == '--silent');
27
 
28
$files = array();
29
 
236 daniel-mar 30
$rii = new RecursiveIteratorIterator(new RecursiveDirectoryIterator(dirname(__DIR__))); // dirname() to check the parent directory
88 daniel-mar 31
foreach ($rii as $file) {
32
        $filename = $file->getPathname();
752 daniel-mar 33
        if (strpos($filename, DIRECTORY_SEPARATOR.'.') !== false) continue; # also hide ".dir" and ".file"
88 daniel-mar 34
        if (!file_exists($filename)) continue;
35
        $files[] = $filename;
36
}
37
 
38
$baddest = 0;
39
 
40
foreach ($files as $filename) {
41
        $h = fopen($filename, 'r');
42
        $headline = fgets($h);
43
        fclose($h);
44
 
45
        $scripttype = 'n/a';
46
 
47
        if (preg_match('@#!(.+)\s@U', $headline, $m)) {
48
                $interpreter = $m[1];
49
 
50
                switch ($interpreter) {
557 daniel-mar 51
                        case '/usr/bin/env php':
88 daniel-mar 52
                        case '/usr/bin/php':
53
                                $scripttype = 'PHP';
54
                                break;
557 daniel-mar 55
                        case '/usr/bin/env perl':
88 daniel-mar 56
                        case '/usr/bin/perl':
57
                                $scripttype = 'Perl';
58
                                break;
59
                }
60
        } else if (strpos($filename, '.php') !== false) {
61
                $scripttype = 'PHP';
62
        } else if ((strpos($filename, '.pl') !== false) || (strpos($filename, '.pm') !== false)) {
63
                $scripttype = 'Perl';
64
        }
65
 
66
        $cmd = '';
67
        switch ($scripttype) {
68
                case 'PHP':
69
                        $cmd = 'php -l '.escapeshellarg($filename);
70
                        break;
71
                case 'Perl':
72
                        $cmd = 'perl -Mstrict -Mdiagnostics -cw '.escapeshellarg($filename);
73
                        break;
74
        }
75
 
76
        if ($cmd) {
77
                $out = array();
78
                exec($cmd." 2>&1", $out, $code);
79
 
80
                if ($code > $baddest) $baddest = $code;
81
 
82
                if ($code != 0) {
83
                        echo "($code) $filename: ".trim(implode("\n    ", $out))."\n";
84
                } else {
85
                        if (!$silent) echo "OK: $filename\n";
86
                }
87
        }
88
}
89
 
90
exit($baddest);
91