/Articles/Forth/PHP/GenerateHTML.php
165,6 → 165,7
print " EnableApache={0|1} - Enable to run in Apache\n";
print " SourceDir=path - path to asm source directory\n";
print " SourceAsm=file - name of top level asm source file\n";
print " SvnInfoFileName - name of Svn Info File\n";
print " TemplateDir=path - path to HTML template\n";
print " DestinationDir=path - path to destination HTML\n";
Error("\n");
174,12 → 175,11
function Parameters(&$CFG)
// Function process Command Line parameters
{
// Info
print "Parameters\n";
// Dummy values
$CFG["EnableApache"] = 0; // Do not allow run in Apache
$CFG["SourceDir"] = "";
$CFG["SourceAsm"] = "";
$CFG["SvnInfoFileName"] = "";
$CFG["TemplateDir"] = "";
$CFG["DestinationDir"] = "";
// Default values (in cfg file)
208,6 → 208,13
}
}
 
// Check if alowed to run in Apache
if ($_SERVER["argc"]==0 & ! $CFG["EnableApache"])
return "<b>This Script is configured so that it will not run in Apache.</b>";
 
// Info
print "Parameters\n";
 
// Correct paths and existence
foreach($CFG as $Key => $Value)
{
233,10 → 240,6
print " $Key=$Value\n";
print "\n";
 
// Check if alowed to run in Apache
if ($_SERVER["argc"]==0 & ! $CFG["Apache"])
return "This Script is configured so that it will not run in Apache.";
 
// No Error
return "";
}
428,7 → 431,7
}
 
 
function GenerateWordList($TemplateDir, $DestinationDir, &$LabelList, &$WordList)
function GenerateWordList($TemplateDir, $SvnInfoFileName, $DestinationDir, &$LabelList, &$WordList)
// Creates HTML pages with Word List
// Returns Error String
// IN $TemplateDir - template directory (file WordList.*.html)
449,6 → 452,34
if ($Error!="")
return $Error;
 
// Find <<SvnInfo>>
if (!preg_match("/( *)(<<SvnInfo>>)/i",$FileContent,$Matches))
{
unset($FileContent);
return "Missing <<SvnInfo>> in template file";
}
$Indent=$Matches[1];
 
// Read Svn Info file
$Error=MyReadFileString($SvnInfoFileName, $SvnInfoFile);
if ($Error!="")
{
// We do not have Svn Info File
$SvnInfoFile="";
}
else
{
// We have Svn Info File
$SvnInfoFile=preg_replace("/^((?:URL|Repository|Last)[^:]*):(.*$)|^.*$/im","<tr><td>$1</td><td>$2</td></tr>",$SvnInfoFile);
$SvnInfoFile=preg_replace("~<tr><td></td><td></td></tr>\n~i","",$SvnInfoFile);
$SvnInfoFile="<tr><th colspan=\"2\">Subversion Info</th></tr>".$SvnInfoFile;
}
 
// Put Svn Info into HTML template
$FileContent=str_ireplace("<<SvnInfo>>", $SvnInfoFile, $FileContent);
#print $FileContent;
 
 
// Find <<WordList>>
if (!preg_match("/( *)(<<WordList>>)/i",$FileContent,$Matches))
{
487,6 → 518,7
// Indent and Concatenate lines
foreach($WordListHTML as $Key => $Value)
{
if ($Key>0)
$WordListHTML[$Key]=$Indent.preg_replace("/\n/","<br>",$Value);
}
$WordListHTML=implode("\n",$WordListHTML);
586,7 → 618,11
Error(CreateWordList($CFG["SourceDir"], $LabelList, $WordList));
 
// Create HTML WordList
Error(GenerateWordList($CFG["TemplateDir"], $CFG["DestinationDir"], $LabelList, $WordList));
Error(GenerateWordList(
$CFG["TemplateDir"],
$CFG["SourceDir"].$CFG["SvnInfoFileName"],
$CFG["DestinationDir"],
$LabelList, $WordList));
 
// Copy ASM files and convert them into HTML
Error(GenerateAsmFiles($CFG["TemplateDir"], $CFG["SourceDir"], $SourceAsmFiles, $CFG["DestinationDir"]));
595,7 → 631,8
print "O.K.\n";
return
 
// Zpracování readme autora + verze
// Zpracování readme autora
// Vyplatilo by se udělat samostatny formatovaci a nahrazovaci mechanizmus
// Zpracování templejtů do samostatného podprogramu (vyřešit indent...)
// tím se vyřeší i en/cs verze Asm souboru
// Generovat log do souboru místo printu (zvážit) oddělit chyby a varování