cvs: peardoc / make-partial.php
| From: | Martin Jansen | Date: | Thu, 27 Jan 2005 19:11:40 +0000 |
| Subject: | cvs: peardoc / make-partial.php | ||
| Groups: | php.pear.doc | ||
| Request: | Send a blank email to pear-doc+get-5478@lists.php.net to get a copy of this message | ||
mj Thu Jan 27 14:11:40 2005 EDT
Added files:
/peardoc make-partial.php
Log:
* Added script to generate partial builds of the manual.
# Explanation following soon.
http://cvs.php.net/co.php/peardoc/make-partial.php?r=1.1&p=1
Index: peardoc/make-partial.php
+++ peardoc/make-partial.php
#!/usr/bin/env php
<?php
/**
* Script to trigger partial builds of the PEAR manual
*
* LICENSE: This source file is subject to version 3.0 of the PHP license
* that is available through the world-wide-web at the following URI:
* http://www.php.net/license/3_0.txt. If you did
not receive a copy of
* the PHP License and are unable to obtain it through the web, please
* send a note to license@php.net so we can mail you a copy immediately.
*
* @author Martin Jansen <mj@php.net>
* @copyright 2005 The PEAR Group
* @version CVS: $Id: make-partial.php,v 1.1 2005/01/27 19:11:39 mj Exp $
*/
require_once "Console/Getopt.php";
$console = new Console_Getopt;
$args = $console->getopt($console->readPHPArgv(), array(),
array("format=", "include="));
if (!function_exists("readline")) {
echo "Error: The readline extension could not be found!";
exit(1);
}
$file = file("manual.xml.in");
if (!$file) {
echo "Error: Unable to read manual.xml.in!";
exit(1);
}
copy("manual.xml.in", "manual.xml.in.partial-backup");
register_shutdown_function("restoreFile");
$newFile = "";
$partStack = array();
$includePart = true;
$notInPart = true;
/**
* Loop through the file and build a new file depending on the users
* choice.
*/
foreach ($file as $line) {
// <part id="foo">
if (preg_match("/<part id=\"([a-z-]+)\">/", $line, $matches)) {
$inPart = true;
$include = readline("Include " . $matches[1] . "? [NO] ");
$includePart = evaluate($include);
if ($includePart == true) {
$newFile .= $line;
}
continue;
}
// </part>
if (preg_match("/<\/part>/", $line)) {
if (count($partStack) > 0) {
$newFile .= implode("", $partStack);
$partStack = array();
}
if ($includePart == true) {
$newFile .= $line;
}
$includePart = false;
$inPart = false;
continue;
}
// <title>
if ($inPart == true && $includePart && preg_match("/<title/",
$line)) {
$partStack[] = $line;
continue;
}
// the rest
if ($inPart == true) {
if ($includePart == false) {
continue;
}
if (preg_match("/(\s\t)*&([a-z0-9\.-]+);/", $line, $matches)) {
$include = evaluate(readline("Include " . $matches[2] . "? [NO] "));
if ($include == true) {
$partStack[] = $line;
}
}
} else {
$newFile .= $line;
}
}
file_put_contents("manual.xml.in", $newFile);
// {{{ Run the build scripts
$format = "html";
foreach ($args[0] as $arg) {
if ($arg[0] == "--format") {
$format = $arg[1];
}
}
$cmd = "make " . $format;
passthru($cmd);
// }}}
// {{{ Helper functions
/**
* Restores the original manual.xml.in file
*/
function restoreFile() {
if (!is_file("manual.xml.in.partial-backup")) {
return;
}
rename("manual.xml.in.partial-backup", "manual.xml.in");
}
/**
* Evaluates the return value of readline()
*
* If the first parameter is either "y" or "yes" the method will
* return true. Otherwise false.
*/
function evaluate($str) {
if ($str == 'y' || $str == "yes") {
return true;
}
return false;
}
// }}}