nlopess         Tue Jun 28 12:59:36 2005 EDT

  Modified files:              
    /phpdoc/scripts/iniupdate   generate_changelog.php ini-update.php 
                                ini_search_lib.php insert_db.php 
                                make_db.php update_db.php 
  Log:
  lots of changes:
   * unify file recursion in the ini_search_lib. most 'dirty work' is now done 
here
   * implement a big TODO for this script: fetch data from cfg_get_*(). it is 
experimental, as it is very difficult to get data from this. some tunes to 
regex might be still needed
   * optimize where I could, so that the script doesnt get too slow
  # most changes werent tested yet. Commiting just to test in a another box. 
But at least it fails in 3 ini options (not bad :))
  
http://cvs.php.net/diff.php/phpdoc/scripts/iniupdate/generate_changelog.php?r1=1.2&r2=1.3&ty=u
Index: phpdoc/scripts/iniupdate/generate_changelog.php
diff -u phpdoc/scripts/iniupdate/generate_changelog.php:1.2 
phpdoc/scripts/iniupdate/generate_changelog.php:1.3
--- phpdoc/scripts/iniupdate/generate_changelog.php:1.2 Sat Mar 26 08:22:31 2005
+++ phpdoc/scripts/iniupdate/generate_changelog.php     Tue Jun 28 12:59:35 2005
@@ -105,7 +105,6 @@
 }
 
 
-$error = '';
 
 if (!$idx = sqlite_open('ini_changelog.sqlite', 0666, $error)) {
     die("Couldn't open the DB: $error");
http://cvs.php.net/diff.php/phpdoc/scripts/iniupdate/ini-update.php?r1=1.2&r2=1.3&ty=u
Index: phpdoc/scripts/iniupdate/ini-update.php
diff -u phpdoc/scripts/iniupdate/ini-update.php:1.2 
phpdoc/scripts/iniupdate/ini-update.php:1.3
--- phpdoc/scripts/iniupdate/ini-update.php:1.2 Sat Mar 26 08:22:31 2005
+++ phpdoc/scripts/iniupdate/ini-update.php     Tue Jun 28 12:59:35 2005
@@ -27,61 +27,7 @@
 
 /******* END of configurations *****/
 
-
-/* Search for INI entrys and C macros in php-src/pecl directory */
-
-function recurse($dir) {
-    global $array, $replace;
-
-    if (!$dh = opendir($dir)) {
-        die ("couldn't open the specified dir ($dir)");
-    }
-
-    while (($file = readdir($dh)) !== false) {
-
-        if($file == '.' || $file == '..') {
-            continue;
-        }
-
-        $path = $dir . '/' .$file;
-
-        if(is_dir($path)) {
-            recurse($path);
-        } else {
-            $file = file_get_contents($path);
-
-            /* delete comments */
-            $file = preg_replace('@(//.*$)|(/\*.*\*/)@SmsU', '', $file);
-
-            /* The MAGIC Regexp :) */
-            
if(preg_match_all('/(?:PHP|ZEND)_INI_(?:ENTRY(?:_EX)?|BOOLEAN)\s*\(\s*"([^"]+)"\s*,((?:".*"|[^,])+)\s*,\s*([^,]+)/S',
 $file, $matches)) {
-
-                $count = count($matches[0]);
-                for($i=0;$i<$count;$i++) {
-
-                    $default = htmlspecialchars(trim($matches[2][$i]), 
ENT_NOQUOTES);
-
-                    $permissions = preg_replace(array('/\s+/', '/ZEND/'), 
array('', 'PHP'), $matches[3][$i]);
-                    $permissions =  ($permissions == 
'PHP_INI_PERDIR|PHP_INI_SYSTEM' || $permissions == 
'PHP_INI_SYSTEM|PHP_INI_PERDIR') ? 'PHP_INI_PERDIR' : $permissions;
-
-                    $array[] = $matches[1][$i] . '-!!-' . $default . '-!!-' . 
$permissions;
-                }
-            } //end of the magic regex
-
-            /* search for C macros */
-            if(preg_match_all('/#\s*define\s+(\S{5,})[ \t]+(.+)/S', $file, 
$matches)) {
-                $count = count($matches[0]);
-                for($i=0;$i<$count;$i++) {
-                    $replace[$matches[1][$i]] = rtrim($matches[2][$i]);
-                }
-            } // end of macros
-
-        } //!is_dir()
-    } //while() loop
-
-    closedir($dh);
-}
-
+require './ini_search_lib.php';
 
 
 /* Fix ini.xml files */
@@ -138,13 +84,11 @@
 
 $array = array();
 $replace = array();
+recurse(array($php_src_dir, $pecl_dir), true);
 
-recurse($php_src_dir);
-recurse($pecl_dir);
-
-natcasesort($array);
 $string = '';
 
+echo 'Found ' . count($array) . " entries\n";
 
 // get the changelog info
 $included = true;
@@ -175,23 +119,19 @@
 }
 
 /* Generate the XML code */
