forked from cosimo/varnish-geoip
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gen_vcl.pl
executable file
·50 lines (41 loc) · 1.28 KB
/
gen_vcl.pl
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
#!/usr/bin/perl
#
# Generates the VCL file from geoip.c
#
use strict;
use warnings;
my @c_code = <STDIN>;
my @vcl_code;
READ_C: while (my $line = shift @c_code) {
# Parse VCL ifdefs
if ($line =~ m{^ \s* \#(ifn?def) \s+ __VCL__}mx) {
#warn "\$1 = $1 \$line = $line\n";
my $include = $1 eq 'ifdef' ? 1 : 0;
IFDEF: while ($line = shift @c_code) {
#warn "\tread_line $line\n";
if ($line =~ m{^ \s* \#endif}mx) {
last IFDEF;
}
elsif ($line =~ m{^ \s* \#else}mx) {
$include = 1 - $include;
}
push @vcl_code, $line if $include;
}
next;
}
elsif ($line =~ m{__GIT_REV__}) {
chomp (my $git_rev = `git describe 2>/dev/null || git rev-parse HEAD`);
$line =~ s{__GIT_REV__}{$git_rev}e;
}
push @vcl_code, $line;
}
@vcl_code = (
"C{\n\n",
"/* ------------------------------------------------------" . ("-" x length($0)) . " */\n",
"/* THIS FILE IS AUTOMATICALLY GENERATED BY $0. DO NOT EDIT. */\n\n",
@vcl_code,
"\n/* THIS FILE IS AUTOMATICALLY GENERATED BY $0. DO NOT EDIT. */\n",
"/* ------------------------------------------------------" . ("-" x length($0)) . " */\n",
"}C\n",
);
print @vcl_code;