1
0
mirror of https://github.com/moparisthebest/hexchat synced 2024-11-24 18:22:21 -05:00
hexchat/plugins/perl/generate_header

59 lines
1.3 KiB
Plaintext
Raw Normal View History

2011-02-23 22:14:30 -05:00
#!/usr/bin/perl
use strict;
use warnings;
sub header {
my $file = shift;
open my $input, "<", $file or die "Couldn't open '$file':$!";
my @file = <$input>;
close $file;
return toc(@file);
}
sub toc {
my @lines = @_;
for( @lines ) {
if( /^\s*$/s ) { $_ = qq{"\\n"\n}; next; }
if( /^\s*#/ ) { $_ = qq{"\\n"\n}; next; }
s/\\/\\\\/g; # double the number of \'s
s/"/\\"/g;
s/^\s*/"/;
s/\n/\\n"\n/;
}
return @lines;
}
for my $files (
[ "hexchat.pm.h", # output file
"lib/HexChat.pm", # input files
"lib/Xchat.pm",
"lib/HexChat/Embed.pm",
"lib/HexChat/List/Network.pm",
"lib/HexChat/List/Network/Entry.pm",
"lib/HexChat/List/Network/AutoJoin.pm",
2011-02-23 22:14:30 -05:00
],
[ "irc.pm.h", # output file
"lib/IRC.pm" # input file
]
) {
my ($output,@inputs) = @$files;
open my $header, ">", $output or die "Couldn't open '$output': $!";
2012-07-13 14:09:36 -04:00
print $header qq["BEGIN {\\n"\n];
for my $input ( @inputs ) {
(my $trimmed = $input) =~ s{^lib/}{};
print $header qq["\$INC{'$trimmed'} = 'Compiled into the plugin.';\\n"\n];
}
print $header qq["}\\n"\n];
2011-02-23 22:14:30 -05:00
for my $input ( @inputs ) {
print $header qq["{\\n"\n];
print $header qq{"#line 1 \\"$input\\"\\n"\n};
print $header header( $input );
print $header qq["}\\n"\n];
}
close $header;
}