Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 238 lines (213 sloc) 5.931 kB
573b460 @andigutmans Zend Library
andigutmans authored
1 /*
2 +----------------------------------------------------------------------+
3 | Zend Engine |
4 +----------------------------------------------------------------------+
e4ca0ed @felipensp - Year++
felipensp authored
5 | Copyright (c) 1998-2012 Zend Technologies Ltd. (http://www.zend.com) |
573b460 @andigutmans Zend Library
andigutmans authored
6 +----------------------------------------------------------------------+
d863d52 Update headers.
Sebastian Bergmann authored
7 | This source file is subject to version 2.00 of the Zend license, |
b5b1117 @zsuraski License update
zsuraski authored
8 | that is bundled with this package in the file LICENSE, and is |
f68c7ff updating license information in the headers.
James Cox authored
9 | available through the world-wide-web at the following url: |
d863d52 Update headers.
Sebastian Bergmann authored
10 | http://www.zend.com/license/2_00.txt. |
b5b1117 @zsuraski License update
zsuraski authored
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. |
573b460 @andigutmans Zend Library
andigutmans authored
14 +----------------------------------------------------------------------+
15 | Authors: Andi Gutmans <andi@zend.com> |
16 | Zeev Suraski <zeev@zend.com> |
17 +----------------------------------------------------------------------+
18 */
19
333406b - Added some missing CVS $Id$ tags, headers and footers.
foobar authored
20 /* $Id$ */
b5b1117 @zsuraski License update
zsuraski authored
21
573b460 @andigutmans Zend Library
andigutmans authored
22 #include "zend.h"
4cf9d27 - Fixed bug #28930 (PHP sources pick wrong header files generated by …
foobar authored
23 #include <zend_language_parser.h>
573b460 @andigutmans Zend Library
andigutmans authored
24 #include "zend_compile.h"
25 #include "zend_highlight.h"
26 #include "zend_ptr_stack.h"
27 #include "zend_globals.h"
28
af49e58 - Reverted r296062 and r296065
Jani Taskinen authored
29 ZEND_API void zend_html_putc(char c)
573b460 @andigutmans Zend Library
andigutmans authored
30 {
31 switch (c) {
32 case '\n':
e8796a1 @zsuraski Improve XHTML compliance (suggested by Anil Madhavapeddy)
zsuraski authored
33 ZEND_PUTS("<br />");
573b460 @andigutmans Zend Library
andigutmans authored
34 break;
35 case '<':
36 ZEND_PUTS("&lt;");
37 break;
38 case '>':
39 ZEND_PUTS("&gt;");
40 break;
41 case '&':
42 ZEND_PUTS("&amp;");
43 break;
44 case ' ':
45 ZEND_PUTS("&nbsp;");
46 break;
47 case '\t':
48 ZEND_PUTS("&nbsp;&nbsp;&nbsp;&nbsp;");
49 break;
50 default:
51 ZEND_PUTC(c);
52 break;
53 }
54 }
55
af49e58 - Reverted r296062 and r296065
Jani Taskinen authored
56
57 ZEND_API void zend_html_puts(const char *s, uint len TSRMLS_DC)
573b460 @andigutmans Zend Library
andigutmans authored
58 {
4ec448e @zsuraski MFZE1
zsuraski authored
59 const char *ptr=s, *end=s+len;
ab9dcec @fujimoto - added script encoding support to Zend Engine 2.
fujimoto authored
60
c3286f3 implemented again zend-multibyte for PHP 5.3
Rui Hirokawa authored
61 #ifdef ZEND_MULTIBYTE
62 char *filtered;
63 int filtered_len;
64
65 if (LANG_SCNG(output_filter)) {
66 LANG_SCNG(output_filter)(&filtered, &filtered_len, s, len TSRMLS_CC);
67 ptr = filtered;
68 end = filtered + filtered_len;
69 }
70 #endif /* ZEND_MULTIBYTE */
71
573b460 @andigutmans Zend Library
andigutmans authored
72 while (ptr<end) {
2931bb6 @zsuraski MFZE1
zsuraski authored
73 if (*ptr==' ') {
76c0560 Fixed bug #29338 (unencoded spaces get ignored after certain tags).
Ilia Alshanetsky authored
74 do {
75 zend_html_putc(*ptr);
76 } while ((++ptr < end) && (*ptr==' '));
2931bb6 @zsuraski MFZE1
zsuraski authored
77 } else {
78 zend_html_putc(*ptr++);
dc30520 @zsuraski Retain single spaces as spaces to condense HTML
zsuraski authored
79 }
573b460 @andigutmans Zend Library
andigutmans authored
80 }
c3286f3 implemented again zend-multibyte for PHP 5.3
Rui Hirokawa authored
81
82 #ifdef ZEND_MULTIBYTE
83 if (LANG_SCNG(output_filter)) {
84 efree(filtered);
85 }
86 #endif /* ZEND_MULTIBYTE */
573b460 @andigutmans Zend Library
andigutmans authored
87 }
88
af49e58 - Reverted r296062 and r296065
Jani Taskinen authored
89
90 ZEND_API void zend_highlight(zend_syntax_highlighter_ini *syntax_highlighter_ini TSRMLS_DC)
573b460 @andigutmans Zend Library
andigutmans authored
91 {
92 zval token;
93 int token_type;
94 char *last_color = syntax_highlighter_ini->highlight_html;
95 char *next_color;
96
7d425f3 Since we're highlighting code, put <code> and </code> around the code.
Andrei Zmievski authored
97 zend_printf("<code>");
9be67e5 - Use <span> instead of <font> in highlight_string(). (Patch by mg@ic…
Derick Rethans authored
98 zend_printf("<span style=\"color: %s\">\n", last_color);
573b460 @andigutmans Zend Library
andigutmans authored
99 /* highlight stuff coming back from zendlex() */
af49e58 - Reverted r296062 and r296065
Jani Taskinen authored
100 token.type = 0;
b4f3b9d @zsuraski Redesigned thread safety mechanism - nua nua
zsuraski authored
101 while ((token_type=lex_scan(&token TSRMLS_CC))) {
573b460 @andigutmans Zend Library
andigutmans authored
102 switch (token_type) {
551fe77 @zsuraski Make token names uniform, they all begin with T_ now.
zsuraski authored
103 case T_INLINE_HTML:
573b460 @andigutmans Zend Library
andigutmans authored
104 next_color = syntax_highlighter_ini->highlight_html;
105 break;
551fe77 @zsuraski Make token names uniform, they all begin with T_ now.
zsuraski authored
106 case T_COMMENT:
39d5a63 - Keep track of starting/ending line numbers for user functions.
Andrei Zmievski authored
107 case T_DOC_COMMENT:
573b460 @andigutmans Zend Library
andigutmans authored
108 next_color = syntax_highlighter_ini->highlight_comment;
109 break;
551fe77 @zsuraski Make token names uniform, they all begin with T_ now.
zsuraski authored
110 case T_OPEN_TAG:
5b570ec @andigutmans - Fix bug in syntax highlighter
andigutmans authored
111 case T_OPEN_TAG_WITH_ECHO:
573b460 @andigutmans Zend Library
andigutmans authored
112 next_color = syntax_highlighter_ini->highlight_default;
113 break;
551fe77 @zsuraski Make token names uniform, they all begin with T_ now.
zsuraski authored
114 case T_CLOSE_TAG:
573b460 @andigutmans Zend Library
andigutmans authored
115 next_color = syntax_highlighter_ini->highlight_default;
116 break;
478acfd . Added support for using static HEREDOCs to initialize static variab…
Dmitry Stogov authored
117 case '"':
118 case T_ENCAPSED_AND_WHITESPACE:
551fe77 @zsuraski Make token names uniform, they all begin with T_ now.
zsuraski authored
119 case T_CONSTANT_ENCAPSED_STRING:
573b460 @andigutmans Zend Library
andigutmans authored
120 next_color = syntax_highlighter_ini->highlight_string;
121 break;
122 case T_WHITESPACE:
1264214 Sync zend_html_puts parameter list with Zend Engine 1.
Sebastian Bergmann authored
123 zend_html_puts(LANG_SCNG(yy_text), LANG_SCNG(yy_leng) TSRMLS_CC); /* no color needed */
af49e58 - Reverted r296062 and r296065
Jani Taskinen authored
124 token.type = 0;
573b460 @andigutmans Zend Library
andigutmans authored
125 continue;
126 break;
127 default:
af49e58 - Reverted r296062 and r296065
Jani Taskinen authored
128 if (token.type == 0) {
573b460 @andigutmans Zend Library
andigutmans authored
129 next_color = syntax_highlighter_ini->highlight_keyword;
130 } else {
0688205 Fixed Bug #26703 (Certain characters inside strings incorrectly treat…
Ilia Alshanetsky authored
131 next_color = syntax_highlighter_ini->highlight_default;
573b460 @andigutmans Zend Library
andigutmans authored
132 }
133 break;
134 }
135
136 if (last_color != next_color) {
137 if (last_color != syntax_highlighter_ini->highlight_html) {
9be67e5 - Use <span> instead of <font> in highlight_string(). (Patch by mg@ic…
Derick Rethans authored
138 zend_printf("</span>");
573b460 @andigutmans Zend Library
andigutmans authored
139 }
140 last_color = next_color;
141 if (last_color != syntax_highlighter_ini->highlight_html) {
9be67e5 - Use <span> instead of <font> in highlight_string(). (Patch by mg@ic…
Derick Rethans authored
142 zend_printf("<span style=\"color: %s\">", last_color);
573b460 @andigutmans Zend Library
andigutmans authored
143 }
144 }
09034cf MFH: Implemented manual scanning for strings/comments, plus misc. fixes
Matt Wilmas authored
145
146 zend_html_puts(LANG_SCNG(yy_text), LANG_SCNG(yy_leng) TSRMLS_CC);
573b460 @andigutmans Zend Library
andigutmans authored
147
af49e58 - Reverted r296062 and r296065
Jani Taskinen authored
148 if (token.type == IS_STRING) {
573b460 @andigutmans Zend Library
andigutmans authored
149 switch (token_type) {
473d1d7 @zsuraski * Fix a bug that occured in case of parse errors. We need to restore…
zsuraski authored
150 case T_OPEN_TAG:
5b570ec @andigutmans - Fix bug in syntax highlighter
andigutmans authored
151 case T_OPEN_TAG_WITH_ECHO:
473d1d7 @zsuraski * Fix a bug that occured in case of parse errors. We need to restore…
zsuraski authored
152 case T_CLOSE_TAG:
153 case T_WHITESPACE:
b208f6b @rlerdorf Fix for bug number 8666
rlerdorf authored
154 case T_COMMENT:
e6255b0 Revert portions of the doc comment patch. There should be no parser
Andrei Zmievski authored
155 case T_DOC_COMMENT:
473d1d7 @zsuraski * Fix a bug that occured in case of parse errors. We need to restore…
zsuraski authored
156 break;
157 default:
af49e58 - Reverted r296062 and r296065
Jani Taskinen authored
158 efree(token.value.str.val);
473d1d7 @zsuraski * Fix a bug that occured in case of parse errors. We need to restore…
zsuraski authored
159 break;
573b460 @andigutmans Zend Library
andigutmans authored
160 }
478acfd . Added support for using static HEREDOCs to initialize static variab…
Dmitry Stogov authored
161 } else if (token_type == T_END_HEREDOC) {
af49e58 - Reverted r296062 and r296065
Jani Taskinen authored
162 efree(token.value.str.val);
573b460 @andigutmans Zend Library
andigutmans authored
163 }
af49e58 - Reverted r296062 and r296065
Jani Taskinen authored
164 token.type = 0;
573b460 @andigutmans Zend Library
andigutmans authored
165 }
b26d5f6 Fixed bug #42767 (highlight_string() truncates trailing comment)
Ilia Alshanetsky authored
166
573b460 @andigutmans Zend Library
andigutmans authored
167 if (last_color != syntax_highlighter_ini->highlight_html) {
9be67e5 - Use <span> instead of <font> in highlight_string(). (Patch by mg@ic…
Derick Rethans authored
168 zend_printf("</span>\n");
573b460 @andigutmans Zend Library
andigutmans authored
169 }
9be67e5 - Use <span> instead of <font> in highlight_string(). (Patch by mg@ic…
Derick Rethans authored
170 zend_printf("</span>\n");
7d425f3 Since we're highlighting code, put <code> and </code> around the code.
Andrei Zmievski authored
171 zend_printf("</code>");
573b460 @andigutmans Zend Library
andigutmans authored
172 }
173
af49e58 - Reverted r296062 and r296065
Jani Taskinen authored
174 ZEND_API void zend_strip(TSRMLS_D)
ff4cc2c MFZE1 (added zend_strip mode in the highliter)
Sebastian Bergmann authored
175 {
176 zval token;
177 int token_type;
2b13eb4 More cleanup of the zend_strip() function.
Ilia Alshanetsky authored
178 int prev_space = 0;
ff4cc2c MFZE1 (added zend_strip mode in the highliter)
Sebastian Bergmann authored
179
af49e58 - Reverted r296062 and r296065
Jani Taskinen authored
180 token.type = 0;
ff4cc2c MFZE1 (added zend_strip mode in the highliter)
Sebastian Bergmann authored
181 while ((token_type=lex_scan(&token TSRMLS_CC))) {
182 switch (token_type) {
183 case T_WHITESPACE:
2b13eb4 More cleanup of the zend_strip() function.
Ilia Alshanetsky authored
184 if (!prev_space) {
60b6ac0 Fixed bug #29606 (php_strip_whitespace() prints to stdout rather then
Ilia Alshanetsky authored
185 zend_write(" ", sizeof(" ") - 1);
2b13eb4 More cleanup of the zend_strip() function.
Ilia Alshanetsky authored
186 prev_space = 1;
ff4cc2c MFZE1 (added zend_strip mode in the highliter)
Sebastian Bergmann authored
187 }
2b13eb4 More cleanup of the zend_strip() function.
Ilia Alshanetsky authored
188 /* lack of break; is intentional */
189 case T_COMMENT:
e6255b0 Revert portions of the doc comment patch. There should be no parser
Andrei Zmievski authored
190 case T_DOC_COMMENT:
af49e58 - Reverted r296062 and r296065
Jani Taskinen authored
191 token.type = 0;
ff4cc2c MFZE1 (added zend_strip mode in the highliter)
Sebastian Bergmann authored
192 continue;
af49e58 - Reverted r296062 and r296065
Jani Taskinen authored
193
3ce2714 Fixed bug #35655 (whitespace following end of heredoc is lost).
Ilia Alshanetsky authored
194 case T_END_HEREDOC:
195 zend_write(LANG_SCNG(yy_text), LANG_SCNG(yy_leng));
af49e58 - Reverted r296062 and r296065
Jani Taskinen authored
196 efree(token.value.str.val);
3ce2714 Fixed bug #35655 (whitespace following end of heredoc is lost).
Ilia Alshanetsky authored
197 /* read the following character, either newline or ; */
198 if (lex_scan(&token TSRMLS_CC) != T_WHITESPACE) {
199 zend_write(LANG_SCNG(yy_text), LANG_SCNG(yy_leng));
ff4cc2c MFZE1 (added zend_strip mode in the highliter)
Sebastian Bergmann authored
200 }
3ce2714 Fixed bug #35655 (whitespace following end of heredoc is lost).
Ilia Alshanetsky authored
201 zend_write("\n", sizeof("\n") - 1);
202 prev_space = 1;
af49e58 - Reverted r296062 and r296065
Jani Taskinen authored
203 token.type = 0;
3ce2714 Fixed bug #35655 (whitespace following end of heredoc is lost).
Ilia Alshanetsky authored
204 continue;
205
2b13eb4 More cleanup of the zend_strip() function.
Ilia Alshanetsky authored
206 default:
60b6ac0 Fixed bug #29606 (php_strip_whitespace() prints to stdout rather then
Ilia Alshanetsky authored
207 zend_write(LANG_SCNG(yy_text), LANG_SCNG(yy_leng));
2b13eb4 More cleanup of the zend_strip() function.
Ilia Alshanetsky authored
208 break;
ff4cc2c MFZE1 (added zend_strip mode in the highliter)
Sebastian Bergmann authored
209 }
210
af49e58 - Reverted r296062 and r296065
Jani Taskinen authored
211 if (token.type == IS_STRING) {
ff4cc2c MFZE1 (added zend_strip mode in the highliter)
Sebastian Bergmann authored
212 switch (token_type) {
213 case T_OPEN_TAG:
214 case T_OPEN_TAG_WITH_ECHO:
215 case T_CLOSE_TAG:
216 case T_WHITESPACE:
217 case T_COMMENT:
e6255b0 Revert portions of the doc comment patch. There should be no parser
Andrei Zmievski authored
218 case T_DOC_COMMENT:
ff4cc2c MFZE1 (added zend_strip mode in the highliter)
Sebastian Bergmann authored
219 break;
220
221 default:
af49e58 - Reverted r296062 and r296065
Jani Taskinen authored
222 efree(token.value.str.val);
ff4cc2c MFZE1 (added zend_strip mode in the highliter)
Sebastian Bergmann authored
223 break;
224 }
225 }
af49e58 - Reverted r296062 and r296065
Jani Taskinen authored
226 prev_space = token.type = 0;
ff4cc2c MFZE1 (added zend_strip mode in the highliter)
Sebastian Bergmann authored
227 }
228 }
333406b - Added some missing CVS $Id$ tags, headers and footers.
foobar authored
229
573b460 @andigutmans Zend Library
andigutmans authored
230 /*
231 * Local variables:
232 * tab-width: 4
233 * c-basic-offset: 4
333406b - Added some missing CVS $Id$ tags, headers and footers.
foobar authored
234 * indent-tabs-mode: t
573b460 @andigutmans Zend Library
andigutmans authored
235 * End:
236 */
af49e58 - Reverted r296062 and r296065
Jani Taskinen authored
237
Something went wrong with that request. Please try again.