[PHP-DOC] cvs: phpdoc /scripts make-partial.php

2005-09-28 Thread anatoly techtonik
techtonik   Wed Sep 28 11:47:52 2005 EDT

  Modified files:  
/phpdoc/scripts make-partial.php 
  Log:
  * (sync) recover manual.xml.in if the script was terminated unexpectedly
  
http://cvs.php.net/diff.php/phpdoc/scripts/make-partial.php?r1=1.2&r2=1.3&ty=u
Index: phpdoc/scripts/make-partial.php
diff -u phpdoc/scripts/make-partial.php:1.2 phpdoc/scripts/make-partial.php:1.3
--- phpdoc/scripts/make-partial.php:1.2 Tue Sep 13 19:41:19 2005
+++ phpdoc/scripts/make-partial.php Wed Sep 28 11:47:51 2005
@@ -12,7 +12,7 @@
  *
  * @authorMartin Jansen <[EMAIL PROTECTED]>
  * @copyright 2005 The PEAR Group
- * @version   CVS: $Id: make-partial.php,v 1.2 2005/09/13 23:41:19 techtonik 
Exp $
+ * @version   CVS: $Id: make-partial.php,v 1.3 2005/09/28 15:47:51 techtonik 
Exp $
  */
 
 // NOTE: originally from peardoc:/make-partial.php ;
@@ -33,6 +33,7 @@
 $format = "html";
 $sections = array();
 
+$incflag = false;
 foreach ($args[0] as $arg) {
 if ($arg[0] == "--help") {
 showHelp();
@@ -41,6 +42,14 @@
 $format = $arg[1];
 } elseif ($arg[0] == '--include') {
 $sections[] = $arg[1];
+$incflag = true;
+}
+}
+
+if ($incflag) {
+// collect other space delimited names as section names
+foreach ($args[1] as $arg) {
+$sections[] = $arg;
 }
 }
 
@@ -57,15 +66,18 @@
 }
 }
 
+// recover manual.xml.in if the script was terminated unexpectedly
+restoreFile();
+
+copy("manual.xml.in", "manual.xml.in.partial-backup");
+register_shutdown_function("restoreFile", filemtime("manual.xml.in"));
+
 $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", filemtime("manual.xml.in"));
-
 $newFile = "";
 $partStack = array();
 $includePart = true;
@@ -162,14 +174,14 @@
 /**
  * Restores the original manual.xml.in file
  */
-function restoreFile($savedmtime) {
+function restoreFile($savedmtime = null) {
 if (!is_file("manual.xml.in.partial-backup")) {
 return;
 }
 
 unlink("manual.xml.in");
 rename("manual.xml.in.partial-backup", "manual.xml.in");
-touch("manual.xml.in", $savedmtime);
+if ($savedmtime) touch("manual.xml.in", $savedmtime);
 }
 
 /**


[PHP-DOC] cvs: phpdoc /scripts make-partial.php

2005-09-13 Thread anatoly techtonik
techtonik   Tue Sep 13 19:41:21 2005 EDT

  Modified files:  
/phpdoc/scripts make-partial.php 
  Log:
  * sync with peardoc
  
http://cvs.php.net/diff.php/phpdoc/scripts/make-partial.php?r1=1.1&r2=1.2&ty=u
Index: phpdoc/scripts/make-partial.php
diff -u phpdoc/scripts/make-partial.php:1.1 phpdoc/scripts/make-partial.php:1.2
--- phpdoc/scripts/make-partial.php:1.1 Fri Jan 28 10:17:01 2005
+++ phpdoc/scripts/make-partial.php Tue Sep 13 19:41:19 2005
@@ -1,6 +1,7 @@
 #!/usr/bin/env php
 
  * @copyright 2005 The PEAR Group
- * @version   CVS: $Id: make-partial.php,v 1.1 2005/01/28 15:17:01 sean Exp $
+ * @version   CVS: $Id: make-partial.php,v 1.2 2005/09/13 23:41:19 techtonik 
Exp $
  */
 
 // NOTE: originally from peardoc:/make-partial.php ;
 // these files should be kept in sync
 
+if (substr(PHP_VERSION, 0, 1) == "4") {
+require_once "PHP/Compat.php";
+$components = PHP_Compat::loadVersion('5.0.0');
+}
+
 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");
+ array("format=", "include=", "help"));
 
 // {{{ gather arguments
 
