Rev 2 | Rev 5 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2 | Rev 4 | ||
---|---|---|---|
Line 18... | Line 18... | ||
18 | */ |
18 | */ |
19 | 19 | ||
20 | // This script generates MD5 files |
20 | // This script generates MD5 files |
21 | // If there is already an MD5 file existing, only new files get appended to the existing MD5 files. |
21 | // If there is already an MD5 file existing, only new files get appended to the existing MD5 files. |
22 | 22 | ||
- | 23 | // TODO: make use of STDERR and return different exit codes |
|
- | 24 | ||
23 | function _rec($directory) { |
25 | function _rec($directory) { |
24 | if (!is_dir($directory)) { |
26 | if (!is_dir($directory)) { |
25 | die("Invalid directory path $directory\n"); |
27 | die("Invalid directory path $directory\n"); |
26 | } |
28 | } |
27 | 29 | ||
Line 42... | Line 44... | ||
42 | 44 | ||
43 | $fullpath = $directory . '/' . $file; |
45 | $fullpath = $directory . '/' . $file; |
44 | if (is_dir($fullpath)) { |
46 | if (is_dir($fullpath)) { |
45 | _rec($fullpath); |
47 | _rec($fullpath); |
46 | } else { |
48 | } else { |
- | 49 | global $show_verbose; |
|
47 | ### echo "$fullpath\n"; |
50 | if ($show_verbose) echo "$fullpath\n"; |
48 | $dir = pathinfo($fullpath, PATHINFO_DIRNAME); |
51 | $dir = pathinfo($fullpath, PATHINFO_DIRNAME); |
49 | 52 | ||
50 | if (!file_exists($md5_file)) { |
53 | if (!file_exists($md5_file)) { |
51 | file_put_contents($md5_file, "; Generated by ViaThinkSoft\r\n"); // TODO: BOM |
54 | file_put_contents($md5_file, "; Generated by ViaThinkSoft\r\n"); // TODO: BOM |
52 | } |
55 | } |
Line 77... | Line 80... | ||
77 | return $out; |
80 | return $out; |
78 | } |
81 | } |
79 | 82 | ||
80 | # --- |
83 | # --- |
81 | 84 | ||
- | 85 | $show_verbose = false; |
|
- | 86 | $dir = ''; |
|
- | 87 | ||
- | 88 | for ($i=1; $i<$argc; $i++) { |
|
82 | if ($argc != 2) { |
89 | if ($argv[$i] == '-v') { |
- | 90 | $show_verbose = true; |
|
- | 91 | } else { |
|
- | 92 | $dir = $argv[$i]; |
|
- | 93 | } |
|
- | 94 | } |
|
- | 95 | ||
- | 96 | if (empty($dir)) { |
|
83 | echo "Syntax: $argv[0] <directory>\n"; |
97 | echo "Syntax: $argv[0] [-v] <directory>\n"; |
84 | exit(2); |
98 | exit(2); |
85 | } |
99 | } |
86 | 100 | ||
87 | if (!is_dir($argv[1])) { |
101 | if (!is_dir($dir)) { |
88 | echo "Directory not found\n"; |
102 | echo "Directory not found\n"; |
89 | exit(1); |
103 | exit(1); |
90 | } |
104 | } |
91 | 105 | ||
92 | _rec($argv[1]); |
106 | _rec($dir); |
93 | 107 | ||
94 | echo "Done.\n"; |
108 | if ($show_verbose) echo "Done.\n"; |