Rev 545 Rev 546
1 <?php 1 <?php
2 // This PHP script generates clickable HTML documentation files for amforth 2 // This PHP script generates clickable HTML documentation files for amforth
3 // project. Script should be run once (offline) when new versions of sorces are 3 // project. Script should be run once (offline) when new versions of sorces are
4 // available. It creates new subdirectory with HTML documentation tree. 4 // available. It creates new subdirectory with HTML documentation tree.
5 // 5 //
6 // Default configuration is in file GenerateHTML.cfg 6 // Default configuration is in file GenerateHTML.cfg
7 // 7 //
8 // Command Line paramaters are available via php GenerateHTML.php --help 8 // Command Line paramaters are available via php GenerateHTML.php --help
9 // 9 //
10 // (c)miho 2007 / http://www.mlab.cz 10 // (c)miho 2007 / http://www.mlab.cz
11   11  
12 // ********************************************************************** 12 // **********************************************************************
13 // History 13 // History
14 // ********************************************************************** 14 // **********************************************************************
15 // 0.00 work wersion 15 // 0.00 work wersion
16 // 0.01 basic functionality 16 // 0.01 basic functionality
17   17  
18   18  
19 // ********************************************************************** 19 // **********************************************************************
20 // Definitions/parameters 20 // Definitions/parameters
21 // ********************************************************************** 21 // **********************************************************************
22   22  
23   23  
24 define ('INCLUDE_PATTERN', "/^ *\.include +\"(\S+)\"/i"); 24 define ('INCLUDE_PATTERN', "/^ *\.include +\"(\S+)\"/i");
25 define ('LABEL_PREFIX', "(VE_|XT_|PFA)"); 25 define ('LABEL_PREFIX', "(VE_|XT_|PFA)");
26 define ('LABEL_PATTERN', "/^ *(".LABEL_PREFIX."\S+):/i"); 26 define ('LABEL_PATTERN', "/^ *(".LABEL_PREFIX."\S+):/i");
27 define ('WORD_PATTERN', "/((?:\\n *;.*)*)\\n *VE_Q:[^\\n]*\\n? *.db +[^,]* *, *(\S[^\\n|;]+)/im"); // Q is used instead of Word 27 define ('WORD_PATTERN', "/((?:\\n *;.*)*)\\n *VE_Q:[^\\n]*\\n? *.db +[^,]* *, *(\S[^\\n|;]+)/im"); // Q is used instead of Word
28 define ('ASMFILES', "CodeAsm/"); 28 define ('ASMFILES', "CodeAsm/");
29   29  
30   30  
31 // ********************************************************************** 31 // **********************************************************************
32 // Generic Funcions 32 // Generic Funcions
33 // ********************************************************************** 33 // **********************************************************************
34   34  
35   35  
36 function Error($ErrorStr) 36 function Error($ErrorStr)
37 // If ErrorStr is not empty print it and die 37 // If ErrorStr is not empty print it and die
38 { 38 {
39 if ($ErrorStr=="") 39 if ($ErrorStr=="")
40 return; 40 return;
41 print "\n"; 41 print "\n";
42 print " ERROR: -->".$ErrorStr."\n"; 42 print " ERROR: -->".$ErrorStr."\n";
43 die(1); 43 die(1);
44 } 44 }
45   45  
46   46  
47 function MyReadFile($FileName, &$FileContent) 47 function MyReadFile($FileName, &$FileContent)
48 // Reads file, returns file as a single string 48 // Reads file, returns file as a single string
49 { 49 {
50 // 50 //
51 if ($FileName=="") 51 if ($FileName=="")
52 return "No File Name"; 52 return "No File Name";
53   53  
54 // Read file 54 // Read file
55 $FileContent=@file($FileName); 55 $FileContent=@file($FileName);
56   56  
57 // Test if file contains any content 57 // Test if file contains any content
58 if ($FileContent==FALSE) 58 if ($FileContent==FALSE)
59 return "No Data in File: $FileName"; 59 return "No Data in File: $FileName";
60   60  
61 // Remove CR or LF or CR/LF 61 // Remove CR or LF or CR/LF
62 foreach($FileContent as $Key => $Line) 62 foreach($FileContent as $Key => $Line)
63 { 63 {
64 $FileContent[$Key]=rtrim($Line); 64 $FileContent[$Key]=rtrim($Line);
65 } 65 }
66   66  
67 // No error 67 // No error
68 return ""; 68 return "";
69 } 69 }
70   70  
71   71  
72 function MyReadFileString($FileName, &$FileContent) 72 function MyReadFileString($FileName, &$FileContent)
73 // Reads file and returns its content as a single string 73 // Reads file and returns its content as a single string
74 { 74 {
75 // No Error 75 // No Error
76 $Error=""; 76 $Error="";
77 77
78 // Read file 78 // Read file
79 $Error=MyReadFile($FileName, &$FileContent); 79 $Error=MyReadFile($FileName, &$FileContent);
80   80  
81 // Convert to a single string 81 // Convert to a single string
82 if ($Error=="") $FileContent=implode("\n",$FileContent); 82 if ($Error=="") $FileContent=implode("\n",$FileContent);
83   83  
84 // Finished 84 // Finished
85 return $Error; 85 return $Error;
86 } 86 }
87   87  
88   88  
89 function MyWriteFile($FileName, $FileContent) 89 function MyWriteFile($FileName, $FileContent)
90 // Creates and writes file 90 // Creates and writes file
91 { 91 {
92 // Create Output File 92 // Create Output File
93 $File=@fopen($FileName,"w"); 93 $File=@fopen($FileName,"w");
94 if ($File==FALSE) 94 if ($File==FALSE)
95 { 95 {
96 return "Unable Write File ".$FileName; 96 return "Unable Write File ".$FileName;
97 } 97 }
98 98
99 // Write content 99 // Write content
100 fwrite($File,$FileContent); 100 fwrite($File,$FileContent);
101 fclose($File); 101 fclose($File);
102 102
103 // No Error 103 // No Error
104 return ""; 104 return "";
105 } 105 }
106   106  
107   107  
108 function FileName2HTML($FileName) 108 function FileName2HTML($FileName)
109 // Converts FileName to FileName of HTML file 109 // Converts FileName to FileName of HTML file
110 { 110 {
111 // Remove path 111 // Remove path
112 $FileName=basename($FileName); 112 $FileName=basename($FileName);
113 // Change suffix 113 // Change suffix
114 $FileName=preg_replace("/\.asm$/i",".html",$FileName); 114 $FileName=preg_replace("/\.asm$/i",".html",$FileName);
115 // Finished 115 // Finished
116 #print $FileName; 116 #print $FileName;
117 return $FileName; 117 return $FileName;
118 } 118 }
119   119  
120   120  
121 function Label2Link($Link, $href, $title, &$LabelList) 121 function Label2Link($Link, $href, $title, &$LabelList)
122 // Converts Label to Link 122 // Converts Label to Link
123 // If label not found returns original text 123 // If label not found returns original text
124 // IN $Link - label to find 124 // IN $Link - label to find
125 // IN $Word - word to show (on mouse) 125 // IN $Word - word to show (on mouse)
126 // IN $LabelList - list of all labels (Label, FileName, LineNumber) 126 // IN $LabelList - list of all labels (Label, FileName, LineNumber)
127 { 127 {
128 // Find label in $LabelList 128 // Find label in $LabelList
129 foreach($LabelList as $Value) 129 foreach($LabelList as $Value)
130 { 130 {
131 if ($Link===$Value["Label"]) 131 if ($Link===$Value["Label"])
132 { 132 {
133 #$LabelListItem=$Value ///////////////////////////// 133 #$LabelListItem=$Value /////////////////////////////
134 print "Found ".$Value["Label"]."\n"; 134 print "Found ".$Value["Label"]."\n";
135 } 135 }
136 } 136 }
137   137  
138 $FileName=$Value["FileName"]."#".$Link; 138 $FileName=$Value["FileName"]."#".$Link;
139 139
140 // Create link 140 // Create link
141 $Link="<a href=\"".$FileName."\" title=\" ".$Word."\">".$Link.'</a>'; 141 $Link="<a href=\"".$FileName."\" title=\" ".$Word."\">".$Link.'</a>';
142   142  
143 return $Link; 143 return $Link;
144 } 144 }
145   145  
146   146  
147 // ********************************************************************** 147 // **********************************************************************
148 // Function for processing 148 // Function for processing
149 // ********************************************************************** 149 // **********************************************************************
150   150  
151   151  
152 function Help() 152 function Help()
153 // Display help 153 // Display help
154 { 154 {
155 print "\n"; 155 print "\n";
156 print "This script takes default parameters from GenerateHTML.cfg.\n"; 156 print "This script takes default parameters from GenerateHTML.cfg.\n";
157 print "\n"; 157 print "\n";
158 print "Parameters can be entered directly on command line as well:\n"; 158 print "Parameters can be entered directly on command line as well:\n";
159 print " php GenerateHTML.php par1=val1 par2=val2\n"; 159 print " php GenerateHTML.php par1=val1 par2=val2\n";
160 print "\n"; 160 print "\n";
161 print "Sometimes (in Windows) it is necessary to use quotation marks this way:\n"; 161 print "Sometimes (in Windows) it is necessary to use quotation marks this way:\n";
162 print " php GenerateHTML.php \"par1=val1\" \"par2=val2\"\n"; 162 print " php GenerateHTML.php \"par1=val1\" \"par2=val2\"\n";
163 print "\n"; 163 print "\n";
164 print "Parameters are: \n"; 164 print "Parameters are: \n";
165 print " EnableApache={0|1} - Enable to run in Apache\n"; 165 print " EnableApache={0|1} - Enable to run in Apache\n";
166 print " SourceDir=path - path to asm source directory\n"; 166 print " SourceDir=path - path to asm source directory\n";
167 print " SourceAsm=file - name of top level asm source file\n"; 167 print " SourceAsm=file - name of top level asm source file\n";
-   168 print " SvnInfoFileName - name of Svn Info File\n";
168 print " TemplateDir=path - path to HTML template\n"; 169 print " TemplateDir=path - path to HTML template\n";
169 print " DestinationDir=path - path to destination HTML\n"; 170 print " DestinationDir=path - path to destination HTML\n";
170 Error("\n"); 171 Error("\n");
171 } 172 }
172   173  
173   174  
174 function Parameters(&$CFG) 175 function Parameters(&$CFG)
175 // Function process Command Line parameters 176 // Function process Command Line parameters
176 { 177 {
177 // Info -  
178 print "Parameters\n"; -  
179 // Dummy values 178 // Dummy values
180 $CFG["EnableApache"] = 0; // Do not allow run in Apache 179 $CFG["EnableApache"] = 0; // Do not allow run in Apache
181 $CFG["SourceDir"] = ""; 180 $CFG["SourceDir"] = "";
182 $CFG["SourceAsm"] = ""; 181 $CFG["SourceAsm"] = "";
-   182 $CFG["SvnInfoFileName"] = "";
183 $CFG["TemplateDir"] = ""; 183 $CFG["TemplateDir"] = "";
184 $CFG["DestinationDir"] = ""; 184 $CFG["DestinationDir"] = "";
185 // Default values (in cfg file) 185 // Default values (in cfg file)
186 @include_once("GenerateHTML.cfg"); 186 @include_once("GenerateHTML.cfg");
187 // Command Line parameters 187 // Command Line parameters
188 if ($_SERVER["argc"]>1) 188 if ($_SERVER["argc"]>1)
189 { 189 {
190 // Help 190 // Help
191 if ($_SERVER["argv"][1]=="--help") 191 if ($_SERVER["argv"][1]=="--help")
192 Help(); 192 Help();
193 // Drop 193 // Drop
194 unset($_SERVER["argv"][0]); 194 unset($_SERVER["argv"][0]);
195 // Go through arguments 195 // Go through arguments
196 foreach($_SERVER["argv"] as $Key => $Value) 196 foreach($_SERVER["argv"] as $Key => $Value)
197 { 197 {
198 $Left=substr($Value,0,strpos($Value,"=")); 198 $Left=substr($Value,0,strpos($Value,"="));
199 $Right=substr($Value,strpos($Value,"=")+1); 199 $Right=substr($Value,strpos($Value,"=")+1);
200 if (isset($CFG[$Left]) && $Right!="" ) 200 if (isset($CFG[$Left]) && $Right!="" )
201 { 201 {
202 $CFG[$Left]=$Right; 202 $CFG[$Left]=$Right;
203 } 203 }
204 else 204 else
205 { 205 {
206 return "Invalid Parameter: $Value"; 206 return "Invalid Parameter: $Value";
207 } 207 }
208 } 208 }
209 } 209 }
210   210  
-   211 // Check if alowed to run in Apache
-   212 if ($_SERVER["argc"]==0 & ! $CFG["EnableApache"])
-   213 return "<b>This Script is configured so that it will not run in Apache.</b>";
-   214  
-   215 // Info
-   216 print "Parameters\n";
-   217  
211 // Correct paths and existence 218 // Correct paths and existence
212 foreach($CFG as $Key => $Value) 219 foreach($CFG as $Key => $Value)
213 { 220 {
214 if (stripos($Key,"Dir")) 221 if (stripos($Key,"Dir"))
215 { 222 {
216 // Correct / at the end of path 223 // Correct / at the end of path
217 if (substr($Value,strlen($Value)-1)!="/") 224 if (substr($Value,strlen($Value)-1)!="/")
218 { 225 {
219 $CFG[$Key]=$Value."/"; 226 $CFG[$Key]=$Value."/";
220 } 227 }
221 // Check existence 228 // Check existence
222 #print "DIR".$CFG[$Key]."\n"; 229 #print "DIR".$CFG[$Key]."\n";
223 if ( ! is_dir($CFG[$Key])) 230 if ( ! is_dir($CFG[$Key]))
224 { 231 {
225 return "Directory does not exist: ".$Key."=".$CFG[$Key]; 232 return "Directory does not exist: ".$Key."=".$CFG[$Key];
226 } 233 }
227 } 234 }
228 } 235 }
229   236  
230 // Print info 237 // Print info
231 if (count(CFG)) 238 if (count(CFG))
232 foreach($CFG as $Key => $Value) 239 foreach($CFG as $Key => $Value)
233 print " $Key=$Value\n"; 240 print " $Key=$Value\n";
234 print "\n"; 241 print "\n";
235   242  
236 // Check if alowed to run in Apache -  
237 if ($_SERVER["argc"]==0 & ! $CFG["Apache"]) -  
238 return "This Script is configured so that it will not run in Apache."; -  
239   -  
240 // No Error 243 // No Error
241 return ""; 244 return "";
242 } 245 }
243   246  
244   247  
245 function SourceAsm($SourceDir, $FileName, &$SourceAsmFiles, &$LabelList ) 248 function SourceAsm($SourceDir, $FileName, &$SourceAsmFiles, &$LabelList )
246 // Process ASM source file, recurse all includes 249 // Process ASM source file, recurse all includes
247 // Returns Error String 250 // Returns Error String
248 // Stores file names and labels into two arrays 251 // Stores file names and labels into two arrays
249 // IN $SourceDir - base directory (not printed) 252 // IN $SourceDir - base directory (not printed)
250 // IN $FileName - file to process 253 // IN $FileName - file to process
251 // OUT $SourceAsmFiles - list of all processed files (Filename) 254 // OUT $SourceAsmFiles - list of all processed files (Filename)
252 // OUT $LabelList - list of all labels (Label, FileName, LineNumber) 255 // OUT $LabelList - list of all labels (Label, FileName, LineNumber)
253 { 256 {
254   257  
255 // Start 258 // Start
256 print "Read Asm: $FileName\n"; 259 print "Read Asm: $FileName\n";
257   260  
258 // Read file 261 // Read file
259 $Error=MyReadFile($SourceDir.$FileName, $FileContent); 262 $Error=MyReadFile($SourceDir.$FileName, $FileContent);
260 if ($Error!="") 263 if ($Error!="")
261 return $Error; 264 return $Error;
262   265  
263 // Remember filename 266 // Remember filename
264 $SourceAsmFiles[]=$FileName; 267 $SourceAsmFiles[]=$FileName;
265   268  
266 // Filter source file line by line - find labels 269 // Filter source file line by line - find labels
267 foreach($FileContent as $Key => $Value) 270 foreach($FileContent as $Key => $Value)
268 { 271 {
269 // Find label definitions 272 // Find label definitions
270 if (preg_match(LABEL_PATTERN,$Value,$Matches)) 273 if (preg_match(LABEL_PATTERN,$Value,$Matches))
271 { 274 {
272 print " label @line ".($Key+1)." ".$Matches[1]."\n"; 275 print " label @line ".($Key+1)." ".$Matches[1]."\n";
273 $LabelList[]=array("Label"=>$Matches[1],"FileName"=>$FileName,"LineNumber"=>($Key+1)); 276 $LabelList[]=array("Label"=>$Matches[1],"FileName"=>$FileName,"LineNumber"=>($Key+1));
274 } 277 }
275 } 278 }
276   279  
277 // Filter source file line by line - find includes 280 // Filter source file line by line - find includes
278 foreach($FileContent as $Key => $Value) 281 foreach($FileContent as $Key => $Value)
279 { 282 {
280 // Find .include "filename" lines 283 // Find .include "filename" lines
281 if (preg_match(INCLUDE_PATTERN,$Value,$Matches)) 284 if (preg_match(INCLUDE_PATTERN,$Value,$Matches))
282 { 285 {
283 print " include @line ".($Key+1)." --> ".$Matches[1]."\n"; 286 print " include @line ".($Key+1)." --> ".$Matches[1]."\n";
284 // Remember links 287 // Remember links
285 $Includes[]=$Matches[1]; 288 $Includes[]=$Matches[1];
286 } 289 }
287 } 290 }
288   291  
289 // Print delimiter 292 // Print delimiter
290 print "\n"; 293 print "\n";
291 294
292 // Recurse includes 295 // Recurse includes
293 if ($Includes) 296 if ($Includes)
294 { 297 {
295 foreach($Includes as $Value) 298 foreach($Includes as $Value)
296 { 299 {
297 $Dir=dirname($FileName)."/"; 300 $Dir=dirname($FileName)."/";
298 if ($Dir=="./") 301 if ($Dir=="./")
299 { 302 {
300 $Dir=""; 303 $Dir="";
301 } 304 }
302 $Error=SourceAsm($SourceDir, $Dir.$Value, $SourceAsmFiles, $LabelList); 305 $Error=SourceAsm($SourceDir, $Dir.$Value, $SourceAsmFiles, $LabelList);
303 if ($Error!="") 306 if ($Error!="")
304 return $Error; 307 return $Error;
305 } 308 }
306 unset($Includes); 309 unset($Includes);
307 } 310 }
308   311  
309 // End 312 // End
310 return ""; 313 return "";
311 } 314 }
312   315  
313   316  
314 function PrintSourceAsm(&$SourceAsmFiles) 317 function PrintSourceAsm(&$SourceAsmFiles)
315 // Prints all procesed ASM files 318 // Prints all procesed ASM files
316 { 319 {
317 print "Asm Source File List\n"; 320 print "Asm Source File List\n";
318 if (count($SourceAsmFiles)) 321 if (count($SourceAsmFiles))
319 foreach($SourceAsmFiles as $Key => $Value) 322 foreach($SourceAsmFiles as $Key => $Value)
320 { 323 {
321 print " ".$Value."\n"; 324 print " ".$Value."\n";
322 } 325 }
323 print "\n"; 326 print "\n";
324 } 327 }
325   328  
326   329  
327 function PrintLabels(&$LabelList) 330 function PrintLabels(&$LabelList)
328 // Prints all found labels 331 // Prints all found labels
329 { 332 {
330 print "Label List\n"; 333 print "Label List\n";
331 if (count($LabelList)) 334 if (count($LabelList))
332 foreach($LabelList as $Key => $Value) 335 foreach($LabelList as $Key => $Value)
333 { 336 {
334 print " ".$Value["Label"]." ".$Value["FileName"]." ".$Value["LineNumber"]."\n"; 337 print " ".$Value["Label"]." ".$Value["FileName"]." ".$Value["LineNumber"]."\n";
335 } 338 }
336 print "\n"; 339 print "\n";
337 } 340 }
338   341  
339   342  
340 function CreateWordList($SourceDir, &$LabelList, &$WordList) 343 function CreateWordList($SourceDir, &$LabelList, &$WordList)
341 // Goes through LabelList and looks for word definitions 344 // Goes through LabelList and looks for word definitions
342 // Returns Error String 345 // Returns Error String
343 // IN $LabelList - Found labels 346 // IN $LabelList - Found labels
344 // OUT $WordList - Word List (ShortLabel, Word, Comment, Label, FileName) 347 // OUT $WordList - Word List (ShortLabel, Word, Comment, Label, FileName)
345 { 348 {
346   349  
347 print "Word List\n"; 350 print "Word List\n";
348 351
349 if (count($LabelList)) 352 if (count($LabelList))
350 foreach ($LabelList as $Value) 353 foreach ($LabelList as $Value)
351 { 354 {
352 // Take all VE definitions 355 // Take all VE definitions
353 if (stristr(substr($Value["Label"],0,3),"VE_")) 356 if (stristr(substr($Value["Label"],0,3),"VE_"))
354 { 357 {
355 // Prepare Label without VE_ 358 // Prepare Label without VE_
356 $ShortLabel=substr($Value["Label"],3); 359 $ShortLabel=substr($Value["Label"],3);
357   360  
358 // Prepare search pattern 361 // Prepare search pattern
359 $Pattern=str_replace("Q",$ShortLabel,WORD_PATTERN); 362 $Pattern=str_replace("Q",$ShortLabel,WORD_PATTERN);
360 #print "Pattern: ".$Pattern." ".$Value["FileName"]."\n"; 363 #print "Pattern: ".$Pattern." ".$Value["FileName"]."\n";
361   364  
362 // Read source file 365 // Read source file
363 $FileName=$SourceDir.$Value["FileName"]; 366 $FileName=$SourceDir.$Value["FileName"];
364 $Error=MyReadFileString($FileName, $FileContent); 367 $Error=MyReadFileString($FileName, $FileContent);
365 if ($Error!="") 368 if ($Error!="")
366 return $Error; 369 return $Error;
367 $FileContent="\n".$FileContent; 370 $FileContent="\n".$FileContent;
368 371
369 // Find label 372 // Find label
370 if (preg_match($Pattern,$FileContent,$Matches)) 373 if (preg_match($Pattern,$FileContent,$Matches))
371 { 374 {
372 // Coments - remove semiculomn 375 // Coments - remove semiculomn
373 $Comment = rtrim(preg_replace("/\\n; ?(.*)/","$1\n",$Matches[1])); 376 $Comment = rtrim(preg_replace("/\\n; ?(.*)/","$1\n",$Matches[1]));
374   377  
375 // Convert .db parameters into string 378 // Convert .db parameters into string
376 $Word=""; 379 $Word="";
377 #$Word=$Matches[2]." : "; 380 #$Word=$Matches[2]." : ";
378   381  
379 foreach(explode(",",$Matches[2]) as $Val) 382 foreach(explode(",",$Matches[2]) as $Val)
380 { 383 {
381 // String element 384 // String element
382 preg_match("/^ *\"([^\"]*)(\" *)/",$Val,$Tmp); 385 preg_match("/^ *\"([^\"]*)(\" *)/",$Val,$Tmp);
383 #print "S:".$Tmp[1]."\n"; 386 #print "S:".$Tmp[1]."\n";
384 if ($Tmp[1]!="") 387 if ($Tmp[1]!="")
385 { 388 {
386 $Word.=$Tmp[1]; 389 $Word.=$Tmp[1];
387 } 390 }
388   391  
389 // Hexa number 392 // Hexa number
390 preg_match("/\\$([0-9A-F]+)/i",$Val,$Tmp); 393 preg_match("/\\$([0-9A-F]+)/i",$Val,$Tmp);
391 #print "H:".$Tmp[1]."\n"; 394 #print "H:".$Tmp[1]."\n";
392 if ($Tmp[1]!="") 395 if ($Tmp[1]!="")
393 { 396 {
394 $Number=hexdec($Tmp[1]); 397 $Number=hexdec($Tmp[1]);
395 if ($Number!=0) 398 if ($Number!=0)
396 $Word.=chr($Number); 399 $Word.=chr($Number);
397 } 400 }
398 401
399 // Decimal number 402 // Decimal number
400 preg_match("/^([0-9]+)/i",$Val,$Tmp); 403 preg_match("/^([0-9]+)/i",$Val,$Tmp);
401 #print "D:".$Tmp[1]."\n"; 404 #print "D:".$Tmp[1]."\n";
402 if ($Tmp[1]!="") 405 if ($Tmp[1]!="")
403 { 406 {
404 $Number=$Tmp[1]; 407 $Number=$Tmp[1];
405 if ($Number!=0) 408 if ($Number!=0)
406 $Word.=chr($Number); 409 $Word.=chr($Number);
407 } 410 }
408 411
409 } 412 }
410   413  
411 // Store label into array 414 // Store label into array
412 $WordList[]=array("Word"=>$Word, "ShortLabel"=>$ShortLabel, "Comment"=>$Comment, 415 $WordList[]=array("Word"=>$Word, "ShortLabel"=>$ShortLabel, "Comment"=>$Comment,
413 "Label"=>$Value["Label"] , "FileName"=>$Value["FileName"] 416 "Label"=>$Value["Label"] , "FileName"=>$Value["FileName"]
414 ); 417 );
415 print " ".$Word." = ".$ShortLabel."\n"; 418 print " ".$Word." = ".$ShortLabel."\n";
416 if($Comment) print " ".preg_replace("/\\n/","\n ",$Comment)."\n"; 419 if($Comment) print " ".preg_replace("/\\n/","\n ",$Comment)."\n";
417 } 420 }
418   421  
419 // Sort Words 422 // Sort Words
420 array_multisort($WordList); 423 array_multisort($WordList);
421   424  
422 // Clean Up 425 // Clean Up
423 unset($FileContent); 426 unset($FileContent);
424 } 427 }
425 } 428 }
426 print "\n"; 429 print "\n";
427 return ""; 430 return "";
428 } 431 }
429   432  
430   433  
431 function GenerateWordList($TemplateDir, $DestinationDir, &$LabelList, &$WordList) 434 function GenerateWordList($TemplateDir, $SvnInfoFileName, $DestinationDir, &$LabelList, &$WordList)
432 // Creates HTML pages with Word List 435 // Creates HTML pages with Word List
433 // Returns Error String 436 // Returns Error String
434 // IN $TemplateDir - template directory (file WordList.*.html) 437 // IN $TemplateDir - template directory (file WordList.*.html)
435 // IN $LabelList - list of labels (Label, FileName, LineNumber) 438 // IN $LabelList - list of labels (Label, FileName, LineNumber)
436 // IN $WordList - list of words (ShortLabel, Word, Comment, Label, FileName) 439 // IN $WordList - list of words (ShortLabel, Word, Comment, Label, FileName)
437 // OUT WordList.*.html - create HTML pages (file WordList.*.html) 440 // OUT WordList.*.html - create HTML pages (file WordList.*.html)
438 { 441 {
439 // Find all templates 442 // Find all templates
440 print "Word List in HTML\n"; 443 print "Word List in HTML\n";
441 if (count(glob($TemplateDir."WordList.*.html"))) 444 if (count(glob($TemplateDir."WordList.*.html")))
442 foreach (glob($TemplateDir."WordList.*.html") as $FileName) 445 foreach (glob($TemplateDir."WordList.*.html") as $FileName)
443 { 446 {
444 // Process template file 447 // Process template file
445 print " Temlate $FileName\n"; 448 print " Temlate $FileName\n";
446   449  
447 // Read template file 450 // Read template file
448 $Error=MyReadFileString($FileName, $FileContent); 451 $Error=MyReadFileString($FileName, $FileContent);
449 if ($Error!="") 452 if ($Error!="")
450 return $Error; 453 return $Error;
451   454  
-   455 // Find <<SvnInfo>>
-   456 if (!preg_match("/( *)(<<SvnInfo>>)/i",$FileContent,$Matches))
-   457 {
-   458 unset($FileContent);
-   459 return "Missing <<SvnInfo>> in template file";
-   460 }
-   461 $Indent=$Matches[1];
-   462  
-   463 // Read Svn Info file
-   464 $Error=MyReadFileString($SvnInfoFileName, $SvnInfoFile);
-   465 if ($Error!="")
-   466 {
-   467 // We do not have Svn Info File
-   468 $SvnInfoFile="";
-   469 }
-   470 else
-   471 {
-   472 // We have Svn Info File
-   473 $SvnInfoFile=preg_replace("/^((?:URL|Repository|Last)[^:]*):(.*$)|^.*$/im","<tr><td>$1</td><td>$2</td></tr>",$SvnInfoFile);
-   474 $SvnInfoFile=preg_replace("~<tr><td></td><td></td></tr>\n~i","",$SvnInfoFile);
-   475 $SvnInfoFile="<tr><th colspan=\"2\">Subversion Info</th></tr>".$SvnInfoFile;
-   476 }
-   477  
-   478 // Put Svn Info into HTML template
-   479 $FileContent=str_ireplace("<<SvnInfo>>", $SvnInfoFile, $FileContent);
-   480 #print $FileContent;
-   481  
-   482  
452 // Find <<WordList>> 483 // Find <<WordList>>
453 if (!preg_match("/( *)(<<WordList>>)/i",$FileContent,$Matches)) 484 if (!preg_match("/( *)(<<WordList>>)/i",$FileContent,$Matches))
454 { 485 {
455 unset($FileContent); 486 unset($FileContent);
456 return "Missing <<WordList>> in template file"; 487 return "Missing <<WordList>> in template file";
457 } 488 }
458 $Indent=$Matches[1]; 489 $Indent=$Matches[1];
459 490
460 // Create HTML code - table header 491 // Create HTML code - table header
461 $WordListHTML[]="<table>"; 492 $WordListHTML[]="<table>";
462 $WordListHTML[]=" <tr>"; 493 $WordListHTML[]=" <tr>";
463 $WordListHTML[]=" <th>Word</th>"; 494 $WordListHTML[]=" <th>Word</th>";
464 $WordListHTML[]=" <th>Label</th>"; 495 $WordListHTML[]=" <th>Label</th>";
465 $WordListHTML[]=" <th>Definition</th>"; 496 $WordListHTML[]=" <th>Definition</th>";
466 $WordListHTML[]=" </tr>"; 497 $WordListHTML[]=" </tr>";
467 498
468 // Create HTML code - table lines 499 // Create HTML code - table lines
469 if (count($WordList)) 500 if (count($WordList))
470 foreach($WordList as $Key => $Value) 501 foreach($WordList as $Key => $Value)
471 { 502 {
472 // Prepare (just for readibility) 503 // Prepare (just for readibility)
473 $Word=$Value["Word"]; 504 $Word=$Value["Word"];
474 $Link="<a href=\"".ASMFILES.FileName2HTML($Value["FileName"])."#".$Value["ShortLabel"]. 505 $Link="<a href=\"".ASMFILES.FileName2HTML($Value["FileName"])."#".$Value["ShortLabel"].
475 "\" title=\"".$Value["Label"]."\">".$Value["ShortLabel"]."</a>"; 506 "\" title=\"".$Value["Label"]."\">".$Value["ShortLabel"]."</a>";
476 $Comment=$Value["Comment"]; 507 $Comment=$Value["Comment"];
477 // Generate HTML 508 // Generate HTML
478 $WordListHTML[]=" <tr>"; 509 $WordListHTML[]=" <tr>";
479 $WordListHTML[]=" <td>".htmlspecialchars($Word)."</td>"; 510 $WordListHTML[]=" <td>".htmlspecialchars($Word)."</td>";
480 $WordListHTML[]=" <td>".$Link."</td>"; 511 $WordListHTML[]=" <td>".$Link."</td>";
481 $WordListHTML[]=" <td>".htmlspecialchars($Comment)."</td>"; 512 $WordListHTML[]=" <td>".htmlspecialchars($Comment)."</td>";
482 $WordListHTML[]=" </tr>"; 513 $WordListHTML[]=" </tr>";
483 } 514 }
484 // Create HTML code - table end 515 // Create HTML code - table end
485 $WordListHTML[]="</table>"; 516 $WordListHTML[]="</table>";
486 517
487 // Indent and Concatenate lines 518 // Indent and Concatenate lines
488 foreach($WordListHTML as $Key => $Value) 519 foreach($WordListHTML as $Key => $Value)
489 { 520 {
-   521 if ($Key>0)
490 $WordListHTML[$Key]=$Indent.preg_replace("/\n/","<br>",$Value); 522 $WordListHTML[$Key]=$Indent.preg_replace("/\n/","<br>",$Value);
491 } 523 }
492 $WordListHTML=implode("\n",$WordListHTML); 524 $WordListHTML=implode("\n",$WordListHTML);
493 525
494 // Put it into HTML template 526 // Put it into HTML template
495 $FileContent=str_ireplace("<<WordList>>", $WordListHTML, $FileContent); 527 $FileContent=str_ireplace("<<WordList>>", $WordListHTML, $FileContent);
496 #print $FileContent; 528 #print $FileContent;
497 529
498 // Create Output File 530 // Create Output File
499 $Error=MyWriteFile($DestinationDir.basename($FileName), $FileContent); 531 $Error=MyWriteFile($DestinationDir.basename($FileName), $FileContent);
500 if ($Error!="") 532 if ($Error!="")
501 return $Error; 533 return $Error;
502   534  
503 // Clear memory 535 // Clear memory
504 unset($FileContent); 536 unset($FileContent);
505 unset($WordListHTML); 537 unset($WordListHTML);
506 } 538 }
507   539  
508 // Delimiter 540 // Delimiter
509 print "\n"; 541 print "\n";
510 return ""; 542 return "";
511 } 543 }
512   544  
513   545  
514 function GenerateAsmFiles($TemplateDir, $SourceDir, &$SourceAsmFiles, $DestinationDir) 546 function GenerateAsmFiles($TemplateDir, $SourceDir, &$SourceAsmFiles, $DestinationDir)
515 // Cretaes HTML files from all processed ASM files 547 // Cretaes HTML files from all processed ASM files
516 // Returns Error String 548 // Returns Error String
517 // IN $TemplateDir - directory with template files 549 // IN $TemplateDir - directory with template files
518 // IN $SourceDir - directory with asm source files 550 // IN $SourceDir - directory with asm source files
519 // OUT $SourceAsmFiles - 551 // OUT $SourceAsmFiles -
520 // IN $DestinationDir - directory for generated HTML files 552 // IN $DestinationDir - directory for generated HTML files
521 { 553 {
522 // Info 554 // Info
523 print "Copy ASM Files\n"; 555 print "Copy ASM Files\n";
524   556  
525 // Destination directory exists 557 // Destination directory exists
526 $DestinationDir.=ASMFILES; 558 $DestinationDir.=ASMFILES;
527 if (!is_dir($DestinationDir)) 559 if (!is_dir($DestinationDir))
528 if (!@mkdir($DestinationDir)) 560 if (!@mkdir($DestinationDir))
529 return "Unable Create Dir ".$DestinationDir; 561 return "Unable Create Dir ".$DestinationDir;
530   562  
531 // Read template 563 // Read template
532 $Error=MyReadFileString($TemplateDir."FileAsm.en.html", $Template); 564 $Error=MyReadFileString($TemplateDir."FileAsm.en.html", $Template);
533 if ($Error!="") 565 if ($Error!="")
534 return $Error; 566 return $Error;
535   567  
536 // Copy all source files 568 // Copy all source files
537 foreach($SourceAsmFiles as $Key => $FileName) 569 foreach($SourceAsmFiles as $Key => $FileName)
538 { 570 {
539 print " ".$FileName."\n"; 571 print " ".$FileName."\n";
540   572  
541 // Read ASM file 573 // Read ASM file
542 $Error=MyReadFileString($SourceDir.$FileName, $FileContent); 574 $Error=MyReadFileString($SourceDir.$FileName, $FileContent);
543 if ($Error!="") 575 if ($Error!="")
544 return $Error; 576 return $Error;
545   577  
546 // Prepare HTML 578 // Prepare HTML
547 $FileContent=htmlspecialchars($FileContent); 579 $FileContent=htmlspecialchars($FileContent);
548 $FileContent="<pre>\n".$FileContent."\n</pre>"; 580 $FileContent="<pre>\n".$FileContent."\n</pre>";
549   581  
550 // Use Template 582 // Use Template
551 $TemplateWork=$Template; 583 $TemplateWork=$Template;
552 $TemplateWork=str_ireplace("<<FileName>>", $FileName, $TemplateWork); 584 $TemplateWork=str_ireplace("<<FileName>>", $FileName, $TemplateWork);
553 $TemplateWork=str_ireplace("<<FileContent>>", $FileContent, $TemplateWork); 585 $TemplateWork=str_ireplace("<<FileContent>>", $FileContent, $TemplateWork);
554   586  
555 // Write ASM file in HTML 587 // Write ASM file in HTML
556 $Error=MyWriteFile($DestinationDir.FileName2HTML($FileName), $TemplateWork); 588 $Error=MyWriteFile($DestinationDir.FileName2HTML($FileName), $TemplateWork);
557 if ($Error!="") 589 if ($Error!="")
558 return $Error; 590 return $Error;
559 } 591 }
560 592
561 // Delimiter 593 // Delimiter
562 print "\n"; 594 print "\n";
563 return ""; 595 return "";
564 } 596 }
565   597  
566   598  
567 // ********************************************************************** 599 // **********************************************************************
568 // Main Block 600 // Main Block
569 // ********************************************************************** 601 // **********************************************************************
570   602  
571 // Global Like Variables (arrays) 603 // Global Like Variables (arrays)
572 // $CFG - Config parameters 604 // $CFG - Config parameters
573 // $SourceAsmFiles - All processed ASM files (filenames) 605 // $SourceAsmFiles - All processed ASM files (filenames)
574 // $LabelList - All label definitions (Label, FileName, LineNumber) 606 // $LabelList - All label definitions (Label, FileName, LineNumber)
575 // $WordList - Word List (ShortLabel, Word, Comment, Label, FileName) 607 // $WordList - Word List (ShortLabel, Word, Comment, Label, FileName)
576   608  
577 // Process Command Line Parameters 609 // Process Command Line Parameters
578 Error(Parameters($CFG)); 610 Error(Parameters($CFG));
579   611  
580 // Process all ASM files from the root level 612 // Process all ASM files from the root level
581 Error(SourceAsm($CFG["SourceDir"], $CFG["SourceAsm"], $SourceAsmFiles, $LabelList)); 613 Error(SourceAsm($CFG["SourceDir"], $CFG["SourceAsm"], $SourceAsmFiles, $LabelList));
582 PrintSourceAsm($SourceAsmFiles); 614 PrintSourceAsm($SourceAsmFiles);
583 PrintLabels($LabelList); 615 PrintLabels($LabelList);
584   616  
585 // Destilate Labels and Words 617 // Destilate Labels and Words
586 Error(CreateWordList($CFG["SourceDir"], $LabelList, $WordList)); 618 Error(CreateWordList($CFG["SourceDir"], $LabelList, $WordList));
587   619  
588 // Create HTML WordList 620 // Create HTML WordList
-   621 Error(GenerateWordList(
-   622 $CFG["TemplateDir"],
589 Error(GenerateWordList($CFG["TemplateDir"], $CFG["DestinationDir"], $LabelList, $WordList)); 623 $CFG["SourceDir"].$CFG["SvnInfoFileName"],
-   624 $CFG["DestinationDir"],
-   625 $LabelList, $WordList));
590   626  
591 // Copy ASM files and convert them into HTML 627 // Copy ASM files and convert them into HTML
592 Error(GenerateAsmFiles($CFG["TemplateDir"], $CFG["SourceDir"], $SourceAsmFiles, $CFG["DestinationDir"])); 628 Error(GenerateAsmFiles($CFG["TemplateDir"], $CFG["SourceDir"], $SourceAsmFiles, $CFG["DestinationDir"]));
593   629  
594 // Finish 630 // Finish
595 print "O.K.\n"; 631 print "O.K.\n";
596 return 632 return
597   633  
598 // Zpracování readme autora + verze 634 // Zpracování readme autora
-   635 // Vyplatilo by se udělat samostatny formatovaci a nahrazovaci mechanizmus
599 // Zpracování templejtů do samostatného podprogramu (vyřešit indent...) 636 // Zpracování templejtů do samostatného podprogramu (vyřešit indent...)
600 // tím se vyřeší i en/cs verze Asm souboru 637 // tím se vyřeší i en/cs verze Asm souboru
601 // Generovat log do souboru místo printu (zvážit) oddělit chyby a varování 638 // Generovat log do souboru místo printu (zvážit) oddělit chyby a varování
602 // Vyčistit cílový adresář 639 // Vyčistit cílový adresář
603 // Process all FORTH files 640 // Process all FORTH files
604 // Problém s rekurzí (potenciální nekonečno) 641 // Problém s rekurzí (potenciální nekonečno)
605 // Chtělo by to do stránek vkládat info o verzi a (c) 642 // Chtělo by to do stránek vkládat info o verzi a (c)
606 ?> 643 ?>