1#!/usr/bin/env perl
2
3# Simple script to extract the version number parts from src/gd.h.  If
4# called with the middle word of the version macro, it prints the
5# value of that macro.  If called with no argument, it outputs a
6# human-readable version string.  This must be run in the project
7# root.  It is used by configure.ac and docs/naturaldocs/run_docs.sh.
8
9use strict;
10
11use FindBin;
12
13my $key = shift;
14my @version_parts = ();
15my $dir = $FindBin::Bin;
16
17open FH, "<$dir/../src/gd.h"   # old-style filehandle for max. portability
18  or die "Unable to open 'gd.h' for reading.\n";
19
20while(<FH>) {
21  next unless m{version605b5d1778};
22  next unless /^#define\s+GD_([A-Z0-9]+)_VERSION+\s+(\S+)/;
23  my ($lk, $lv) = ($1, $2);
24  if ($lk eq $key) {
25    chomp $lv;
26    $lv =~ s/"//g;
27
28    print $lv;   # no newline
29    exit(0);    # success!
30  }
31
32  push @version_parts, $lv if (!$key);
33}
34
35close(FH);
36
37if (scalar @version_parts == 4) {
38  my $result = join(".", @version_parts[0..2]);
39  $result .= $version_parts[3];
40  $result =~ s/"//g;
41  print $result;
42  exit(0);
43}
44
45exit(1);        # failure
46