use strict;
use File::Basename;
use Cwd;
use Win32;
require 'cmn.pl';
sub Main;
sub CheckForProgs;
sub CopyAndEolU2W;
sub MkDirP;
my $g_PathDocRoot=&cmn_ValuePathfile('path_svnbook');
my $g_PathSubvRoot=&cmn_ValuePathfile('path_subversion');
my $g_PathMiscIn=&cmn_ValuePathfile('path_setup_in');
my %g_FilesToCpAndConv=
(
'COPYING', 'subversion\SubversionLicense.txt',
'README', 'subversion\Readme.dist',
'doc\user\lj_article.txt', 'doc\lj_article.txt',
'doc\programmer\WritingChangeLogs.txt', 'doc\WritingChangeLogs.txt',
);
my $g_Prog_hhc='';
my %g_ProgsInPath=
(
'libxslt is needed for converting the XML-documentaion.',
'xsltproc.exe',
'iconv is needed by libxslt and libxslt for converting the XML-documentaion.',
'iconv.exe',
'libxml2 is needed by libxslt for converting the XML-documentaion.',
'libxml2.dll'
);
Main;
sub Main
{
my $CntMkHtmBat='';
my %Values;
my $RootSvnBook=&cmn_ValuePathfile('path_svnbook');
my $DocOut=&cmn_ValuePathfile('path_setup_in');
my $PathWinIsPack='';
my $Pwd='';
my $CntVerXml='';
$PathWinIsPack=getcwd;
$Pwd=basename($PathWinIsPack);
$PathWinIsPack =~ s/\//\\/g;
$PathWinIsPack =~ s/\\$Pwd$//;
if ($DocOut eq 'in')
{
$DocOut = "$PathWinIsPack\\in\\doc";
}
&MkDirP ("$RootSvnBook\\src\\out") unless (-e "$RootSvnBook\\src\\out");
&MkDirP ("$DocOut") unless (-e "$DocOut");
&CheckForProgs;
&CopyAndEolU2W;
%Values =
(
tv_path_hhc => $g_Prog_hhc,
tv_bookdest => $DocOut
);
$CntMkHtmBat=&cmn_Template("$PathWinIsPack\\templates\\mk_htmlhelp.bat", \%Values);
open (FH_HHP, ">" . "$RootSvnBook\\src\\out\\mk_htmlhelp.bat");
print FH_HHP $CntMkHtmBat;
close (FH_HHP);
system ("copy /Y ..\\templates\\svn-doc.css $RootSvnBook\\src\\out");
system ("copy /Y ..\\images\\svn_bck.png $RootSvnBook\\src\\out");
chdir "$RootSvnBook\\src\\en";
$CntVerXml=`svnversion .`;
chomp($CntVerXml);
open (FH_VERXML, ">" . "$RootSvnBook\\src\\en\\book\\version.xml");
print FH_VERXML "<!ENTITY svn.version \"Revision $CntVerXml\">";
close (FH_VERXML);
chdir "$RootSvnBook\\src\\out";
system ("$RootSvnBook\\src\\out\\mk_htmlhelp.bat");
chdir $Pwd;
}
sub CheckForProgs
{
my @MissingProgs;
my @SysPath;
my $bMissingProgs=0;
my $Prog2CheckDesc='';
my $Prog2Check='';
@SysPath = split (/;/, $ENV{PATH});
while (($Prog2CheckDesc, $Prog2Check) = each %g_ProgsInPath)
{
my $bProg2CheckExists=0;
for (@SysPath)
{
if (-e "$_\\$Prog2Check")
{
$bProg2CheckExists=1;
last;
}
}
if (! $bProg2CheckExists)
{
$bMissingProgs = 1;
push @MissingProgs, $Prog2CheckDesc;
}
}
$g_Prog_hhc = &cmn_ValuePathfile('path_hhc');
$g_Prog_hhc = "$g_Prog_hhc\\hhc.exe";
if (! -e $g_Prog_hhc)
{
$bMissingProgs = 1;
push @MissingProgs, 'Microsoft HTML Help Workshop is needed for making the HTML-help file';
}
$g_Prog_hhc = "\"$g_Prog_hhc\"";
if ($bMissingProgs)
{
my $Msg="One or more required programs needed for making the docs are missing:\n\n";
for (@MissingProgs)
{
$Msg=$Msg . " - $_\n";
}
$Msg=$Msg . "\nPlease, check that everything are installed properly as described in\n";
$Msg=$Msg . "the documentation in packages\\windows-innosetup\\tools\\readme.txt\n";
Win32::MsgBox($Msg, 0+MB_ICONSTOP, 'ERROR: Missing required programs.');
exit 1;
}
}
sub CopyAndEolU2W
{
my $FileSrc='';
my $FileDest='';
my $FileCnt='';
my $PathWinIsPack='';
my $Pwd='';
$PathWinIsPack=getcwd;
$Pwd=basename($PathWinIsPack);
$PathWinIsPack =~ s/\//\\/g;
$PathWinIsPack =~ s/\\$Pwd$//;
while (($FileSrc, $FileDest) = each %g_FilesToCpAndConv)
{
$FileSrc = "$g_PathSubvRoot\\$FileSrc";
$FileDest = "$PathWinIsPack\\$g_PathMiscIn\\$FileDest";
print "Copying and converting EOL's from $FileSrc to $FileDest\n";
open (FH_SRC, $FileSrc);
while (<FH_SRC>)
{
chomp($_);
$_ = "$_\r\n";
if ($FileCnt)
{
$FileCnt = $FileCnt . $_;
}
else
{
$FileCnt = $_;
}
}
close (FH_SRC);
&MkDirP (dirname($FileDest)) unless (-e dirname($FileDest));
open (FH_DEST, ">" . $FileDest);
print FH_DEST $FileCnt;
close (FH_DEST);
$FileCnt='';
}
}