summaryrefslogtreecommitdiff
path: root/ext/pcre/upgrade-pcre.php
blob: a48f8d76043e3ef226fd6dba3e7873dba57a6e8d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
<?php

// script to upgrade PCRE. just drop the pcre-x.x.tar.xx here and run the script

$pattern = 'pcre-*.tar.*';
$newpcre = glob($pattern);

if (count($newpcre) > 1) {
	echo "more than one '$pattern' file. aborting\n";
	print_r($newpcre);
	exit;
}

if (count($newpcre) == 0) {
	die("need one '$pattern' file. aborting.\n");
}


$newpcre = $newpcre[0];

if (strpos($newpcre, 'gz')) {
	system("tar xfz $newpcre");
} elseif (strpos($newpcre, 'bz2')) {
	system("tar xfj $newpcre");
} else {
	die("file type not recognized: $newpcre\n");
}

$newpcre = substr($newpcre, 0, strpos($newpcre, '.tar'));
$dirlen = strlen('pcrelib');

function recurse($path)
{
	global $newpcre, $dirlen;

	foreach (scandir($path) as $file) {

		if ($file[0] === '.' ||
		$file === 'CVS' ||
		@substr_compare($file, '.lo', -3, 3) === 0 ||
		@substr_compare($file, '.loT', -4, 4) === 0 ||
		@substr_compare($file, '.o', -2, 2) === 0) continue;

		$file = "$path/$file";

		if (is_dir($file)) {
			recurse($file);
			continue;
		}

		echo "processing $file... ";

		$newfile = $newpcre . substr($file, $dirlen);

		if (is_file($tmp = $newfile . '.generic') || is_file($tmp = $newfile . '.dist')) {
			$newfile = $tmp;
		}


		if (!is_file($newfile)) {
			die("$newfile is not available any more\n");
		}

		// maintain file mtimes so that cvs doesnt get crazy
		if (file_get_contents($newfile) !== file_get_contents($file)) {
			copy($newfile, $file);
		}

		// always include the config.h file
		$content    = file_get_contents($newfile);
		$newcontent = preg_replace('/#\s*ifdef HAVE_CONFIG_H\s*(.+)\s*#\s*endif/', '$1', $content);

		if ($content !== $newcontent) {
			file_put_contents($file, $newcontent);
		}

		echo "OK\n";
	}

}


recurse('pcrelib');

$dirorig = scandir('pcrelib/testdata');
$k = array_search('CVS', $dirorig);
if ($k !== false)
	unset($dirorig[$k]);

$k = array_search('.svn', $dirorig);
if ($k !== false)
	unset($dirorig[$k]);

$dirnew = scandir("$newpcre/testdata");
$diff   = array_diff($dirorig, $dirnew);

foreach ($diff as $file) {
	$file2 = 'pcrelib'.substr($file, strlen($newpcre));
	copy($file, $file2);
}


// the config.h needs special care
$prepend_config_h = '
#include <php_compat.h>

#ifndef PHP_WIN32
# include <php_config.h>
#endif

#undef PACKAGE_NAME
#undef PACKAGE_VERSION
#undef PACKAGE_TARNAME
#undef PACKAGE_STRING

#define SUPPORT_UCP
#define SUPPORT_UTF8

#if defined(__GNUC__) && __GNUC__ >= 4
# ifdef __cplusplus
#  define PCRE_EXP_DECL		extern "C" __attribute__ ((visibility("default")))
# else
#  define PCRE_EXP_DECL		extern __attribute__ ((visibility("default")))
# endif
# define PCRE_EXP_DEFN		__attribute__ ((visibility("default")))
# define PCRE_EXP_DATA_DEFN	__attribute__ ((visibility("default")))
#endif


';

file_put_contents('pcrelib/config.h', $prepend_config_h . file_get_contents('pcrelib/config.h'));


echo "\nThe End :-)\n\n"

?>