nlopess         Tue Feb 22 12:54:59 2005 EDT

  Added files:                 
    /phpdoc/scripts/iniupdate   .cvsignore README cvs-get-release 
                                generate_changelog.php ini-update.php 
                                ini_search_lib.php insert_db.php 
                                make_db.php update-all update_db.php 
                                version4.tags version5.tags 
  Log:
  commit script to update ini.xml files
  contains code by Jakub
  
http://cvs.php.net/co.php/phpdoc/scripts/iniupdate/.cvsignore?r=1.1&p=1
Index: phpdoc/scripts/iniupdate/.cvsignore
+++ phpdoc/scripts/iniupdate/.cvsignore
sources
*.sqlite

http://cvs.php.net/co.php/phpdoc/scripts/iniupdate/generate_changelog.php?r=1.1&p=1
Index: phpdoc/scripts/iniupdate/generate_changelog.php
+++ phpdoc/scripts/iniupdate/generate_changelog.php
<?php
/*
  +----------------------------------------------------------------------+
  | ini doc settings updater                                             |
  +----------------------------------------------------------------------+
  | Copyright (c) 1997-2005 The PHP Group                                |
  +----------------------------------------------------------------------+
  | This source file is subject to version 3.0 of the PHP license,       |
  | that is bundled with this package in the file LICENSE, and is        |
  | available through the world-wide-web at the following url:           |
  | http://www.php.net/license/3_0.txt.                                  |
  | If you did not receive a copy of the PHP license and are unable to   |
  | obtain it through the world-wide-web, please send a note to          |
  | [EMAIL PROTECTED] so we can mail you a copy immediately.               |
  +----------------------------------------------------------------------+
  | Authors:    Nuno Lopes <[EMAIL PROTECTED]>                             |
  +----------------------------------------------------------------------+
*/

/** converts a tag like php_5_0_0 into a version like 5.0.0 */
function tag2version($tag) {
    $s = strtr(substr($tag, 4), '_', '.');

    return substr($s, 2) == 'cvs' ? $s{0} . '-cvs' : $s;
}


/** checks if an ini setting has changed its value in PHP 5  */
function check_php4($array) {

    foreach($array as $key => $val) {
        if (substr($key, 0, 5) != 'php_4') {
            continue;
        }

        if ($val) {
            if (isset($old)) {
                if ($val != $old) {
                    return '';
                }
            } else {
                $old = $val;
            }
        }
    }

    if (isset($old) && $old != $array['php_5_0_0'] && $array['php_5_0_0']) {
        return "$old in PHP 4.";
    }
}


/** return when the option become available */
function available_since($array) {

    if ($array['php_4_0_0']) {
        return '';
    }

    foreach($array as $key => $val) {
        if ($val) {
            return 'Available since PHP ' . tag2version($key) . '.';
        }
    }

}


/** check for changes between versions */
function last_version($array) {

    $php4 = check_php4($array);
    $str  = '';

    foreach($array as $key => $val) {
        if ($php4 && substr($key, 0, 5) == 'php_4') {
            continue;
        }

        if ($val) {
            if (isset($old)) {
                if ($val != $old) {
                    $str .= " $old in PHP &lt;= " . tag2version($old_tag) . '.';
                }
            }

            $old     = $val;
            $old_tag = $key;
        }
    }

    return $php4 . $str;
}


/** generate the changelog column */
function generate_changelog($array) {

    array_shift($array);
    return trim(last_version($array) . ' ' . available_since($array));
}


$error = '';

if (!$idx = sqlite_open('ini_changelog.sqlite', 0666, $error)) {
    die("Couldn't open the DB: $error");
}

$q = sqlite_unbuffered_query($idx, 'SELECT * FROM changelog');

/* This hack is needed because sqlite 2 sort case-sensitive */
while($row = sqlite_fetch_array($q, SQLITE_ASSOC)) {
    uksort($row, 'strnatcmp');
    $info[$row['name']] = $row;
}

uksort($info, 'strnatcasecmp');

foreach ($info as $row) {
    $changelog[$row['name']] = generate_changelog($row);
}

