cvs: peardoc /scripts make-chm.php
| From: | anatoly techtonik | Date: | Thu, 08 Dec 2005 22:05:46 +0000 |
| Subject: | cvs: peardoc /scripts make-chm.php | ||
| Groups: | php.pear.doc | ||
| Request: | Send a blank email to pear-doc+get-7281@lists.php.net to get a copy of this message | ||
techtonik Thu Dec 8 17:05:46 2005 EDT
Modified files:
/peardoc/scripts make-chm.php
Log:
and now real stuff
- convert russian CHM files to windows-1251, because MS HtmlHelp
compiler doesn't know anything about KOI8-R
- parse alternative date format in source index.html
http://cvs.php.net/diff.php/peardoc/scripts/make-chm.php?r1=1.6&r2=1.7&ty=u
Index: peardoc/scripts/make-chm.php
diff -u peardoc/scripts/make-chm.php:1.6 peardoc/scripts/make-chm.php:1.7
--- peardoc/scripts/make-chm.php:1.6 Thu Dec 8 17:01:23 2005
+++ peardoc/scripts/make-chm.php Thu Dec 8 17:05:44 2005
@@ -18,7 +18,7 @@
| Mark Wiesemann <wiesemann@php.net> |
+----------------------------------------------------------------------+
- $Id: make-chm.php,v 1.6 2005/12/08 22:01:23 techtonik Exp $
+ $Id: make-chm.php,v 1.7 2005/12/08 22:05:44 techtonik Exp $
*/
/**
@@ -36,6 +36,12 @@
* in chm/ directory by default. All you need to do is to copy this
* directory to Windows machine and execute:
* HHC.EXE pear_manual_en.hhp
+ *
+ * Remarks:
+ * - this script uses File_SearchReplace library available from PEAR
+ * - iconv extension is required to build russian version of CHM.
+ * MS HtmlHelp doesn't support russian KOI8-R encoding in CHM index
+ * and ToC, so pages should be converted to windows-1251
*/
// Note: File_SearchReplace >= 1.1.0 is needed
@@ -50,6 +56,11 @@
echo "Preparing '$lang' version of CHM manual...\n";
+// ru:
+if ($lang === 'ru' && !function_exists('iconv')) {
+ die("Error: Iconv is required to produce russian version of manual");
+}
+
$ind = "$cwd/../html"; // source directory
$chmd = "$cwd/../chm"; // path for HH project files (autopurged)
$pref = "pear_manual_$lang"; // name and path substitutions
@@ -218,6 +229,13 @@
</div>
</BODY';
+// ru:
+if ($lang === 'ru') {
+ $find_rx[] = '|text/html; charset=KOI8-R|ims';
+ $replace[] = 'text/html; charset=windows-1251';
+ // look conversion code is at the end of this script
+}
+
$sr = &new File_SearchReplace(
$find_rx,
$replace,
@@ -232,9 +250,14 @@
// pull date, copyright from original index.html
$index = file_get_contents("$ind/index.html");
preg_match("!pubdate\".*?>(.+?)<!is", $index, $matches);
-// $matches[1] is Wed Mar 2 20:31:52 JST 2005
-list($dw, $m, $d, $time, $l, $Y) = sscanf($matches[1], "%s %s %d %s %s %s");
-echo "\nPubdate: " . $date = date("d-m-Y", strtotime("$dw, $d $m $Y
$time"));
+// $matches[1] is Wed Mar 2 20:31:52 JST 2005 or 07-12-2005 print_r($matches[1]);
+if (strlen($matches[1]) > 10) {
+ list($dw, $m, $d, $time, $l, $Y) = sscanf($matches[1], "%s %s %d %s %s %s");
+ $date = date("d-m-Y", strtotime("$dw, $d $m $Y $time"));
+} else {
+ $date = $matches[1];
+}
+echo "\nPubdate: " . $date;
preg_match("!©[^<]+!is", $index, $matches);
$copy = $matches[0];
@@ -498,6 +521,24 @@
");
fclose($fhk);
+
+// ru: MS HtmlHelp engine support only windows-1251 russian encoding in ToC and index
+if ($lang === 'ru') {
+ echo "\nRussian CHM must be converted to windows-1251. Processing... ";
+ $thtmlfiles = array_merge(
+ glob("$chmd/$pref.hh[kc]"),
+ glob("$outd/*.html")
+ );
+ foreach ($thtmlfiles as $f) {
+ $fcontents = file_get_contents($f);
+ $converted = iconv("koi8-r", "windows-1251", $fcontents);
+// debug: if (strlen($converted) !== strlen($fcontents)) echo "\n$f conversion
failed";
+ $fp = fopen($f,"w");
+ fwrite($fp, $converted);
+ fclose($fp);
+ }
+}
+
echo "Done.\n";
echo "\nNow you can follow into \"$chmd\" directory and launch MS HTMLHELP compiler
to build CHM";
echo "\n\n HHC.EXE $pref.hhp\n";