ILIAS  Release_4_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
MagicConfig.php
Go to the documentation of this file.
1 <?
2 
3 /*
4 
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9 
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14 
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 
19 */
20 
22 {
23  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  function detect_cpp()
114  {
115  return !(strpos($this->file, "//") === false);
116  }
117 
118  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)) return true;
130  else return false;
131  }
132 
133  function detect_perl()
134  {
135  if (preg_match("/^#!\s+\/bin\/perl/", $this->file)
136  || preg_match("/^eval\s+\"exec\s+\/bin\/perl/", $this->file)
137  || preg_match("/^#!\s+\/usr\/bin\/perl/", $this->file)
138  || preg_match("/^eval\s+\"exec\s+\/usr\/bin\/perl/", $this->file)
139  || preg_match("/^#!\s+\/usr\/local\/bin\/perl/", $this->file)
140  || preg_match("/^eval\s+\"exec\s+\/usr\/local\/bin\/perl/", $this->file)) return true;
141  else return false;
142  }
143 
144  function detect_bash()
145  {
146  if (preg_match("/^#!\s+\/bin\/bash/", $this->file)
147  || preg_match("/^#!\s+\/usr\/local\/bin\/bash/", $this->file)) return true;
148  else return false;
149  }
150 
151  function detect_rc()
152  {
153  if (preg_match("/^#!\s+\/bin\/rc/", $this->file)) return true;
154  else return false;
155  }
156 
157  function detect_env()
158  {
159  if (preg_match("/^#!\s*\/usr\/bin\/env/", $this->file)) return true;
160  else return false;
161  }
162 
164  {
165  if (preg_match("/^#!/", $this->file)) return true;
166  else return false;
167  }
168 
169  function detect_diff()
170  {
171  if (preg_match("/^diff\s+/", $this->file)
172  || preg_match("/^\*\*\*\s+/", $this->file)
173  || preg_match("/^Only\s+in\s+/", $this->file)
174  || preg_match("/^Common\s+subdirectories:\s+/", $this->file)) return true;
175  else return false;
176  }
177 
178  function detect_xdiff()
179  {
180  if (preg_match("/^%XDZ/", $this->file)) return true;
181  else return false;
182  }
183 
184  function detect_swf()
185  {
186  if (preg_match("/^FWS/", $this->file)) return true;
187  else return false;
188  }
189 
190  function detect_psfont()
191  {
192  if (preg_match("/^(.*?)PS-AdobeFont-1\.0/", $this->file)) return true;
193  else return false;
194  }
195 
196  function detect_lex()
197  {
198  if (substr($this->file, 53, 10)=="yyprevious"
199  || substr($this->file, 21, 17)=="generated by flex") return true;
200  else return false;
201  }
202 
203  function detect_lisp()
204  {
205  return !(strpos($this->file, ";;") === false);
206  }
207 
208  function detect_magic()
209  {
210  return preg_match("/^#\s+Magic/", $this->file);
211  }
212 
213  function detect_mime()
214  {
215  return preg_match("/^Content-Type:/", $this->file);
216  }
217 
218  function detect_postscript()
219  {
220  return (substr($this->file, 0, 2)=="%!" || substr($this->file, 0, 3)==(string)(4)."%!");
221  }
222 
223  function detect_rtf()
224  {
225  return substr($this->file, 0, 5)=="{\\rtf";
226  }
227 
228  function detect_html()
229  {
230  if (preg_match("/\s*<!doctype\s+html/", $this->file)
231  || preg_match("/\s*<head/", $this->file)
232  || preg_match("/\s*<title/", $this->file)
233  || preg_match("/\s*<html/", $this->file)) return true;
234  else return false;
235  }
236 
237  function detect_xml()
238  {
239  if (preg_match("/\s*<\?xml/", $this->file)) return true;
240  else return false;
241  }
242 
243  function detect_sgml()
244  {
245  if (preg_match("/\s*<!doctype/", $this->file)
246  || preg_match("/\s*<!subdoc/", $this->file)
247  || preg_match("/\s*<!--/", $this->file)) return true;
248  else return false;
249  }
250 
251  // --- Images
252 
253  function detect_gif()
254  {
255  return (substr($this->file, 0, 6) == "GIF89a");
256  }
257 
258  function detect_jpeg()
259  {
260  return !(strpos(substr($this->file, 0, 16), "JFIF") === false);
261  }
262 
263  function detect_png()
264  {
265  $arr = unpack("C*", $this->file);
266  if (sizeof($arr)<9) return false;
267  return ($arr[1] == 0x89 && $arr[2] == 0x50
268  && $arr[3] == 0x4E && $arr[4] == 0x47
269  && $arr[5] == 0x0D && $arr[6] == 0x0A
270  && $arr[7] == 0x1A && $arr[8] == 0x0A);
271  }
272 
273  function detect_bmp()
274  {
275  return (substr($this->file, 0, 2) == "BM");
276  }
277 
278  function detect_tif()
279  {
280  return ((substr($this->file, 0, 2) == "MM") || (substr($this->file, 0, 2) == "II"));
281  }
282 }
283 
284 
285 
286 ?>