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

syntax_highlight/php/HFile/HFile_conv.php

Go to the documentation of this file.
00001 
00002 <?php
00003 
00004 ini_set('max_execution_time', 300000);
00005 
00006 $BEAUT_PATH = realpath(".")."/syntax_highlight/php";
00007 if (!isset ($BEAUT_PATH)) return;
00008 require "$BEAUT_PATH/Beautifier/HFile.php";
00009 
00010 //######## Configuration Conversion functions
00011 
00012 // Function to go through an Ultraedit-style configuration file and convert to a PHP include
00013 
00014 function HFile_print_php_file($tofile = 1)
00015 {
00016 
00017 global $LANGNAME;
00018         global $indent, $unindent, $stringchars, $config, $keywords, $delimiters, $lang_name;
00019         global $linecommenton, $blockcommenton, $blockcommentoff;
00020         global $perl, $nocase, $notrim;
00021         if ($tofile) print "<?php\n"; else print "&lt;?\n";
00022         
00023         print 'require_once(\'HFile.php\');'."\n";
00024         print '  class HFile_'.$LANGNAME.' extends HFile{'."\n";
00025         print '   function HFile_'.$LANGNAME.'(){'."\n";
00026         print '     $this->HFile();     '."\n";
00027 
00028         
00029         
00030         print "######################################\n";
00031         print "# Beautifier Highlighting Configuration File \n";
00032         print "# $lang_name\n";
00033         print "######################################\n";
00034         print "# Flags\n\n";
00035         dump_var($nocase,                       "\$this->nocase            ");
00036         dump_var($notrim,                       "\$this->notrim            ");
00037         dump_var($perl,                         "\$this->perl              ");
00038         print "\n# Colours\n\n";
00039         $used_categories = get_categories();
00040         dump_colours($used_categories);
00041         dump_var("blue",                        "\$this->quotecolour       ");
00042         dump_var("green",                       "\$this->blockcommentcolour");
00043         dump_var("green",                       "\$this->linecommentcolour ");
00044         print "\n# Indent Strings\n\n";
00045         dump_array($indent,                     "\$this->indent            ");
00046         dump_array($unindent,                   "\$this->unindent          ");
00047         print "\n# String characters and delimiters\n\n";
00048         dump_array($stringchars,                "\$this->stringchars       ");
00049         dump_array($delimiters,                 "\$this->delimiters        ");
00050         dump_var  ($escchar,                    "\$this->escchar           ");
00051         print "\n# Comment settings\n\n";
00052         dump_var  ($linecommenton,              "\$this->linecommenton     ");
00053         dump_var  ($blockcommenton,             "\$this->blockcommenton    ");
00054         dump_var  ($blockcommentoff,            "\$this->blockcommentoff   ");
00055         print "\n# Keywords (keyword mapping to colour number)\n\n";
00056         dump_hash ($keywords,                   "\$this->keywords          ");
00057         print "\n# Special extensions\n";
00058         dump_linkscripts($used_categories);
00059         if ($tofile) print "\n}?>"; else print "}\n?&gt;";
00060 }
00061 
00062 function get_categories()
00063 {
00064         global $keywords;
00065         $usedcats = array();
00066         
00067         foreach(array_keys($keywords) as $k)
00068         {
00069                 $cat = $keywords[$k];
00070                 if (!in_array($cat, $usedcats)) array_push($usedcats, $cat);
00071         }
00072         return $usedcats;
00073 }
00074 
00075 function dump_linkscripts($cats)
00076 {
00077         print "
00078 // Each category can specify a PHP function that returns an altered
00079 // version of the keyword.
00080         # This link is then placed in a <a href=\"...\">foo</a>; structure around keyword 'foo' - which is
00081         \n\n";
00082         
00083         $linkhash = array();
00084         
00085         foreach($cats as $c)
00086         {
00087                 $linkhash{$c} = "donothing";
00088         }
00089         
00090         dump_hash($linkhash, "\$this->linkscripts    ");
00091         print "}\n# DoNothing link function\n\n";
00092         print "function donothing(\$keywordin)\n{\n     return \$keywordin;\n}\n";
00093 }
00094 
00095 function dump_colours($cats)
00096 {
00097         global $colours;
00098         
00099         $usedcols = array();
00100         foreach($cats as $c)
00101         {
00102                 array_push($usedcols, $colours[$c-1]);
00103         }
00104         dump_array($usedcols, "\$this->colours        ");
00105 }
00106 
00107 function dump_var($variable, $name)
00108 {
00109         print $name."   = \"".addslashes($variable)."\";\n";
00110 }
00111 
00112 function dump_array($array, $name)
00113 {
00114         $first = 1;
00115         print $name."   = array(";
00116         foreach($array as $a)
00117         {
00118                 if (!$first) print ", "; else $first = 0;
00119                 print "\"".addslashes($a)."\"";
00120         }
00121         print ");\n";
00122 }
00123 
00124 function dump_hash($hash, $name)
00125 {
00126         $first = 1;
00127         print $name."   = array(";
00128         foreach(array_keys($hash) as $k)
00129         {
00130                 if (!$first) print ", "; else $first = 0;
00131                 print "\n                       \"".addslashes($k)."\"";
00132                 print " => \"".addslashes($hash[$k])."\"";
00133         }
00134         print ");\n";
00135 }
00136 
00137 function convert($file){
00138   $file = str_replace("./", "", $file);
00139   global $LANGNAME;
00140   $LANGNAME = $file;
00141   $LANGNAME = str_replace(".txt", "", $LANGNAME);
00142   
00143   $fileout = '../object/'.$LANGNAME . '.php';
00144 
00145   print "Writing $file to $fileout\n";
00146   
00147         HFile_parse_file($file);
00148 
00149         ob_start();
00150         ob_implicit_flush(0);
00151 
00152         HFile_print_php_file(isset($fileout));
00153         $out = ob_get_contents();               
00154         ob_end_clean(); 
00155   
00156         if (isset($fileout))
00157         {
00158                 $fd = fopen($fileout, "w");
00159                 fputs($fd, $out);
00160                 fclose($fd);
00161         }
00162   
00163 
00164 
00165 
00166   
00167 
00168 
00169 }
00170 
00171 
00172 convert($argv[1]);
00173 
00174 
00175 
00176 
00177 ?>

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