Re: [PHP4BETA] cvs: /php4 configuration-parser.y configuration-scanner.l php.ini-dist

From: Date: Fri, 24 Dec 1999 14:23:58 +0000
Subject: Re: [PHP4BETA] cvs: /php4 configuration-parser.y configuration-scanner.l php.ini-dist
References: 1  Groups: php.version4 
Request: Send a blank email to php-version4+get-8480@lists.php.net to get a copy of this message
Nice one! Andi At 01:46 PM 12/24/99 +0000, Zeev Suraski wrote:
zeev            Fri Dec 24 08:46:55 1999 EDT
Modified files:
    /php4       configuration-parser.y configuration-scanner.l php.ini-dist
Log: - 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)
Index: php4/configuration-parser.y diff -u php4/configuration-parser.y:1.25 php4/configuration-parser.y:1.26
--- php4/configuration-parser.y:1.25    Fri Dec 17 15:54:32 1999
+++ php4/configuration-parser.y Fri Dec 24 08:46:24 1999 @@ -19,9 +19,9 @@ -/* $Id: configuration-parser.y,v 1.25 1999/12/17 20:54:32 zeev Exp $ */ +/* $Id: configuration-parser.y,v 1.26 1999/12/24 13:46:24 zeev Exp $ */ -#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 @@
                        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 @@
        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 @@ %token T_ZEND_EXTENSION_TS %token T_ZEND_EXTENSION_DEBUG %token T_ZEND_EXTENSION_DEBUG_TS +%left '|' '&' +%right '~' %% @@ -349,8 +406,8 @@ ; 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 @@
                        }
                        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 @@ ; -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 Index: php4/configuration-scanner.l diff -u php4/configuration-scanner.l:1.7 php4/configuration-scanner.l:1.8
--- php4/configuration-scanner.l:1.7    Fri Dec 17 14:50:56 1999
+++ php4/configuration-scanner.l        Fri Dec 24 08:46:24 1999
@@ -120,8 +120,12 @@
        return TC_ENCAPSULATED_STRING;
} +<INITIAL>[&|~()] {
+       return yytext[0];
+} -<INITIAL>[^=\n\r\t;"]+ { + +<INITIAL>[^=\n\r\t;|&~()"]+ {
        /* STRING */
        register int i;
Index: php4/php.ini-dist diff -u php4/php.ini-dist:1.16 php4/php.ini-dist:1.17
--- php4/php.ini-dist:1.16      Wed Dec 15 16:20:34 1999
+++ php4/php.ini-dist Fri Dec 24 08:46:24 1999 @@ -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. ; -; 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 +; 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
+; ; 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 @@ ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; 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)
-- PHP 4.0 Beta Mailing List <http://www.php.net/version4/> To unsubscribe, e-mail: php4beta-unsubscribe@lists.php.net For additional commands, e-mail: php4beta-help@lists.php.net To contact the list administrators, e-mail: php4beta-admin@lists.php.net
--- Andi Gutmans <andi@zend.com> http://www.zend.com/

« previous php.version4 (#8480) next »