-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathfill_r3_source.pl
57 lines (49 loc) · 1.06 KB
/
fill_r3_source.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
50
51
52
53
54
55
56
57
#!/usr/bin/perl
use strict;
use warnings;
sub read_file {
local $/;
my($out, $f);
open $f, $_[0];
$out = <$f>;
close $f;
return $out;
}
sub write_file {
my $f;
open $f, ">$_[0]";
print $f $_[1];
close $f;
}
my $xs_code = read_file('R3.xs');
my $source_code = '';
$source_code =<<'END';
#define HAVE_STRNDUP
#define HAVE_STRDUP
END
for(qw(
r3/3rdparty/zmalloc.h
r3/include/r3_define.h
r3/include/str_array.h
r3/include/match_entry.h
r3/include/r3.h
r3/include/r3_list.h
r3/include/r3_str.h
r3/src/slug.h
r3/3rdparty/zmalloc.c
r3/src/match_entry.c
r3/src/edge.c
r3/src/list.c
r3/src/node.c
r3/src/str.c
r3/src/token.c
r3/src/slug.c
)) {
print "fetching file $_\n";
$source_code .= "/******* $_ *******/\n";
$source_code .= read_file($_);
}
$source_code =~ s!(#include\s+".*)!/* $1 */!g;
# $source_code =~ s!\b(strn?dup)\b!my_$1!g;
$xs_code =~ s!(__R3_SOURCE_SLOT_BEGIN__.*?\n)(.*?)([^\n]*?__R3_SOURCE_SLOT_END__)!$1$source_code$3!s;
write_file('R3.xs', $xs_code);