summary refs log blame commit diff stats
path: root/plugins/perl/generate_header
blob: 37e7d3238846450d9392a341b5249b0f130fe084 (plain) (tree)
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
pre { line-height: 125%; }
td.linenos .normal { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; }
span.linenos { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; }
td.linenos .special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; }
span.linenos.special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; }
.highlight .hll { background-color: #ffffcc }
.highlight .c { color: #888888 } /* Comment */
.highlight .err { color: #a61717; background-color: #e3d2d2 } /* Error */
.highlight .k { color: #008800; font-weight: bold } /* Keyword */
.highlight .ch { color: #888888 } /* Comment.Hashbang */
.highlight .cm { color: #888888 } /* Comment.Multiline */
.highlight .cp { color: #cc0000; font-weight: bold } /* Comment.Preproc */
.highlight .cpf { color: #888888 } /* Comment.PreprocFile */
.highlight .c1 { color: #888888 } /* Comment.Single */
.highlight .cs { color: #cc0000; font-weight: bold; background-color: #fff0f0 } /* Comment.Special */
.highlight .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */
.highlight .ge { font-style: italic } /* Generic.Emph */
.highlight .ges { font-weight: bold; font-style: italic } /* Generic.EmphStrong */
.highlight .gr { color: #aa0000 } /* Generic.E
#!/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': $!";

	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];

	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;
}