3
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
5
* Console highlighter class generator
9
* LICENSE: This source file is subject to version 3.0 of the PHP license
10
* that is available through the world-wide-web at the following URI:
11
* http://www.php.net/license/3_0.txt. If you did not receive a copy of
12
* the PHP License and are unable to obtain it through the web, please
13
* send a note to license@php.net so we can mail you a copy immediately.
16
* @package Text_Highlighter
17
* @author Andrey Demenev <demenev@gmail.com>
18
* @copyright 2004 Andrey Demenev
19
* @license http://www.php.net/license/3_0.txt PHP License
20
* @version CVS: $Id: generate,v 1.1 2007/06/03 02:35:28 ssttoo Exp $
21
* @link http://pear.php.net/package/Text_Highlighter
24
require_once 'Text/Highlighter/Generator.php';
25
require_once 'Console/Getopt.php';
27
$options = Console_Getopt::getopt($argv, 'x:p:d:h', array('xml=', 'php=','dir=', 'help'));
29
if (PEAR::isError($options)) {
30
$message = str_replace('Console_Getopt: ','',$options->message);
44
foreach ($options[0] as $option) {
48
$source[$si] = $option[1];
65
$dest[$di] = $option[1];
83
if ($unexpectedx && !$dir) {
84
usage('Unexpected -x or --xml', STDERR);
88
usage('Unexpected -p or --php', STDERR);
91
$nsource = count($source);
92
$ndest = count($dest);
94
if (!$nsource && !$ndest) {
95
$source[]='php://stdin';
97
$dest[]='php://stdout';
101
} elseif ($expectp && !$dir && $nsource > 1) {
102
usage('-x or --xml without following -p or --php', STDERR);
103
} elseif ($nsource == 1 && !$ndest && !$dir) {
104
$dest[]='php://stdout';
107
if ($dir && substr($dir,-1)!='/' && substr($dir,-1)!=='\\' ) {
108
$dir .= DIRECTORY_SEPARATOR;
112
foreach ($source as $i => $xmlfile)
114
$gen =& new Text_Highlighter_Generator;
115
$gen->setInputFile($xmlfile);
116
if ($gen->hasErrors()) {
120
if ($gen->hasErrors()) {
123
if (isset($dest[$i])) {
124
$phpfile = $dest[$i];
126
$phpfile = $dir . $gen->language . '.php';
128
$gen->saveCode($phpfile);
129
if ($gen->hasErrors()) {
133
if ($gen->hasErrors()) {
134
$errors = $gen->getErrors();
135
foreach ($errors as $error) {
136
fwrite (STDERR, $error . "\n");
141
function usage($message='', $file=STDOUT)
149
Generates a highlighter class from XML source
154
-x filename, --xml=filename
155
source XML file. Multiple input files can be specified, in which
156
case each -x option must be followed by -p unless -d is specified
158
-p filename, --php=filename
159
destination PHP file. Defaults to stdout. If specied multiple times,
160
each -p must follow -x
161
-d dirname, --dir=dirname
162
Default destination directory. File names will be taken from XML input
163
("lang" attribute of <highlight> tag)
167
fwrite ($file, $message);
3
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
5
* Console highlighter class generator
9
* LICENSE: This source file is subject to version 3.0 of the PHP license
10
* that is available through the world-wide-web at the following URI:
11
* http://www.php.net/license/3_0.txt. If you did not receive a copy of
12
* the PHP License and are unable to obtain it through the web, please
13
* send a note to license@php.net so we can mail you a copy immediately.
16
* @package Text_Highlighter
17
* @author Andrey Demenev <demenev@gmail.com>
18
* @copyright 2004 Andrey Demenev
19
* @license http://www.php.net/license/3_0.txt PHP License
20
* @version CVS: $Id: generate,v 1.1 2007/06/03 02:35:28 ssttoo Exp $
21
* @link http://pear.php.net/package/Text_Highlighter
24
require_once 'Text/Highlighter/Generator.php';
25
require_once 'Console/Getopt.php';
27
$options = Console_Getopt::getopt($argv, 'x:p:d:h', array('xml=', 'php=','dir=', 'help'));
29
if (PEAR::isError($options)) {
30
$message = str_replace('Console_Getopt: ','',$options->message);
44
foreach ($options[0] as $option) {
48
$source[$si] = $option[1];
65
$dest[$di] = $option[1];
83
if ($unexpectedx && !$dir) {
84
usage('Unexpected -x or --xml', STDERR);
88
usage('Unexpected -p or --php', STDERR);
91
$nsource = count($source);
92
$ndest = count($dest);
94
if (!$nsource && !$ndest) {
95
$source[]='php://stdin';
97
$dest[]='php://stdout';
101
} elseif ($expectp && !$dir && $nsource > 1) {
102
usage('-x or --xml without following -p or --php', STDERR);
103
} elseif ($nsource == 1 && !$ndest && !$dir) {
104
$dest[]='php://stdout';
107
if ($dir && substr($dir,-1)!='/' && substr($dir,-1)!=='\\' ) {
108
$dir .= DIRECTORY_SEPARATOR;
112
foreach ($source as $i => $xmlfile)
114
$gen =& new Text_Highlighter_Generator;
115
$gen->setInputFile($xmlfile);
116
if ($gen->hasErrors()) {
120
if ($gen->hasErrors()) {
123
if (isset($dest[$i])) {
124
$phpfile = $dest[$i];
126
$phpfile = $dir . $gen->language . '.php';
128
$gen->saveCode($phpfile);
129
if ($gen->hasErrors()) {
133
if ($gen->hasErrors()) {
134
$errors = $gen->getErrors();
135
foreach ($errors as $error) {
136
fwrite (STDERR, $error . "\n");
141
function usage($message='', $file=STDOUT)
149
Generates a highlighter class from XML source
154
-x filename, --xml=filename
155
source XML file. Multiple input files can be specified, in which
156
case each -x option must be followed by -p unless -d is specified
158
-p filename, --php=filename
159
destination PHP file. Defaults to stdout. If specied multiple times,
160
each -p must follow -x
161
-d dirname, --dir=dirname
162
Default destination directory. File names will be taken from XML input
163
("lang" attribute of <highlight> tag)
167
fwrite ($file, $message);