Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 156 lines (143 sloc) 4.154 kb
573b4602 » andigutmans
1999-04-07 Zend Library
1 /*
2 +----------------------------------------------------------------------+
3 | Zend Engine |
4 +----------------------------------------------------------------------+
8775a375 » felipensp
2012-01-01 - Year++
5 | Copyright (c) 1998-2012 Zend Technologies Ltd. (http://www.zend.com) |
573b4602 » andigutmans
1999-04-07 Zend Library
6 +----------------------------------------------------------------------+
d863d52a » Sebastian Bergmann
2001-12-11 Update headers.
7 | This source file is subject to version 2.00 of the Zend license, |
b5b11177 » zsuraski
1999-07-16 License update
8 | that is bundled with this package in the file LICENSE, and is |
f68c7ff2 » James Cox
2003-06-10 updating license information in the headers.
9 | available through the world-wide-web at the following url: |
d863d52a » Sebastian Bergmann
2001-12-11 Update headers.
10 | http://www.zend.com/license/2_00.txt. |
b5b11177 » zsuraski
1999-07-16 License update
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. |
573b4602 » andigutmans
1999-04-07 Zend Library
14 +----------------------------------------------------------------------+
15 | Authors: Andi Gutmans <andi@zend.com> |
16 | Zeev Suraski <zeev@zend.com> |
17 +----------------------------------------------------------------------+
18 */
19
333406bd » foobar
2003-02-01 - Added some missing CVS $Id$ tags, headers and footers.
20 /* $Id$ */
b5b11177 » zsuraski
1999-07-16 License update
21
573b4602 » andigutmans
1999-04-07 Zend Library
22 /* This indenter doesn't really work, it's here for no particular reason. */
23
24
25 #include "zend.h"
4cf9d270 » foobar
2004-12-30 - Fixed bug #28930 (PHP sources pick wrong header files generated by …
26 #include <zend_language_parser.h>
573b4602 » andigutmans
1999-04-07 Zend Library
27 #include "zend_compile.h"
28 #include "zend_indent.h"
29
609d58a4 » zsuraski
2001-08-06 Merge from branch - move to standard C scanners in thread safe mode
30 #define zendtext LANG_SCNG(yy_text)
31 #define zendleng LANG_SCNG(yy_leng)
1aa2c5c0 » zsuraski
1999-04-23 Ok, call me crazy, because I probably am.
32
af49e58f » Jani Taskinen
2010-03-12 - Reverted r296062 and r296065
33
34 static void handle_whitespace(int *emit_whitespace)
573b4602 » andigutmans
1999-04-07 Zend Library
35 {
36 unsigned char c;
af49e58f » Jani Taskinen
2010-03-12 - Reverted r296062 and r296065
37 int i;
573b4602 » andigutmans
1999-04-07 Zend Library
38
39 for (c=0; c<128; c++) {
40 if (emit_whitespace[c]>0) {
41 for (i=0; i<emit_whitespace[c]; i++) {
88029643 » Sascha Schumann
1999-05-30 * fix some casts
42 zend_write((char *) &c, 1);
573b4602 » andigutmans
1999-04-07 Zend Library
43 }
44 }
45 }
46 memset(emit_whitespace, 0, sizeof(int)*256);
47 }
48
af49e58f » Jani Taskinen
2010-03-12 - Reverted r296062 and r296065
49
50 ZEND_API void zend_indent()
573b4602 » andigutmans
1999-04-07 Zend Library
51 {
52 zval token;
53 int token_type;
54 int in_string=0;
af49e58f » Jani Taskinen
2010-03-12 - Reverted r296062 and r296065
55 int nest_level=0;
56 int emit_whitespace[256];
57 int i;
b4f3b9d3 » zsuraski
2001-07-28 Redesigned thread safety mechanism - nua nua
58 TSRMLS_FETCH();
573b4602 » andigutmans
1999-04-07 Zend Library
59
60 memset(emit_whitespace, 0, sizeof(int)*256);
61
62 /* highlight stuff coming back from zendlex() */
af49e58f » Jani Taskinen
2010-03-12 - Reverted r296062 and r296065
63 token.type = 0;
b4f3b9d3 » zsuraski
2001-07-28 Redesigned thread safety mechanism - nua nua
64 while ((token_type=lex_scan(&token TSRMLS_CC))) {
573b4602 » andigutmans
1999-04-07 Zend Library
65 switch (token_type) {
551fe778 » zsuraski
1999-04-22 Make token names uniform, they all begin with T_ now.
66 case T_INLINE_HTML:
e43ff135 » Dmitry Stogov
2011-09-13 Fixed ZE specific compile warnings (Bug #55629)
67 zend_write((char*)LANG_SCNG(yy_text), LANG_SCNG(yy_leng));
573b4602 » andigutmans
1999-04-07 Zend Library
68 break;
69 case T_WHITESPACE: {
af49e58f » Jani Taskinen
2010-03-12 - Reverted r296062 and r296065
70 token.type = 0;
573b4602 » andigutmans
1999-04-07 Zend Library
71 /* eat whitespace, emit newlines */
2c8ec7f9 » zsuraski
2001-08-06 Commit uncommitted build fix
72 for (i=0; i<LANG_SCNG(yy_leng); i++) {
73 emit_whitespace[(unsigned char) LANG_SCNG(yy_text)[i]]++;
573b4602 » andigutmans
1999-04-07 Zend Library
74 }
75 continue;
76 }
77 break;
78 case '"':
79 in_string = !in_string;
80 /* break missing intentionally */
81 default:
af49e58f » Jani Taskinen
2010-03-12 - Reverted r296062 and r296065
82 if (token.type==0) {
573b4602 » andigutmans
1999-04-07 Zend Library
83 /* keyword */
671fff2f » andigutmans
2002-11-30 h WHitespace
84 switch (token_type) {
573b4602 » andigutmans
1999-04-07 Zend Library
85 case ',':
86 ZEND_PUTS(", ");
87 goto dflt_printout;
88 break;
89 case '{':
90 nest_level++;
91 if (emit_whitespace['\n']>0) {
92 ZEND_PUTS(" {\n");
93 memset(emit_whitespace, 0, sizeof(int)*256);
94 } else {
95 ZEND_PUTS("{");
96 }
97 break;
98 case '}':
99 nest_level--;
100 if (emit_whitespace['\n']==0) {
101 ZEND_PUTS("\n");
102 }
103 for (i=0; i<nest_level; i++) {
104 ZEND_PUTS(" ");
105 }
106 goto dflt_printout;
107 break;
108 dflt_printout:
109 default:
110 if (emit_whitespace['\n']>0) {
111 for (i=0; i<emit_whitespace['\n']; i++) {
112 ZEND_PUTS("\n");
113 }
114 memset(emit_whitespace, 0, sizeof(int)*256);
115 for (i=0; i<nest_level; i++) {
116 ZEND_PUTS(" ");
117 }
118 } else {
119 handle_whitespace(emit_whitespace);
120 }
e43ff135 » Dmitry Stogov
2011-09-13 Fixed ZE specific compile warnings (Bug #55629)
121 zend_write((char*)LANG_SCNG(yy_text), LANG_SCNG(yy_leng));
573b4602 » andigutmans
1999-04-07 Zend Library
122 break;
123 }
124 } else {
125 handle_whitespace(emit_whitespace);
126 if (in_string) {
e43ff135 » Dmitry Stogov
2011-09-13 Fixed ZE specific compile warnings (Bug #55629)
127 zend_write((char*)LANG_SCNG(yy_text), LANG_SCNG(yy_leng));
573b4602 » andigutmans
1999-04-07 Zend Library
128 /* a part of a string */
129 } else {
e43ff135 » Dmitry Stogov
2011-09-13 Fixed ZE specific compile warnings (Bug #55629)
130 zend_write((char*)LANG_SCNG(yy_text), LANG_SCNG(yy_leng));
573b4602 » andigutmans
1999-04-07 Zend Library
131 }
132 }
133 break;
134 }
af49e58f » Jani Taskinen
2010-03-12 - Reverted r296062 and r296065
135 if (token.type == IS_STRING) {
573b4602 » andigutmans
1999-04-07 Zend Library
136 switch (token_type) {
551fe778 » zsuraski
1999-04-22 Make token names uniform, they all begin with T_ now.
137 case T_OPEN_TAG:
138 case T_CLOSE_TAG:
573b4602 » andigutmans
1999-04-07 Zend Library
139 case T_WHITESPACE:
140 break;
141 default:
af49e58f » Jani Taskinen
2010-03-12 - Reverted r296062 and r296065
142 efree(token.value.str.val);
573b4602 » andigutmans
1999-04-07 Zend Library
143 break;
144 }
145 }
af49e58f » Jani Taskinen
2010-03-12 - Reverted r296062 and r296065
146 token.type = 0;
573b4602 » andigutmans
1999-04-07 Zend Library
147 }
148 }
333406bd » foobar
2003-02-01 - Added some missing CVS $Id$ tags, headers and footers.
149
150 /*
151 * Local variables:
152 * tab-width: 4
153 * c-basic-offset: 4
154 * indent-tabs-mode: t
155 * End:
156 */
Something went wrong with that request. Please try again.