if (!isset($included)) {
    foreach ($changelog as $key => $val) {
        echo "$key : $val\n";
    }
}

sqlite_close($idx);

?>

http://cvs.php.net/co.php/phpdoc/scripts/iniupdate/ini-update.php?r=1.1&p=1
Index: phpdoc/scripts/iniupdate/ini-update.php
+++ phpdoc/scripts/iniupdate/ini-update.php
<?php
/*
  +----------------------------------------------------------------------+
  | ini doc settings updater                                             |
  +----------------------------------------------------------------------+
  | Copyright (c) 1997-2005 The PHP Group                                |
  +----------------------------------------------------------------------+
  | This source file is subject to version 3.0 of the PHP license,       |
  | that is bundled with this package in the file LICENSE, and is        |
  | available through the world-wide-web at the following url:           |
  | http://www.php.net/license/3_0.txt.                                  |
  | If you did not receive a copy of the PHP license and are unable to   |
  | obtain it through the world-wide-web, please send a note to          |
  | [EMAIL PROTECTED] so we can mail you a copy immediately.               |
  +----------------------------------------------------------------------+
  | Authors:    Nuno Lopes <[EMAIL PROTECTED]>                             |
  |             Jakub Vr�na <[EMAIL PROTECTED]>                              |
  +----------------------------------------------------------------------+
*/


/* Configuration Options */

$php_src_dir = '../../../php-src'; //php-src path
$pecl_dir    = '../../../pecl';    //pecl path
$phpdoc_dir  = '../../';           //phpdoc path

/******* 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*,\s*([^,]+)/S',
 $file, $matches)) {

                $count = count($matches[0]);
                for($i=0;$i<$count;$i++) {

                    $default = htmlspecialchars($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);
}



/* Fix ini.xml files */

function fix_ini_xml($filename) {
    global $info;

    $original = $file = file_get_contents($filename);

    // insert the changelog column if it doesn't exist
    $file = 
preg_replace('@<tgroup\s+cols=[\'"]3[\'"]>(\s*<thead>\s*<row>\s*<entry>&?Name;?</entry>\s*<entry>&?Default;?</entry>(\s*)<entry>&?Changeable;?</entry>)(\s*</row>\s*</thead>)@US',
 '<tgroup cols="4">\1\2<entry>Changelog</entry>\3', $file);

    // remove old permissions constants usage about PHP_INI_PERDIR
    $file = 
preg_replace('/(?:PHP_INI_SYSTEM\s*\|\s*)?PHP_INI_PERDIR(?:\s*\|\s*PHP_INI_SYSTEM)?/',
 'PHP_INI_PERDIR', $file);

    preg_match_all('@<tbody>.+</tbody>@USs', $file, $matches);

    foreach ($matches[0] as $match) {
        preg_match_all('@<row>.+</row>@USs', $match, $matches_row);

        foreach ($matches_row[0] as $match_row) {
            preg_match_all('@<entry>.+</entry>@USs', $match_row, 
$matches_entry);

            foreach ($matches_entry as $val) {

                // create changelog column
                if (count($val) == 3) {
                    $file = 
preg_replace("@(<row>\s*$val[0]\s*$val[1](\s*)$val[2])(\s*</row>)@", 
'\1\2<entry></entry>\3', $file);
                    $val[3] = '<entry></entry>';
                }

                // now update the info
                $entry = substr($val[0], 7, -8);
                if (isset($info[$entry])) {
                    $file = 
preg_replace("@(<row>\s*$val[0]\s*)$val[1](\s*)$val[2](\s*)$val[3](\s*</row>)@",
 
"\\1<entry>{$info[$entry]['default']}</entry>\\2<entry>{$info[$entry]['permissions']}</entry>\\3<entry>{$info[$entry]['changelog']}</entry>\\4",
 $file);
                }
            }

        }

    }


    // if the file was modified, write the changes
    if ($original != $file) {
        file_put_contents($filename, $file);
    }
}



/* Start the main program */

$array = array();
$replace = array();

recurse($php_src_dir);
recurse($pecl_dir);