-foreach($array as $key => $value) {
-    $arr   = explode('-!!-', $value);
-    $entry = $arr[0];
+foreach($array as $entry => $arr) {
 
-    if(isset($info[$entry])) {
-        continue;
-    }
+    $oldentry = $entry;
 
     /* link entries */
     if (isset($links[$entry])) {
         $entry = '<link linkend="' . $links[$entry] . '">' . $entry . 
'</link>';
-        unset($link_files[$arr[0]]);
+        unset($link_files[$oldentry]);
     }
 
 
     /* replace macros and make the $default var */
-    $new = $arr[1];
+    $new = $arr[0];
 
     do {
         $old = $new;
@@ -215,19 +155,19 @@
 
     /* end of $default stuff */
 
-    $permissions = isset($special[$arr[0]]) ? '&php.ini; only' : $arr[2];
+    $permissions = isset($special[$oldentry]) ? '&php.ini; only' : $arr[1];
 
 
-    $info[$arr[0]]['default']     = $default;
-    $info[$arr[0]]['permissions'] = $permissions;
-    $info[$arr[0]]['changelog']   = isset($changelog[$arr[0]]) ? 
$changelog[$arr[0]] : '';
+    $info[$oldentry]['default']     = $default;
+    $info[$oldentry]['permissions'] = $permissions;
+    $info[$oldentry]['changelog']   = isset($changelog[$oldentry]) ? 
$changelog[$oldentry] : '';
 
 
     $string .= '      <row>' . PHP_EOL.
                "       <entry>$entry</entry>" . PHP_EOL.
                "       <entry>$default</entry>" . PHP_EOL.
                "       <entry>$permissions</entry>" . PHP_EOL.
-               "       <entry>{$info[$arr[0]]['changelog']}</entry>" . PHP_EOL.
+               "       <entry>{$info[$oldentry]['changelog']}</entry>" . 
PHP_EOL.
                '      </row>'.PHP_EOL;
 }
 
http://cvs.php.net/diff.php/phpdoc/scripts/iniupdate/ini_search_lib.php?r1=1.2&r2=1.3&ty=u
Index: phpdoc/scripts/iniupdate/ini_search_lib.php
diff -u phpdoc/scripts/iniupdate/ini_search_lib.php:1.2 
phpdoc/scripts/iniupdate/ini_search_lib.php:1.3
--- phpdoc/scripts/iniupdate/ini_search_lib.php:1.2     Sat Mar 26 08:22:31 2005
+++ phpdoc/scripts/iniupdate/ini_search_lib.php Tue Jun 28 12:59:35 2005
@@ -17,9 +17,34 @@
   +----------------------------------------------------------------------+
 */
 
-function recurse($dir) {
+function recurse($dirs, $search_macros = false) {
     global $array;
 
+    $cfg_get = array();
+
+    if (is_array($dirs)) {
+        foreach($dirs as $dir)
+            recurse_aux($dir, $search_macros);
+    } else {
+        recurse_aux($dirs, $search_macros);
+    }
+
+    /* insert only if the key doesn't exist, as will probably have
+       more accurant data in $array than here */
+    foreach($cfg_get as $entry) {
+        if (!isset($array[$entry[0]]))
+            $array[$entry[0]] = array($entry[1], 'PHP_INI_ALL');
+
+    }
+
+    uksort($array, 'strnatcasecmp');
+}
+
+
+// recurse through the dirs and do the 'dirty work'
+function recurse_aux($dir, $search_macros) {
+    global $array, $replace, $cfg_get;
+
     if (!$dh = opendir($dir)) {
         die ("couldn't open the specified dir ($dir)");
     }
@@ -51,10 +76,40 @@
                     $permissions = preg_replace(array('/\s+/', '/ZEND/'), 
array('', 'PHP'), $matches[3][$i]);
                     $permissions =  ($permissions == 
'PHP_INI_PERDIR|PHP_INI_SYSTEM' || $permissions == 
'PHP_INI_SYSTEM|PHP_INI_PERDIR') ? 'PHP_INI_PERDIR' : $permissions;
 
-                    $array[] = array($matches[1][$i], $permissions);
+                    $array[$matches[1][$i]] = array($default, $permissions);
                 }
+
             } //end of the magic regex
 
+
+            // find the nasty cfg_get_*() stuff
+            
if(preg_match_all('/cfg_get_([^(]+)\s*\(\s*"([^"]+)",\s*&([^\s=]+)\s*\)/S', 
$file, $match, PREG_SET_ORDER)) {
+
+                foreach($match as $arr) {
+                    
preg_match('/(?:(FAILURE|SUCCESS)\s*==\s*)?'.preg_quote($arr[0]).'(?:\s*==\s*(FAILURE|SUCCESS))?(?:(?:.|[\r\n]){1,30}'.preg_quote($arr[3]).'\s*=\s*(.+);)?/',
 $file, $m);
+
+                    if ($m[1] == 'FAILURE' || $m[2] == 'FAILURE') {
+                        $cfg_get[] = array($arr[2], $arr[1] == 'string' ? 
$m[3] : '"'.$m[3].'"');
+
+                    } else { //$m[1] == 'SUCCESS'
+                        if ($arr[1] == 'string')
+                            $cfg_get[] = array($arr[2], '""');
+                        else
+                            $cfg_get[] = array($arr[2], '"0"');
+                    }
+                } //foreach cfg_get_*()
+            } //end of nasty cfg_get_*() regex
+
+
+            /* search for C macros */
+            if($search_macros && preg_match_all('/#\s*define\s+(\S{5,})[ 
\t]+(.+)/S', $file, $matches)) {
+                $count = count($matches[0]);
+                for($i=0;$i<$count;$i++) {
+                    $replace[$matches[1][$i]] = rtrim($matches[2][$i]);
+                }
+            } // end of macros
+
+
         } //!is_dir()
     } //while() loop
 
