2
+----------------------------------------------------------------------+
4
+----------------------------------------------------------------------+
5
| Copyright (c) 1998-2004 Zend Technologies Ltd. (http://www.zend.com) |
6
+----------------------------------------------------------------------+
7
| This source file is subject to version 2.00 of the Zend license, |
8
| that is bundled with this package in the file LICENSE, and is |
9
| available through the world-wide-web at the following url: |
10
| http://www.zend.com/license/2_00.txt. |
11
| If you did not receive a copy of the Zend license and are unable to |
12
| obtain it through the world-wide-web, please send a note to |
13
| license@zend.com so we can mail you a copy immediately. |
14
+----------------------------------------------------------------------+
15
| Authors: Andi Gutmans <andi@zend.com> |
16
| Zeev Suraski <zeev@zend.com> |
17
+----------------------------------------------------------------------+
20
/* $Id: zend_highlight.c,v 1.43.2.5 2005/05/22 16:40:49 iliaa Exp $ */
23
#include <zend_language_parser.h>
24
#include "zend_compile.h"
25
#include "zend_highlight.h"
26
#include "zend_ptr_stack.h"
27
#include "zend_globals.h"
29
ZEND_API void zend_html_putc(char c)
48
ZEND_PUTS(" ");
57
ZEND_API void zend_html_puts(const char *s, uint len TSRMLS_DC)
59
const char *ptr=s, *end=s+len;
65
if (LANG_SCNG(output_filter)) {
66
LANG_SCNG(output_filter)(&filtered, &filtered_len, s, len TSRMLS_CC);
68
end = filtered + filtered_len;
70
#endif /* ZEND_MULTIBYTE */
76
} while ((++ptr < end) && (*ptr==' '));
78
zend_html_putc(*ptr++);
83
if (LANG_SCNG(output_filter)) {
86
#endif /* ZEND_MULTIBYTE */
91
ZEND_API void zend_highlight(zend_syntax_highlighter_ini *syntax_highlighter_ini TSRMLS_DC)
95
char *last_color = syntax_highlighter_ini->highlight_html;
97
int in_string=0, post_heredoc = 0;
99
zend_printf("<code>");
100
zend_printf("<span style=\"color: %s\">\n", last_color);
101
/* highlight stuff coming back from zendlex() */
103
while ((token_type=lex_scan(&token TSRMLS_CC))) {
104
switch (token_type) {
106
next_color = syntax_highlighter_ini->highlight_html;
110
next_color = syntax_highlighter_ini->highlight_comment;
113
case T_OPEN_TAG_WITH_ECHO:
114
next_color = syntax_highlighter_ini->highlight_default;
117
next_color = syntax_highlighter_ini->highlight_default;
119
case T_CONSTANT_ENCAPSED_STRING:
120
next_color = syntax_highlighter_ini->highlight_string;
123
next_color = syntax_highlighter_ini->highlight_string;
124
in_string = !in_string;
127
zend_html_puts(LANG_SCNG(yy_text), LANG_SCNG(yy_leng) TSRMLS_CC); /* no color needed */
133
next_color = syntax_highlighter_ini->highlight_string;
134
} else if (token.type == 0) {
135
next_color = syntax_highlighter_ini->highlight_keyword;
137
next_color = syntax_highlighter_ini->highlight_default;
142
if (last_color != next_color) {
143
if (last_color != syntax_highlighter_ini->highlight_html) {
144
zend_printf("</span>");
146
last_color = next_color;
147
if (last_color != syntax_highlighter_ini->highlight_html) {
148
zend_printf("<span style=\"color: %s\">", last_color);
151
switch (token_type) {
153
zend_html_puts(token.value.str.val, token.value.str.len TSRMLS_CC);
157
zend_html_puts(LANG_SCNG(yy_text), LANG_SCNG(yy_leng) TSRMLS_CC);
159
zend_html_putc('\n');
165
if (token.type == IS_STRING) {
166
switch (token_type) {
168
case T_OPEN_TAG_WITH_ECHO:
175
efree(token.value.str.val);
178
} else if (token_type == T_END_HEREDOC) {
179
efree(token.value.str.val);
183
if (last_color != syntax_highlighter_ini->highlight_html) {
184
zend_printf("</span>\n");
186
zend_printf("</span>\n");
187
zend_printf("</code>");
192
ZEND_API void zend_strip(TSRMLS_D)
199
while ((token_type=lex_scan(&token TSRMLS_CC))) {
200
switch (token_type) {
203
zend_write(" ", sizeof(" ") - 1);
206
/* lack of break; is intentional */
212
case T_END_HEREDOC: {
213
char *ptr = LANG_SCNG(yy_text);
215
zend_write(ptr, LANG_SCNG(yy_leng) - 1);
216
/* The ensure that we only write one ; and that it followed by the required newline */
217
zend_write("\n", sizeof("\n") - 1);
218
if (ptr[LANG_SCNG(yy_leng) - 1] == ';') {
219
lex_scan(&token TSRMLS_CC);
221
efree(token.value.str.val);
226
zend_write(LANG_SCNG(yy_text), LANG_SCNG(yy_leng));
230
if (token.type == IS_STRING) {
231
switch (token_type) {
233
case T_OPEN_TAG_WITH_ECHO:
241
efree(token.value.str.val);
245
prev_space = token.type = 0;
253
* indent-tabs-mode: t