| 1 |
#!/usr/bin/perl |
| 2 |
|
| 3 |
use strict; |
| 4 |
use warnings; |
| 5 |
|
| 6 |
sub header { |
| 7 |
my $file = shift; |
| 8 |
open my $input, "<", $file or die "Couldn't open '$file':$!"; |
| 9 |
my @file = <$input>; |
| 10 |
close $file; |
| 11 |
return toc(@file); |
| 12 |
} |
| 13 |
|
| 14 |
sub toc { |
| 15 |
my @lines = @_; |
| 16 |
for( @lines ) { |
| 17 |
if( /^\s*$/s ) { $_ = qq{"\\n"\n}; next; } |
| 18 |
if( /^\s*#/ ) { $_ = qq{"\\n"\n}; next; } |
| 19 |
s/\\/\\\\/g; # double the number of \'s |
| 20 |
s/"/\\"/g; |
| 21 |
s/^\s*/"/; |
| 22 |
s/\n/\\n"\n/; |
| 23 |
} |
| 24 |
return @lines; |
| 25 |
} |
| 26 |
|
| 27 |
for my $files ( |
| 28 |
[ "hexchat.pm.h", # output file |
| 29 |
"lib/HexChat.pm", # input files |
| 30 |
"lib/Xchat.pm", |
| 31 |
"lib/HexChat/Embed.pm", |
| 32 |
"lib/HexChat/List/Network.pm", |
| 33 |
"lib/HexChat/List/Network/Entry.pm", |
| 34 |
"lib/HexChat/List/Network/AutoJoin.pm", |
| 35 |
], |
| 36 |
[ "irc.pm.h", # output file |
| 37 |
"lib/IRC.pm" # input file |
| 38 |
] |
| 39 |
) { |
| 40 |
my ($output,@inputs) = @$files; |
| 41 |
|
| 42 |
open my $header, ">", $output or die "Couldn't open '$output': $!"; |
| 43 |
|
| 44 |
print $header qq["BEGIN {\\n"\n]; |
| 45 |
for my $input ( @inputs ) { |
| 46 |
(my $trimmed = $input) =~ s{^lib/}{}; |
| 47 |
print $header qq["\$INC{'$trimmed'} = 'Compiled into the plugin.';\\n"\n]; |
| 48 |
} |
| 49 |
print $header qq["}\\n"\n]; |
| 50 |
|
| 51 |
for my $input ( @inputs ) { |
| 52 |
print $header qq["{\\n"\n]; |
| 53 |
print $header qq{"#line 1 \\"$input\\"\\n"\n}; |
| 54 |
print $header header( $input ); |
| 55 |
print $header qq["}\\n"\n]; |
| 56 |
} |
| 57 |
close $header; |
| 58 |
} |