Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 0.8.0

Bug #6691 generate.bat can't work
Submitted: 2006-02-04 12:33 UTC
From: farell Assigned: blindman
Status: Closed Package: Text_Highlighter (version 0.6.8)
PHP Version: 4.4.2 OS: Windows XP
Roadmaps: (Not assigned)    
Comments Add Comment Add patch

Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know! Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
Solve the problem : 42 - 2 = ?

 [2006-02-04 12:33 UTC] farell
Description: ------------ Hi Andrey, i am crazy, to see "generate.bat" won't run. So i've quickly learnt Console_Getopt and analysed your scripts. i've discovered many problems. 1. you've merged script launcher (.bat on Windows) and php script ==> Win interpreter can't run a php script 2. you don't read args values, and so you can't manage them 3. you don't display usage when none args are given. 4. minor render with missing blank lines at bottom of usage text For all of these comments, i suggest a new .bat and a new php script as below: (i may also send it to you by mail, for better reading) Hope it will help BTW , i didn't test all parts of your script, and didn't test the unix version too. Take care !!! Laurent Test script: --------------- generate.bat ************** @echo off rem vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: rem Console highlighter class generator rem PHP versions 4 and 5 rem LICENSE: This source file is subject to version 3.0 of the PHP license rem that is available through the world-wide-web at the following URI: rem If you did not receive a copy of rem the PHP License and are unable to obtain it through the web, please rem send a note to so we can mail you a copy immediately. rem @category Text rem @package Text_Highlighter rem @author Andrey Demenev <> rem @copyright 2004 Andrey Demenev rem @license PHP License rem @version CVS: $Id: generate.bat 46 2006-02-03 15:16:04Z andrey $ rem @link @php_bin@ -d output_buffering=1 -d include_path="@php_dir@" -f "@bin_dir@\Text\Highlighter\generate.php" -- %1 generate.php ************** <?php ob_end_clean(); ob_implicit_flush(true); require_once 'Text/Highlighter/Generator.php'; require_once 'Console/Getopt.php'; $argv = Console_Getopt::readPHPArgv(); if (in_array('getopt2', get_class_methods('Console_Getopt'))) { array_shift($argv); $options = Console_Getopt::getopt2($argv, 'x:p:d:h', array('xml=', 'php=','dir=', 'help')); } else { $options = Console_Getopt::getopt($argv, 'x:p:d:h', array('xml=', 'php=','dir=', 'help')); } if (PEAR::isError($options)) { $message = str_replace('Console_Getopt: ','',$options->message); usage($message); } $source = array(); $dest = array(); $dir = ''; $expectp = false; $expectx = false; $unexpectedx = false; $unexpectedp = false; $si = $di = 0; if (count($options[0]) == 0) { // display help when none params are given on command line usage(); } foreach ($options[0] as $option) { switch ($option[0]) { case 'x': case '--xml': $source[$si] = $option[1]; if ($si) { $di++; } $si++; if ($expectp) { $unexpectedx = true; } $expectp = true; $expectx = false; break; case 'p': case '--php': if ($expectx) { $unexpectedp = true; } $dest[$di] = $option[1]; $expectp = false; $expectx = true; break; case 'd': case '--dir': $dir = $option[1]; break; case 'h': case '--help': usage(); break; } } if ($unexpectedx && !$dir) { usage('Unexpected -x or --xml', STDERR); } if ($unexpectedp) { usage('Unexpected -p or --php', STDERR); } $nsource = count($source); $ndest = count($dest); if (!$nsource && !$ndest) { $source[]='php://stdin'; if (!$dir) { $dest[]='php://stdout'; } else { $dest[] = null; } } elseif ($expectp && !$dir && $nsource > 1) { usage('-x or --xml without following -p or --php', STDERR); } elseif ($nsource == 1 && !$ndest && !$dir) { $dest[]='php://stdout'; } if ($dir && substr($dir,-1)!='/' && substr($dir,-1)!=='\\' ) { $dir .= DIRECTORY_SEPARATOR; } foreach ($source as $i => $xmlfile) { $gen =& new Text_Highlighter_Generator; $gen->setInputFile($xmlfile); if ($gen->hasErrors()) { break; } $gen->generate(); if ($gen->hasErrors()) { break; } if (isset($dest[$i])) { $phpfile = $dest[$i]; } else { $phpfile = $dir . $gen->language . '.php'; } $gen->saveCode($phpfile); if ($gen->hasErrors()) { break; } } if ($gen->hasErrors()) { $errors = $gen->getErrors(); foreach ($errors as $error) { fwrite (STDERR, $error . "\n"); } exit(1); } function usage($message='', $file=STDOUT) { $code = 0; if ($message) { $message .= "\n\n"; $code = 1; } $message .= <<<MSG Generates a highlighter class from XML source Usage: generate options Options: -x filename, --xml=filename source XML file. Multiple input files can be specified, in which case each -x option must be followed by -p unless -d is specified Defaults to stdin -p filename, --php=filename destination PHP file. Defaults to stdout. If specied multiple times, each -p must follow -x -d dirname, --dir=dirname Default destination directory. File names will be taken from XML input ("lang" attribute of <highlight> tag) -h, --help This help MSG; fwrite ($file, $message); exit($code); } ?> Expected result: ---------------- generate.bat will display help usage when none params are given, and will finally run Actual result: -------------- generate.bat won't run, and quickly close windows command line boxe.


 [2006-02-04 13:48 UTC] blindman
Hi Laurent 1. The script is run by PHP, not Windows command-line interpreter. 2. the script does read args 3. I do not have to display usage. When no args given, XML source is read from stdin and written to stdout. Actually, I did not do testing on Windows (except the first version). Today, I did a fresh PHP installation on a Windows machine and installed Text_Highlighter. So far, I see 2 problems : 1. PHP is used without -q option, and headers garbage the output when CGI binary is used -- this is minor, however 2. The major one is that STDIN and STDERR constants are used in the generate.bat script -- and CGI binary does not define them. Could you please post the output of the script you recieve? On unix, the script is much better tested (I use it each time I make a release to generate PHP files from XML sources).
 [2006-02-05 22:53 UTC] farell
Andrey, If i test the "generate.bat" script given with 0.6.8 release, here are output i got: 1. after opening a windows command line box, and run the generate.bat ==> my win box closed itself. It's due to 'exit' on line 32. 2. if i remove 'exit' on line 32, i get Fatal error: main(): Failed opening required 'Text/Highlighter/Generator.php' (i nclude_path='.;c:\php4\pear') in E:\wamp\php4\Text\Highlighter\generate.bat on l ine 35 Normal, because path to pear installation is available only on my php.ini which is access by sapi and not cli interface. Need to add : -d include_path="@php_dir@" 3. after i add this missing stuff, i get only echo off as output Normal, what did you expect to have there : a script (generate.bat) that try to call itself. It can't work ! Laurent
 [2006-02-11 03:05 UTC] blindman at php dot net
Thank you for your bug report. This issue has been fixed in the latest released version of the package, which you can download at