1<?php 2 3// script to upgrade PCRE. just drop the pcre-x.x.tar.xx here and run the script 4 5$pattern = 'pcre-*.tar.*'; 6$newpcre = glob($pattern); 7 8if (count($newpcre) > 1) { 9 echo "more than one '$pattern' file. aborting\n"; 10 print_r($newpcre); 11 exit; 12} 13 14if (count($newpcre) == 0) { 15 die("need one '$pattern' file. aborting.\n"); 16} 17 18 19$newpcre = $newpcre[0]; 20 21if (strpos($newpcre, 'gz')) { 22 system("tar xfz $newpcre"); 23} elseif (strpos($newpcre, 'bz2')) { 24 system("tar xfj $newpcre"); 25} else { 26 die("file type not recognized: $newpcre\n"); 27} 28 29$newpcre = substr($newpcre, 0, strpos($newpcre, '.tar')); 30$dirlen = strlen('pcrelib'); 31 32function recurse($path) 33{ 34 global $newpcre, $dirlen; 35 36 foreach (scandir($path) as $file) { 37 38 if ($file[0] === '.' || 39 $file === 'CVS' || 40 @substr_compare($file, '.lo', -3, 3) === 0 || 41 @substr_compare($file, '.loT', -4, 4) === 0 || 42 @substr_compare($file, '.o', -2, 2) === 0) continue; 43 44 $file = "$path/$file"; 45 46 if (is_dir($file)) { 47 recurse($file); 48 continue; 49 } 50 51 echo "processing $file... "; 52 53 $newfile = $newpcre . substr($file, $dirlen); 54 55 if (is_file($tmp = $newfile . '.generic') || is_file($tmp = $newfile . '.dist')) { 56 $newfile = $tmp; 57 } 58 59 60 if (!is_file($newfile)) { 61 die("$newfile is not available any more\n"); 62 } 63 64 // maintain file mtimes so that cvs doesnt get crazy 65 if (file_get_contents($newfile) !== file_get_contents($file)) { 66 copy($newfile, $file); 67 } 68 69 // always include the config.h file 70 $content = file_get_contents($newfile); 71 //$newcontent = preg_replace('/#\s*ifdef HAVE_CONFIG_H\s*(.+)\s*#\s*endif/', '$1', $content); 72 73 //if ($content !== $newcontent) { 74 // file_put_contents($file, $newcontent); 75 //} 76 77 echo "OK\n"; 78 } 79 80} 81 82 83recurse('pcrelib'); 84 85$dirorig = scandir('pcrelib/testdata'); 86$k = array_search('CVS', $dirorig); 87if ($k !== false) 88 unset($dirorig[$k]); 89 90$k = array_search('.svn', $dirorig); 91if ($k !== false) 92 unset($dirorig[$k]); 93 94$dirnew = scandir("$newpcre/testdata"); 95$diff = array_diff($dirorig, $dirnew); 96 97foreach ($diff as $file) { 98 $file2 = 'pcrelib'.substr($file, strlen($newpcre)); 99 copy($file, $file2); 100} 101 102 103// the config.h needs special care 104$prepend_config_h = ' 105#include <php_compat.h> 106 107#ifndef PHP_WIN32 108# include <php_config.h> 109#endif 110 111#undef PACKAGE_NAME 112#undef PACKAGE_VERSION 113#undef PACKAGE_TARNAME 114#undef PACKAGE_STRING 115 116#define SUPPORT_UCP 117#define SUPPORT_UTF8 118 119#if defined(__GNUC__) && __GNUC__ >= 4 120# ifdef __cplusplus 121# define PCRE_EXP_DECL extern "C" __attribute__ ((visibility("default"))) 122# else 123# define PCRE_EXP_DECL extern __attribute__ ((visibility("default"))) 124# endif 125# define PCRE_EXP_DEFN __attribute__ ((visibility("default"))) 126# define PCRE_EXP_DATA_DEFN __attribute__ ((visibility("default"))) 127#endif 128 129 130'; 131 132file_put_contents('pcrelib/config.h', $prepend_config_h . file_get_contents('pcrelib/config.h')); 133 134 135echo "\nThe End :-)\n\n" 136 137?> 138