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