natcasesort($array);
$string = '';


// get the changelog info
$included = true;
require('./generate_changelog.php');
unset($info, $included, $error, $row);


/* &php.ini; only */
$special = array('disable_functions' => 1, 'disable_classes' => 1, 'expose_php' 
=> 1);

/* Find links to documentation */
$links       = array();
$link_files  = array();
$ini_files   = glob("$phpdoc_dir/en/reference/*/ini.xml");
$ini_files[] = "$phpdoc_dir/en/features/safe-mode.xml";
$ini_files[] = "$phpdoc_dir/en/appendices/ini.xml";

foreach ($ini_files as $filename) {

    preg_match_all('~<varlistentry id="(ini.[^"]*)">(.*)</varlistentry>~USs', 
file_get_contents($filename), $matches, PREG_SET_ORDER);
    foreach ($matches as $varlistentry) {
        preg_match_all('~<term>.*<parameter>(.*)</parameter>~USs', 
$varlistentry[2], $matches2);
        foreach ($matches2[1] as $parameter) {
            $links[trim($parameter)] = $varlistentry[1];
            $link_files[trim($parameter)] = $filename;
        }
    }
}

/* Generate the XML code */
foreach($array as $key => $value) {
    $arr   = explode('-!!-', $value);
    $entry = $arr[0];

    if(isset($info[$entry])) {
        continue;
    }

    /* link entries */
    if (isset($links[$entry])) {
        $entry = '<link linkend="' . $links[$entry] . '">' . $entry . '</link>';
        unset($link_files[$arr[0]]);
    }


    /* replace macros and make the $default var */
    $new = $arr[1];

    do {
        $old = $new;
        $new = strtr($new,$replace);

    } while($new != $old);

    $default = $new;

    if(preg_match_all('/"([^"]+)"/S', $default, $match) > 1) {
        $default = '"';

        foreach($match[1] as $add) {
            $default .= $add;
        }
        $default .= '"';
    }

    // replace the @PREFIX@ stuff
    $default = preg_replace(array('[EMAIL PROTECTED]@~i', '~[\\\\]{2}~'), 
array('/path/to/php', '/'), $default);

    /* end of $default stuff */

    $permissions = isset($special[$arr[0]]) ? '&php.ini; only' : $arr[2];


    $info[$arr[0]]['default']     = $default;
    $info[$arr[0]]['permissions'] = $permissions;
    $info[$arr[0]]['changelog']   = isset($changelog[$arr[0]]) ? 
$changelog[$arr[0]] : '';


    $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.
               '      </row>'.PHP_EOL;
}


/* Print unmatched links */
$deprecated = array('track_vars', 'debugger.host', 'debugger.port', 
'debugger.enabled', 'sesam_oml', 'sesam_configfile', 'sesam_messagecatalog', 
'gpc_order', 'allow_webdav_methods');
foreach ($deprecated as $val) {
    unset($link_files[$val]);
}
if ($link_files) {
    echo "Warning - unmatched links:\n";
    foreach ($link_files as $ini => $file) {
        echo str_pad("$ini", 30, " ", STR_PAD_RIGHT) . " => " . substr($file, 
strlen($phpdoc_dir)+4) . "\n";
    }
}


/* Now write the final result */
$file = file_get_contents("$phpdoc_dir/en/appendices/ini.xml");

