ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
MagicConfig.php
Go to the documentation of this file.
1<?php
2
3/*
4
5This program is free software; you can redistribute it and/or modify
6it under the terms of the GNU General Public License as published by
7the Free Software Foundation; either version 2 of the License, or
8(at your option) any later version.
9
10This program is distributed in the hope that it will be useful,
11but WITHOUT ANY WARRANTY; without even the implied warranty of
12MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13GNU General Public License for more details.
14
15You should have received a copy of the GNU General Public License
16along with this program; if not, write to the Free Software
17Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
19*/
20
22{
23 public function MagicConfig()
24 {
25 $this->separator = ".";
26
27 $this->extensions = array(
28 "a" => "ada95",
29 "ada" => "ada95",
30 "adb" => "ada95",
31 "ads" => "ada95",
32 "asm" => "asm_x86",
33 "asp" => "jscript|vb|vbdotnet",
34 "awk" => "awk",
35 "bas" => "vb|vbdotnet",
36 "c" => "c",
37 "cbl" => "cobol",
38 "cls" => "vb|vbdotnet",
39 "cob" => "cobol",
40 "cpy" => "cobol",
41 "cpp" => "cpp",
42 "cs" => "csharp",
43 "cxx" => "cpp",
44 "dat" => "mumps",
45 "dpr" => "delphi",
46 "e" => "eiffel|euphoria",
47 "ew" => "euphoria",
48 "eu" => "euphoria",
49 "ex" => "euphoria",
50 "exw" => "euphoria",
51 "exu" => "euphoria",
52 "frm" => "vb|vbdotnet",
53 "h" => "c",
54 "hpp" => "cpp",
55 "inc" => "turbopascal|vb|vbdotnet",
56 "java" => "javaswing",
57 "js" => "jscript|javascript",
58 "lsp" => "lisp",
59 "m" => "mumps",
60 "pas" => "delphi|turbopascal",
61 "php" => "php3",
62 "php3" => "php3",
63 "php4" => "php3",
64 "pl" => "perl",
65 "pm" => "perl",
66 "py" => "python",
67 "pyc" => "python",
68 "rtn" => "mumps",
69 "scm" => "scheme",
70 "vb" => "vb|vbdotnet",
71 "vbs" => "vb|vbdotnet|vbscript",
72 "wsf" => "vbscript"
73 );
74
75 $this->langfunctions = array(
76 // ASCII
77 // --- Languages
78 "awk",
79 "bash",
80 "perl",
81 "rc",
82 "env",
83 "cpp",
84 "diff",
85 "xdiff",
86 "swf",
87 "psfont",
88 "lex",
89 "lisp",
90 "magic",
91 "mime",
92 // --- Markup
93 "postscript",
94 "rtf",
95 "html",
96 "xml",
97 "sgml",
98 // --- Generic tests
99 "genericshell");
100
101 $this->binfunctions = array(
102 // Binary
103 // --- Images
104 "gif",
105 "jpeg",
106 "png",
107 "bmp",
108 "tif"
109 // --- Compressed
110 );
111 }
112
113 public function detect_cpp()
114 {
115 return !(strpos($this->file, "//") === false);
116 }
117
118 public function detect_awk()
119 {
120 if (preg_match("/^#!\s+\/bin\/nawk/", $this->file)
121 || preg_match("/^#!\s+\/bin\/nawk/", $this->file)
122 || preg_match("/^#!\s+\/usr\/bin\/nawk/", $this->file)
123 || preg_match("/^#!\s+\/usr\/local\/bin\/nawk/", $this->file)
124 || preg_match("/^#!\s+\/bin\/gawk/", $this->file)
125 || preg_match("/^#!\s+\/usr\/bin\/gawk/", $this->file)
126 || preg_match("/^#!\s+\/usr\/local\/bin\/gawk/", $this->file)
127 || preg_match("/^#!\s+\/bin\/awk/", $this->file)
128 || preg_match("/^#!\s+\/usr\/bin\/awk/", $this->file)
129 || preg_match("/^BEGIN\s+/", $this->file)) {
130 return true;
131 } else {
132 return false;
133 }
134 }
135
136 public function detect_perl()
137 {
138 if (preg_match("/^#!\s+\/bin\/perl/", $this->file)
139 || preg_match("/^eval\s+\"exec\s+\/bin\/perl/", $this->file)
140 || preg_match("/^#!\s+\/usr\/bin\/perl/", $this->file)
141 || preg_match("/^eval\s+\"exec\s+\/usr\/bin\/perl/", $this->file)
142 || preg_match("/^#!\s+\/usr\/local\/bin\/perl/", $this->file)
143 || preg_match("/^eval\s+\"exec\s+\/usr\/local\/bin\/perl/", $this->file)) {
144 return true;
145 } else {
146 return false;
147 }
148 }
149
150 public function detect_bash()
151 {
152 if (preg_match("/^#!\s+\/bin\/bash/", $this->file)
153 || preg_match("/^#!\s+\/usr\/local\/bin\/bash/", $this->file)) {
154 return true;
155 } else {
156 return false;
157 }
158 }
159
160 public function detect_rc()
161 {
162 if (preg_match("/^#!\s+\/bin\/rc/", $this->file)) {
163 return true;
164 } else {
165 return false;
166 }
167 }
168
169 public function detect_env()
170 {
171 if (preg_match("/^#!\s*\/usr\/bin\/env/", $this->file)) {
172 return true;
173 } else {
174 return false;
175 }
176 }
177
178 public function detect_genericshell()
179 {
180 if (preg_match("/^#!/", $this->file)) {
181 return true;
182 } else {
183 return false;
184 }
185 }
186
187 public function detect_diff()
188 {
189 if (preg_match("/^diff\s+/", $this->file)
190 || preg_match("/^\*\*\*\s+/", $this->file)
191 || preg_match("/^Only\s+in\s+/", $this->file)
192 || preg_match("/^Common\s+subdirectories:\s+/", $this->file)) {
193 return true;
194 } else {
195 return false;
196 }
197 }
198
199 public function detect_xdiff()
200 {
201 if (preg_match("/^%XDZ/", $this->file)) {
202 return true;
203 } else {
204 return false;
205 }
206 }
207
208 public function detect_swf()
209 {
210 if (preg_match("/^FWS/", $this->file)) {
211 return true;
212 } else {
213 return false;
214 }
215 }
216
217 public function detect_psfont()
218 {
219 if (preg_match("/^(.*?)PS-AdobeFont-1\.0/", $this->file)) {
220 return true;
221 } else {
222 return false;
223 }
224 }
225
226 public function detect_lex()
227 {
228 if (substr($this->file, 53, 10)=="yyprevious"
229 || substr($this->file, 21, 17)=="generated by flex") {
230 return true;
231 } else {
232 return false;
233 }
234 }
235
236 public function detect_lisp()
237 {
238 return !(strpos($this->file, ";;") === false);
239 }
240
241 public function detect_magic()
242 {
243 return preg_match("/^#\s+Magic/", $this->file);
244 }
245
246 public function detect_mime()
247 {
248 return preg_match("/^Content-Type:/", $this->file);
249 }
250
251 public function detect_postscript()
252 {
253 return (substr($this->file, 0, 2)=="%!" || substr($this->file, 0, 3)==(string) (4) . "%!");
254 }
255
256 public function detect_rtf()
257 {
258 return substr($this->file, 0, 5)=="{\\rtf";
259 }
260
261 public function detect_html()
262 {
263 if (preg_match("/\s*<!doctype\s+html/", $this->file)
264 || preg_match("/\s*<head/", $this->file)
265 || preg_match("/\s*<title/", $this->file)
266 || preg_match("/\s*<html/", $this->file)) {
267 return true;
268 } else {
269 return false;
270 }
271 }
272
273 public function detect_xml()
274 {
275 if (preg_match("/\s*<\?xml/", $this->file)) {
276 return true;
277 } else {
278 return false;
279 }
280 }
281
282 public function detect_sgml()
283 {
284 if (preg_match("/\s*<!doctype/", $this->file)
285 || preg_match("/\s*<!subdoc/", $this->file)
286 || preg_match("/\s*<!--/", $this->file)) {
287 return true;
288 } else {
289 return false;
290 }
291 }
292
293 // --- Images
294
295 public function detect_gif()
296 {
297 return (substr($this->file, 0, 6) == "GIF89a");
298 }
299
300 public function detect_jpeg()
301 {
302 return !(strpos(substr($this->file, 0, 16), "JFIF") === false);
303 }
304
305 public function detect_png()
306 {
307 $arr = unpack("C*", $this->file);
308 if (sizeof($arr)<9) {
309 return false;
310 }
311 return ($arr[1] == 0x89 && $arr[2] == 0x50
312 && $arr[3] == 0x4E && $arr[4] == 0x47
313 && $arr[5] == 0x0D && $arr[6] == 0x0A
314 && $arr[7] == 0x1A && $arr[8] == 0x0A);
315 }
316
317 public function detect_bmp()
318 {
319 return (substr($this->file, 0, 2) == "BM");
320 }
321
322 public function detect_tif()
323 {
324 return ((substr($this->file, 0, 2) == "MM") || (substr($this->file, 0, 2) == "II"));
325 }
326}
An exception for terminatinating execution or to throw for unit testing.