diff options
author | Zeev Suraski <zeev@php.net> | 1999-12-24 13:46:24 +0000 |
---|---|---|
committer | Zeev Suraski <zeev@php.net> | 1999-12-24 13:46:24 +0000 |
commit | af925f0a14c661aefbc1abbdc464cd775bf2bc9b (patch) | |
tree | bff693b8921b9abd3f2117a49fc27bef077a0c20 | |
parent | 9903bb93a26ba91a8920b6908b740fa2a0591c18 (diff) | |
download | php-git-af925f0a14c661aefbc1abbdc464cd775bf2bc9b.tar.gz |
- Beef up the INI file reader - it now supports PHP constants, as well as
bitwise operators on them (no more error_reporting = 7, from now on you
can use error_reporting = E_ALL & ~E_NOTICE
@- Improved the php.ini reader to support constants and bitwise operators (Zeev)
-rw-r--r-- | main/configuration-parser.y | 98 | ||||
-rw-r--r-- | main/configuration-scanner.l | 6 | ||||
-rw-r--r-- | php.ini-dist | 47 |
3 files changed, 123 insertions, 28 deletions
diff --git a/main/configuration-parser.y b/main/configuration-parser.y index 2be8e02cb4..8461effb77 100644 --- a/main/configuration-parser.y +++ b/main/configuration-parser.y @@ -21,7 +21,7 @@ /* $Id$ */ -#define DEBUG_CFG_PARSER 1 +#define DEBUG_CFG_PARSER 0 #include "php.h" #include "php_globals.h" #include "php_ini.h" @@ -30,8 +30,6 @@ #include "ext/standard/php_browscap.h" #include "zend_extensions.h" -#undef YYPARSE_PARAM -#undef YYLEX_PARAM #if WIN32 #define WIN32_LEAN_AND_MEAN @@ -224,7 +222,7 @@ int php_init_config(void) tmp.value.str.len = strlen(opened_path); tmp.type = IS_STRING; zend_hash_update(&configuration_hash,"cfg_file_path",sizeof("cfg_file_path"),(void *) &tmp,sizeof(pval),NULL); -#if 0 +#if DEBUG_CFG_PARSER php_printf("INI file opened at '%s'\n",opened_path); #endif } @@ -327,6 +325,63 @@ static void convert_browscap_pattern(pval *pattern) return; } + +void do_cfg_op(char type, zval *result, zval *op1, zval *op2) +{ + int i_result; + int i_op1, i_op2; + char str_result[MAX_LENGTH_OF_LONG]; + + i_op1 = atoi(op1->value.str.val); + free(op1->value.str.val); + if (op2) { + i_op2 = atoi(op2->value.str.val); + free(op2->value.str.val); + } else { + i_op2 = 0; + } + + switch (type) { + case '|': + i_result = i_op1 | i_op2; + break; + case '&': + i_result = i_op1 & i_op2; + break; + case '~': + i_result = ~i_op1; + break; + default: + result = 0; + break; + } + + result->value.str.len = zend_sprintf(str_result, "%ld", i_result); + result->value.str.val = (char *) malloc(result->value.str.len+1); + memcpy(result->value.str.val, str_result, result->value.str.len); + result->value.str.val[result->value.str.len] = 0; + result->type = IS_STRING; +} + + +void do_cfg_get_constant(zval *result, zval *name) +{ + zval z_constant; + + if (zend_get_constant(name->value.str.val, name->value.str.len, &z_constant)) { + /* z_constant is emalloc()'d */ + convert_to_string(&z_constant); + result->value.str.val = zend_strndup(z_constant.value.str.val, z_constant.value.str.len); + result->value.str.len = z_constant.value.str.len; + result->type = z_constant.type; + zval_dtor(&z_constant); + free(name->value.str.val); + } else { + *result = *name; + } +} + + %} %pure_parser @@ -340,6 +395,8 @@ static void convert_browscap_pattern(pval *pattern) %token T_ZEND_EXTENSION_TS %token T_ZEND_EXTENSION_DEBUG %token T_ZEND_EXTENSION_DEBUG_TS +%left '|' '&' +%right '~' %% @@ -349,8 +406,8 @@ statement_list: ; statement: - string '=' string_or_value { -#if 0 + TC_STRING '=' string_or_value { +#if DEBUG_CFG_PARSER printf("'%s' = '%s'\n",$1.value.str.val,$3.value.str.val); #endif $3.type = IS_STRING; @@ -365,34 +422,34 @@ statement: } free($1.value.str.val); } - | string { free($1.value.str.val); } - | EXTENSION '=' string { + | TC_STRING { free($1.value.str.val); } + | EXTENSION '=' string_foo { pval dummy; -#if 0 +#if DEBUG_CFG_PARSER printf("Loading '%s'\n",$3.value.str.val); #endif php_dl(&$3,MODULE_PERSISTENT,&dummy); } - | T_ZEND_EXTENSION '=' string { + | T_ZEND_EXTENSION '=' string_foo { #if !defined(ZTS) && !ZEND_DEBUG zend_load_extension($3.value.str.val); #endif free($3.value.str.val); } - | T_ZEND_EXTENSION_TS '=' string { + | T_ZEND_EXTENSION_TS '=' string_foo { #if defined(ZTS) && !ZEND_DEBUG zend_load_extension($3.value.str.val); #endif free($3.value.str.val); } - | T_ZEND_EXTENSION_DEBUG '=' string { + | T_ZEND_EXTENSION_DEBUG '=' string_foo { #if !defined(ZTS) && ZEND_DEBUG zend_load_extension($3.value.str.val); #endif free($3.value.str.val); } - | T_ZEND_EXTENSION_DEBUG_TS '=' string { + | T_ZEND_EXTENSION_DEBUG_TS '=' string_foo { #if defined(ZTS) && ZEND_DEBUG zend_load_extension($3.value.str.val); #endif @@ -419,19 +476,30 @@ statement: ; -string: +string_foo: TC_STRING { $$ = $1; } | TC_ENCAPSULATED_STRING { $$ = $1; } ; string_or_value: - string { $$ = $1; } + expr { $$ = $1; } + | TC_ENCAPSULATED_STRING { $$ = $1; } | CFG_TRUE { $$ = $1; } | CFG_FALSE { $$ = $1; } | '\n' { $$.value.str.val = strdup(""); $$.value.str.len=0; $$.type = IS_STRING; } ; +expr: + constant_string { $$ = $1; } + | expr '|' expr { do_cfg_op('|', &$$, &$1, &$3); } + | expr '&' expr { do_cfg_op('&', &$$, &$1, &$3); } + | '~' expr { do_cfg_op('~', &$$, &$2, NULL); } + | '(' expr ')' { $$ = $2; } +; +constant_string: + TC_STRING { do_cfg_get_constant(&$$, &$1); } +; /* * Local variables: * tab-width: 4 diff --git a/main/configuration-scanner.l b/main/configuration-scanner.l index d7fe0f862c..b020d9f551 100644 --- a/main/configuration-scanner.l +++ b/main/configuration-scanner.l @@ -120,8 +120,12 @@ void init_cfg_scanner() return TC_ENCAPSULATED_STRING; } +<INITIAL>[&|~()] { + return yytext[0]; +} + -<INITIAL>[^=\n\r\t;"]+ { +<INITIAL>[^=\n\r\t;|&~()"]+ { /* STRING */ register int i; diff --git a/php.ini-dist b/php.ini-dist index 9f906a38b3..99a07c8a21 100644 --- a/php.ini-dist +++ b/php.ini-dist @@ -14,16 +14,28 @@ ; The syntax of the file is extremely simple. Whitespace and Lines ; beginning with a semicolon are silently ignored (as you probably guessed). ; Section headers (e.g. [Foo]) are also silently ignored, even though -; they might mean something in the future (they probably won't). +; they might mean something in the future. +; +; Directives are specified using the following syntax: +; directive = value +; Directive names are *case sensitive* - foo=bar is different from FOO=bar. +; +; The value can be a string, a number, a PHP constant (e.g. E_ALL or M_PI), one +; of the INI constants (On, Off, True, False, Yes and No) or an expression +; (e.g. E_ALL & ~E_NOTICE), or a quoted string ("foo"). +; +; Expressions in the INI file are limited to bitwise operators and parentheses: +; | bitwise OR +; & bitwise AND +; ~ bitwise NOT ; -; Options are specified using the syntax key = value or key = "complex value". -; Key names are *case sensitive*. foo = bar is different from FOO = bar. -; 'value' can be any number, word or keyword (keywords are On, Off, True, -; False, Yes and No, and are case insensitive). -; 'complex value' can be just about anything, expcept for " and a newline ; Boolean flags can be turned on using the values 1, On, True or Yes. ; They can be turned off using the values 0, Off, False or No. ; +; If you use constants in your value, and these constants belong to a dynamically +; loaded extension (either a PHP extension or a Zend extension), you may only +; use these constants *after* the line that loads the extension. +; ; All the values in the php.ini-dist file correspond to the builtin ; defaults (that is, if no php.ini is used, or if you delete these lines, ; the builtin defaults will be identical). @@ -87,12 +99,23 @@ memory_limit = 8388608 ; Maximum amount of memory a script may consume (8MB) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; Error handling and logging ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -; error_reporting is a bit-field. Add each number up to get desired error reporting level -; 1 = Normal errors -; 2 = Normal warnings -; 4 = Parser errors -; 8 = Notices - warnings you can ignore, but sometimes imply a bug (e.g., using an uninitialized variable) -error_reporting = 7 +; error_reporting is a bit-field. Or each number up to get desired error reporting level +; E_ALL - All errors and warnings +; E_ERROR - fatal run-time errors +; E_WARNING - run-time warnings (non fatal errors) +; E_PARSE - compile-time parse errors +; E_NOTICE - run-time notices (these are warnings which often result from a bug in +; your code, but it's possible that it was intentional (e.g., using an +; uninitialized variable and relying on the fact it's automatically +; initialized to an empty string) +; E_CORE_ERROR - fatal errors that occur during PHP's initial startup +; E_CORE_WARNING - warnings (non fatal errors) that occur during PHP's initial startup +; E_COMPILE_ERROR - fatal compile-time errors +; E_COMPILE_WARNING - compile-time warnings (non fatal errors) +; Examples: +; error_reporting = E_ALL & ~E_NOTICE ; show all errors, except for notices +; error_reporting = E_COMPILE_ERROR|E_ERROR|E_CORE_ERROR ; show only errors +error_reporting = E_ALL & ~E_NOTICE ; Show all errors except for notices display_errors = On ; Print out errors (as a part of the HTML script) log_errors = Off ; Log errors into a log file (server-specific log, stderr, or error_log (below)) track_errors = Off ; Store the last error/warning message in $php_errormsg (boolean) |