2 rem vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4:
4 rem Console highlighter class generator
6 rem PHP versions 4 and 5
8 rem LICENSE: This source file is subject to version 3.0 of the PHP license
9 rem that is available through the world-wide-web at the following URI:
10 rem http://www.php.net/license/3_0.txt. If you did not receive a copy of
11 rem the PHP License and are unable to obtain it through the web, please
12 rem send a note to license@php.net so we can mail you a copy immediately.
15 rem @package Text_Highlighter
16 rem @author Andrey Demenev <demenev@gmail.com>
17 rem @copyright 2004 Andrey Demenev
18 rem @license http://www.php.net/license/3_0.txt PHP License
19 rem @version CVS: $Id: generate.bat,v 1.1 2007-06-03 02:35:28 ssttoo Exp $
20 rem @link http://pear.php.net/package/Text_Highlighter
24 set "MHL_PARAMS=%MHL_PARAMS% %1"
26 if -%1- == -- GOTO noshift
29 @php_bin@ -q -d output_buffering=1 -d include_path="@php_dir@" @bin_dir@/Text/Highlighter/generate.bat %MHL_PARAMS%
35 if (!defined('STDOUT')) {
36 define('STDOUT', fopen('php://stdout', 'wb'));
37 define('STDERR', fopen('php://stderr', 'wb'));
39 require_once 'Text/Highlighter/Generator.php';
40 require_once 'Console/Getopt.php';
42 $options = Console_Getopt::getopt($argv, 'x:p:d:h', array('xml=', 'php=','dir=', 'help'));
44 if (PEAR::isError($options)) {
45 $message = str_replace('Console_Getopt: ','',$options->message);
59 foreach ($options[0] as $option) {
63 $source[$si] = $option[1];
80 $dest[$di] = $option[1];
98 if ($unexpectedx && !$dir) {
99 usage('Unexpected -x or --xml', STDERR);
103 usage('Unexpected -p or --php', STDERR);
106 $nsource = count($source);
107 $ndest = count($dest);
109 if (!$nsource && !$ndest) {
110 $source[]='php://stdin';
112 $dest[]='php://stdout';
116 } elseif ($expectp && !$dir && $nsource > 1) {
117 usage('-x or --xml without following -p or --php', STDERR);
118 } elseif ($nsource == 1 && !$ndest && !$dir) {
119 $dest[]='php://stdout';
122 if ($dir && substr($dir,-1)!='/' && substr($dir,-1)!=='\\' ) {
123 $dir .= DIRECTORY_SEPARATOR;
127 foreach ($source as $i => $xmlfile)
129 $gen = new Text_Highlighter_Generator;
130 $gen->setInputFile($xmlfile);
131 if ($gen->hasErrors()) {
135 if ($gen->hasErrors()) {
138 if (isset($dest[$i])) {
139 $phpfile = $dest[$i];
141 $phpfile = $dir . $gen->language . '.php';
143 $gen->saveCode($phpfile);
144 if ($gen->hasErrors()) {
148 if ($gen->hasErrors()) {
149 $errors = $gen->getErrors();
150 foreach ($errors as $error) {
151 fwrite (STDERR, $error . "\n");
158 function usage($message='', $file=STDOUT)
166 Generates a highlighter class from XML source
171 -x filename, --xml=filename
172 source XML file. Multiple input files can be specified, in which
173 case each -x option must be followed by -p unless -d is specified
175 -p filename, --php=filename
176 destination PHP file. Defaults to stdout. If specied multiple times,
177 each -p must follow -x
178 -d dirname, --dir=dirname
179 Default destination directory. File names will be taken from XML input
180 ("lang" attribute of <highlight> tag)
184 fwrite ($file, $message);