| 1 |
#!/usr/local/bin/perl |
| 2 |
# |
| 3 |
# Special features: |
| 4 |
# 1) The item |
| 5 |
# <!-- newfile filename other_words_for_title --> |
| 6 |
# if it occurs on a line all by itself, causes |
| 7 |
# this perlscript to chop files here. The filename |
| 8 |
# will be as specified. The other_words |
| 9 |
# will be used as the title. If neither the |
| 10 |
# filename nor the other_words are present, then |
| 11 |
# this script makes up filenames using numbers, e.g., |
| 12 |
# gri1.html, gri2.html. If the filename is ".", |
| 13 |
# then this same naming scheme is used, but the titles |
| 14 |
# are used. |
| 15 |
# 2) If the item <!-- occurs on a line all by itself, then |
| 16 |
# this perlscript skips until a line containing --> all |
| 17 |
# by itself is encountered. This is a kludge because |
| 18 |
# xmosaic refuses to skip comments if a <PRE> item is |
| 19 |
# contained within them. |
| 20 |
# |
| 21 |
$debug = 0; |
| 22 |
|
| 23 |
$num_files = 1; |
| 24 |
die "Need 2 arg (eg chop_into_subfiles gri.hml \"The Gri graphing language\")" if ($#ARGV != 1); |
| 25 |
|
| 26 |
$basefile = "gri"; |
| 27 |
#$file = "$basefile$num_files.html"; |
| 28 |
$file = "index.html"; |
| 29 |
$basetitle = $ARGV[1]; |
| 30 |
$title = $basetitle; |
| 31 |
$marginnote[0] = "Gri"; |
| 32 |
$#ARGV = 0; # Dumb way to ignore |
| 33 |
print STDOUT "$file " if $debug; |
| 34 |
if (open (OUT, ">", "$file")) { #|| die "Cannot open $file"; |
| 35 |
$file_list[$num_files++] = $file; |
| 36 |
|
| 37 |
$name_of_top_node = "index.html#Top"; |
| 38 |
|
| 39 |
|
| 40 |
print OUT "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n"; |
| 41 |
print OUT "<html>\n"; |
| 42 |
print OUT "<head>\n"; |
| 43 |
print OUT "<title>$title</title>\n"; |
| 44 |
print OUT "<META NAME=\"author\" CONTENT=\"Dan E. Kelley\">\n"; |
| 45 |
print OUT "<META NAME=\"keywords\" CONTENT=\"gri gre science scientific graphics graph\">\n"; |
| 46 |
print OUT "<META NAME=\"description\" CONTENT=\"Gri is an extensible plotting language for producing scientific graphs, such as x-y plots, contour plots, and image plots. It was written by a scientist and therefore has the sorts of things a scientist needs. It is much like LaTeX, in that it rewards users who climb the learning curve, in a way that GUI-based programs do not. Gri is a free version of the more powerful commercial program Gre (still in development).\">\n"; |
| 47 |
print OUT "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\">"; |
| 48 |
print OUT "</head>\n"; |
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
#$body_start = "<body bgcolor=\"#ffffff\" link=\"#993333\" vlink=\"#333399 alink=\"#cc3333\">"; |
| 53 |
#$body_start = "<body bgcolor=\"#ffffff\" link=\"#993333\" vlink=\"#333399\">"; |
| 54 |
|
| 55 |
# Colors below from Mozilla page as of 2001-mar-05. |
| 56 |
$body_start = "<body bgcolor=\"#FFFFFF\" text=\"#000000\" link=\"#0000EE\" vlink=\"#551A8B\" alink=\"FF0000\">"; |
| 57 |
|
| 58 |
print OUT "$body_start\n"; |
| 59 |
|
| 60 |
while(<>) { |
| 61 |
# Skip comment blocks (kludge; see above) |
| 62 |
if (/^\s*<!--\s*$/) { |
| 63 |
while(<>) { |
| 64 |
last if /^\s*-->\s*$/; |
| 65 |
} |
| 66 |
$_ = <>; |
| 67 |
} |
| 68 |
if (/^<a name\s*=\s*"([^"]*)/i){ |
| 69 |
$key = $1; |
| 70 |
$key =~ s/ //g; |
| 71 |
$ref{$key} = "$file#$key"; |
| 72 |
} |
| 73 |
if (/^\s*<!-- newfile\s+([^ ]*)\s+"(.*)"\s+"(.*)"\s*-->\s*$/) { |
| 74 |
$file = (length($1) > 0 && $1 ne ".") |
| 75 |
? $1 : "$basefile$num_files.html"; |
| 76 |
if (length($2) > 0) { |
| 77 |
$title = $2; |
| 78 |
} else { |
| 79 |
$title = $basetitle; |
| 80 |
} |
| 81 |
if (length($3) > 0) { |
| 82 |
$marginnote[$num_files] = $3; |
| 83 |
} |
| 84 |
$titleList{$file} = $title; |
| 85 |
print OUT "</table> |
| 86 |
<img src=\"./resources/bottom_banner.gif\" alt=\"navigation map\" usemap=\"#navigate_bottom\" border=\"0\"> |
| 87 |
"; |
| 88 |
close OUT; |
| 89 |
open (OUT, ">$file") || die "Cannot open $file"; |
| 90 |
$file_list[$num_files++] = $file; |
| 91 |
print OUT "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n"; |
| 92 |
print OUT "<html>\n"; |
| 93 |
print OUT "<head>\n"; |
| 94 |
print OUT "<title>$title</title>\n"; |
| 95 |
print OUT "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\">"; |
| 96 |
print OUT "</head>\n"; |
| 97 |
print OUT "$body_start\n"; |
| 98 |
print "Creating $file\n" if $debug; |
| 99 |
} |
| 100 |
print OUT; |
| 101 |
} |
| 102 |
close OUT; |
| 103 |
|
| 104 |
for ($i = 1; $i < $num_files; $i++) { |
| 105 |
$file = $file_list[$i]; |
| 106 |
$ofile = "$file.pass2"; |
| 107 |
open (IN, "$file") || die "Cannot open $file"; |
| 108 |
open (PASS2, ">$ofile") || die "Cannot open $ofile"; |
| 109 |
print "$file " if $debug; |
| 110 |
$node_parent = ""; |
| 111 |
$need_to_find_parent = 1; |
| 112 |
while(<IN>) { |
| 113 |
if (/\s*href\s*=\s*"#([^"]*)/i) { |
| 114 |
$key = $1; # suck out key |
| 115 |
$key =~ s/ //g; # despace key |
| 116 |
s,href\s*=\s*"#[^"]*,href="$ref{$key},; # replace key with what is keyed to |
| 117 |
s,="#,=",; |
| 118 |
} elsif (/<a\s*name\s*=\s*"([^"]*)/i) { |
| 119 |
# <a name="foo bar"> |
| 120 |
$key = $1; |
| 121 |
$key =~ s/ //g; |
| 122 |
s,"[^"]*","$key",; |
| 123 |
} |
| 124 |
if ($need_to_find_parent && /a href="([^"]*)">parent/) { |
| 125 |
$need_to_find_parent = 0; |
| 126 |
$node_parent = $1; |
| 127 |
} |
| 128 |
# Do not print those 'Navigation' things |
| 129 |
if (!/^<b>Navigation<\/b>:/ |
| 130 |
&& !/<a href=".*">next<\/a>,/ |
| 131 |
&& !/<a href=".*">previous<\/a>,/ |
| 132 |
&& !/<a href=".*">parent<\/a>/) { |
| 133 |
print PASS2 if (!/href=""/); |
| 134 |
} |
| 135 |
} |
| 136 |
print "." if $debug; |
| 137 |
close IN; |
| 138 |
close PASS2; |
| 139 |
open (PASS3, ">$file.pass3") || die "Cannot open $file.pass3"; |
| 140 |
open (PASS2, "$file.pass2") || die "Cannot open $file.pass2"; |
| 141 |
$need_table_cmd = 1; |
| 142 |
while(<PASS2>) { |
| 143 |
if (/^<\s*a\s*name="(.*)"\s*>/ && $need_table_cmd) { |
| 144 |
$need_table_cmd = 0; |
| 145 |
print PASS3; |
| 146 |
$this_chapter = $marginnote[$i]; |
| 147 |
if ($this_chapter eq "") { |
| 148 |
$this_chapter = "Gri"; |
| 149 |
} |
| 150 |
#print STDERR "[$file]\n"; |
| 151 |
print PASS3 " |
| 152 |
<img src=\"./resources/top_banner.gif\" alt=\"navigation map\" usemap=\"#navigate_top\" border=\"0\"> |
| 153 |
<table summary=\"top banner\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\"> |
| 154 |
<tr> |
| 155 |
<td width=\"150\" valign=\"top\"> |
| 156 |
<font size=-1> |
| 157 |
<br> |
| 158 |
Chapters: |
| 159 |
<br> |
| 160 |
<a href=\"Introduction.html\">1: Introduction</a><br> |
| 161 |
<a href=\"SimpleExample.html\">2: Simple example</a><br> |
| 162 |
<a href=\"InvokingGri.html\">3: Invocation</a><br> |
| 163 |
<a href=\"GettingMoreControl.html\">4: Finer Control</a><br> |
| 164 |
<a href=\"X-Y.html\">5: X-Y Plots</a><br> |
| 165 |
<a href=\"ContourPlots.html\">6: Contour Plots</a><br> |
| 166 |
<a href=\"Images.html\">7: Image Plots</a><br> |
| 167 |
<a href=\"Examples.html\">8: Examples</a><br> |
| 168 |
<a href=\"Commands.html\">9: Gri Commands</a><br> |
| 169 |
<a href=\"Programming.html\">10: Programming</a><br> |
| 170 |
<a href=\"Environment.html\">11: Environment</a><br> |
| 171 |
<a href=\"Emacs.html\">12: Emacs Mode</a><br> |
| 172 |
<a href=\"History.html\">13: History</a><br> |
| 173 |
<a href=\"Installation.html\">14: Installation</a><br> |
| 174 |
<a href=\"Bugs.html\">15: Gri Bugs</a><br> |
| 175 |
<a href=\"TestSuite.html\">16: Test Suite</a><br> |
| 176 |
<a href=\"GriInThePress.html\">17: Gri in Press</a><br> |
| 177 |
<a href=\"Acknowledgments.html\">18: Acknowledgments</a><br> |
| 178 |
<a href=\"License.html\">19: License</a><br> |
| 179 |
<br> |
| 180 |
Indices:<br> |
| 181 |
<a href=\"ConceptIndex.html\"><i>Concepts</i></a><br> |
| 182 |
<a href=\"CommandIndex.html\"><i>Commands</i></a><br> |
| 183 |
<a href=\"BuiltinIndex.html\"><i>Variables</i></a><br> |
| 184 |
</font> |
| 185 |
<td width=\"500\" valign=\"top\"> |
| 186 |
"; |
| 187 |
print "file $file\n" if $debug; |
| 188 |
if ($file ne "index.html") { |
| 189 |
print PASS3 "<map name=\"navigate_top\">\n"; |
| 190 |
print PASS3 "<area alt=\"$name_of_top_node\" shape=\"rect\" coords=\"5,2,218,24\" href=\"$name_of_top_node\">\n"; |
| 191 |
if ($node_parent ne "") { |
| 192 |
print PASS3 "<area alt=\"$node_parent\" shape=\"rect\" coords=\"516,2,532,24\" href=\"$node_parent\">\n"; |
| 193 |
} |
| 194 |
print PASS3 "<area alt=\"$titleList{$file_list[$i-1]}\" shape=\"rect\" coords=\"557,2,573,24\" href=\"", |
| 195 |
$file_list[$i-1], "\">\n"; |
| 196 |
print PASS3 "<area alt=\"$titleList{$file_list[$i+1]}\" shape=\"rect\" coords=\"581,2,599,24\" href=\"", |
| 197 |
$file_list[$i+1], "\">\n" if $file_list[$i+1] ne ""; |
| 198 |
print PASS3 "</map>\n"; |
| 199 |
print PASS3 "<map name=\"navigate_bottom\">\n"; |
| 200 |
print PASS3 "<area alt=\"$name_of_top_node\" shape=\"rect\" coords=\"5,2,218,24\" href=\"", |
| 201 |
$name_of_top_node, "\">\n"; |
| 202 |
print PASS3 "<area alt=\"$titleList{$file_list[$i+1]}\" shape=\"rect\" coords=\"581,2,599,24\" href=\"", |
| 203 |
$file_list[$i+1], "\">\n</map>\n" if $file_list[$i+1] ne ""; |
| 204 |
} |
| 205 |
} else { |
| 206 |
print PASS3; |
| 207 |
} |
| 208 |
} |
| 209 |
close(PASS2); |
| 210 |
print PASS3 " |
| 211 |
</body> |
| 212 |
</html> |
| 213 |
"; |
| 214 |
close(PASS3); |
| 215 |
rename("$file.pass3", "$file"); |
| 216 |
print ".\n" if $debug; |
| 217 |
} |
| 218 |
} |