ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
HFile.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
21class HFile
22{
23
24 function HFile()
25 {
26 # Language name.
27 $this->lang_name = "";
28 # Language configuration hashtable.
29 $this->indent_depth = 8;
30
31 $this->config = array();
32 $color = 0;
33 $parsing = "";
34 $this->validkeys = array();
35
36 $this->indent = array();
37 $this->unindent = array();
38 $this->blockcommenton = array();
39 $this->blockcommentoff = array();
40 $this->linecommenton = array();
41 $this->preprocessors = array();
42
43 # Zoning
44 $this->zones = array();
45
46 # Hashtable of keywords - maps from keyword to colour.
47 $this->keywords = array();
48
49 # Used for conversion from keyword -> regexp.
50 $this->keypats = array();
51
52 # Which colours to use for each 'level'.
53 $this->colours = array("blue", "purple", "gray", "brown", "blue", "purple", "gray", "brown");
54 $this->quotecolour = "blue";
55 $this->blockcommentcolour = "green";
56 $this->linecommentcolour = "green";
57 $this->stringchars = array();
58 $this->delimiters = array();
59 $this->escchar = "\\";
60
61 # Caches for the harvesters.
62 $this->comcache = "";
63 $this->stringcache = "";
64
65 # Toggles
66 $this->perl = 0;
67 $this->notrim = 0;
68 $this->nocase = 0;
69 }
70
71 function parse_file($file)
72 {
73 print "This method should not be called from here, but from an extending configuration class.<br>";
74 }
75
76 function to_perl($stub, $tofile = 1)
77 {
78 $this->used_categories = $this->_get_categories();
79 print "
80package HFile::$stub;
81
82###############################
83#
84# Beautifier Perl HFile
85# Language: $stub
86#
87###############################
88
89use Beautifier::HFile;
90@ISA = qw(HFile);
91sub new
92{
93 my( \$class ) = @_;
94 my \$self = {};
95 bless \$self, \$class;
96
97 # Flags:
98";
99 $this->_dump_var($this->nocase, " \$self->{nocase} ");
100 $this->_dump_var($this->notrim, " \$self->{notrim} ");
101 $this->_dump_var($this->perl, " \$self->{perl} ");
102 $this->_dump_perl_array($this->indent, " \$self->{indent} ");
103 $this->_dump_perl_array($this->unindent, " \$self->{unindent} ");
104 $this->_dump_perl_array($this->stringchars, " \$self->{stringchars} ");
105 $this->_dump_perl_array($this->delimiters, " \$self->{delimiters} ");
106 $this->_dump_var($this->escchar, " \$self->{escchar} ");
107 $this->_dump_perl_array($this->linecommenton, " \$self->{linecommenton} ");
108 $this->_dump_perl_array($this->blockcommenton, " \$self->{blockcommenton} ");
109 $this->_dump_perl_array($this->blockcommentoff, " \$self->{blockcommentoff}");
110 $this->_dump_perl_hash($this->keywords, " \$self->{keywords} ");
111 $this->_dump_perl_linkscripts();
112print "
113 return \$self;
114}
115
116";
117
118 $this->_dump_perl_defaultscripts();
119print "1;\n";
120 }
121
122 function to_php($stub, $tofile = 1)
123 {
124
125
126 $this->used_categories = $this->_get_categories();
127
128 if ($tofile) print "<?php\n"; else print "&lt;?\n";
129 print "require_once('psh.php');\n";
130 print "class psh_$stub extends psh\n{\n";
131 print "function psh_$stub(){\n";
132 print "\$this->psh();\n";
133 print "######################################\n";
134 print "# Beautifier Highlighting Configuration File \n";
135 print "# $this->lang_name\n";
136 print "######################################\n";
137 print "# Flags\n\n";
138 $this->_dump_var($this->nocase, "\$this->nocase ");
139 $this->_dump_var($this->notrim, "\$this->notrim ");
140 $this->_dump_var($this->perl, "\$this->perl ");
141 print "\n# Colours\n\n";
142 $this->_dump_colours();
143 $this->_dump_var("blue", "\$this->quotecolour ");
144 $this->_dump_var("green", "\$this->blockcommentcolour");
145 $this->_dump_var("green", "\$this->linecommentcolour ");
146 print "\n# Indent Strings\n\n";
147 $this->_dump_array($this->indent, "\$this->indent ");
148 $this->_dump_array($this->unindent, "\$this->unindent ");
149 print "\n# String characters and delimiters\n\n";
150 $this->_dump_array($this->stringchars, "\$this->stringchars ");
151 $this->_dump_array($this->delimiters, "\$this->delimiters ");
152 $this->_dump_var ($this->escchar, "\$this->escchar ");
153 print "\n# Comment settings\n\n";
154 $this->_dump_array($this->linecommenton, "\$this->linecommenton ");
155 $this->_dump_var ($this->blockcommenton, "\$this->blockcommenton ");
156 $this->_dump_var ($this->blockcommentoff, "\$this->blockcommentoff ");
157 print "\n# Keywords (keyword mapping to colour number)\n\n";
158 $this->_dump_hash ($this->keywords, "\$this->keywords ");
159 print "\n# Special extensions\n";
160 $this->_dump_linkscripts();
161 print "}\n";
162 if ($tofile) print "\n?>"; else print "\n?&gt;";
163 }
164
165 function _get_categories()
166 {
167 $usedcats = array();
168
169 foreach(array_keys($this->keywords) as $k)
170 {
171 $cat = $this->keywords[$k];
172 if (!in_array($cat, $usedcats)) array_push($usedcats, $cat);
173 }
174 return $usedcats;
175 }
176
177 function _dump_linkscripts()
178 {
179 print "
180# Each category can specify a PHP function that takes in the function name, and returns a string
181# to put in its place. This can be used to generate links, images, etc.\n\n";
182
183 $linkhash = array();
184
185 foreach($this->used_categories as $c)
186 {
187 $linkhash{$c} = "donothing";
188 }
189
190 $this->_dump_hash($linkhash, "\$this->linkscripts ");
191 print "}\n";
192 print "\n# DoNothing link function\n\n";
193 print "function donothing(\$keywordin)\n{\n return \$keywordin;\n}\n";
194 }
195
196 function _dump_perl_linkscripts()
197 {
198 print "
199# Each category can specify a Perl function that takes in the function name, and returns a string
200# to put in its place. This can be used to generate links, images, etc.\n\n";
201
202 $linkhash = array();
203 foreach($this->used_categories as $c)
204 {
205 $linkhash{$c} = "donothing";
206 }
207
208 $this->_dump_perl_hash($linkhash, "\$self->{linkscripts} ");
209 }
210
211 function _dump_perl_defaultscripts()
212 {
213 print "\n# DoNothing link function\n\n";
214 print "sub donothing\n{\nmy ( \$self ) = @_;\nreturn;\n}\n";
215 }
216
217 function _dump_colours()
218 {
219 $usedcols = array();
220 foreach($this->used_categories as $c)
221 {
222 array_push($usedcols, $this->colours[$c-1]);
223 }
224 $this->_dump_array($usedcols, "\$this->colours ");
225 }
226
227 function _dump_var($variable, $name)
228 {
229 print $name." = \"".addslashes($variable)."\";\n";
230 }
231
232 function _dump_array($array, $name)
233 {
234 $first = 1;
235 print $name." = array(";
236 foreach($array as $a)
237 {
238 if (!$first) print ", "; else $first = 0;
239 print "\"".addslashes($a)."\"";
240 }
241 print ");\n";
242 }
243
244 function _dump_perl_array($array, $name)
245 {
246 $first = 1;
247 print $name." = [";
248 foreach($array as $a)
249 {
250 if (!$first) print ", "; else $first = 0;
251 print "\"".addslashes($a)."\"";
252 }
253 print "];\n";
254 }
255
256 function _dump_hash($hash, $name)
257 {
258 $first = 1;
259 print $name." = array(";
260 foreach(array_keys($hash) as $k)
261 {
262 if (!$first) print ", "; else $first = 0;
263 print "\n \"".addslashes($k)."\"";
264 print " => \"".addslashes($hash[$k])."\"";
265 }
266 print ");\n";
267 }
268
269 function _dump_perl_hash($hash, $name)
270 {
271 $first = 1;
272 print $name." = {";
273 foreach(array_keys($hash) as $k)
274 {
275 if (!$first) print ", "; else $first = 0;
276 print "\n \"".addslashes($k)."\"";
277 print " => \"".addslashes($hash[$k])."\"";
278 }
279 print "};\n";
280 }
281}
282
283?>
print $file
if(! $in) print