5 * Generate php_pq_type.h from
6 * postgresql.git/src/include/catalog/pg_type.dat
11 $dir = $argv[1] ?? __DIR__
."/../../postgresql.git";
12 $dat = file_get_contents($dir . "/src/include/catalog/pg_type.dat");
19 if (!preg_match_all('/{(.*?)}/s', $dat, $matches)) {
20 fprintf(STDERR
, "Failed to find entries in pg_type.dat\n");
24 foreach ($matches[1] as $set_data) {
25 if (!preg_match_all('/(?P<key>\w+) => \'(?P<val>(?:[^\']|(?<=\\\\)\')+)\'/', $set_data, $set_matches)) {
26 fprintf(STDERR
, "Failed matching key value pairs in set: '%s'\n", $set_data);
29 $set = array_combine($set_matches["key"], $set_matches["val"]);
30 $ucn = strtoupper($set["typname"]);
31 $typ[$set["oid"]] = $ucn;
33 if (isset($set["array_type_oid"])) {
34 $arr[$set["array_type_oid"]] = $set["oid"];
35 $typ[$set["array_type_oid"]] = $ucn . "ARRAY";
37 if (isset($set["typdelim"])) {
38 $delims[$set["oid"]] = $delims[$set["array_type_oid"]] = $set["typdelim"];
42 ksort($typ, SORT_NUMERIC
);
43 ksort($arr, SORT_NUMERIC
);
46 /* Generated file. See scripts/gen_pq_type-pq11.php */
49 # define PHP_PQ_TYPE(t,o)
52 <?php
foreach ($typ as $oid => $ucn) : ?
>
53 #ifndef PHP_PQ_OID_<?=$ucn?>
55 # define PHP_PQ_OID_<?=$ucn?> <?=$oid?>
58 PHP_PQ_TYPE("<?=$ucn?>", <?
=$oid?
>)
61 #ifndef PHP_PQ_TYPE_IS_ARRAY
62 # define PHP_PQ_TYPE_IS_ARRAY(oid) ( \
64 <?php
foreach ($arr as $oid => $type) : ?
>
65 ||
((oid
) == <?
=$oid?
>) \
70 #ifndef PHP_PQ_TYPE_OF_ARRAY
71 # define PHP_PQ_TYPE_OF_ARRAY(oid) ( \
72 <?php
foreach ($arr as $oid => $type) : ?
>
73 (oid
) == <?
=$oid?
> ?
<?
=$type?
> : \
79 #ifndef PHP_PQ_DELIM_OF_ARRAY
80 # define PHP_PQ_DELIM_OF_ARRAY(oid) ((char) ( \
81 <?php
foreach ($delims as $oid => $delim) : ?
>
82 (oid
) == <?
=$oid?
> ?
'<?=$delim?>' : \