ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
HFile_conv.php
Go to the documentation of this file.
1 <?php
3 
4 ini_set('max_execution_time', 300000);
5 
6 $BEAUT_PATH = realpath(".") . "/Services/COPage/syntax_highlight/php";
7 if (!isset($BEAUT_PATH)) {
8  return;
9 }
10 require "$BEAUT_PATH/Beautifier/HFile.php";
11 
12 //######## Configuration Conversion functions
13 
14 // Function to go through an Ultraedit-style configuration file and convert to a PHP include
15 
16 function HFile_print_php_file($tofile = 1)
17 {
18  global $LANGNAME;
19  global $indent, $unindent, $stringchars, $config, $keywords, $delimiters, $lang_name;
20  global $linecommenton, $blockcommenton, $blockcommentoff;
21  global $perl, $nocase, $notrim;
22  if ($tofile) {
23  print "<?php\n";
24  } else {
25  print "&lt;?\n";
26  }
27 
28  print 'require_once(\'HFile.php\');' . "\n";
29  print ' class HFile_' . $LANGNAME . ' extends HFile{' . "\n";
30  print ' function HFile_' . $LANGNAME . '(){' . "\n";
31  print ' $this->HFile(); ' . "\n";
32 
33 
34 
35  print "######################################\n";
36  print "# Beautifier Highlighting Configuration File \n";
37  print "# $lang_name\n";
38  print "######################################\n";
39  print "# Flags\n\n";
40  dump_var($nocase, "\$this->nocase ");
41  dump_var($notrim, "\$this->notrim ");
42  dump_var($perl, "\$this->perl ");
43  print "\n# Colours\n\n";
44  $used_categories = get_categories();
45  dump_colours($used_categories);
46  dump_var("blue", "\$this->quotecolour ");
47  dump_var("green", "\$this->blockcommentcolour");
48  dump_var("green", "\$this->linecommentcolour ");
49  print "\n# Indent Strings\n\n";
50  dump_array($indent, "\$this->indent ");
51  dump_array($unindent, "\$this->unindent ");
52  print "\n# String characters and delimiters\n\n";
53  dump_array($stringchars, "\$this->stringchars ");
54  dump_array($delimiters, "\$this->delimiters ");
55  dump_var($escchar, "\$this->escchar ");
56  print "\n# Comment settings\n\n";
57  dump_var($linecommenton, "\$this->linecommenton ");
58  dump_var($blockcommenton, "\$this->blockcommenton ");
59  dump_var($blockcommentoff, "\$this->blockcommentoff ");
60  print "\n# Keywords (keyword mapping to colour number)\n\n";
61  dump_hash($keywords, "\$this->keywords ");
62  print "\n# Special extensions\n";
63  dump_linkscripts($used_categories);
64  if ($tofile) {
65  print "\n}?>";
66  } else {
67  print "}\n?&gt;";
68  }
69 }
70 
71 function get_categories()
72 {
73  global $keywords;
74  $usedcats = array();
75 
76  foreach (array_keys($keywords) as $k) {
77  $cat = $keywords[$k];
78  if (!in_array($cat, $usedcats)) {
79  array_push($usedcats, $cat);
80  }
81  }
82  return $usedcats;
83 }
84 
85 function dump_linkscripts($cats)
86 {
87  print "
88 // Each category can specify a PHP function that returns an altered
89 // version of the keyword.
90  # This link is then placed in a <a href=\"...\">foo</a>; structure around keyword 'foo' - which is
91  \n\n";
92 
93  $linkhash = array();
94 
95  foreach ($cats as $c) {
96  $linkhash{$c} = "donothing";
97  }
98 
99  dump_hash($linkhash, "\$this->linkscripts ");
100  print "}\n# DoNothing link function\n\n";
101  print "function donothing(\$keywordin)\n{\n return \$keywordin;\n}\n";
102 }
103 
104 function dump_colours($cats)
105 {
106  global $colours;
107 
108  $usedcols = array();
109  foreach ($cats as $c) {
110  array_push($usedcols, $colours[$c-1]);
111  }
112  dump_array($usedcols, "\$this->colours ");
113 }
114 
115 function dump_var($variable, $name)
116 {
117  print $name . " = \"" . addslashes($variable) . "\";\n";
118 }
119 
120 function dump_array($array, $name)
121 {
122  $first = 1;
123  print $name . " = array(";
124  foreach ($array as $a) {
125  if (!$first) {
126  print ", ";
127  } else {
128  $first = 0;
129  }
130  print "\"" . addslashes($a) . "\"";
131  }
132  print ");\n";
133 }
134 
135 function dump_hash($hash, $name)
136 {
137  $first = 1;
138  print $name . " = array(";
139  foreach (array_keys($hash) as $k) {
140  if (!$first) {
141  print ", ";
142  } else {
143  $first = 0;
144  }
145  print "\n \"" . addslashes($k) . "\"";
146  print " => \"" . addslashes($hash[$k]) . "\"";
147  }
148  print ");\n";
149 }
150 
151 function convert($file)
152 {
153  $file = str_replace("./", "", $file);
154  global $LANGNAME;
155  $LANGNAME = $file;
156  $LANGNAME = str_replace(".txt", "", $LANGNAME);
157 
158  $fileout = '../object/' . $LANGNAME . '.php';
159 
160  print "Writing $file to $fileout\n";
161 
162  HFile_parse_file($file);
163 
164  ob_start();
165  ob_implicit_flush(0);
166 
167  HFile_print_php_file(isset($fileout));
168  $out = ob_get_contents();
169  ob_end_clean();
170 
171  if (isset($fileout)) {
172  $fd = fopen($fileout, "w");
173  fputs($fd, $out);
174  fclose($fd);
175  }
176 }
177 
178 
179 convert($argv[1]);
180 
181 
182 
183 
184 ?>
global $argv
Definition: svg-scanner.php:41
HFile_print_php_file($tofile=1)
Definition: HFile_conv.php:16
convert($file)
Definition: HFile_conv.php:151
get_categories()
Definition: HFile_conv.php:71
$BEAUT_PATH
Definition: HFile_conv.php:6
if($format !==null) $name
Definition: metadata.php:146
dump_linkscripts($cats)
Definition: HFile_conv.php:85
dump_hash($hash, $name)
Definition: HFile_conv.php:135
Create styles array
The data for the language used.
dump_colours($cats)
Definition: HFile_conv.php:104
dump_array($array, $name)
Definition: HFile_conv.php:120
dump_var($variable, $name)
Definition: HFile_conv.php:115
if(!file_exists("$old.txt")) if($old===$new) if(file_exists("$new.txt")) $file