@@ -42,7 +34,10 @@
 $sections = array();
 
 foreach ($args[0] as $arg) {
-if ($arg[0] == "--format") {
+if ($arg[0] == "--help") {
+showHelp();
+exit(0);
+} elseif ($arg[0] == "--format") {
 $format = $arg[1];
 } elseif ($arg[0] == '--include') {
 $sections[] = $arg[1];
@@ -51,6 +46,25 @@
 
 // }}}
 
+$hasReadline = true;
+if (!function_exists("readline")) {
+$hasReadline = false;
+echo "Warning: The readline extension could not be found!\n";
+if (count($sections) == 0) {
+showHelp();
+echo "Exiting because no --include parameters were specified.\n";
+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", filemtime("manual.xml.in"));
 
 $newFile = "";
 $partStack = array();
@@ -68,12 +82,12 @@
 
 if ($sections) {
 echo "Including ". $matches[1] ."? ";
-if ($includePart = in_string($sections, $matches[1])) {
+if ($includePart = inString($sections, $matches[1])) {
 echo "YES\n";
 } else {
 echo "NO\n";
 }
-} else {
+} else if ($hasReadline) {
 $include = readline("Include " . $matches[1] . "? [NO] ");
 $includePart = evaluate($include);
 }
@@ -117,12 +131,12 @@
 
 if ($sections) {
 echo "Including ". $matches[2] ."? ";
-if ($include = in_string($sections, $matches[2])) {
+if ($include = inString($sections, $matches[2])) {
 echo "YES\n";
 } else {
 echo "NO\n";
 }
-} else {
+} else if ($hasReadline) {
 $include = evaluate(readline("Include " . $matches[2] . "? 
[NO] "));
 }
 
@@ -148,12 +162,14 @@
 /**
  * Restores the original manual.xml.in file
  */
-function restoreFile() {
+function restoreFile($savedmtime) {
 if (!is_file("manual.xml.in.partial-backup")) {
 return;
 }
 
+unlink("manual.xml.in");
 rename("manual.xml.in.partial-backup", "manual.xml.in");
+touch("manual.xml.in", $savedmtime);
 }
 
 /**
@@ -170,12 +186,16 @@
 }
 
 /**
- * $needle (array) is in $haystack?
+ * Checks if one element of the first parameter is part of the second parameter
  *
+ * @param  array List of needles
+ * @param  string Haystack
+ * @return boolean True if one of the needles is in the haystack,
+ * false otherwise.
  */
-function in_string($needle, $haystack)
+function inString($needle, $haystack)
 {
-foreach ((array) $needle AS $n) {
+foreach ((array) $needle as $n) {
 if (stripos($haystack, $n) !== false) {
 return true;
 }
@@ -183,4 +203,22 @@
 return false;
 }
 
+/**
+ * Prints a usage notice for the script
+ *
+ * @return void
+ */
+function showHelp()
+{
+echo "Usage: make-partial.php [--format ] [--include ] 
[--include ] ...\n";
+echo "   make-partial.php --help\n";
+echo "\n";
+echo "  --format Which format to build. Can be one of 'html', 
'pearweb'.\n";
+echo "   Default is 'html'.\n";
+echo "  --include   Automatically include certa

Re: [PHP-DOC] cvs: phpdoc /scripts make-partial.php

2005-01-28 Thread Nuno Lopes
just a tip :) :
You can build a part of the manual using 'xsltproc --timing --stringparam 
rootid "++ID++" xsl/html.xsl manual.xml'
where ++ID++ is the id to build, like migration5, faq, etc..

my old patch: http://marc.theaimsgroup.com/?l=phpdoc&m=107384347206304&w=2
Nuno 


Re: [PHP-DOC] cvs: phpdoc /scripts make-partial.php

2005-01-28 Thread Philip Olson

Nice!!!

Regards,
Philip

On Fri, 28 Jan 2005, Sean Coates wrote:

> sean  Fri Jan 28 10:17:02 2005 EDT
> 
>   Added files: 
> /phpdoc/scripts   make-partial.php 
>   Log:
>   See:
>   http://news.php.net/php.pear.doc/5479
>   http://news.php.net/php.pear.doc/5481
>   http://news.php.net/php.pear.doc/5482
>   (import to phpdoc)
>   
>   
> 
> http://cvs.php.net/co.php/phpdoc/scripts/make-partial.php?r=1.1&p=1
> Index: phpdoc/scripts/make-partial.php
> +++ phpdoc/scripts/make-partial.php
> #!/usr/bin/env php
>  /** vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4:
>  * 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 [EMAIL PROTECTED] so we can mail you a copy immediately.
>  *
>  * @authorMartin Jansen <[EMAIL PROTECTED]>
>  * @copyright 2005 The PEAR Group
>  * @version   CVS: $Id: make-partial.php,v 1.1 2005/01/28 15:17:01 sean Exp $
>  */
> 
> // NOTE: originally from peardoc:/make-partial.php ;
> // these files should be kept in sync
> 
> 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");
> 
> // {{{ gather arguments
> 
> $format = "html";
> $sections = array();
> 
> foreach ($args[0] as $arg) {
> if ($arg[0] == "--format") {
> $format = $arg[1];
> } elseif ($arg[0] == '--include') {
> $sections[] = $arg[1];
> }
> }
> 
> // }}}
> 
> 
> $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) {
> // 
> if (preg_match("//", $line, $matches)) {
> $inPart = true;
> 
> if ($sections) {
> echo "Including ". $matches[1] ."? ";
> if ($includePart = in_string($sections, $matches[1])) {
> echo "YES\n";
> } else {
> echo "NO\n";
> }
> } else {
> $include = readline("Include " . $matches[1] . "? [NO] ");
> $includePart = evaluate($include);
> }
> 
> if ($includePart == true) {
> $newFile .= $line;
> }
> 
> continue;
> }
> 
> // 
> if (preg_match("/<\/part>/", $line)) {
> if (count($partStack) > 0) {
> $newFile .= implode("", $partStack);
> $partStack = array();
> }
> 
> if ($includePart == true) {
> $newFile .= $line;
> }
> $includePart = false;
> $inPart = false;
> 
> continue;
> }
> 
> // 
> if ($inPart == true && $includePart && preg_match("/ $partStack[] = $line;
> continue;
> }
> 
> // the rest
> if ($inPart == true) {
> if ($includePart == false) {
> continue;
> }
> 
> if (preg_match("/(\s\t)*&([a-z0-9\.-]+);/", $line, $matches)) {
> 
> if ($sections) {
> echo "Including ". $matches[2] ."? ";
> if ($include = in_string($sections, $matches[2])) {
> echo "YES\n";
> } else {
> echo "NO\n";
> }
> } else {
> $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
> 
> $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;
> }
> 
> /**
>  * $needle (array) is in $hayst

[PHP-DOC] cvs: phpdoc /scripts make-partial.php

2005-01-28 Thread Sean Coates
seanFri Jan 28 10:17:02 2005 EDT

  Added files: 
/phpdoc/scripts make-partial.php 
  Log:
  See:
  http://news.php.net/php.pear.doc/5479
  http://news.php.net/php.pear.doc/5481
  http://news.php.net/php.pear.doc/5482
  (import to phpdoc)
  
  

http://cvs.php.net/co.php/phpdoc/scripts/make-partial.php?r=1.1&p=1
Index: phpdoc/scripts/make-partial.php
+++ phpdoc/scripts/make-partial.php
#!/usr/bin/env php
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 [EMAIL PROTECTED] so we can mail you a copy immediately.
 *
 * @authorMartin Jansen <[EMAIL PROTECTED]>
 * @copyright 2005 The PEAR Group
 * @version   CVS: $Id: make-partial.php,v 1.1 2005/01/28 15:17:01 sean Exp $
 */

// NOTE: originally from peardoc:/make-partial.php ;
// these files should be kept in sync

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");

// {{{ gather arguments

$format = "html";
$sections = array();

foreach ($args[0] as $arg) {
if ($arg[0] == "--format") {
$format = $arg[1];
} elseif ($arg[0] == '--include') {
$sections[] = $arg[1];
}
}

// }}}


$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) {
// 
if (preg_match("//", $line, $matches)) {
$inPart = true;

if ($sections) {
echo "Including ". $matches[1] ."? ";
if ($includePart = in_string($sections, $matches[1])) {
echo "YES\n";
} else {
echo "NO\n";
}
} else {
$include = readline("Include " . $matches[1] . "? [NO] ");
$includePart = evaluate($include);
}

if ($includePart == true) {
$newFile .= $line;
}

continue;
}

// 
if (preg_match("/<\/part>/", $line)) {
if (count($partStack) > 0) {
$newFile .= implode("", $partStack);
$partStack = array();
}

if ($includePart == true) {
$newFile .= $line;
}
$includePart = false;
$inPart = false;

continue;
}

// 
if ($inPart == true && $includePart && preg_match("/