xchat/etc/wyatt8740/plugins/perl/generate_header

37 lines
760 B
Perl
Executable File

#!/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 qq{"#line 1 \\"$file\\"\\n"\n}, 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 ( [ "Xchat.pm", "xchat.pm.h" ], [ "IRC.pm", "irc.pm.h" ] ) {
my ($input, $output) = @$files;
open my $header, ">", $output or die "Couldn't open '$output': $!";
print $header qq{#line 1 "$input"\n};
print $header header( $input );
close $header;
}