Skip to content

Commit

Permalink
Merge pull request #79 from fpl/parse_headers
Browse files Browse the repository at this point in the history
Revised parse_h.pl script to parse GDAL headers up to v3.9
  • Loading branch information
shawnlaffan authored Jun 18, 2024
2 parents c782ae7 + 2e577ec commit d5eea44
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 7 deletions.
76 changes: 69 additions & 7 deletions build-tools/parse_h.pl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
'gcore/gdal.h',
'ogr/ogr_api.h',
'ogr/ogr_srs_api.h',
'apps/gdal_utils.h'
'apps/gdal_utils.h',
#'alg/gdal_alg.h'
);

my %pre = (
Expand Down Expand Up @@ -41,6 +42,9 @@
GDALGridAlgorithm => 1,
GDALRelationshipCardinality => 1,
GDALRelationshipType => 1,
GDALViewshedMode => 1,
GDALViewshedOutputType => 1,
OGRwkbVariant => 1,
);

my %callbacks = (
Expand All @@ -50,6 +54,9 @@
GDALTransformerFunc => 1,
GDALContourWriter => 1,
GDALQueryLoggerFunc => 1,
GDALVRTProcessedDatasetFuncInit => 1,
GDALVRTProcessedDatasetFuncFree => 1,
GDALVRTProcessedDatasetFuncProcess => 1,
);

my %char_p_p_ok = (
Expand Down Expand Up @@ -187,12 +194,49 @@
OGR_F_SetFieldIntegerList => 1,
OGR_F_SetFieldInteger64List => 1,
OGR_F_SetFieldDoubleList => 1,
GDALInvGeoTransform => 1,
OCTTransform => 1,
OCTTransformEx => 1,
OCTTransform4D => 1,
OCTTransform4DWithErrorCodes => 1,
OCTTransformBounds => 1,
GDALUseTransformer => 1,
GDALGenImgProjTransform => 1,
GDALReprojectionTransform => 1,
GDALGCPTransform => 1,
GDALTPSTransform => 1,
GDALRPCTransform => 1,
GDALGeoLocTransform => 1,
GDALApproxTransform => 1,
OGRContourWriter => 1,
GDALContourGenerate => 1,
GDALRasterizeGeometries => 1,
GDALRasterizeGeometriesInt64 => 1,
GDALRasterizeLayers => 1,
GDALRasterizeLayersBuf => 1,
GDALGridCreate => 1,
GDALGridContextCreate => 1,
GDALTriangulationCreateDelaunay => 1,
GDALTriangulationComputeBarycentricCoefficients => 1,
);

my %use_array6 = (
GDALGetGeoTransform => 1,
GDALSetGeoTransform => 1,
GDALComposeGeoTransforms => 1,
GDALInvGeoTransform => 1,
GDALSetTransformerDstGeoTransform => 1,
GDALGetTransformerDstGeoTransform => 1,
GDALCreateGenImgProjTransformer3 => 1,
GDALCreateGenImgProjTransformer4 => 1,
GDALSetGenImgProjTransformerDstGeoTransform => 1,
);

my %use_opaque_array = (
GDALWarp => 1,
GDALVectorTranslate => 1,
GDALBuildVRT => 1,
GDALRasterizeLayersBuf => 1,
);

my %use_ret_pointer = (
Expand Down Expand Up @@ -237,6 +281,15 @@
ArrowArrayStream => 1,
GDALVectorInfoOptions => 1,
GDALVectorInfoOptionsForBinary => 1,
ArrowSchema => 1,
ArrowArray => 1,
GDALFootprintOptions => 1,
GDALFootprintOptionsForBinary => 1,
GDALRPCInfoV2 => 1,
GDALViewshedMode => 1,
OGRwkbExportOptions =>1,
GDALTileIndexOptions => 1,
GDALTileIndexOptionsForBinary => 1,
);

my %defines;
Expand Down Expand Up @@ -299,13 +352,14 @@ sub parse_h {
my $args = $2;
my $ret = $s;
$ret =~ s/$name.*//;
$ret = parse_type($name, $ret, 'ret');
$ret = parse_type($name, $ret, 'ret', 0);
#print "parse type returns: $ret\n";
my @args = split /\s*,\s*/, $args;
my $qw = 1;
my $idx = 0;
for my $arg (@args) {
$arg = parse_type($name, $arg, 'arg');
#print "parse type returns: $ret\n";
$arg = parse_type($name, $arg, 'arg', $idx++);
#print "parse type returns: $arg\n";
$qw = 0 if $arg =~ /\s/;
}
#say "ret: $ret";
Expand All @@ -328,12 +382,12 @@ sub parse_h {
}

sub parse_type {
my ($name, $arg, $mode) = @_;
my ($name, $arg, $mode, $argno) = @_;
$arg =~ s/^\s+//;
$arg =~ s/\s+$//;
my $var = '';
$var = $1 if $arg =~ /(\w+)$/;
#print "parse type: name=$name arg=$arg var=$var mode$mode\n";
#print "parse type: argno=$argno name=$name arg=$arg var=$var mode$mode\n";
for my $c (keys %constants) {
if ($arg =~ /^$c/ or $arg =~ /^const $c/) {
$arg = 'unsigned int';
Expand Down Expand Up @@ -413,8 +467,16 @@ sub parse_type {
} elsif ($arg =~ /^long/) {
$arg = 'long';
} elsif ($arg =~ /double\s*\*/) {
if ($name eq 'GDALGetGeoTransform' or $name eq 'GDALSetGeoTransform') {
if ($use_array6{$name}) {
$arg = 'double[6]';
} elsif ($name eq 'GDALApplyGeoTransform' and $argno == 0) {
$arg = 'double[6]';
} elsif ($name eq 'GDALSuggestedWarpOutput' and $argno == 3) {
$arg = 'double[6]';
} elsif ($name eq 'GDALSuggestedWarpOutput2' and $argno == 3) {
$arg = 'double[6]';
} elsif ($name eq 'GDALSuggestedWarpOutput2' and $argno == 6) {
$arg = 'double[4]';
} elsif ($use_array{$name}) {
$arg = 'double[]';
} elsif ($mode eq 'ret' && $use_ret_pointer{$name}) {
Expand Down
3 changes: 3 additions & 0 deletions lib/Geo/GDAL/FFI.pm
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,9 @@ sub new {
$ffi->type('(pointer,int,int,pointer,pointer,pointer,pointer)->int' => 'GDALTransformerFunc');
$ffi->type('(double,int,pointer,pointer,pointer)->int' => 'GDALContourWriter');
$ffi->type('(string,string,sint64,sint64,pointer)->void' => 'GDALQueryLoggerFunc');
$ffi->type('(string,pointer,pointer,int,int,pointer,pointer,pointer,pointer,pointer,pointer)->int' => 'GDALVRTProcessedDatasetFuncInit');
$ffi->type('(string,pointer,pointer)->void' => 'GDALVRTProcessedDatasetFuncFree');
$ffi->type('(string,pointer,pointer,int,int,int,pointer,size_t,int,int,pointer,pointer,size_t,int,int,pointer,double,double,double,double,pointer,string,int)->int' => 'GDALVRTProcessedDatasetFuncProcess');

$ffi->ignore_not_found(1);

Expand Down

0 comments on commit d5eea44

Please sign in to comment.