summaryrefslogtreecommitdiff
path: root/lib/libsqlite3/tsrc/header_regen
blob: 976635060673b6a54e671e5fcd59053795fdcf63 (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
#! /usr/bin/perl
# Written by Marc Espie 2012, Public Domain
use strict;
use warnings;

@ARGV == 3 or
	die "Usage: $0 version src dest\n";

my ($vfname, $src, $dest) = @ARGV;
open(my $fh, '<', $vfname)
	or die "Can't read $vfname: $!\n";
my $version = <$fh>;
chomp $version;
my @l = split(/\./, $version);
my $v2 = sprintf("%d%03d%03d", @l);

open(my $in, '<', $src)
	or die "Can't read $src: $!\n";
open(my $out, '>', $dest)
	or die "Can't write to $dest: $!\n";

select($out);

while (<$in>) {
	s/\-\-VERS\-\-/$version/;
	s/\-\-VERSION\-NUMBER\-\-/$v2/;
	s/\-\-SOURCE\-ID\-\-/OpenBSD/;

	if (m/^\#ifdef\s+SQLITE_INT64_TYPE/) {
		while(<$in>) {
			last if m/^\#endif/;
		}
		print "typedef int64_t sqlite_int64;\n";
		print "typedef uint64_t sqlite_uint64;\n";
	} else {
		print $_;
	}
	if (m/^\#\s*include\s*\<stdarg\.h\>/) {
		print "#include <stdint.h>\n";
	}
}