• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

syntax_highlight/php/Beautifier/MagicConfig.php

Go to the documentation of this file.
00001 <?
00002 
00003 /*
00004 
00005 This program is free software; you can redistribute it and/or modify
00006 it under the terms of the GNU General Public License as published by
00007 the Free Software Foundation; either version 2 of the License, or
00008 (at your option) any later version.
00009 
00010 This program is distributed in the hope that it will be useful,
00011 but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 GNU General Public License for more details.
00014 
00015 You should have received a copy of the GNU General Public License
00016 along with this program; if not, write to the Free Software
00017 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018 
00019 */
00020 
00021 class MagicConfig
00022 {
00023         function MagicConfig()
00024         {
00025                 $this->separator = ".";
00026 
00027                 $this->extensions = array(
00028                         "a"     => "ada95",
00029                         "ada"   => "ada95",
00030                         "adb"   => "ada95",
00031                         "ads"   => "ada95",
00032                         "asm"   => "asm_x86",
00033                         "asp"   => "jscript|vb|vbdotnet",
00034                         "awk"   => "awk",
00035                         "bas"   => "vb|vbdotnet",
00036                         "c"     => "c",
00037                         "cbl"   => "cobol",
00038                         "cls"   => "vb|vbdotnet",
00039                         "cob"   => "cobol",
00040                         "cpy"   => "cobol",
00041                         "cpp"   => "cpp",
00042                         "cs"    => "csharp",
00043                         "cxx"   => "cpp",
00044                         "dat"   => "mumps",
00045                         "dpr"   => "delphi",
00046                         "e"     => "eiffel|euphoria",
00047                         "ew"    => "euphoria",
00048                         "eu"    => "euphoria",
00049                         "ex"    => "euphoria",
00050                         "exw"   => "euphoria",
00051                         "exu"   => "euphoria",
00052                         "frm"   => "vb|vbdotnet",
00053                         "h"     => "c", 
00054                         "hpp"   => "cpp",
00055                         "inc"   => "turbopascal|vb|vbdotnet",
00056                         "java"  => "javaswing",
00057                         "js"    => "jscript|javascript",
00058                         "lsp"   => "lisp",
00059                         "m"     => "mumps",
00060                         "pas"   => "delphi|turbopascal",
00061                         "php"   => "php3",
00062                         "php3"  => "php3",
00063                         "php4"  => "php3",
00064                         "pl"    => "perl",
00065                         "pm"    => "perl",
00066                         "py"    => "python",
00067                         "pyc"   => "python",
00068                         "rtn"   => "mumps",
00069                         "scm"   => "scheme",
00070                         "vb"    => "vb|vbdotnet",
00071                         "vbs"   => "vb|vbdotnet|vbscript",
00072                         "wsf"   => "vbscript"
00073                 );
00074                 
00075                 $this->langfunctions = array(
00076                         // ASCII
00077                         // --- Languages
00078                         "awk",
00079                         "bash",
00080                         "perl",
00081                         "rc",
00082                         "env",
00083                         "cpp",
00084                         "diff",
00085                         "xdiff",
00086                         "swf",
00087                         "psfont",
00088                         "lex",
00089                         "lisp",
00090                         "magic",
00091                         "mime",
00092                         // --- Markup
00093                         "postscript",
00094                         "rtf",
00095                         "html",
00096                         "xml",
00097                         "sgml",
00098                         // --- Generic tests
00099                         "genericshell");
00100                         
00101                 $this->binfunctions = array(
00102                         // Binary
00103                         // --- Images
00104                         "gif",
00105                         "jpeg",
00106                         "png",
00107                         "bmp"
00108                         "tif"
00109                         // --- Compressed
00110                 );
00111         }
00112         
00113         function detect_cpp()
00114         {
00115                 return !(strpos($this->file, "//") === false);
00116         }
00117         
00118         function detect_awk()
00119         {
00120                 if (preg_match("/^#!\s+\/bin\/nawk/", $this->file)
00121                         || preg_match("/^#!\s+\/bin\/nawk/", $this->file)               
00122                         || preg_match("/^#!\s+\/usr\/bin\/nawk/", $this->file)          
00123                         || preg_match("/^#!\s+\/usr\/local\/bin\/nawk/", $this->file)   
00124                         || preg_match("/^#!\s+\/bin\/gawk/", $this->file)               
00125                         || preg_match("/^#!\s+\/usr\/bin\/gawk/", $this->file)          
00126                         || preg_match("/^#!\s+\/usr\/local\/bin\/gawk/", $this->file) 
00127                         || preg_match("/^#!\s+\/bin\/awk/", $this->file)                
00128                         || preg_match("/^#!\s+\/usr\/bin\/awk/", $this->file)           
00129                         || preg_match("/^BEGIN\s+/", $this->file)) return true; 
00130                 else return false;
00131         }
00132         
00133         function detect_perl()
00134         {
00135                 if (preg_match("/^#!\s+\/bin\/perl/", $this->file)
00136                         || preg_match("/^eval\s+\"exec\s+\/bin\/perl/", $this->file)
00137                         || preg_match("/^#!\s+\/usr\/bin\/perl/", $this->file)
00138                         || preg_match("/^eval\s+\"exec\s+\/usr\/bin\/perl/", $this->file)
00139                         || preg_match("/^#!\s+\/usr\/local\/bin\/perl/", $this->file)
00140                         || preg_match("/^eval\s+\"exec\s+\/usr\/local\/bin\/perl/", $this->file)) return true;
00141                 else return false;
00142         }
00143         
00144         function detect_bash()
00145         {
00146                 if (preg_match("/^#!\s+\/bin\/bash/", $this->file) 
00147                         || preg_match("/^#!\s+\/usr\/local\/bin\/bash/", $this->file)) return true;
00148                 else return false;
00149         }
00150         
00151         function detect_rc()
00152         {
00153                 if (preg_match("/^#!\s+\/bin\/rc/", $this->file)) return true;
00154                 else return false;
00155         }
00156         
00157         function detect_env()
00158         {
00159                 if (preg_match("/^#!\s*\/usr\/bin\/env/", $this->file)) return true;
00160                 else return false;
00161         }
00162         
00163         function detect_genericshell()
00164         {
00165                 if (preg_match("/^#!/", $this->file)) return true;
00166                 else return false;
00167         }
00168         
00169         function detect_diff()
00170         {
00171                 if (preg_match("/^diff\s+/", $this->file)
00172                         || preg_match("/^\*\*\*\s+/", $this->file)
00173                         || preg_match("/^Only\s+in\s+/", $this->file)
00174                         || preg_match("/^Common\s+subdirectories:\s+/", $this->file)) return true;
00175                 else return false;
00176         }
00177         
00178         function detect_xdiff()
00179         {
00180                 if (preg_match("/^%XDZ/", $this->file)) return true;
00181                 else return false;
00182         }
00183         
00184         function detect_swf()
00185         {
00186                 if (preg_match("/^FWS/", $this->file)) return true;
00187                 else return false;
00188         }
00189         
00190         function detect_psfont()
00191         {
00192                 if (preg_match("/^(.*?)PS-AdobeFont-1\.0/", $this->file)) return true;
00193                 else return false;
00194         }
00195         
00196         function detect_lex()
00197         {
00198                 if (substr($this->file, 53, 10)=="yyprevious"
00199                         || substr($this->file, 21, 17)=="generated by flex") return true;
00200                 else return false;
00201         }
00202         
00203         function detect_lisp()
00204         {
00205                 return !(strpos($this->file, ";;") === false);
00206         }
00207         
00208         function detect_magic()
00209         {
00210                 return preg_match("/^#\s+Magic/", $this->file);
00211         }
00212         
00213         function detect_mime()
00214         {
00215                 return preg_match("/^Content-Type:/", $this->file);
00216         }
00217         
00218         function detect_postscript()
00219         {
00220                 return (substr($this->file, 0, 2)=="%!" || substr($this->file, 0, 3)==(string)(4)."%!");
00221         }
00222         
00223         function detect_rtf()
00224         {
00225                 return substr($this->file, 0, 5)=="{\\rtf";
00226         }
00227         
00228         function detect_html()
00229         {
00230                 if (preg_match("/\s*<!doctype\s+html/", $this->file)
00231                         || preg_match("/\s*<head/", $this->file)
00232                         || preg_match("/\s*<title/", $this->file)
00233                         || preg_match("/\s*<html/", $this->file)) return true;
00234                 else return false;
00235         }
00236         
00237         function detect_xml()
00238         {
00239                 if (preg_match("/\s*<\?xml/", $this->file)) return true; 
00240                 else return false;
00241         }
00242         
00243         function detect_sgml()
00244         {
00245                 if (preg_match("/\s*<!doctype/", $this->file)
00246                         || preg_match("/\s*<!subdoc/", $this->file)
00247                         || preg_match("/\s*<!--/", $this->file)) return true;
00248                 else return false;
00249         }
00250         
00251         // --- Images
00252         
00253         function detect_gif()
00254         {
00255                 return (substr($this->file, 0, 6) == "GIF89a");
00256         }
00257         
00258         function detect_jpeg()
00259         {
00260                 return !(strpos(substr($this->file, 0, 16), "JFIF") === false);
00261         }
00262 
00263         function detect_png()
00264         {       
00265                 $arr = unpack("C*", $this->file);
00266                 if (sizeof($arr)<9) return false;
00267                 return ($arr[1] == 0x89 && $arr[2] == 0x50
00268                                 && $arr[3] == 0x4E && $arr[4] == 0x47
00269                                 && $arr[5] == 0x0D && $arr[6] == 0x0A
00270                                 && $arr[7] == 0x1A && $arr[8] == 0x0A);
00271         }
00272 
00273         function detect_bmp()
00274         {
00275                 return (substr($this->file, 0, 2) == "BM");
00276         }
00277 
00278         function detect_tif()
00279         {
00280                 return (substr($this->file, 0, 2) == "MM") || substr($this->file, 0, 2) == "II");
00281         }
00282 }
00283 
00284 
00285 
00286 ?>

Generated on Fri Dec 13 2013 09:06:39 for ILIAS Release_3_4_x_branch .rev 46804 by  doxygen 1.7.1