Subversion-Projekte lars-tiefland.prado

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 1
@echo off
2
rem vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4:
3
 
4
rem Console highlighter class generator
5
 
6
rem PHP versions 4 and 5
7
 
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.
13
 
14
rem @category   Text
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
21
 
22
set "MHL_PARAMS="
23
:doshift
24
set "MHL_PARAMS=%MHL_PARAMS% %1"
25
shift
26
if -%1- == -- GOTO noshift
27
GOTO doshift
28
:noshift
29
@php_bin@ -q -d output_buffering=1 -d include_path="@php_dir@" @bin_dir@/Text/Highlighter/generate.bat %MHL_PARAMS%
30
 
31
GOTO finish
32
<?php
33
ob_end_clean();
34
 
35
if (!defined('STDOUT')) {
36
    define('STDOUT', fopen('php://stdout', 'wb'));
37
    define('STDERR', fopen('php://stderr', 'wb'));
38
}
39
require_once 'Text/Highlighter/Generator.php';
40
require_once 'Console/Getopt.php';
41
 
42
$options = Console_Getopt::getopt($argv, 'x:p:d:h', array('xml=', 'php=','dir=', 'help'));
43
 
44
if (PEAR::isError($options)) {
45
    $message = str_replace('Console_Getopt: ','',$options->message);
46
    usage($message);
47
}
48
 
49
$source = array();
50
$dest   = array();
51
$dir    = '';
52
 
53
$expectp = false;
54
$expectx = false;
55
$unexpectedx = false;
56
$unexpectedp = false;
57
$si = $di = 0;
58
 
59
foreach ($options[0] as $option) {
60
    switch ($option[0]) {
61
        case 'x':
62
        case '--xml':
63
            $source[$si] = $option[1];
64
            if ($si) {
65
                $di++;
66
            }
67
            $si++;
68
            if ($expectp) {
69
                $unexpectedx = true;
70
            }
71
            $expectp = true;
72
            $expectx = false;
73
            break;
74
 
75
        case 'p':
76
        case '--php':
77
            if ($expectx) {
78
                $unexpectedp = true;
79
            }
80
            $dest[$di] = $option[1];
81
            $expectp = false;
82
            $expectx = true;
83
            break;
84
 
85
        case 'd':
86
        case '--dir':
87
            $dir = $option[1];
88
            break;
89
 
90
        case 'h':
91
        case '--help':
92
            usage();
93
            break;
94
    }
95
}
96
 
97
 
98
if ($unexpectedx && !$dir) {
99
    usage('Unexpected -x or --xml', STDERR);
100
}
101
 
102
if ($unexpectedp) {
103
    usage('Unexpected -p or --php', STDERR);
104
}
105
 
106
$nsource = count($source);
107
$ndest = count($dest);
108
 
109
if (!$nsource && !$ndest) {
110
    $source[]='php://stdin';
111
    if (!$dir) {
112
        $dest[]='php://stdout';
113
    } else {
114
      $dest[] = null;
115
    }
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';
120
}
121
 
122
if ($dir && substr($dir,-1)!='/' && substr($dir,-1)!=='\\' ) {
123
    $dir .= DIRECTORY_SEPARATOR;
124
}
125
 
126
 
127
foreach ($source as $i => $xmlfile)
128
{
129
    $gen =& new Text_Highlighter_Generator;
130
    $gen->setInputFile($xmlfile);
131
    if ($gen->hasErrors()) {
132
        break;
133
    }
134
    $gen->generate();
135
    if ($gen->hasErrors()) {
136
        break;
137
    }
138
    if (isset($dest[$i])) {
139
        $phpfile = $dest[$i];
140
    } else {
141
        $phpfile = $dir . $gen->language . '.php';
142
    }
143
    $gen->saveCode($phpfile);
144
    if ($gen->hasErrors()) {
145
        break;
146
    }
147
}
148
if ($gen->hasErrors()) {
149
    $errors = $gen->getErrors();
150
    foreach ($errors as $error) {
151
        fwrite (STDERR, $error . "\n");
152
    }
153
    exit(1);
154
}
155
 
156
exit(0);
157
 
158
function usage($message='', $file=STDOUT)
159
{
160
    $code = 0;
161
    if ($message) {
162
        $message .= "\n\n";
163
        $code = 1;
164
    }
165
    $message .= <<<MSG
166
Generates a highlighter class from XML source
167
Usage:
168
generate options
169
 
170
Options:
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
174
        Defaults to stdin
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)
181
  -h, --help
182
        This help
183
MSG;
184
    fwrite ($file, $message);
185
    exit($code);
186
}
187
?>
188
:finish