diff options
author | berkeviktor@aol.com <berkeviktor@aol.com> | 2011-02-24 04:14:30 +0100 |
---|---|---|
committer | berkeviktor@aol.com <berkeviktor@aol.com> | 2011-02-24 04:14:30 +0100 |
commit | 4a6ceffb98a0b785494f680d3776c4bfc4052f9e (patch) | |
tree | 850703c1c841ccd99f58d0b06084615aaebe782c /plugins/perl/generate_header | |
parent | f16af8be941b596dedac3bf4e371ee2d21f4b598 (diff) |
add xchat r1489
Diffstat (limited to 'plugins/perl/generate_header')
-rw-r--r-- | plugins/perl/generate_header | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/plugins/perl/generate_header b/plugins/perl/generate_header new file mode 100644 index 00000000..d6c8a65f --- /dev/null +++ b/plugins/perl/generate_header @@ -0,0 +1,50 @@ +#!/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 ( + [ "xchat.pm.h", # output file + "lib/Xchat.pm", # input files + "lib/Xchat/Embed.pm", + "lib/Xchat/List/Network.pm", + "lib/Xchat/List/Network/Entry.pm", + "lib/Xchat/List/Network/AutoJoin.pm", + ], + [ "irc.pm.h", # output file + "lib/IRC.pm" # input file + ] +) { + my ($output,@inputs) = @$files; + + open my $header, ">", $output or die "Couldn't open '$output': $!"; + + 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; +} |