Go to the documentation of this file.00001 <?php
00002 $BEAUT_PATH = realpath(".")."/syntax_highlight/php";
00003 if (!isset ($BEAUT_PATH)) return;
00004 require "$BEAUT_PATH/Beautifier/HFile.php";
00005
00006
00007
00008
00009
00010 function HFile_print_php_file($tofile = 1)
00011 {
00012 global $indent, $unindent, $stringchars, $config, $keywords, $delimiters, $lang_name;
00013 global $linecommenton, $blockcommenton, $blockcommentoff;
00014 global $perl, $nocase, $notrim;
00015 if ($tofile) print "<?php\n"; else print "<?\n";
00016 print "######################################\n";
00017 print "# Beautifier Highlighting Configuration File \n";
00018 print "# $lang_name\n";
00019 print "######################################\n";
00020 print "# Flags\n\n";
00021 dump_var($nocase, "\$nocase ");
00022 dump_var($notrim, "\$notrim ");
00023 dump_var($perl, "\$perl ");
00024 print "\n# Colours\n\n";
00025 $used_categories = get_categories();
00026 dump_colours($used_categories);
00027 dump_var("blue", "\$quotecolour ");
00028 dump_var("green", "\$blockcommentcolour");
00029 dump_var("green", "\$linecommentcolour ");
00030 print "\n# Indent Strings\n\n";
00031 dump_array($indent, "\$indent ");
00032 dump_array($unindent, "\$unindent ");
00033 print "\n# String characters and delimiters\n\n";
00034 dump_array($stringchars, "\$stringchars ");
00035 dump_array($delimiters, "\$delimiters ");
00036 dump_var ($escchar, "\$escchar ");
00037 print "\n# Comment settings\n\n";
00038 dump_var ($linecommenton, "\$linecommenton ");
00039 dump_var ($blockcommenton, "\$blockcommenton ");
00040 dump_var ($blockcommentoff, "\$blockcommentoff ");
00041 print "\n# Keywords (keyword mapping to colour number)\n\n";
00042 dump_hash ($keywords, "\$keywords ");
00043 print "\n# Special extensions\n";
00044 dump_linkscripts($used_categories);
00045 if ($tofile) print "\n?>"; else print "\n?>";
00046 }
00047
00048 function get_categories()
00049 {
00050 global $keywords;
00051 $usedcats = array();
00052
00053 foreach(array_keys($keywords) as $k)
00054 {
00055 $cat = $keywords[$k];
00056 if (!in_array($cat, $usedcats)) array_push($usedcats, $cat);
00057 }
00058 return $usedcats;
00059 }
00060
00061 function dump_linkscripts($cats)
00062 {
00063 print "
00064 // Each category can specify a PHP function that returns an altered
00065 // version of the keyword.
00066 # This link is then placed in a <a href=\"...\">foo</a>; structure around keyword 'foo' - which is
00067 \n\n";
00068
00069 $linkhash = array();
00070
00071 foreach($cats as $c)
00072 {
00073 $linkhash{$c} = "donothing";
00074 }
00075
00076 dump_hash($linkhash, "\$linkscripts ");
00077 print "\n# DoNothing link function\n\n";
00078 print "function donothing(\$keywordin)\n{\n return \$keywordin;\n}\n";
00079 }
00080
00081 function dump_colours($cats)
00082 {
00083 global $colours;
00084
00085 $usedcols = array();
00086 foreach($cats as $c)
00087 {
00088 array_push($usedcols, $colours[$c-1]);
00089 }
00090 dump_array($usedcols, "\$colours ");
00091 }
00092
00093 function dump_var($variable, $name)
00094 {
00095 print $name." = \"".addslashes($variable)."\";\n";
00096 }
00097
00098 function dump_array($array, $name)
00099 {
00100 $first = 1;
00101 print $name." = array(";
00102 foreach($array as $a)
00103 {
00104 if (!$first) print ", "; else $first = 0;
00105 print "\"".addslashes($a)."\"";
00106 }
00107 print ");\n";
00108 }
00109
00110 function dump_hash($hash, $name)
00111 {
00112 $first = 1;
00113 print $name." = array(";
00114 foreach(array_keys($hash) as $k)
00115 {
00116 if (!$first) print ", "; else $first = 0;
00117 print "\n \"".addslashes($k)."\"";
00118 print " => \"".addslashes($hash[$k])."\"";
00119 }
00120 print ");\n";
00121 }
00122
00123 ?>
00124 <html><title>Configuration Converter</title><body>
00125 <h1>Important Note</h1>
00126 <p>This script should <b>not</b> be run on a public server. It is possible to access files other than syntax highlight files (by entering /etc/passwd, for example). Although this should not display anything useful, it is still possible that important data may be extractable. As such, only run this script <b>locally</b> (it should not be necessary to run it on a public server, anyway).</p>
00127 <form action="HFileconv.php">Please specify a syntax file to convert:<br />
00128 <input type="text" width="64" size="64" name="file" value="<?php print $file; ?>" /><br />
00129 Save to:<br />
00130 <input type="text" width="64" size="64" name="fileout" value="<?php print stripslashes($fileout); ?>" /><br />
00131 <input type="submit" /></form><hr />
00132 <pre>
00133 <?php
00134 if (isset($fileout) && $fileout == "") unset($fileout);
00135 if (isset($file) && file_exists($file))
00136 {
00137 HFile_parse_file($file);
00138 ob_start();
00139 HFile_print_php_file(isset($fileout));
00140 $out = ob_get_contents();
00141 if (isset($fileout))
00142 {
00143 $fd = fopen($fileout, "w");
00144 fputs($fd, $out);
00145 fclose($fd);
00146 }
00147 ob_end_flush();
00148 }
00149 ?>
00150 </pre>
00151 </body></html>
00152
00153
00154