chiark / gitweb /
Fix completion checking in Killer Solo.
[sgt-puzzles.git] / html / javapage.pl
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 open my $footerfile, "<", shift @ARGV or die "footer: open: $!\n";
7 my $footer = "";
8 $footer .= $_ while <$footerfile>;
9 close $footerfile;
10
11 for my $arg (@ARGV) {
12     $arg =~ /(.*\/)?([^\/]+)\.html$/ or die;
13     my $filename = $2;
14     open my $gamefile, "<", $arg or die "$arg: open: $!\n";
15     my $unfinished = 0;
16     my $docname = $filename;
17     chomp(my $puzzlename = <$gamefile>);
18     while ($puzzlename =~ s/^([^:=]+)(=([^:]+))?://) {
19         if ($1 eq "unfinished") {
20             $unfinished = 1;
21         } elsif ($1 eq "docname") {
22             $docname = $3;
23         } else {
24             die "$arg: unknown keyword '$1'\n";
25         }
26     }
27     my $instructions = "";
28     $instructions .= $_ while <$gamefile>;
29     close $gamefile;
30
31     open my $outpage, ">", "${filename}.html";
32
33     my $unfinishedtitlefragment = $unfinished ? "an unfinished puzzle " : "";
34     my $unfinishedheading = $unfinished ? "<h2 align=center>an unfinished puzzle</h2>\n" : "";
35     my $unfinishedpara;
36     my $links;
37     if ($unfinished) {
38         $unfinishedpara = <<EOF;
39 <p>
40 You have found your way to a page containing an <em>unfinished</em>
41 puzzle in my collection, not linked from the <a href="../">main
42 puzzles page</a>. Don't be surprised if things are hard to understand
43 or don't work as you expect.
44 EOF
45         $links = <<EOF;
46 <p align="center">
47 <a href="../">Back to main puzzles page</a> (which does not link to this)
48 EOF
49     } else {
50         $unfinishedpara = "";
51         $links = <<EOF;
52 <p align="center">
53 <a href="../doc/${docname}.html#${docname}">Full instructions</a>
54 |
55 <a href="../">Back to main puzzles page</a>
56 EOF
57     }
58
59     print $outpage <<EOF;
60 <html>
61 <head>
62 <title>${puzzlename}, ${unfinishedtitlefragment}from Simon Tatham's Portable Puzzle Collection</title>
63 <link rel="stylesheet" type="text/css" href="../../sitestyle.css" name="Simon Tatham's Home Page Style">
64 <script type="text/javascript" src="resize-puzzle-applet.js"></script>
65 </head>
66 <body onLoad="initResizablePuzzleApplet();">
67 <h1 align=center>${puzzlename}</h1>
68 ${unfinishedheading}
69 <h2 align=center>from Simon Tatham's Portable Puzzle Collection</h2>
70
71 ${unfinishedpara}
72
73 <p align="center">
74 <table cellpadding="0">
75 <tr>
76 <td>
77 <applet id="applet" archive="${filename}.jar" code="PuzzleApplet"
78         width="700" height="500">
79 </applet>
80 </td>
81 <td>
82 <div id="eresize" style="width:5px;height:500px;cursor:e-resize;"></div>
83 </td>
84 </tr>
85 <td>
86 <div id="sresize" style="width:700px;height:5px;cursor:s-resize;"></div>
87 </td>
88 <td>
89 <div id="seresize" style="width:5px;height:5px;cursor:se-resize;"></div>
90 </td>
91 </tr>
92 </table>
93
94 ${instructions}
95
96 ${links}
97
98 ${footer}
99 </body>
100 </html>
101 EOF
102
103     close $outpage;
104 }