1 : %{
2 : /*
3 : +----------------------------------------------------------------------+
4 : | Zend Engine |
5 : +----------------------------------------------------------------------+
6 : | Copyright (c) 1998-2006 Zend Technologies Ltd. (http://www.zend.com) |
7 : +----------------------------------------------------------------------+
8 : | This source file is subject to version 2.00 of the Zend license, |
9 : | that is bundled with this package in the file LICENSE, and is |
10 : | available through the world-wide-web at the following url: |
11 : | http://www.zend.com/license/2_00.txt. |
12 : | If you did not receive a copy of the Zend license and are unable to |
13 : | obtain it through the world-wide-web, please send a note to |
14 : | license@zend.com so we can mail you a copy immediately. |
15 : +----------------------------------------------------------------------+
16 : | Author: Zeev Suraski <zeev@zend.com> |
17 : +----------------------------------------------------------------------+
18 : */
19 :
20 : /* $Id: zend_ini_scanner.l 240224 2007-07-23 16:17:10Z jani $ */
21 :
22 : #define yyleng SCNG(yy_leng)
23 : #define yytext SCNG(yy_text)
24 : #define yytext_ptr SCNG(yy_text)
25 : #define yyin SCNG(yy_in)
26 : #define yyout SCNG(yy_out)
27 : #define yy_last_accepting_state SCNG(_yy_last_accepting_state)
28 : #define yy_last_accepting_cpos SCNG(_yy_last_accepting_cpos)
29 : #define yy_more_flag SCNG(_yy_more_flag)
30 : #define yy_more_len SCNG(_yy_more_len)
31 :
32 : #include <errno.h>
33 : #include "zend.h"
34 : #include "zend_globals.h"
35 : #include <zend_ini_parser.h>
36 : #include "zend_ini_scanner.h"
37 :
38 : #undef YYSTYPE
39 : #define YYSTYPE zval
40 :
41 : #define YY_DECL int ini_lex(zval *ini_lval TSRMLS_DC)
42 :
43 : /* Globals Macros */
44 : #define SCNG INI_SCNG
45 : #ifdef ZTS
46 : ZEND_API ts_rsrc_id ini_scanner_globals_id;
47 : #else
48 : ZEND_API zend_scanner_globals ini_scanner_globals;
49 : #endif
50 :
51 : # define YY_INPUT(buf, result, max_size) \
52 : if ( ((result = zend_stream_read(yyin, buf, max_size TSRMLS_CC)) == 0) \
53 : && zend_stream_ferror( yyin TSRMLS_CC) ) \
54 : YY_FATAL_ERROR( "input in flex scanner failed" );
55 :
56 : static char *ini_filename;
57 :
58 : void init_ini_scanner(TSRMLS_D)
59 13529 : {
60 13529 : SCNG(lineno)=1;
61 13529 : }
62 :
63 : int zend_ini_scanner_get_lineno(TSRMLS_D)
64 2 : {
65 2 : return SCNG(lineno);
66 : }
67 :
68 : char *zend_ini_scanner_get_filename(TSRMLS_D)
69 2 : {
70 2 : return ini_filename;
71 : }
72 :
73 : int zend_ini_open_file_for_scanning(zend_file_handle *fh TSRMLS_DC)
74 13567 : {
75 13567 : if (FAILURE == zend_stream_fixup(fh TSRMLS_CC)) {
76 38 : return FAILURE;
77 : }
78 :
79 13529 : init_ini_scanner(TSRMLS_C);
80 13529 : yyin = fh;
81 13529 : yy_switch_to_buffer(yy_create_buffer(yyin, YY_BUF_SIZE TSRMLS_CC) TSRMLS_CC);
82 13529 : ini_filename = fh->filename;
83 13529 : return SUCCESS;
84 : }
85 :
86 : int zend_ini_prepare_string_for_scanning(char *str TSRMLS_DC)
87 13546 : {
88 13546 : int len = strlen(str);
89 :
90 13546 : yyin = NULL;
91 13546 : yy_scan_buffer(str, len + 2 TSRMLS_CC);
92 13546 : ini_filename = NULL;
93 13546 : return SUCCESS;
94 : }
95 :
96 : void zend_ini_close_file(zend_file_handle *fh TSRMLS_DC)
97 13529 : {
98 13529 : zend_stream_close(fh);
99 13529 : }
100 :
101 : %}
102 :
103 : NEWLINE ("\r"|"\n"|"\r\n")
104 :
105 : %option noyywrap
106 : %option never-interactive
107 :
108 : %%
109 :
110 : <INITIAL>[ ]*[\[][ ]*[\]][ ]* {
111 2 : return BRACK;
112 : }
113 :
114 : <INITIAL>[ ]*("true"|"on"|"yes")[ ]* {
115 83 : Z_STRVAL_P(ini_lval) = zend_strndup("1", 1);
116 83 : Z_STRLEN_P(ini_lval) = 1;
117 83 : Z_TYPE_P(ini_lval) = IS_STRING;
118 83 : return CFG_TRUE;
119 : }
120 :
121 :
122 : <INITIAL>[ ]*("false"|"off"|"no"|"none"|"null")[ ]* {
123 26906 : Z_STRVAL_P(ini_lval) = zend_strndup("", 0);
124 26906 : Z_STRLEN_P(ini_lval) = 0;
125 26906 : Z_TYPE_P(ini_lval) = IS_STRING;
126 26906 : return CFG_FALSE;
127 : }
128 :
129 : <INITIAL>[[][^\]\n]+[\]][ ]*{NEWLINE}? {
130 : /* SECTION */
131 :
132 : /* eat trailing ] and spaces */
133 222 : while (yyleng>0 && (yytext[yyleng-1]=='\n' || yytext[yyleng-1]=='\r' || yytext[yyleng-1]==']' || yytext[yyleng-1]==' ')) {
134 112 : yyleng--;
135 112 : yytext[yyleng]=0;
136 : }
137 :
138 55 : SCNG(lineno)++;
139 :
140 : /* eat leading [ */
141 55 : yytext++;
142 55 : yyleng--;
143 :
144 55 : Z_STRVAL_P(ini_lval) = zend_strndup(yytext, yyleng);
145 55 : Z_STRLEN_P(ini_lval) = yyleng;
146 55 : Z_TYPE_P(ini_lval) = IS_STRING;
147 55 : return SECTION;
148 : }
149 :
150 : <INITIAL>["][^"]*["] {
151 13750 : char *p = yytext;
152 :
153 : /* ENCAPSULATED TC_STRING */
154 :
155 27515 : while ((p = strpbrk(p, "\r\n"))) {
156 15 : if (*p == '\r' && *(p + 1) == '\n') {
157 0 : p++;
158 : }
159 15 : SCNG(lineno)++;
160 15 : p++;
161 : }
162 :
163 : /* eat trailing " */
164 13750 : yytext[yyleng-1]=0;
165 :
166 : /* eat leading " */
167 13750 : yytext++;
168 :
169 13750 : Z_STRVAL_P(ini_lval) = zend_strndup(yytext, yyleng - 2);
170 13750 : Z_STRLEN_P(ini_lval) = yyleng - 2;
171 13750 : Z_TYPE_P(ini_lval) = IS_STRING;
172 13750 : return TC_ENCAPSULATED_STRING;
173 : }
174 :
175 : <INITIAL>"${" {
176 0 : return TC_DOLLAR_CURLY;
177 : }
178 :
179 : <INITIAL>"}" {
180 0 : Z_LVAL_P(ini_lval) = (long) yytext[0];
181 0 : return yytext[0];
182 : }
183 :
184 : <INITIAL>[&|~$(){}!] {
185 35 : return yytext[0];
186 : }
187 :
188 : <INITIAL>[^=\n\r\t;|&$~(){}!"\[]+ {
189 : /* STRING */
190 : register int i;
191 :
192 : /* eat trailing whitespace */
193 879349 : for (i=yyleng-1; i>=0; i--) {
194 879231 : if (yytext[i]==' ' || yytext[i]=='\t') {
195 390 : yytext[i]=0;
196 390 : yyleng--;
197 : } else {
198 : break;
199 : }
200 : }
201 : /* eat leading whitespace */
202 1758005 : while (yytext[0]) {
203 878928 : if (yytext[0]==' ' || yytext[0]=='\t') {
204 87 : yytext++;
205 87 : yyleng--;
206 : } else {
207 : break;
208 : }
209 : }
210 878959 : if (yyleng!=0) {
211 878841 : Z_STRVAL_P(ini_lval) = zend_strndup(yytext, yyleng);
212 878841 : Z_STRLEN_P(ini_lval) = yyleng;
213 878841 : Z_TYPE_P(ini_lval) = IS_STRING;
214 878841 : return TC_STRING;
215 : } else {
216 : /* whitespace */
217 : }
218 : }
219 118 :
220 : <INITIAL>[=\n] {
221 1027343 : if (yytext[0] == '\n') {
222 513673 : SCNG(lineno)++;
223 : }
224 1027343 : return yytext[0];
225 : }
226 :
227 : <INITIAL>{NEWLINE} {
228 0 : SCNG(lineno)++;
229 0 : return '\n';
230 : }
231 :
232 : <INITIAL>[;][^\r\n]*{NEWLINE}? {
233 : /* comment */
234 122 : SCNG(lineno)++;
235 122 : return '\n';
236 : }
237 :
238 : <INITIAL>[ \t] {
239 : /* eat whitespace */
240 : }
241 4 :
242 : <INITIAL>. {
243 : #if DEBUG
244 : php_error(E_NOTICE,"Unexpected character on line %d: '%s' (ASCII %d)\n", yylineno, yytext, yytext[0]);
245 : #endif
246 : }
247 0 :
248 : <<EOF>> {
249 27073 : yy_delete_buffer(YY_CURRENT_BUFFER TSRMLS_CC);
250 27073 : yyterminate();
251 : }
|