$pos = strpos($file, '<tbody>', strpos($file, '<title>Configuration 
options</title>')) + strlen('<tbody>');
$pos2 = strpos($file, '</tbody>', $pos);

file_put_contents("$phpdoc_dir/en/appendices/ini.xml", substr($file, 0, $pos) . 
PHP_EOL . $string . '     ' . substr($file, $pos2));



/* fix ini.xml files (if needed) */
foreach ($ini_files as $file) {
    fix_ini_xml($file);
}

?>

http://cvs.php.net/co.php/phpdoc/scripts/iniupdate/ini_search_lib.php?r=1.1&p=1
Index: phpdoc/scripts/iniupdate/ini_search_lib.php
+++ phpdoc/scripts/iniupdate/ini_search_lib.php
<?php
/*
  +----------------------------------------------------------------------+
  | ini doc settings updater                                             |
  +----------------------------------------------------------------------+
  | Copyright (c) 1997-2005 The PHP Group                                |
  +----------------------------------------------------------------------+
  | This source file is subject to version 3.0 of the PHP license,       |
  | that is bundled with this package in the file LICENSE, and is        |
  | available through the world-wide-web at the following url:           |
  | http://www.php.net/license/3_0.txt.                                  |
  | If you did not receive a copy of the PHP license and are unable to   |
  | obtain it through the world-wide-web, please send a note to          |
  | [EMAIL PROTECTED] so we can mail you a copy immediately.               |
  +----------------------------------------------------------------------+
  | Authors:    Nuno Lopes <[EMAIL PROTECTED]>                             |
  +----------------------------------------------------------------------+
*/

function recurse($dir) {
    global $array;

    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*,\s*([^,]+)/S',
 $file, $matches)) {

                $count = count($matches[0]);
                for($i=0;$i<$count;$i++) {

                    $default = htmlspecialchars($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[] = array($matches[1][$i], $permissions);
                }
            } //end of the magic regex

        } //!is_dir()
    } //while() loop

    closedir($dh);
}
?>

http://cvs.php.net/co.php/phpdoc/scripts/iniupdate/insert_db.php?r=1.1&p=1
Index: phpdoc/scripts/iniupdate/insert_db.php
+++ phpdoc/scripts/iniupdate/insert_db.php
<?php
/*
  +----------------------------------------------------------------------+
  | ini doc settings updater                                             |
  +----------------------------------------------------------------------+
  | Copyright (c) 1997-2005 The PHP Group                                |
  +----------------------------------------------------------------------+
  | This source file is subject to version 3.0 of the PHP license,       |
  | that is bundled with this package in the file LICENSE, and is        |
  | available through the world-wide-web at the following url:           |
  | http://www.php.net/license/3_0.txt.                                  |
  | If you did not receive a copy of the PHP license and are unable to   |
  | obtain it through the world-wide-web, please send a note to          |
  | [EMAIL PROTECTED] so we can mail you a copy immediately.               |
  +----------------------------------------------------------------------+
  | Authors:    Nuno Lopes <[EMAIL PROTECTED]>                             |
  +----------------------------------------------------------------------+
*/

require './ini_search_lib.php';

function insert_in_db($tag) {
    global $array, $idx;

    $sql = '';
    $sanity = array();

    foreach ($array as $entry) {

        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]}';";
        } else {
            $sql .= "INSERT INTO changelog (name, $tag) VALUES ('{$entry[0]}', 
'{$entry[1]}');";
        }

    }

    sqlite_query($idx, $sql);
}



$error = '';
$db_open = isset($idx) ? true : false;

if (!$db_open && !$idx = sqlite_open('ini_changelog.sqlite', 0666, $error)) {
    die("Couldn't create the DB: $error");
}

if (!isset($tags)) {
    $tags[] = 'php_4_cvs';
    $tags[] = 'php_5_cvs';
    $tags = array_merge($tags, array_map('rtrim', 
array_merge(file('version4.tags'), file('version5.tags'))));
}

foreach($tags as $tag) {
    $array = array();
    recurse("./sources/$tag");
    insert_in_db($tag);

    echo "$tag\n";
}

if (!$db_open) {
    sqlite_close($idx);
}

?>

http://cvs.php.net/co.php/phpdoc/scripts/iniupdate/make_db.php?r=1.1&p=1
Index: phpdoc/scripts/iniupdate/make_db.php
+++ phpdoc/scripts/iniupdate/make_db.php
<?php
/*
  +----------------------------------------------------------------------+
  | ini doc settings updater                                             |
  +----------------------------------------------------------------------+
  | Copyright (c) 1997-2005 The PHP Group                                |
  +----------------------------------------------------------------------+
  | This source file is subject to version 3.0 of the PHP license,       |
  | that is bundled with this package in the file LICENSE, and is        |
  | available through the world-wide-web at the following url:           |
  | http://www.php.net/license/3_0.txt.                                  |
  | If you did not receive a copy of the PHP license and are unable to   |
  | obtain it through the world-wide-web, please send a note to          |
  | [EMAIL PROTECTED] so we can mail you a copy immediately.               |
  +----------------------------------------------------------------------+
  | Authors:    Nuno Lopes <[EMAIL PROTECTED]>                             |
  +----------------------------------------------------------------------+
*/

