javapage.pl 2.6 KB

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