Back to index

php5  5.3.10
upgrade-pcre.php
Go to the documentation of this file.
00001 <?php
00002 
00003 // script to upgrade PCRE. just drop the pcre-x.x.tar.xx here and run the script
00004 
00005 $pattern = 'pcre-*.tar.*';
00006 $newpcre = glob($pattern);
00007 
00008 if (count($newpcre) > 1) {
00009        echo "more than one '$pattern' file. aborting\n";
00010        print_r($newpcre);
00011        exit;
00012 }
00013 
00014 if (count($newpcre) == 0) {
00015        die("need one '$pattern' file. aborting.\n");
00016 }
00017 
00018 
00019 $newpcre = $newpcre[0];
00020 
00021 if (strpos($newpcre, 'gz')) {
00022        system("tar xfz $newpcre");
00023 } elseif (strpos($newpcre, 'bz2')) {
00024        system("tar xfj $newpcre");
00025 } else {
00026        die("file type not recognized: $newpcre\n");
00027 }
00028 
00029 $newpcre = substr($newpcre, 0, strpos($newpcre, '.tar'));
00030 $dirlen = strlen('pcrelib');
00031 
00032 function recurse($path)
00033 {
00034        global $newpcre, $dirlen;
00035 
00036        foreach (scandir($path) as $file) {
00037 
00038               if ($file[0] === '.' ||
00039               $file === 'CVS' ||
00040               @substr_compare($file, '.lo', -3, 3) === 0 ||
00041               @substr_compare($file, '.loT', -4, 4) === 0 ||
00042               @substr_compare($file, '.o', -2, 2) === 0) continue;
00043 
00044               $file = "$path/$file";
00045 
00046               if (is_dir($file)) {
00047                      recurse($file);
00048                      continue;
00049               }
00050 
00051               echo "processing $file... ";
00052 
00053               $newfile = $newpcre . substr($file, $dirlen);
00054 
00055               if (is_file($tmp = $newfile . '.generic') || is_file($tmp = $newfile . '.dist')) {
00056                      $newfile = $tmp;
00057               }
00058 
00059 
00060               if (!is_file($newfile)) {
00061                      die("$newfile is not available any more\n");
00062               }
00063 
00064               // maintain file mtimes so that cvs doesnt get crazy
00065               if (file_get_contents($newfile) !== file_get_contents($file)) {
00066                      copy($newfile, $file);
00067               }
00068 
00069               // always include the config.h file
00070               $content    = file_get_contents($newfile);
00071               $newcontent = preg_replace('/#\s*ifdef HAVE_CONFIG_H\s*(.+)\s*#\s*endif/', '$1', $content);
00072 
00073               if ($content !== $newcontent) {
00074                      file_put_contents($file, $newcontent);
00075               }
00076 
00077               echo "OK\n";
00078        }
00079 
00080 }
00081 
00082 
00083 recurse('pcrelib');
00084 
00085 $dirorig = scandir('pcrelib/testdata');
00086 $k = array_search('CVS', $dirorig);
00087 if ($k !== false)
00088        unset($dirorig[$k]);
00089 
00090 $k = array_search('.svn', $dirorig);
00091 if ($k !== false)
00092        unset($dirorig[$k]);
00093 
00094 $dirnew = scandir("$newpcre/testdata");
00095 $diff   = array_diff($dirorig, $dirnew);
00096 
00097 foreach ($diff as $file) {
00098        $file2 = 'pcrelib'.substr($file, strlen($newpcre));
00099        copy($file, $file2);
00100 }
00101 
00102 
00103 // the config.h needs special care
00104 $prepend_config_h = '
00105 #include <php_compat.h>
00106 
00107 #ifndef PHP_WIN32
00108 # include <php_config.h>
00109 #endif
00110 
00111 #undef PACKAGE_NAME
00112 #undef PACKAGE_VERSION
00113 #undef PACKAGE_TARNAME
00114 #undef PACKAGE_STRING
00115 
00116 #define SUPPORT_UCP
00117 #define SUPPORT_UTF8
00118 
00119 #if defined(__GNUC__) && __GNUC__ >= 4
00120 # ifdef __cplusplus
00121 #  define PCRE_EXP_DECL            extern "C" __attribute__ ((visibility("default")))
00122 # else
00123 #  define PCRE_EXP_DECL            extern __attribute__ ((visibility("default")))
00124 # endif
00125 # define PCRE_EXP_DEFN             __attribute__ ((visibility("default")))
00126 # define PCRE_EXP_DATA_DEFN __attribute__ ((visibility("default")))
00127 #endif
00128 
00129 
00130 ';
00131 
00132 file_put_contents('pcrelib/config.h', $prepend_config_h . file_get_contents('pcrelib/config.h'));
00133 
00134 
00135 echo "\nThe End :-)\n\n"
00136 
00137 ?>