http://cvs.php.net/diff.php/phpdoc/scripts/iniupdate/insert_db.php?r1=1.1&r2=1.2&ty=u
Index: phpdoc/scripts/iniupdate/insert_db.php
diff -u phpdoc/scripts/iniupdate/insert_db.php:1.1 
phpdoc/scripts/iniupdate/insert_db.php:1.2
--- phpdoc/scripts/iniupdate/insert_db.php:1.1  Tue Feb 22 12:54:58 2005
+++ phpdoc/scripts/iniupdate/insert_db.php      Tue Jun 28 12:59:35 2005
@@ -23,20 +23,13 @@
     global $array, $idx;
 
     $sql = '';
-    $sanity = array();
 
-    foreach ($array as $entry) {
+    foreach ($array as $key => $data) {
 
-        if (isset($sanity[$entry[0]])) {
-            continue;
-        }
-
-        $sanity[$entry[0]] = 1;
-
-        if ($a= sqlite_single_query($idx, "SELECT name FROM changelog WHERE 
name='{$entry[0]}'")) {
-            $sql .= "UPDATE changelog SET $tag='{$entry[1]}' WHERE 
name='{$entry[0]}';";
+        if (sqlite_single_query($idx, "SELECT name FROM changelog WHERE 
name='$key'")) {
+            $sql .= "UPDATE changelog SET $tag='{$data[1]}' WHERE 
name='$key';";
         } else {
-            $sql .= "INSERT INTO changelog (name, $tag) VALUES ('{$entry[0]}', 
'{$entry[1]}');";
+            $sql .= "INSERT INTO changelog (name, $tag) VALUES ('$key', 
'{$data[1]}');";
         }
 
     }
@@ -46,7 +39,6 @@
 
 
 
-$error = '';
 $db_open = isset($idx) ? true : false;
 
 if (!$db_open && !$idx = sqlite_open('ini_changelog.sqlite', 0666, $error)) {
http://cvs.php.net/diff.php/phpdoc/scripts/iniupdate/make_db.php?r1=1.1&r2=1.2&ty=u
Index: phpdoc/scripts/iniupdate/make_db.php
diff -u phpdoc/scripts/iniupdate/make_db.php:1.1 
phpdoc/scripts/iniupdate/make_db.php:1.2
--- phpdoc/scripts/iniupdate/make_db.php:1.1    Tue Feb 22 12:54:58 2005
+++ phpdoc/scripts/iniupdate/make_db.php        Tue Jun 28 12:59:35 2005
@@ -17,7 +17,6 @@
   +----------------------------------------------------------------------+
 */
 
-$error = '';
 $db_open = isset($idx) ? true : false;
 
 if (!$db_open && !$idx = sqlite_open('ini_changelog.sqlite', 0666, $error)) {
http://cvs.php.net/diff.php/phpdoc/scripts/iniupdate/update_db.php?r1=1.1&r2=1.2&ty=u
Index: phpdoc/scripts/iniupdate/update_db.php
diff -u phpdoc/scripts/iniupdate/update_db.php:1.1 
phpdoc/scripts/iniupdate/update_db.php:1.2
--- phpdoc/scripts/iniupdate/update_db.php:1.1  Tue Feb 22 12:54:58 2005
+++ phpdoc/scripts/iniupdate/update_db.php      Tue Jun 28 12:59:35 2005
@@ -17,15 +17,15 @@
   +----------------------------------------------------------------------+
 */
 
-$error = '';
 copy('ini_changelog.sqlite', 'backup.sqlite');
 
 if (!$idx = sqlite_open('ini_changelog.sqlite', 0666, $error)) {
-    die("Couldn't create the DB: $error");
+    die("Couldn't open the DB: $error");
 }
 
 $olddata = sqlite_fetch_all(sqlite_query($idx, 'SELECT * FROM changelog'), 
SQLITE_ASSOC);
-$columns = sqlite_fetch_array(sqlite_query($idx, 'SELECT * FROM changelog 
LIMIT 1'), SQLITE_ASSOC);
+$columns = array_keys($olddata[0]);
+$columns_str = implode(',', $columns);
 
 sqlite_query($idx, 'DROP TABLE changelog; VACUUM;');
 
@@ -35,14 +35,7 @@
 $sql = '';
 
 foreach ($olddata as $row) {
-    $keys = '';
-
-    foreach ($row as $key => $val) {
-        $keys .= ",$key";
-    }
-    $keys = substr($keys, 1);
-
-    $sql .= "INSERT INTO changelog ($keys) VALUES (\"" . implode('", "', $row) 
. '");';
+    $sql .= "INSERT INTO changelog ($columns_str) VALUES (\"" . implode('", 
"', $row) . '");';
 }
 
 sqlite_query($idx, $sql);
@@ -56,6 +49,8 @@
     }
 }
 
+unset($tmp, $columns, $sql);
+
 // finally recurse through the new PHP versions
 include './insert_db.php';
 

Reply via email to