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