]> asedeno.scripts.mit.edu Git - PuTTY.git/blob - licence.pl
Stop copying the licence text into C source code.
[PuTTY.git] / licence.pl
1 #!/usr/bin/env perl -w
2
3 # This script generates licence.h (containing the PuTTY licence in the
4 # form of macros expanding to C string literals) from the LICENCE
5 # master file.
6
7 use File::Basename;
8
9 $infile = "LICENCE";
10 $outfile = "licence.h";
11 open my $in, $infile or die "$infile: open: $!\n";
12 open my $out, ">", $outfile or die "$outfile: open: $!\n";
13 select $out;
14
15 print "/*\n";
16 print " * $outfile - macro definitions for the PuTTY licence.\n";
17 print " *\n";
18 print " * Generated by @{[basename __FILE__]} from $infile.\n";
19 print " * You should edit those files rather than editing this one.\n";
20 print " */\n";
21 print "\n";
22
23 my @lines = ();
24 while (<$in>) {
25     chomp;
26     push @lines, $_;
27 }
28 close $in;
29
30 # Format into paragraphs.
31 my @paras = ();
32 my $para = undef;
33 for my $line (@lines) {
34     if ($line eq "") {
35         $para = undef;
36     } elsif (!defined $para) {
37         push @paras, $line;
38         $para = \$paras[$#paras];
39     } else {
40         $$para .= " " . $line;
41     }
42 }
43
44 print "#define LICENCE_TEXT(parsep) \\\n";
45 for my $i (0..$#paras) {
46     my $lit = &stringlit($paras[$i]);
47     print "    parsep \\\n" if $i > 0;
48     print "    \"$lit\"";
49     print " \\" if $i < $#paras;
50     print "\n";
51 }
52 print "\n";
53
54 die "bad format of first paragraph\n"
55     unless $paras[0] =~ m!copyright ([^\.]*)\.!i;
56
57 printf "#define SHORT_COPYRIGHT_DETAILS \"%s\"\n", &stringlit($1);
58
59 sub stringlit {
60     my ($lit) = @_;
61     $lit =~ s!\\!\\\\!g;
62     $lit =~ s!"!\\"!g;
63     return $lit;
64 }