$error = '';
$db_open = isset($idx) ? true : false;

if (!$db_open && !$idx = sqlite_open('ini_changelog.sqlite', 0666, $error)) {
    die("Couldn't create the DB: $error");
}

$sql = 'CREATE TABLE changelog (
name TEXT PRIMARY KEY,';

$tags[] = 'php_4_cvs';
$tags[] = 'php_5_cvs';
$tags = array_merge($tags, array_map('rtrim', 
array_merge(file('version4.tags'), file('version5.tags'))));

foreach($tags as $tag) {
    $sql .= "$tag TEXT,";
}

$sql = substr($sql, 0, -1) . ');';

sqlite_query($idx, $sql);

if (!$db_open) {
    sqlite_close($idx);
}

?>

http://cvs.php.net/co.php/phpdoc/scripts/iniupdate/update_db.php?r=1.1&p=1
Index: phpdoc/scripts/iniupdate/update_db.php
+++ phpdoc/scripts/iniupdate/update_db.php
<?php
/*
  +----------------------------------------------------------------------+
  | ini doc settings updater                                             |
  +----------------------------------------------------------------------+
  | Copyright (c) 1997-2005 The PHP Group                                |
  +----------------------------------------------------------------------+
  | This source file is subject to version 3.0 of the PHP license,       |
  | that is bundled with this package in the file LICENSE, and is        |
  | available through the world-wide-web at the following url:           |
  | http://www.php.net/license/3_0.txt.                                  |
  | If you did not receive a copy of the PHP license and are unable to   |
  | obtain it through the world-wide-web, please send a note to          |
  | [EMAIL PROTECTED] so we can mail you a copy immediately.               |
  +----------------------------------------------------------------------+
  | Authors:    Nuno Lopes <[EMAIL PROTECTED]>                             |
  +----------------------------------------------------------------------+
*/

$error = '';
copy('ini_changelog.sqlite', 'backup.sqlite');

if (!$idx = sqlite_open('ini_changelog.sqlite', 0666, $error)) {
    die("Couldn't create 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);

sqlite_query($idx, 'DROP TABLE changelog; VACUUM;');

// make a new table. this also fills the $tags array
include './make_db.php';

$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) 
. '");';
}

sqlite_query($idx, $sql);

$tmp = $tags;
$tags = array('php_4_cvs', 'php_5_cvs');

foreach($tmp as $tag) {
    if (!isset($columns[$tag])) {
        $tags[] = $tag;
    }
}

// finally recurse through the new PHP versions
include './insert_db.php';

sqlite_close($idx);

?>

http://cvs.php.net/co.php/phpdoc/scripts/iniupdate/version4.tags?r=1.1&p=1
Index: phpdoc/scripts/iniupdate/version4.tags
+++ phpdoc/scripts/iniupdate/version4.tags
php_4_0_0
php_4_0_1
php_4_0_2
php_4_0_3
php_4_0_4
php_4_0_5
php_4_0_6
php_4_1_0
php_4_1_1
php_4_1_2
php_4_2_0
php_4_2_1
php_4_2_2
php_4_2_3
php_4_3_0
php_4_3_1
php_4_3_2
php_4_3_3
php_4_3_4
php_4_3_5
php_4_3_6
php_4_3_7
php_4_3_8
php_4_3_9
php_4_3_10

http://cvs.php.net/co.php/phpdoc/scripts/iniupdate/version5.tags?r=1.1&p=1
Index: phpdoc/scripts/iniupdate/version5.tags
+++ phpdoc/scripts/iniupdate/version5.tags
php_5_0_0
php_5_0_1
php_5_0_2
php_5_0_3

Reply via email to